Skip to content

Commit

Permalink
Merge pull request #143 from hatena/improve-eslint-plugin-import-usage
Browse files Browse the repository at this point in the history
eslint-plugin-import の設定を更新
  • Loading branch information
susisu authored Oct 6, 2024
2 parents caf031b + 1d7200f commit 87391d4
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 12 deletions.
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
@@ -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({}, [
{
Expand Down
27 changes: 20 additions & 7 deletions lib/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function config(options, configs) {
const prettier = options?.prettier ?? true;

return tsEslint.config(
// # Linter 自体の設定
// # Linter やプラグインの設定
{
plugins: {
'@typescript-eslint': tsEslint.plugin,
Expand All @@ -51,6 +51,25 @@ function config(options, configs) {
// eslint-plugin-react-hooks v4.6.2時点ではESLint v9に対応していないため、互換性ユーティリティを通す。
'react-hooks': compat.fixupPluginRules(reactHooksPlugin),
},
settings: {
'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: {
alwaysTryTypes: true,
},
},
},
},
// # 言語ごとの構文や実行環境などの設定
{
Expand All @@ -59,9 +78,6 @@ function config(options, configs) {
ecmaVersion: 'latest',
parserOptions: react ? { ecmaFeatures: { jsx: true } } : {},
},
settings: {
react: { version: 'detect' },
},
},
{
files: ['**/*.{js,jsx,mjs}'],
Expand All @@ -87,9 +103,6 @@ function config(options, configs) {
tsconfigRootDir,
},
},
settings: {
...importPlugin.configs.typescript.settings,
},
},
// # ルール設定
{
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
89 changes: 85 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 87391d4

Please sign in to comment.