Skip to content

Commit 2ad78aa

Browse files
authored
fix(create-vite): fix eslint configuration for React templates (#13749)
1 parent 4eb3154 commit 2ad78aa

File tree

6 files changed

+42
-16
lines changed

6 files changed

+42
-16
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,18 @@
1-
/* eslint-env node */
2-
31
module.exports = {
42
root: true,
53
env: { browser: true, es2020: true },
64
extends: [
75
'eslint:recommended',
86
'plugin:@typescript-eslint/recommended',
9-
'plugin:@typescript-eslint/recommended-requiring-type-checking',
107
'plugin:react-hooks/recommended',
118
],
9+
ignorePatterns: ['dist', '.eslintrc.cjs'],
1210
parser: '@typescript-eslint/parser',
13-
parserOptions: {
14-
ecmaVersion: 'latest',
15-
sourceType: 'module',
16-
project: true,
17-
tsconfigRootDir: __dirname,
18-
},
1911
plugins: ['react-refresh'],
2012
rules: {
2113
'react-refresh/only-export-components': [
2214
'warn',
2315
{ allowConstantExport: true },
2416
],
25-
'@typescript-eslint/no-non-null-assertion': 'off',
2617
},
2718
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# React + TypeScript + Vite
2+
3+
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4+
5+
Currently, two official plugins are available:
6+
7+
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
8+
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
9+
10+
## Expanding the ESLint configuration
11+
12+
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:
13+
14+
- Configure the top-level `parserOptions` property like this:
15+
16+
```js
17+
parserOptions: {
18+
ecmaVersion: 'latest',
19+
sourceType: 'module',
20+
project: ['./tsconfig.json', './tsconfig.node.json'],
21+
tsconfigRootDir: __dirname,
22+
},
23+
```
24+
25+
- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
26+
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
27+
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list

packages/create-vite/template-react-ts/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"dev": "vite",
88
"build": "tsc && vite build",
9-
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
9+
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
1010
"preview": "vite preview"
1111
},
1212
"dependencies": {
@@ -16,8 +16,8 @@
1616
"devDependencies": {
1717
"@types/react": "^18.2.15",
1818
"@types/react-dom": "^18.2.7",
19-
"@typescript-eslint/eslint-plugin": "^5.62.0",
20-
"@typescript-eslint/parser": "^5.62.0",
19+
"@typescript-eslint/eslint-plugin": "^6.0.0",
20+
"@typescript-eslint/parser": "^6.0.0",
2121
"@vitejs/plugin-react": "^4.0.3",
2222
"eslint": "^8.45.0",
2323
"eslint-plugin-react-hooks": "^4.6.0",

packages/create-vite/template-react/.eslintrc.cjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
/* eslint-env node */
2-
31
module.exports = {
2+
root: true,
43
env: { browser: true, es2020: true },
54
extends: [
65
'eslint:recommended',
76
'plugin:react/recommended',
87
'plugin:react/jsx-runtime',
98
'plugin:react-hooks/recommended',
109
],
10+
ignorePatterns: ['dist', '.eslintrc.cjs'],
1111
parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
1212
settings: { react: { version: '18.2' } },
1313
plugins: ['react-refresh'],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# React + Vite
2+
3+
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4+
5+
Currently, two official plugins are available:
6+
7+
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
8+
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

packages/create-vite/template-react/package.json

+1-1
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 . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
1010
"preview": "vite preview"
1111
},
1212
"dependencies": {

0 commit comments

Comments
 (0)