From 045b992ea585efc636c65a5f6ea820904efd8645 Mon Sep 17 00:00:00 2001 From: Susisu Date: Sun, 6 Oct 2024 20:45:49 +0900 Subject: [PATCH 1/6] install eslint-import-resolver-typescript --- package.json | 1 + pnpm-lock.yaml | 89 +++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 86 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index c69025d..eec882f 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ "@typescript-eslint/eslint-plugin": "^8.8.0", "@typescript-eslint/parser": "^8.8.0", "eslint-config-prettier": "^9.1.0", + "eslint-import-resolver-typescript": "^3.6.3", "eslint-plugin-import": "^2.31.0", "eslint-plugin-react": "^7.37.1", "eslint-plugin-react-hooks": "^4.6.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1e3f960..e0dba7d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -26,9 +26,12 @@ importers: eslint-config-prettier: specifier: ^9.1.0 version: 9.1.0(eslint@9.12.0) + eslint-import-resolver-typescript: + specifier: ^3.6.3 + version: 3.6.3(@typescript-eslint/parser@8.8.0(eslint@9.12.0)(typescript@5.6.2))(eslint-plugin-import@2.31.0)(eslint@9.12.0) eslint-plugin-import: specifier: ^2.31.0 - version: 2.31.0(@typescript-eslint/parser@8.8.0(eslint@9.12.0)(typescript@5.6.2))(eslint@9.12.0) + version: 2.31.0(@typescript-eslint/parser@8.8.0(eslint@9.12.0)(typescript@5.6.2))(eslint-import-resolver-typescript@3.6.3)(eslint@9.12.0) eslint-plugin-react: specifier: ^7.37.1 version: 7.37.1(eslint@9.12.0) @@ -152,6 +155,10 @@ packages: resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==} engines: {node: '>= 8'} + '@nolyfill/is-core-module@1.0.39': + resolution: {integrity: sha512-nn5ozdjYQpUCZlWGuxcJY/KpxkWQs4DcbMCmKojjyrYDEAGy4Ce19NN4v5MduafTwJlbKc99UA8YhSVqq9yPZA==} + engines: {node: '>=12.4.0'} + '@rtsao/scc@1.1.0': resolution: {integrity: sha512-zt6OdqaDoOnJ1ZYsCYGt9YmWzDXl4vQdKTyJev62gFhRGKdx7mcT54V9KIjg+d2wi9EXsPvAPKe7i7WjfVWB8g==} @@ -385,6 +392,10 @@ packages: resolution: {integrity: sha512-35mSku4ZXK0vfCuHEDAwt55dg2jNajHZ1odvF+8SSr82EsZY4QmXfuWso8oEd8zRhVObSN18aM0CjSdoBX7zIw==} engines: {node: '>=0.10.0'} + enhanced-resolve@5.17.1: + resolution: {integrity: sha512-LMHl3dXhTcfv8gM4kEzIUeTQ+7fpdA0l2tUf34BddXPkz2A5xJ5L/Pchd5BL6rdccM9QGvu0sWZzK1Z1t4wwyg==} + engines: {node: '>=10.13.0'} + es-abstract@1.23.3: resolution: {integrity: sha512-e+HfNH61Bj1X9/jLc5v1owaLYuHdeHHSQlkhCBiTK8rBvKaULl/beGMxwrMXjpYrv4pz22BlY570vVePA2ho4A==} engines: {node: '>= 0.4'} @@ -429,6 +440,19 @@ packages: eslint-import-resolver-node@0.3.9: resolution: {integrity: sha512-WFj2isz22JahUv+B788TlO3N6zL3nNJGU8CcZbPZvVEkBPaJdCV4vy5wyghty5ROFbCRnm132v8BScu5/1BQ8g==} + eslint-import-resolver-typescript@3.6.3: + resolution: {integrity: sha512-ud9aw4szY9cCT1EWWdGv1L1XR6hh2PaRWif0j2QjQ0pgTY/69iw+W0Z4qZv5wHahOl8isEr+k/JnyAqNQkLkIA==} + engines: {node: ^14.18.0 || >=16.0.0} + peerDependencies: + eslint: '*' + eslint-plugin-import: '*' + eslint-plugin-import-x: '*' + peerDependenciesMeta: + eslint-plugin-import: + optional: true + eslint-plugin-import-x: + optional: true + eslint-module-utils@2.12.0: resolution: {integrity: sha512-wALZ0HFoytlyh/1+4wuZ9FJCD/leWHQzzrxJ8+rebyReSLk7LApMyd3WJaLVoN+D5+WIdJyDK1c6JnE65V4Zyg==} engines: {node: '>=4'} @@ -570,6 +594,9 @@ packages: resolution: {integrity: sha512-g0QYk1dZBxGwk+Ngc+ltRH2IBp2f7zBkBMBJZCDerh6EhlhSR6+9irMCuT/09zD6qkarHUSn529sK/yL4S27mg==} engines: {node: '>= 0.4'} + get-tsconfig@4.8.1: + resolution: {integrity: sha512-k9PN+cFBmaLWtVz29SkUoqU5O0slLuHJXt/2P+tMVFT+phsSGXGkp9t3rQIqdz0e+06EHNGs3oM6ZX1s2zHxRg==} + glob-parent@5.1.2: resolution: {integrity: sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==} engines: {node: '>= 6'} @@ -593,6 +620,9 @@ packages: gopd@1.0.1: resolution: {integrity: sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==} + graceful-fs@4.2.11: + resolution: {integrity: sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==} + graphemer@1.4.0: resolution: {integrity: sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==} @@ -653,6 +683,9 @@ packages: resolution: {integrity: sha512-gDYaKHJmnj4aWxyj6YHyXVpdQawtVLHU5cb+eztPGczf6cjuTdwve5ZIEfgXqH4e57An1D1AKf8CZ3kYrQRqYA==} engines: {node: '>= 0.4'} + is-bun-module@1.2.1: + resolution: {integrity: sha512-AmidtEM6D6NmUiLOvvU7+IePxjEjOzra2h0pSrsfSAcXwl/83zLLXDByafUJy9k/rKK0pvXMLdwKwGHlX2Ke6Q==} + is-callable@1.2.7: resolution: {integrity: sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA==} engines: {node: '>= 0.4'} @@ -941,6 +974,9 @@ packages: resolution: {integrity: sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==} engines: {node: '>=4'} + resolve-pkg-maps@1.0.0: + resolution: {integrity: sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==} + resolve@1.22.8: resolution: {integrity: sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw==} hasBin: true @@ -1030,6 +1066,10 @@ packages: resolution: {integrity: sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==} engines: {node: '>= 0.4'} + tapable@2.2.1: + resolution: {integrity: sha512-GNzQvQTOIP6RyTfE2Qxb8ZVlNmw0n88vp1szwWRimP02mnTsx3Wtn5qRdqY9w2XduFNUgvOwhNnQsjwCp+kqaQ==} + engines: {node: '>=6'} + text-table@0.2.0: resolution: {integrity: sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==} @@ -1189,6 +1229,8 @@ snapshots: '@nodelib/fs.scandir': 2.1.5 fastq: 1.17.1 + '@nolyfill/is-core-module@1.0.39': {} + '@rtsao/scc@1.1.0': {} '@types/eslint-config-prettier@6.11.3': {} @@ -1480,6 +1522,11 @@ snapshots: dependencies: esutils: 2.0.3 + enhanced-resolve@5.17.1: + dependencies: + graceful-fs: 4.2.11 + tapable: 2.2.1 + es-abstract@1.23.3: dependencies: array-buffer-byte-length: 1.0.1 @@ -1586,17 +1633,37 @@ snapshots: transitivePeerDependencies: - supports-color - eslint-module-utils@2.12.0(@typescript-eslint/parser@8.8.0(eslint@9.12.0)(typescript@5.6.2))(eslint-import-resolver-node@0.3.9)(eslint@9.12.0): + eslint-import-resolver-typescript@3.6.3(@typescript-eslint/parser@8.8.0(eslint@9.12.0)(typescript@5.6.2))(eslint-plugin-import@2.31.0)(eslint@9.12.0): + dependencies: + '@nolyfill/is-core-module': 1.0.39 + debug: 4.3.7 + enhanced-resolve: 5.17.1 + eslint: 9.12.0 + eslint-module-utils: 2.12.0(@typescript-eslint/parser@8.8.0(eslint@9.12.0)(typescript@5.6.2))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3(@typescript-eslint/parser@8.8.0(eslint@9.12.0)(typescript@5.6.2))(eslint-plugin-import@2.31.0)(eslint@9.12.0))(eslint@9.12.0) + fast-glob: 3.3.2 + get-tsconfig: 4.8.1 + is-bun-module: 1.2.1 + is-glob: 4.0.3 + optionalDependencies: + eslint-plugin-import: 2.31.0(@typescript-eslint/parser@8.8.0(eslint@9.12.0)(typescript@5.6.2))(eslint-import-resolver-typescript@3.6.3)(eslint@9.12.0) + transitivePeerDependencies: + - '@typescript-eslint/parser' + - eslint-import-resolver-node + - eslint-import-resolver-webpack + - supports-color + + eslint-module-utils@2.12.0(@typescript-eslint/parser@8.8.0(eslint@9.12.0)(typescript@5.6.2))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3(@typescript-eslint/parser@8.8.0(eslint@9.12.0)(typescript@5.6.2))(eslint-plugin-import@2.31.0)(eslint@9.12.0))(eslint@9.12.0): dependencies: debug: 3.2.7 optionalDependencies: '@typescript-eslint/parser': 8.8.0(eslint@9.12.0)(typescript@5.6.2) eslint: 9.12.0 eslint-import-resolver-node: 0.3.9 + eslint-import-resolver-typescript: 3.6.3(@typescript-eslint/parser@8.8.0(eslint@9.12.0)(typescript@5.6.2))(eslint-plugin-import@2.31.0)(eslint@9.12.0) transitivePeerDependencies: - supports-color - eslint-plugin-import@2.31.0(@typescript-eslint/parser@8.8.0(eslint@9.12.0)(typescript@5.6.2))(eslint@9.12.0): + eslint-plugin-import@2.31.0(@typescript-eslint/parser@8.8.0(eslint@9.12.0)(typescript@5.6.2))(eslint-import-resolver-typescript@3.6.3)(eslint@9.12.0): dependencies: '@rtsao/scc': 1.1.0 array-includes: 3.1.8 @@ -1607,7 +1674,7 @@ snapshots: doctrine: 2.1.0 eslint: 9.12.0 eslint-import-resolver-node: 0.3.9 - eslint-module-utils: 2.12.0(@typescript-eslint/parser@8.8.0(eslint@9.12.0)(typescript@5.6.2))(eslint-import-resolver-node@0.3.9)(eslint@9.12.0) + eslint-module-utils: 2.12.0(@typescript-eslint/parser@8.8.0(eslint@9.12.0)(typescript@5.6.2))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3(@typescript-eslint/parser@8.8.0(eslint@9.12.0)(typescript@5.6.2))(eslint-plugin-import@2.31.0)(eslint@9.12.0))(eslint@9.12.0) hasown: 2.0.2 is-core-module: 2.15.1 is-glob: 4.0.3 @@ -1785,6 +1852,10 @@ snapshots: es-errors: 1.3.0 get-intrinsic: 1.2.4 + get-tsconfig@4.8.1: + dependencies: + resolve-pkg-maps: 1.0.0 + glob-parent@5.1.2: dependencies: is-glob: 4.0.3 @@ -1806,6 +1877,8 @@ snapshots: dependencies: get-intrinsic: 1.2.4 + graceful-fs@4.2.11: {} + graphemer@1.4.0: {} has-bigints@1.0.2: {} @@ -1861,6 +1934,10 @@ snapshots: call-bind: 1.0.7 has-tostringtag: 1.0.2 + is-bun-module@1.2.1: + dependencies: + semver: 7.6.3 + is-callable@1.2.7: {} is-core-module@2.15.1: @@ -2139,6 +2216,8 @@ snapshots: resolve-from@4.0.0: {} + resolve-pkg-maps@1.0.0: {} + resolve@1.22.8: dependencies: is-core-module: 2.15.1 @@ -2254,6 +2333,8 @@ snapshots: supports-preserve-symlinks-flag@1.0.0: {} + tapable@2.2.1: {} + text-table@0.2.0: {} to-regex-range@5.0.1: From 8b4a950adb06ae283be40082ccb2f00566b8c295 Mon Sep 17 00:00:00 2001 From: Susisu Date: Sun, 6 Oct 2024 20:58:56 +0900 Subject: [PATCH 2/6] =?UTF-8?q?import=20=E3=81=AE=E8=A8=AD=E5=AE=9A?= =?UTF-8?q?=E7=AE=87=E6=89=80=E3=82=92=E7=A7=BB=E5=8B=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/config/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/config/index.js b/lib/config/index.js index 1900b03..423c8c3 100644 --- a/lib/config/index.js +++ b/lib/config/index.js @@ -60,7 +60,10 @@ function config(options, configs) { parserOptions: react ? { ecmaFeatures: { jsx: true } } : {}, }, settings: { - react: { version: 'detect' }, + ...importPlugin.configs.typescript.settings, + react: { + version: 'detect', + }, }, }, { @@ -87,9 +90,6 @@ function config(options, configs) { tsconfigRootDir, }, }, - settings: { - ...importPlugin.configs.typescript.settings, - }, }, // # ルール設定 { From 36c4f23e879d852ba7f60be2605d950d9afdf471 Mon Sep 17 00:00:00 2001 From: Susisu Date: Sun, 6 Oct 2024 20:59:41 +0900 Subject: [PATCH 3/6] =?UTF-8?q?import/typescript=20=E3=82=92=E5=8F=96?= =?UTF-8?q?=E3=82=8A=E8=BE=BC=E3=81=BF=E3=81=A4=E3=81=A4=20typescript=20re?= =?UTF-8?q?solver=20=E3=82=92=E6=9C=89=E5=8A=B9=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/config/index.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/config/index.js b/lib/config/index.js index 423c8c3..4581818 100644 --- a/lib/config/index.js +++ b/lib/config/index.js @@ -60,10 +60,21 @@ function config(options, configs) { parserOptions: react ? { ecmaFeatures: { jsx: true } } : {}, }, settings: { - ...importPlugin.configs.typescript.settings, - react: { + 'react': { version: 'detect', }, + // 参考: https://github.com/import-js/eslint-plugin-import/blob/main/config/typescript.js + 'import/extensions': ['.js', '.jsx', '.cjs', '.mjs', '.ts', '.tsx', '.cts', '.mts'], + 'import/external-module-folders': ['node_modules', 'node_modules/@types'], + 'import/parsers': { + '@typescript-eslint/parser': ['.ts', '.tsx', '.cts', '.mts'], + }, + 'import/resolver': { + node: { + extensions: ['.js', '.jsx', '.cjs', '.mjs', '.ts', '.tsx', '.cts', '.mts'], + }, + typescript: true, + }, }, }, { From 419d7c873e127fa47526d8e2eecc5eaa17f114bf Mon Sep 17 00:00:00 2001 From: Susisu Date: Sun, 6 Oct 2024 21:00:11 +0900 Subject: [PATCH 4/6] =?UTF-8?q?alwaysTryTypes=20=E3=82=92=E6=9C=89?= =?UTF-8?q?=E5=8A=B9=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit eslint-config-next に倣う --- lib/config/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/config/index.js b/lib/config/index.js index 4581818..9245ed2 100644 --- a/lib/config/index.js +++ b/lib/config/index.js @@ -73,7 +73,9 @@ function config(options, configs) { node: { extensions: ['.js', '.jsx', '.cjs', '.mjs', '.ts', '.tsx', '.cts', '.mts'], }, - typescript: true, + typescript: { + alwaysTryTypes: true, + }, }, }, }, From 934b6a513508d9293a50d6b49f2789dd8ad4b1cc Mon Sep 17 00:00:00 2001 From: Susisu Date: Sun, 6 Oct 2024 21:01:52 +0900 Subject: [PATCH 5/6] =?UTF-8?q?settings=20=E3=81=AE=E8=A8=98=E8=BF=B0?= =?UTF-8?q?=E3=82=92=20Linter=20=E3=82=84=E3=83=97=E3=83=A9=E3=82=B0?= =?UTF-8?q?=E3=82=A4=E3=83=B3=E3=81=AE=E8=A8=AD=E5=AE=9A=E3=81=AB=E7=A7=BB?= =?UTF-8?q?=E5=8B=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/config/index.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/config/index.js b/lib/config/index.js index 9245ed2..f61cefb 100644 --- a/lib/config/index.js +++ b/lib/config/index.js @@ -42,7 +42,7 @@ function config(options, configs) { const prettier = options?.prettier ?? true; return tsEslint.config( - // # Linter 自体の設定 + // # Linter やプラグインの設定 { plugins: { '@typescript-eslint': tsEslint.plugin, @@ -51,14 +51,6 @@ function config(options, configs) { // eslint-plugin-react-hooks v4.6.2時点ではESLint v9に対応していないため、互換性ユーティリティを通す。 'react-hooks': compat.fixupPluginRules(reactHooksPlugin), }, - }, - // # 言語ごとの構文や実行環境などの設定 - { - files: ['**/*.{js,jsx,cjs,mjs}', '**/*.{ts,tsx,cts,mts}'], - languageOptions: { - ecmaVersion: 'latest', - parserOptions: react ? { ecmaFeatures: { jsx: true } } : {}, - }, settings: { 'react': { version: 'detect', @@ -79,6 +71,14 @@ function config(options, configs) { }, }, }, + // # 言語ごとの構文や実行環境などの設定 + { + files: ['**/*.{js,jsx,cjs,mjs}', '**/*.{ts,tsx,cts,mts}'], + languageOptions: { + ecmaVersion: 'latest', + parserOptions: react ? { ecmaFeatures: { jsx: true } } : {}, + }, + }, { files: ['**/*.{js,jsx,mjs}'], languageOptions: { From 1d7200fd1b660192e518fb92d42ac7e975c6dfc0 Mon Sep 17 00:00:00 2001 From: Susisu Date: Sun, 6 Oct 2024 21:02:58 +0900 Subject: [PATCH 6/6] lint fix --- eslint.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eslint.config.js b/eslint.config.js index 1eda273..82301c4 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,7 +1,7 @@ 'use strict'; -const { config } = require('@hatena/eslint-config-hatena/flat'); const globals = require('globals'); +const { config } = require('@hatena/eslint-config-hatena/flat'); module.exports = config({}, [ {