From 85f22a4947224303bc1c8cb5e45381309ae28992 Mon Sep 17 00:00:00 2001 From: Michael Cousins Date: Thu, 25 Jan 2024 11:12:36 +1000 Subject: [PATCH 1/5] chore: incorporate prettier into precommit and CI --- .eslintrc.cjs | 25 +++++++++++++++++++++---- .husky/commit-msg | 4 ++++ .husky/pre-commit | 4 ++++ .prettierrc.yaml | 7 +++++++ package.json | 36 +++++++++++++++++++----------------- types/index.d.ts | 7 +++---- vite.config.js | 2 +- 7 files changed, 59 insertions(+), 26 deletions(-) create mode 100755 .husky/commit-msg create mode 100755 .husky/pre-commit diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 97b6929..5172dfc 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -3,19 +3,36 @@ module.exports = { env: { browser: true, es6: true, - 'vitest-globals/env': true + 'vitest-globals/env': true, }, - extends: ['standard', 'plugin:vitest-globals/recommended'], + extends: [ + 'standard', + 'plugin:vitest-globals/recommended', + 'plugin:svelte/recommended', + 'prettier', + ], plugins: ['svelte', 'simple-import-sort'], rules: { - 'max-len': ['warn', { code: 100 }], 'simple-import-sort/imports': 'error', - 'no-multiple-empty-lines': ['error', { max: 2, maxBOF: 2, maxEOF: 0 }], }, overrides: [ + { + files: ['*.ts'], + parser: '@typescript-eslint/parser', + extends: [ + 'plugin:@typescript-eslint/recommended', + 'plugin:@typescript-eslint/stylistic', + 'prettier', + ], + rules: { + '@typescript-eslint/no-explicit-any': 'off', + 'import/export': 'off', + }, + }, ], parserOptions: { ecmaVersion: 2022, sourceType: 'module', }, + ignorePatterns: ['!.*'], } diff --git a/.husky/commit-msg b/.husky/commit-msg new file mode 100755 index 0000000..1a089f4 --- /dev/null +++ b/.husky/commit-msg @@ -0,0 +1,4 @@ +#!/usr/bin/env sh +. "$(dirname -- "$0")/_/husky.sh" + +npx --no-install commitlint --edit $1 diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 0000000..cf0c46b --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,4 @@ +#!/usr/bin/env sh +. "$(dirname -- "$0")/_/husky.sh" + +npx --no-install lint-staged diff --git a/.prettierrc.yaml b/.prettierrc.yaml index 1d2127c..e1bf864 100644 --- a/.prettierrc.yaml +++ b/.prettierrc.yaml @@ -1,2 +1,9 @@ semi: false singleQuote: true +trailingComma: es5 +plugins: + - prettier-plugin-svelte +overrides: + - files: "*.svelte" + options: + parser: svelte diff --git a/package.json b/package.json index c1cdb30..dbd0af3 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,8 @@ ], "scripts": { "toc": "doctoc README.md", - "lint": "eslint src --fix", + "lint": "(prettier . --check || true) && eslint .", + "format": "prettier . --write && eslint . --fix", "test": "vitest run src", "test:watch": "npm run test -- --watch", "test:update": "npm run test -- --updateSnapshot --coverage", @@ -61,10 +62,13 @@ "@commitlint/config-conventional": "^17.6.6", "@sveltejs/vite-plugin-svelte": "^2.4.2", "@testing-library/jest-dom": "^5.16.5", + "@typescript-eslint/eslint-plugin": "^6.19.1", + "@typescript-eslint/parser": "^6.19.1", "@vitest/coverage-c8": "^0.33.0", "all-contributors-cli": "^6.26.0", "doctoc": "^2.2.1", "eslint": "^8.43.0", + "eslint-config-prettier": "^9.1.0", "eslint-config-standard": "^17.1.0", "eslint-plugin-import": "^2.27.5", "eslint-plugin-n": "^16.0.1", @@ -77,30 +81,28 @@ "lint-staged": "^13.2.3", "npm-run-all": "^4.1.5", "prettier": "^3.0.0", + "prettier-plugin-svelte": "^3.1.2", "svelte": "^4.0.1", + "svelte-jester": "^3.0.0", + "typescript": "^5.3.3", "vite": "^4.3.9", "vitest": "^0.33.0" }, - "husky": { - "hooks": { - "pre-commit": "lint-staged", - "commit-msg": "commitlint -E HUSKY_GIT_PARAMS" - } - }, "lint-staged": { - "README.md": [ + "{README.md,.all-contributorsrc}": [ "npm run toc", - "prettier --parser markdown --write", - "git add" - ], - ".all-contributorsrc": [ "npm run contributors:generate", - "git add" + "npx --no-install prettier --write README.md .all-contributorsrc", + "git add README.md .all-contributorsrc" + ], + "src/**/*": [ + "npx --no-install vitest run" + ], + "*.{js,cjs,ts,svelte,json,yml,yaml}": [ + "npx --no-install prettier --check" ], - "**/*.js": [ - "npm run lint", - "npm test", - "git add" + "*.{js,cjs,ts,svelte}": [ + "npx --no-install eslint" ] }, "commitlint": { diff --git a/types/index.d.ts b/types/index.d.ts index c1de78a..d45ae90 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -2,9 +2,8 @@ // Project: https://github.com/testing-library/svelte-testing-library // Definitions by: Rahim Alwer -import {queries, Queries, BoundFunction, EventType} from '@testing-library/dom' - -import { SvelteComponent, ComponentProps, ComponentConstructorOptions } from 'svelte' +import {BoundFunction, EventType,Queries, queries} from '@testing-library/dom' +import { ComponentConstructorOptions,ComponentProps, SvelteComponent } from 'svelte' export * from '@testing-library/dom' @@ -54,7 +53,7 @@ export function cleanup(): void export type FireFunction = (element: Document | Element | Window, event: Event) => Promise; export type FireObject = { - [K in EventType]: (element: Document | Element | Window, options?: {}) => Promise; + [K in EventType]: (element: Document | Element | Window, options?: Record) => Promise; }; export const fireEvent: FireFunction & FireObject; diff --git a/vite.config.js b/vite.config.js index 65a1618..a32b963 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,5 +1,5 @@ -import { defineConfig } from 'vite' import { svelte } from '@sveltejs/vite-plugin-svelte' +import { defineConfig } from 'vite' // https://vitejs.dev/config/ export default defineConfig({ From 71154affbd1f521077571b2feae04b05e4119c95 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Fri, 26 Jan 2024 14:46:03 -0500 Subject: [PATCH 2/5] Update .eslintrc.cjs Co-authored-by: Michael Cousins --- .eslintrc.cjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 5172dfc..d1caef7 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -34,5 +34,5 @@ module.exports = { ecmaVersion: 2022, sourceType: 'module', }, - ignorePatterns: ['!.*'], + ignorePatterns: ['!/.*'], } From e4718115ce65b0d6e490aaf22c5d861c2eeb5bb6 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Fri, 26 Jan 2024 14:46:21 -0500 Subject: [PATCH 3/5] Update package.json Co-authored-by: Michael Cousins --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dbd0af3..b842ef7 100644 --- a/package.json +++ b/package.json @@ -96,7 +96,7 @@ "git add README.md .all-contributorsrc" ], "src/**/*": [ - "npx --no-install vitest run" + "npx --no-install vitest related --run" ], "*.{js,cjs,ts,svelte,json,yml,yaml}": [ "npx --no-install prettier --check" From 3d046ebf581301f085a8617265abec8259bc4720 Mon Sep 17 00:00:00 2001 From: Michael Cousins Date: Sat, 27 Jan 2024 07:35:07 +1100 Subject: [PATCH 4/5] s/uknown/unknown/ --- types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/index.d.ts b/types/index.d.ts index d45ae90..905ce04 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -53,7 +53,7 @@ export function cleanup(): void export type FireFunction = (element: Document | Element | Window, event: Event) => Promise; export type FireObject = { - [K in EventType]: (element: Document | Element | Window, options?: Record) => Promise; + [K in EventType]: (element: Document | Element | Window, options?: Record) => Promise; }; export const fireEvent: FireFunction & FireObject; From 0314335b0782d015840dad61ea11d48c1ccac654 Mon Sep 17 00:00:00 2001 From: Michael Cousins Date: Sat, 27 Jan 2024 07:42:11 +1100 Subject: [PATCH 5/5] fixup: revert options type to match dom-testing-library --- .eslintrc.cjs | 4 ++++ types/index.d.ts | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index d1caef7..0bd04ba 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -25,6 +25,10 @@ module.exports = { 'prettier', ], rules: { + '@typescript-eslint/ban-types': [ + 'error', + { types: { '{}': false }, extendDefaults: true }, + ], '@typescript-eslint/no-explicit-any': 'off', 'import/export': 'off', }, diff --git a/types/index.d.ts b/types/index.d.ts index 905ce04..26d85d7 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -53,7 +53,7 @@ export function cleanup(): void export type FireFunction = (element: Document | Element | Window, event: Event) => Promise; export type FireObject = { - [K in EventType]: (element: Document | Element | Window, options?: Record) => Promise; + [K in EventType]: (element: Document | Element | Window, options?: {}) => Promise; }; export const fireEvent: FireFunction & FireObject;