Skip to content

Commit 976103e

Browse files
authored
feat(create-vite): use more extends in eslint config (#20008)
1 parent 0387447 commit 976103e

File tree

3 files changed

+58
-56
lines changed

3 files changed

+58
-56
lines changed

packages/create-vite/template-react-ts/README.md

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,31 @@ Currently, two official plugins are available:
1212
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
1313

1414
```js
15-
export default tseslint.config({
16-
extends: [
17-
// Remove ...tseslint.configs.recommended and replace with this
18-
...tseslint.configs.recommendedTypeChecked,
19-
// Alternatively, use this for stricter rules
20-
...tseslint.configs.strictTypeChecked,
21-
// Optionally, add this for stylistic rules
22-
...tseslint.configs.stylisticTypeChecked,
23-
],
24-
languageOptions: {
25-
// other options...
26-
parserOptions: {
27-
project: ['./tsconfig.node.json', './tsconfig.app.json'],
28-
tsconfigRootDir: import.meta.dirname,
15+
export default tseslint.config([
16+
globalIgnores(['dist']),
17+
{
18+
files: ['**/*.{ts,tsx}'],
19+
extends: [
20+
// Other configs...
21+
22+
// Remove tseslint.configs.recommended and replace with this
23+
...tseslint.configs.recommendedTypeChecked,
24+
// Alternatively, use this for stricter rules
25+
...tseslint.configs.strictTypeChecked,
26+
// Optionally, add this for stylistic rules
27+
...tseslint.configs.stylisticTypeChecked,
28+
29+
// Other configs...
30+
],
31+
languageOptions: {
32+
parserOptions: {
33+
project: ['./tsconfig.node.json', './tsconfig.app.json'],
34+
tsconfigRootDir: import.meta.dirname,
35+
},
36+
// other options...
2937
},
3038
},
31-
})
39+
])
3240
```
3341

3442
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
@@ -38,20 +46,24 @@ You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-re
3846
import reactX from 'eslint-plugin-react-x'
3947
import reactDom from 'eslint-plugin-react-dom'
4048

41-
export default tseslint.config({
42-
extends: [
43-
// other configs...
44-
// Enable lint rules for React
45-
reactX.configs['recommended-typescript'],
46-
// Enable lint rules for React DOM
47-
reactDom.configs.recommended,
48-
],
49-
languageOptions: {
50-
// other options...
51-
parserOptions: {
52-
project: ['./tsconfig.node.json', './tsconfig.app.json'],
53-
tsconfigRootDir: import.meta.dirname,
49+
export default tseslint.config([
50+
globalIgnores(['dist']),
51+
{
52+
files: ['**/*.{ts,tsx}'],
53+
extends: [
54+
// Other configs...
55+
// Enable lint rules for React
56+
reactX.configs['recommended-typescript'],
57+
// Enable lint rules for React DOM
58+
reactDom.configs.recommended,
59+
],
60+
languageOptions: {
61+
parserOptions: {
62+
project: ['./tsconfig.node.json', './tsconfig.app.json'],
63+
tsconfigRootDir: import.meta.dirname,
64+
},
65+
// other options...
5466
},
5567
},
56-
})
68+
])
5769
```

packages/create-vite/template-react-ts/eslint.config.js

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,21 @@ import globals from 'globals'
33
import reactHooks from 'eslint-plugin-react-hooks'
44
import reactRefresh from 'eslint-plugin-react-refresh'
55
import tseslint from 'typescript-eslint'
6+
import { globalIgnores } from 'eslint/config'
67

7-
export default tseslint.config(
8-
{ ignores: ['dist'] },
8+
export default tseslint.config([
9+
globalIgnores(['dist']),
910
{
10-
extends: [js.configs.recommended, ...tseslint.configs.recommended],
1111
files: ['**/*.{ts,tsx}'],
12+
extends: [
13+
js.configs.recommended,
14+
tseslint.configs.recommended,
15+
reactHooks.configs['recommended-latest'],
16+
reactRefresh.configs.vite,
17+
],
1218
languageOptions: {
1319
ecmaVersion: 2020,
1420
globals: globals.browser,
1521
},
16-
plugins: {
17-
'react-hooks': reactHooks,
18-
'react-refresh': reactRefresh,
19-
},
20-
rules: {
21-
...reactHooks.configs.recommended.rules,
22-
'react-refresh/only-export-components': [
23-
'warn',
24-
{ allowConstantExport: true },
25-
],
26-
},
2722
},
28-
)
23+
])

packages/create-vite/template-react/eslint.config.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ import js from '@eslint/js'
22
import globals from 'globals'
33
import reactHooks from 'eslint-plugin-react-hooks'
44
import reactRefresh from 'eslint-plugin-react-refresh'
5-
import { defineConfig } from 'eslint/config'
5+
import { defineConfig, globalIgnores } from 'eslint/config'
66

77
export default defineConfig([
8-
{ ignores: ['dist'] },
8+
globalIgnores(['dist']),
99
{
1010
files: ['**/*.{js,jsx}'],
11-
extends: [js.configs.recommended],
11+
extends: [
12+
js.configs.recommended,
13+
reactHooks.configs['recommended-latest'],
14+
reactRefresh.configs.vite,
15+
],
1216
languageOptions: {
1317
ecmaVersion: 2020,
1418
globals: globals.browser,
@@ -18,17 +22,8 @@ export default defineConfig([
1822
sourceType: 'module',
1923
},
2024
},
21-
plugins: {
22-
'react-hooks': reactHooks,
23-
'react-refresh': reactRefresh,
24-
},
2525
rules: {
26-
...reactHooks.configs.recommended.rules,
2726
'no-unused-vars': ['error', { varsIgnorePattern: '^[A-Z_]' }],
28-
'react-refresh/only-export-components': [
29-
'warn',
30-
{ allowConstantExport: true },
31-
],
3227
},
3328
},
3429
])

0 commit comments

Comments
 (0)