diff --git a/eslint.config.js b/eslint.config.js index 4955c48..73f4f28 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -8,13 +8,17 @@ import globals from "globals"; export default [ eslint.configs.recommended, { - files: ["**/*.ts", "**/*.vue"], + files: ["**/*.ts", "**/*.tsx", "**/*.vue"], languageOptions: { parser: vueParser, parserOptions: { parser: tsparser, ecmaVersion: "latest", sourceType: "module", + // build 用 tsconfig は demo の .tsx を含まないので、型情報ルール用に lint 専用の設定を使う + project: ["./tsconfig.eslint.json"], + tsconfigRootDir: import.meta.dirname, + extraFileExtensions: [".vue"], }, globals: { ...globals.browser, @@ -26,10 +30,22 @@ export default [ vue: vuePlugin, }, rules: { - ...tseslint.configs.recommended.rules, + ...tseslint.configs.strict.rules, + // as を止める consistent-type-assertions は stylistic にしか入っていない + ...tseslint.configs.stylistic.rules, ...vuePlugin.configs["flat/recommended"].rules, "vue/multi-word-component-names": "off", - "@typescript-eslint/no-explicit-any": "off", + // 未定義参照は TypeScript 自身が検出する。型のみの参照 (React.FormEvent 等) を誤検出する + "no-undef": "off", + "@typescript-eslint/no-explicit-any": "warn", + "@typescript-eslint/ban-ts-comment": "error", + "@typescript-eslint/no-non-null-assertion": "error", + "@typescript-eslint/consistent-type-assertions": ["warn", { assertionStyle: "never" }], + // 型情報を使うルール。parserOptions.project から型が供給される + "@typescript-eslint/no-floating-promises": "warn", + "@typescript-eslint/no-misused-promises": "error", + "@typescript-eslint/await-thenable": "warn", + "@typescript-eslint/no-base-to-string": "error", }, }, { diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json new file mode 100644 index 0000000..2d3f8e8 --- /dev/null +++ b/tsconfig.eslint.json @@ -0,0 +1,23 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "noEmit": true, + "emitDeclarationOnly": false, + "declaration": false, + "declarationDir": null, + "jsx": "react-jsx" + }, + "include": [ + "*.ts", + "src/**/*.ts", + "src/**/*.tsx", + "src/**/*.vue", + "demo/**/*.ts", + "demo/**/*.tsx", + "demo/**/*.vue" + ], + "exclude": [ + "node_modules", + "dist" + ] +} diff --git a/tsconfig.json b/tsconfig.json index 50d9fbe..c6efb75 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -15,6 +15,12 @@ "declarationDir": "./dist", "jsx": "preserve", "strict": true, + "useUnknownInCatchVariables": true, + "noImplicitOverride": true, + "noImplicitReturns": true, + "noUncheckedIndexedAccess": true, + "noPropertyAccessFromIndexSignature": true, + "exactOptionalPropertyTypes": true, "noUnusedLocals": true, "noUnusedParameters": true, "noFallthroughCasesInSwitch": true,