Skip to content

Commit 55a7d0a

Browse files
sukvvondai-shi
andauthored
chore(eslint): migrate to flat config and simplify (#2912)
* chore(package.json): update related eslint library, update script for eslint.config.js * chore(pnpm-lock.yaml): reflect changes in package.json * chore(eslint): migrate eslint configuration .eslintrc.json to eslint.config.js * chore(examples/demo/package.json): update related eslint library, update script for eslint.config.js * chore(examples/demo/pnpm-lock.yaml): reflect changes in package.json * chore(examples/demo/eslint): migrate eslint configuration .eslintrc.cjs to eslint.config.js * style(examples/demo/utils/copy-to-clipboard.js): add global comment for eslint * chore(eslint): change file extension 'js' to 'mjs' * chore(package.json): consise 'lint' scripts * chore(examples/demo): remove eslint.config.js * chore(examples/demo/package.json): remove libraries associated wiht eslint, update lint script * chore(examples/demo/pnpm-lock.yaml): reflect changes in package.json * chore(examples/demo): reflect 'eslint . --fix' changes based on main 'eslint.config.mjs' * chore(examples/demo/package.json): add libraries associated wiht eslint, update lint script * chore(examples/demo/pnpm-lock.yaml): reflect changes in package.json * chore(examples/demo): add eslint.config.js * chore(package.json): add mjs in 'eslint', 'test:lint' script * Update eslint.config.mjs Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com> * Update examples/demo/eslint.config.js Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com> * chore(eslint): remove eslint configuration related to prettier * chore(package.json): remove eslint-{config,plugin}-prettier * chore(package.json): add tslib in devDependencies * chore(eslint): remove duplicate shared-node-browser from globals * chore(eslint): change 'eslint-import-resolver-alias' to 'eslint-import-resolver-typescript' * chore(eslint): add 'import/no-named-as-default-member' off * chore(eslint): remove duplicate rules, rearrange sequentially within a rule * chore(eslint): remove the ‘off’ settings in ‘eslint-plugin-import’ to ensure clearer usage. * chore(eslint): remove 'no-console' in rules * chore(eslint): simplify settings 'import/resolver' * chore(eslint): remove 'globals' config * chore(rollup): add 'eslint-disable no-undef' * chore(package.json): remove 'globals' library * chore(pnpm-lock.yaml): reflect changes in package.json * chore(eslint): add 'importPlugin.flatConfigs.recommended' * chore(eslint): remove duplicate 'languageOptions' * chore(eslint): remove 'import/extensions', 'import/parsers' to simplify * chore(eslint): add 'examples/**' in 'ignores' * chore(package.json): simplify 'lint' scripts --------- Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
1 parent ebf2b7a commit 55a7d0a

File tree

10 files changed

+1172
-1014
lines changed

10 files changed

+1172
-1014
lines changed

.eslintrc.json

Lines changed: 0 additions & 122 deletions
This file was deleted.

eslint.config.mjs

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import eslint from '@eslint/js'
2+
import vitest from '@vitest/eslint-plugin'
3+
import importPlugin from 'eslint-plugin-import'
4+
import jestDom from 'eslint-plugin-jest-dom'
5+
import react from 'eslint-plugin-react'
6+
import reactCompiler from 'eslint-plugin-react-compiler'
7+
import reactHooks from 'eslint-plugin-react-hooks'
8+
import testingLibrary from 'eslint-plugin-testing-library'
9+
import tseslint from 'typescript-eslint'
10+
11+
export default tseslint.config(
12+
{
13+
ignores: ['**/dist/', 'examples/**'],
14+
},
15+
eslint.configs.recommended,
16+
importPlugin.flatConfigs.recommended,
17+
tseslint.configs.recommended,
18+
react.configs.flat.recommended,
19+
react.configs.flat['jsx-runtime'],
20+
{
21+
plugins: {
22+
'react-compiler': reactCompiler,
23+
'react-hooks': reactHooks,
24+
},
25+
settings: {
26+
react: {
27+
version: 'detect',
28+
},
29+
'import/resolver': {
30+
typescript: true,
31+
},
32+
},
33+
rules: {
34+
eqeqeq: 'error',
35+
curly: ['warn', 'multi-line', 'consistent'],
36+
'sort-imports': [
37+
'error',
38+
{
39+
ignoreDeclarationSort: true,
40+
},
41+
],
42+
'import/no-unresolved': ['error', { commonjs: true, amd: true }],
43+
'import/named': 'off',
44+
'import/namespace': 'off',
45+
'import/no-named-as-default-member': 'off',
46+
'import/no-duplicates': 'error',
47+
'import/extensions': ['error', 'always'],
48+
'import/order': [
49+
'error',
50+
{
51+
alphabetize: { order: 'asc', caseInsensitive: true },
52+
groups: [
53+
'builtin',
54+
'external',
55+
'internal',
56+
'parent',
57+
'sibling',
58+
'index',
59+
'object',
60+
],
61+
'newlines-between': 'never',
62+
pathGroups: [
63+
{
64+
pattern: 'react',
65+
group: 'builtin',
66+
position: 'before',
67+
},
68+
],
69+
pathGroupsExcludedImportTypes: ['builtin'],
70+
},
71+
],
72+
'@typescript-eslint/no-unused-vars': [
73+
'warn',
74+
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
75+
],
76+
'@typescript-eslint/no-explicit-any': 'off',
77+
...reactHooks.configs.recommended.rules,
78+
'react-compiler/react-compiler': 'warn',
79+
},
80+
},
81+
{
82+
files: ['tests/**/*.{ts,tsx}'],
83+
...testingLibrary.configs['flat/react'],
84+
...jestDom.configs['flat/recommended'],
85+
...vitest.configs.recommended,
86+
rules: {
87+
'import/extensions': ['error', 'never'],
88+
'testing-library/no-node-access': 'off',
89+
'vitest/expect-expect': 'off',
90+
'vitest/consistent-test-it': [
91+
'error',
92+
{ fn: 'it', withinDescribe: 'it' },
93+
],
94+
'@typescript-eslint/no-unused-vars': 'off',
95+
},
96+
},
97+
{
98+
files: ['*.js'],
99+
rules: {
100+
'@typescript-eslint/no-require-imports': 'off',
101+
},
102+
},
103+
)

examples/demo/.eslintrc.cjs

Lines changed: 0 additions & 16 deletions
This file was deleted.

examples/demo/eslint.config.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import eslint from '@eslint/js'
2+
import react from 'eslint-plugin-react'
3+
import reactHooks from 'eslint-plugin-react-hooks'
4+
import reactRefresh from 'eslint-plugin-react-refresh'
5+
import globals from 'globals'
6+
7+
export default [
8+
{
9+
ignores: ['dist'],
10+
},
11+
eslint.configs.recommended,
12+
react.configs.flat.recommended,
13+
react.configs.flat['jsx-runtime'],
14+
{
15+
languageOptions: {
16+
globals: {
17+
...globals.browser,
18+
...globals.es2020,
19+
},
20+
parserOptions: {
21+
ecmaVersion: 'latest',
22+
sourceType: 'module',
23+
},
24+
},
25+
plugins: {
26+
'react-hooks': reactHooks,
27+
'react-refresh': reactRefresh,
28+
},
29+
settings: {
30+
react: {
31+
version: 'detect',
32+
},
33+
},
34+
rules: {
35+
...reactHooks.configs.recommended.rules,
36+
'react-refresh/only-export-components': [
37+
'warn',
38+
{ allowConstantExport: true },
39+
],
40+
'react/prop-types': 'off',
41+
'react/no-unknown-property': ['off'],
42+
},
43+
},
44+
]

examples/demo/package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"dev": "vite",
88
"build": "vite build",
9-
"lint": "eslint src --ext js,jsx --report-unused-disable-directives --max-warnings 0",
9+
"lint": "eslint .",
1010
"preview": "vite preview"
1111
},
1212
"prettier": {
@@ -29,13 +29,15 @@
2929
"zustand": "^4.3.9"
3030
},
3131
"devDependencies": {
32+
"@eslint/js": "^9.17.0",
3233
"@types/react": "^18.2.14",
3334
"@types/react-dom": "^18.2.6",
3435
"@vitejs/plugin-react-swc": "^3.3.2",
35-
"eslint": "^8.44.0",
36-
"eslint-plugin-react": "^7.32.2",
37-
"eslint-plugin-react-hooks": "^4.6.0",
38-
"eslint-plugin-react-refresh": "^0.4.1",
36+
"eslint": "^9.17.0",
37+
"eslint-plugin-react": "^7.37.2",
38+
"eslint-plugin-react-hooks": "^5.1.0",
39+
"eslint-plugin-react-refresh": "^0.4.16",
40+
"globals": "^15.14.0",
3941
"vite": "^4.4.0"
4042
}
4143
}

0 commit comments

Comments
 (0)