From eb9fb0ef686dba40996cb1041c90ba95e8ae5b8c Mon Sep 17 00:00:00 2001 From: Shaoyu Meng Date: Sat, 11 Nov 2023 14:50:40 -0600 Subject: [PATCH 01/14] rebased for new eslint flat config --- .../template-react-ts/.eslintrc.cjs | 18 --------- .../template-react-ts/eslint.config.js | 31 ++++++++++++++++ .../template-react-ts/package.json | 6 ++- .../create-vite/template-react/.eslintrc.cjs | 21 ----------- .../template-react/eslint.config.js | 37 +++++++++++++++++++ .../create-vite/template-react/package.json | 12 +++--- 6 files changed, 79 insertions(+), 46 deletions(-) delete mode 100644 packages/create-vite/template-react-ts/.eslintrc.cjs create mode 100644 packages/create-vite/template-react-ts/eslint.config.js delete mode 100644 packages/create-vite/template-react/.eslintrc.cjs create mode 100644 packages/create-vite/template-react/eslint.config.js diff --git a/packages/create-vite/template-react-ts/.eslintrc.cjs b/packages/create-vite/template-react-ts/.eslintrc.cjs deleted file mode 100644 index d6c953795300e4..00000000000000 --- a/packages/create-vite/template-react-ts/.eslintrc.cjs +++ /dev/null @@ -1,18 +0,0 @@ -module.exports = { - root: true, - env: { browser: true, es2020: true }, - extends: [ - 'eslint:recommended', - 'plugin:@typescript-eslint/recommended', - 'plugin:react-hooks/recommended', - ], - ignorePatterns: ['dist', '.eslintrc.cjs'], - parser: '@typescript-eslint/parser', - plugins: ['react-refresh'], - rules: { - 'react-refresh/only-export-components': [ - 'warn', - { allowConstantExport: true }, - ], - }, -} diff --git a/packages/create-vite/template-react-ts/eslint.config.js b/packages/create-vite/template-react-ts/eslint.config.js new file mode 100644 index 00000000000000..4297b6695cff41 --- /dev/null +++ b/packages/create-vite/template-react-ts/eslint.config.js @@ -0,0 +1,31 @@ +import js from '@eslint/js'; +import globals from 'globals'; +import reactHooks from 'eslint-plugin-react-hooks'; +import reactRefresh from 'eslint-plugin-react-refresh'; +import tsParser from '@typescript-eslint/parser'; +import tsPlugin from '@typescript-eslint/eslint-plugin'; + +export default [ + { + files: ['**/*.{ts,tsx}'], + languageOptions: { + ecmaVersion: 2020, + globals: globals.browser, + parser: tsParser, + }, + plugins: { + 'react-hooks': reactHooks, + 'react-refresh': reactRefresh, + '@typescript-eslint': tsPlugin, + }, + rules: { + ...js.configs.recommended.rules, + ...tsPlugin.configs.recommended.rules, + ...reactHooks.configs.recommended.rules, + 'react-refresh/only-export-components': [ + 'warn', + { allowConstantExport: true }, + ], + }, + }, +]; diff --git a/packages/create-vite/template-react-ts/package.json b/packages/create-vite/template-react-ts/package.json index 9463c88eff00cb..f7e37aee546704 100644 --- a/packages/create-vite/template-react-ts/package.json +++ b/packages/create-vite/template-react-ts/package.json @@ -6,7 +6,7 @@ "scripts": { "dev": "vite", "build": "tsc -b && vite build", - "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", + "lint": "eslint . --report-unused-disable-directives --max-warnings 0", "preview": "vite preview" }, "dependencies": { @@ -14,14 +14,16 @@ "react-dom": "^18.3.1" }, "devDependencies": { + "@eslint/js": "^9.0.0", "@types/react": "^18.3.3", "@types/react-dom": "^18.3.0", "@typescript-eslint/eslint-plugin": "^7.13.1", "@typescript-eslint/parser": "^7.13.1", "@vitejs/plugin-react": "^4.3.1", - "eslint": "^8.57.0", + "eslint": "^9.0.0", "eslint-plugin-react-hooks": "^4.6.2", "eslint-plugin-react-refresh": "^0.4.7", + "globals": "^15.6.0", "typescript": "^5.2.2", "vite": "^5.3.1" } diff --git a/packages/create-vite/template-react/.eslintrc.cjs b/packages/create-vite/template-react/.eslintrc.cjs deleted file mode 100644 index 3e212e1d4307a3..00000000000000 --- a/packages/create-vite/template-react/.eslintrc.cjs +++ /dev/null @@ -1,21 +0,0 @@ -module.exports = { - root: true, - env: { browser: true, es2020: true }, - extends: [ - 'eslint:recommended', - 'plugin:react/recommended', - 'plugin:react/jsx-runtime', - 'plugin:react-hooks/recommended', - ], - ignorePatterns: ['dist', '.eslintrc.cjs'], - parserOptions: { ecmaVersion: 'latest', sourceType: 'module' }, - settings: { react: { version: '18.2' } }, - plugins: ['react-refresh'], - rules: { - 'react/jsx-no-target-blank': 'off', - 'react-refresh/only-export-components': [ - 'warn', - { allowConstantExport: true }, - ], - }, -} diff --git a/packages/create-vite/template-react/eslint.config.js b/packages/create-vite/template-react/eslint.config.js new file mode 100644 index 00000000000000..4844904113eb6c --- /dev/null +++ b/packages/create-vite/template-react/eslint.config.js @@ -0,0 +1,37 @@ +import js from '@eslint/js' +import globals from 'globals' +import react from 'eslint-plugin-react' +import reactHooks from 'eslint-plugin-react-hooks' +import reactRefresh from 'eslint-plugin-react-refresh' + +export default [ + { + files: ['**/*.{js,jsx}'], + languageOptions: { + ecmaVersion: 2020, + globals: globals.browser, + parserOptions: { + ecmaFeatures: { + jsx: true, + }, + }, + }, + plugins: { + react, + 'react-hooks': reactHooks, + 'react-refresh': reactRefresh, + }, + rules: { + ...js.configs.recommended.rules, + ...react.configs.recommended.rules, + ...react.configs['jsx-runtime'].rules, + ...reactHooks.configs.recommended.rules, + 'react/jsx-no-target-blank': 'off', + 'react-refresh/only-export-components': [ + 'warn', + { allowConstantExport: true }, + ], + }, + settings: { react: { version: '18.2' } }, + }, +] diff --git a/packages/create-vite/template-react/package.json b/packages/create-vite/template-react/package.json index 138cb218e58416..b84e5dbc5c0945 100644 --- a/packages/create-vite/template-react/package.json +++ b/packages/create-vite/template-react/package.json @@ -6,7 +6,7 @@ "scripts": { "dev": "vite", "build": "vite build", - "lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0", + "lint": "eslint . --report-unused-disable-directives --max-warnings 0", "preview": "vite preview" }, "dependencies": { @@ -14,13 +14,15 @@ "react-dom": "^18.3.1" }, "devDependencies": { + "@eslint/js": "^9.0.0", "@types/react": "^18.3.3", "@types/react-dom": "^18.3.0", "@vitejs/plugin-react": "^4.3.1", - "eslint": "^8.57.0", - "eslint-plugin-react": "^7.34.2", - "eslint-plugin-react-hooks": "^4.6.2", - "eslint-plugin-react-refresh": "^0.4.7", + "eslint": "^9.0.0", + "eslint-plugin-react": "^7.34.1", + "eslint-plugin-react-hooks": "^4.6.0", + "eslint-plugin-react-refresh": "^0.4.6", + "globals": "^15.0.0", "vite": "^5.3.1" } } From 63e44167fe3e31c240bec03d6c55dd081fc81159 Mon Sep 17 00:00:00 2001 From: Shaoyu Meng Date: Sat, 11 Nov 2023 15:28:51 -0600 Subject: [PATCH 02/14] add ignore patterns --- packages/create-vite/template-react-ts/eslint.config.js | 1 + packages/create-vite/template-react/eslint.config.js | 3 +++ packages/create-vite/template-react/src/App.jsx | 4 ++-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/create-vite/template-react-ts/eslint.config.js b/packages/create-vite/template-react-ts/eslint.config.js index 4297b6695cff41..30fbee84ef157d 100644 --- a/packages/create-vite/template-react-ts/eslint.config.js +++ b/packages/create-vite/template-react-ts/eslint.config.js @@ -8,6 +8,7 @@ import tsPlugin from '@typescript-eslint/eslint-plugin'; export default [ { files: ['**/*.{ts,tsx}'], + ignores: ['dist'], languageOptions: { ecmaVersion: 2020, globals: globals.browser, diff --git a/packages/create-vite/template-react/eslint.config.js b/packages/create-vite/template-react/eslint.config.js index 4844904113eb6c..0430a12b2a8efc 100644 --- a/packages/create-vite/template-react/eslint.config.js +++ b/packages/create-vite/template-react/eslint.config.js @@ -7,13 +7,16 @@ import reactRefresh from 'eslint-plugin-react-refresh' export default [ { files: ['**/*.{js,jsx}'], + ignores: ['dist', 'eslint.config.js'], languageOptions: { ecmaVersion: 2020, globals: globals.browser, parserOptions: { + ecmaVersion: 'latest', ecmaFeatures: { jsx: true, }, + sourceType: 'module', }, }, plugins: { diff --git a/packages/create-vite/template-react/src/App.jsx b/packages/create-vite/template-react/src/App.jsx index b8b8473a3696b4..b46dfcf85f4b59 100644 --- a/packages/create-vite/template-react/src/App.jsx +++ b/packages/create-vite/template-react/src/App.jsx @@ -9,10 +9,10 @@ function App() { return ( <>
- + Vite logo - + React logo
From 37e1a062d1ae5552aafa8104bfd62b121acedfc8 Mon Sep 17 00:00:00 2001 From: Shaoyu Meng Date: Sat, 11 Nov 2023 15:32:37 -0600 Subject: [PATCH 03/14] fix lint issue --- .../create-vite/template-react-ts/eslint.config.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/create-vite/template-react-ts/eslint.config.js b/packages/create-vite/template-react-ts/eslint.config.js index 30fbee84ef157d..b9a11c8e920206 100644 --- a/packages/create-vite/template-react-ts/eslint.config.js +++ b/packages/create-vite/template-react-ts/eslint.config.js @@ -1,9 +1,9 @@ -import js from '@eslint/js'; -import globals from 'globals'; -import reactHooks from 'eslint-plugin-react-hooks'; -import reactRefresh from 'eslint-plugin-react-refresh'; -import tsParser from '@typescript-eslint/parser'; -import tsPlugin from '@typescript-eslint/eslint-plugin'; +import js from '@eslint/js' +import globals from 'globals' +import reactHooks from 'eslint-plugin-react-hooks' +import reactRefresh from 'eslint-plugin-react-refresh' +import tsParser from '@typescript-eslint/parser' +import tsPlugin from '@typescript-eslint/eslint-plugin' export default [ { @@ -29,4 +29,4 @@ export default [ ], }, }, -]; +] From 6057fe5eea78959f35d36ec0214de7ffcce8436b Mon Sep 17 00:00:00 2001 From: smeng9 <38666763+smeng9@users.noreply.github.com> Date: Sat, 6 Apr 2024 11:23:49 +0800 Subject: [PATCH 04/14] ignore the config file itself --- packages/create-vite/template-react-ts/eslint.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/create-vite/template-react-ts/eslint.config.js b/packages/create-vite/template-react-ts/eslint.config.js index b9a11c8e920206..ece43af2281b48 100644 --- a/packages/create-vite/template-react-ts/eslint.config.js +++ b/packages/create-vite/template-react-ts/eslint.config.js @@ -8,7 +8,7 @@ import tsPlugin from '@typescript-eslint/eslint-plugin' export default [ { files: ['**/*.{ts,tsx}'], - ignores: ['dist'], + ignores: ['dist', 'eslint.config.js'], languageOptions: { ecmaVersion: 2020, globals: globals.browser, From c1bffdab7686c77495f345b7c434456d65b301c2 Mon Sep 17 00:00:00 2001 From: smeng9 <38666763+smeng9@users.noreply.github.com> Date: Sat, 6 Apr 2024 11:45:10 +0800 Subject: [PATCH 05/14] incorporate changes in #13750 --- packages/create-vite/template-react/src/App.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/create-vite/template-react/src/App.jsx b/packages/create-vite/template-react/src/App.jsx index b46dfcf85f4b59..b8b8473a3696b4 100644 --- a/packages/create-vite/template-react/src/App.jsx +++ b/packages/create-vite/template-react/src/App.jsx @@ -9,10 +9,10 @@ function App() { return ( <>
- + Vite logo - + React logo
From 297690f3a76e97cca219051d72f5e0492165ae1f Mon Sep 17 00:00:00 2001 From: shaoyu Date: Tue, 18 Jun 2024 19:53:42 +0800 Subject: [PATCH 06/14] add eslint compat layer --- .../create-vite/template-react-ts/eslint.config.js | 3 ++- packages/create-vite/template-react-ts/package.json | 7 ++++--- .../create-vite/template-react/eslint.config.js | 5 +++-- packages/create-vite/template-react/package.json | 13 +++++++------ 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/packages/create-vite/template-react-ts/eslint.config.js b/packages/create-vite/template-react-ts/eslint.config.js index ece43af2281b48..482cb31d650931 100644 --- a/packages/create-vite/template-react-ts/eslint.config.js +++ b/packages/create-vite/template-react-ts/eslint.config.js @@ -1,3 +1,4 @@ +import { fixupPluginRules } from "@eslint/compat"; import js from '@eslint/js' import globals from 'globals' import reactHooks from 'eslint-plugin-react-hooks' @@ -15,7 +16,7 @@ export default [ parser: tsParser, }, plugins: { - 'react-hooks': reactHooks, + 'react-hooks': fixupPluginRules(reactHooks), 'react-refresh': reactRefresh, '@typescript-eslint': tsPlugin, }, diff --git a/packages/create-vite/template-react-ts/package.json b/packages/create-vite/template-react-ts/package.json index f7e37aee546704..0971d2b2c41cb4 100644 --- a/packages/create-vite/template-react-ts/package.json +++ b/packages/create-vite/template-react-ts/package.json @@ -14,17 +14,18 @@ "react-dom": "^18.3.1" }, "devDependencies": { - "@eslint/js": "^9.0.0", + "@eslint/compat": "^1.1.0", + "@eslint/js": "^9.5.0", "@types/react": "^18.3.3", "@types/react-dom": "^18.3.0", "@typescript-eslint/eslint-plugin": "^7.13.1", "@typescript-eslint/parser": "^7.13.1", "@vitejs/plugin-react": "^4.3.1", - "eslint": "^9.0.0", + "eslint": "^9.5.0", "eslint-plugin-react-hooks": "^4.6.2", "eslint-plugin-react-refresh": "^0.4.7", "globals": "^15.6.0", - "typescript": "^5.2.2", + "typescript": "^5.4.5", "vite": "^5.3.1" } } diff --git a/packages/create-vite/template-react/eslint.config.js b/packages/create-vite/template-react/eslint.config.js index 0430a12b2a8efc..b413a4dbc6cc73 100644 --- a/packages/create-vite/template-react/eslint.config.js +++ b/packages/create-vite/template-react/eslint.config.js @@ -1,3 +1,4 @@ +import { fixupPluginRules } from "@eslint/compat"; import js from '@eslint/js' import globals from 'globals' import react from 'eslint-plugin-react' @@ -20,8 +21,8 @@ export default [ }, }, plugins: { - react, - 'react-hooks': reactHooks, + react: fixupPluginRules(react), + 'react-hooks': fixupPluginRules(reactHooks), 'react-refresh': reactRefresh, }, rules: { diff --git a/packages/create-vite/template-react/package.json b/packages/create-vite/template-react/package.json index b84e5dbc5c0945..638034bb8f8c09 100644 --- a/packages/create-vite/template-react/package.json +++ b/packages/create-vite/template-react/package.json @@ -14,15 +14,16 @@ "react-dom": "^18.3.1" }, "devDependencies": { - "@eslint/js": "^9.0.0", + "@eslint/compat": "^1.1.0", + "@eslint/js": "^9.5.0", "@types/react": "^18.3.3", "@types/react-dom": "^18.3.0", "@vitejs/plugin-react": "^4.3.1", - "eslint": "^9.0.0", - "eslint-plugin-react": "^7.34.1", - "eslint-plugin-react-hooks": "^4.6.0", - "eslint-plugin-react-refresh": "^0.4.6", - "globals": "^15.0.0", + "eslint": "^9.5.0", + "eslint-plugin-react": "^7.34.2", + "eslint-plugin-react-hooks": "^4.6.2", + "eslint-plugin-react-refresh": "^0.4.7", + "globals": "^15.6.0", "vite": "^5.3.1" } } From 2e43ed93a1bf3afaf03d41d983df5ca13df56b38 Mon Sep 17 00:00:00 2001 From: shaoyu Date: Tue, 18 Jun 2024 20:18:38 +0800 Subject: [PATCH 07/14] fix linter --- packages/create-vite/template-react-ts/eslint.config.js | 2 +- packages/create-vite/template-react/eslint.config.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/create-vite/template-react-ts/eslint.config.js b/packages/create-vite/template-react-ts/eslint.config.js index 482cb31d650931..75a1c7d13998c3 100644 --- a/packages/create-vite/template-react-ts/eslint.config.js +++ b/packages/create-vite/template-react-ts/eslint.config.js @@ -1,4 +1,4 @@ -import { fixupPluginRules } from "@eslint/compat"; +import { fixupPluginRules } from '@eslint/compat' import js from '@eslint/js' import globals from 'globals' import reactHooks from 'eslint-plugin-react-hooks' diff --git a/packages/create-vite/template-react/eslint.config.js b/packages/create-vite/template-react/eslint.config.js index b413a4dbc6cc73..367a562446a285 100644 --- a/packages/create-vite/template-react/eslint.config.js +++ b/packages/create-vite/template-react/eslint.config.js @@ -1,4 +1,4 @@ -import { fixupPluginRules } from "@eslint/compat"; +import { fixupPluginRules } from '@eslint/compat' import js from '@eslint/js' import globals from 'globals' import react from 'eslint-plugin-react' @@ -36,6 +36,6 @@ export default [ { allowConstantExport: true }, ], }, - settings: { react: { version: '18.2' } }, + settings: { react: { version: '18.3' } }, }, ] From a13e87b1231d301cb0b2f028ad262076577f8280 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnaud=20Barr=C3=A9?= Date: Wed, 19 Jun 2024 00:38:14 +0200 Subject: [PATCH 08/14] nits --- packages/create-vite/template-react-ts/eslint.config.js | 2 +- packages/create-vite/template-react-ts/package.json | 2 +- packages/create-vite/template-react/eslint.config.js | 8 +++----- packages/create-vite/template-react/package.json | 2 +- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/create-vite/template-react-ts/eslint.config.js b/packages/create-vite/template-react-ts/eslint.config.js index 75a1c7d13998c3..b35d29d7067c7b 100644 --- a/packages/create-vite/template-react-ts/eslint.config.js +++ b/packages/create-vite/template-react-ts/eslint.config.js @@ -9,7 +9,7 @@ import tsPlugin from '@typescript-eslint/eslint-plugin' export default [ { files: ['**/*.{ts,tsx}'], - ignores: ['dist', 'eslint.config.js'], + ignores: ['dist'], languageOptions: { ecmaVersion: 2020, globals: globals.browser, diff --git a/packages/create-vite/template-react-ts/package.json b/packages/create-vite/template-react-ts/package.json index 0971d2b2c41cb4..7d25c1a518909b 100644 --- a/packages/create-vite/template-react-ts/package.json +++ b/packages/create-vite/template-react-ts/package.json @@ -6,7 +6,7 @@ "scripts": { "dev": "vite", "build": "tsc -b && vite build", - "lint": "eslint . --report-unused-disable-directives --max-warnings 0", + "lint": "eslint . --max-warnings 0", "preview": "vite preview" }, "dependencies": { diff --git a/packages/create-vite/template-react/eslint.config.js b/packages/create-vite/template-react/eslint.config.js index 367a562446a285..9ede35a74b4cac 100644 --- a/packages/create-vite/template-react/eslint.config.js +++ b/packages/create-vite/template-react/eslint.config.js @@ -8,18 +8,17 @@ import reactRefresh from 'eslint-plugin-react-refresh' export default [ { files: ['**/*.{js,jsx}'], - ignores: ['dist', 'eslint.config.js'], + ignores: ['dist'], languageOptions: { ecmaVersion: 2020, globals: globals.browser, parserOptions: { ecmaVersion: 'latest', - ecmaFeatures: { - jsx: true, - }, + ecmaFeatures: { jsx: true }, sourceType: 'module', }, }, + settings: { react: { version: '18.3' } }, plugins: { react: fixupPluginRules(react), 'react-hooks': fixupPluginRules(reactHooks), @@ -36,6 +35,5 @@ export default [ { allowConstantExport: true }, ], }, - settings: { react: { version: '18.3' } }, }, ] diff --git a/packages/create-vite/template-react/package.json b/packages/create-vite/template-react/package.json index 638034bb8f8c09..07996ea9655559 100644 --- a/packages/create-vite/template-react/package.json +++ b/packages/create-vite/template-react/package.json @@ -6,7 +6,7 @@ "scripts": { "dev": "vite", "build": "vite build", - "lint": "eslint . --report-unused-disable-directives --max-warnings 0", + "lint": "eslint . --max-warnings 0", "preview": "vite preview" }, "dependencies": { From a5a5012857ba16762fdc1a72d04b253952a17a57 Mon Sep 17 00:00:00 2001 From: smeng9 <38666763+smeng9@users.noreply.github.com> Date: Wed, 19 Jun 2024 16:00:28 +0800 Subject: [PATCH 09/14] peer dependency override --- packages/create-vite/template-react-ts/package.json | 3 +++ packages/create-vite/template-react/package.json | 3 +++ 2 files changed, 6 insertions(+) diff --git a/packages/create-vite/template-react-ts/package.json b/packages/create-vite/template-react-ts/package.json index 7d25c1a518909b..3be9a95e0e14ef 100644 --- a/packages/create-vite/template-react-ts/package.json +++ b/packages/create-vite/template-react-ts/package.json @@ -27,5 +27,8 @@ "globals": "^15.6.0", "typescript": "^5.4.5", "vite": "^5.3.1" + }, + "overrides": { + "eslint": "$eslint" } } diff --git a/packages/create-vite/template-react/package.json b/packages/create-vite/template-react/package.json index 07996ea9655559..be80ff13f8f7bc 100644 --- a/packages/create-vite/template-react/package.json +++ b/packages/create-vite/template-react/package.json @@ -25,5 +25,8 @@ "eslint-plugin-react-refresh": "^0.4.7", "globals": "^15.6.0", "vite": "^5.3.1" + }, + "overrides": { + "eslint": "$eslint" } } From a69d7b4593bcbf229961ebf66ae789e8f89742e2 Mon Sep 17 00:00:00 2001 From: bluwy Date: Tue, 30 Jul 2024 14:18:42 +0800 Subject: [PATCH 10/14] chore: use canary --- packages/create-vite/template-react-ts/eslint.config.js | 3 +-- packages/create-vite/template-react-ts/package.json | 5 ++--- packages/create-vite/template-react/eslint.config.js | 5 ++--- packages/create-vite/template-react/package.json | 8 ++------ 4 files changed, 7 insertions(+), 14 deletions(-) diff --git a/packages/create-vite/template-react-ts/eslint.config.js b/packages/create-vite/template-react-ts/eslint.config.js index b35d29d7067c7b..b9a11c8e920206 100644 --- a/packages/create-vite/template-react-ts/eslint.config.js +++ b/packages/create-vite/template-react-ts/eslint.config.js @@ -1,4 +1,3 @@ -import { fixupPluginRules } from '@eslint/compat' import js from '@eslint/js' import globals from 'globals' import reactHooks from 'eslint-plugin-react-hooks' @@ -16,7 +15,7 @@ export default [ parser: tsParser, }, plugins: { - 'react-hooks': fixupPluginRules(reactHooks), + 'react-hooks': reactHooks, 'react-refresh': reactRefresh, '@typescript-eslint': tsPlugin, }, diff --git a/packages/create-vite/template-react-ts/package.json b/packages/create-vite/template-react-ts/package.json index 54b1dc87c52655..ac2a7a714314d7 100644 --- a/packages/create-vite/template-react-ts/package.json +++ b/packages/create-vite/template-react-ts/package.json @@ -6,7 +6,7 @@ "scripts": { "dev": "vite", "build": "tsc -b && vite build", - "lint": "eslint . --max-warnings 0", + "lint": "eslint .", "preview": "vite preview" }, "dependencies": { @@ -14,7 +14,6 @@ "react-dom": "^18.3.1" }, "devDependencies": { - "@eslint/compat": "^1.1.0", "@eslint/js": "^9.5.0", "@types/react": "^18.3.3", "@types/react-dom": "^18.3.0", @@ -22,7 +21,7 @@ "@typescript-eslint/parser": "^7.18.0", "@vitejs/plugin-react": "^4.3.1", "eslint": "^9.5.0", - "eslint-plugin-react-hooks": "^4.6.2", + "eslint-plugin-react-hooks": "^5.1.0-rc.0", "eslint-plugin-react-refresh": "^0.4.7", "globals": "^15.6.0", "typescript": "^5.5.3", diff --git a/packages/create-vite/template-react/eslint.config.js b/packages/create-vite/template-react/eslint.config.js index 9ede35a74b4cac..964a299ddfa52e 100644 --- a/packages/create-vite/template-react/eslint.config.js +++ b/packages/create-vite/template-react/eslint.config.js @@ -1,4 +1,3 @@ -import { fixupPluginRules } from '@eslint/compat' import js from '@eslint/js' import globals from 'globals' import react from 'eslint-plugin-react' @@ -20,8 +19,8 @@ export default [ }, settings: { react: { version: '18.3' } }, plugins: { - react: fixupPluginRules(react), - 'react-hooks': fixupPluginRules(reactHooks), + react, + 'react-hooks': reactHooks, 'react-refresh': reactRefresh, }, rules: { diff --git a/packages/create-vite/template-react/package.json b/packages/create-vite/template-react/package.json index 39adcd5129a518..86af249bde7b29 100644 --- a/packages/create-vite/template-react/package.json +++ b/packages/create-vite/template-react/package.json @@ -6,7 +6,7 @@ "scripts": { "dev": "vite", "build": "vite build", - "lint": "eslint . --max-warnings 0", + "lint": "eslint .", "preview": "vite preview" }, "dependencies": { @@ -14,19 +14,15 @@ "react-dom": "^18.3.1" }, "devDependencies": { - "@eslint/compat": "^1.1.0", "@eslint/js": "^9.5.0", "@types/react": "^18.3.3", "@types/react-dom": "^18.3.0", "@vitejs/plugin-react": "^4.3.1", "eslint": "^9.5.0", "eslint-plugin-react": "^7.35.0", - "eslint-plugin-react-hooks": "^4.6.2", + "eslint-plugin-react-hooks": "^5.1.0-rc.0", "eslint-plugin-react-refresh": "^0.4.9", "globals": "^15.6.0", "vite": "^5.3.5" - }, - "overrides": { - "eslint": "$eslint" } } From d6089bc74b22817dbded904965c04dc2cdea594f Mon Sep 17 00:00:00 2001 From: bluwy Date: Tue, 30 Jul 2024 14:38:59 +0800 Subject: [PATCH 11/14] docs: update readme [skip ci] --- .../create-vite/template-react-ts/README.md | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/packages/create-vite/template-react-ts/README.md b/packages/create-vite/template-react-ts/README.md index e1cdc89db11c9d..5482ff8469dd7d 100644 --- a/packages/create-vite/template-react-ts/README.md +++ b/packages/create-vite/template-react-ts/README.md @@ -25,6 +25,24 @@ export default { } ``` -- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked` -- Optionally add `plugin:@typescript-eslint/stylistic-type-checked` -- 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 +- Replace `tsPlugin.configs.recommended.rules` to `tsPlugin.configs['recommended-type-checked'].rules` or `tsPlugin.configs['strict-type-checked'].rules` +- Optionally add `tsPlugin.configs['stylistic-type-checked'].rules` +- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config: + +```js +// eslint.config.js +import react from 'eslint-plugin-react' + +export default { + // other rules... + plugins: { + // Add the react plugin + react, + }, + rules: { + // Enable its recommended rules + ...react.configs.recommended.rules, + ...react.configs['jsx-runtime'].rules, + }, +} +``` From da21981f61a6e1113857103242b30370e3793b6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnaud=20Barr=C3=A9?= Date: Tue, 30 Jul 2024 16:15:41 +0200 Subject: [PATCH 12/14] use tseslint --- .../template-react-ts/eslint.config.js | 49 +++++++++---------- .../template-react-ts/package.json | 3 +- 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/packages/create-vite/template-react-ts/eslint.config.js b/packages/create-vite/template-react-ts/eslint.config.js index b9a11c8e920206..760861802100bd 100644 --- a/packages/create-vite/template-react-ts/eslint.config.js +++ b/packages/create-vite/template-react-ts/eslint.config.js @@ -2,31 +2,28 @@ import js from '@eslint/js' import globals from 'globals' import reactHooks from 'eslint-plugin-react-hooks' import reactRefresh from 'eslint-plugin-react-refresh' -import tsParser from '@typescript-eslint/parser' -import tsPlugin from '@typescript-eslint/eslint-plugin' +import tseslint from 'typescript-eslint' -export default [ - { - files: ['**/*.{ts,tsx}'], - ignores: ['dist'], - languageOptions: { - ecmaVersion: 2020, - globals: globals.browser, - parser: tsParser, - }, - plugins: { - 'react-hooks': reactHooks, - 'react-refresh': reactRefresh, - '@typescript-eslint': tsPlugin, - }, - rules: { - ...js.configs.recommended.rules, - ...tsPlugin.configs.recommended.rules, - ...reactHooks.configs.recommended.rules, - 'react-refresh/only-export-components': [ - 'warn', - { allowConstantExport: true }, - ], - }, +export default tseslint.config({ + files: ['**/*.{ts,tsx}'], + ignores: ['dist'], + languageOptions: { + ecmaVersion: 2020, + globals: globals.browser, + parser: tseslint.parser, }, -] + plugins: { + 'react-hooks': reactHooks, + 'react-refresh': reactRefresh, + '@typescript-eslint': tseslint.plugin, + }, + rules: { + ...js.configs.recommended.rules, + ...tseslint.configs.recommended.rules, + ...reactHooks.configs.recommended.rules, + 'react-refresh/only-export-components': [ + 'warn', + { allowConstantExport: true }, + ], + }, +}) diff --git a/packages/create-vite/template-react-ts/package.json b/packages/create-vite/template-react-ts/package.json index ac2a7a714314d7..9c2913bf88f156 100644 --- a/packages/create-vite/template-react-ts/package.json +++ b/packages/create-vite/template-react-ts/package.json @@ -17,14 +17,13 @@ "@eslint/js": "^9.5.0", "@types/react": "^18.3.3", "@types/react-dom": "^18.3.0", - "@typescript-eslint/eslint-plugin": "^7.18.0", - "@typescript-eslint/parser": "^7.18.0", "@vitejs/plugin-react": "^4.3.1", "eslint": "^9.5.0", "eslint-plugin-react-hooks": "^5.1.0-rc.0", "eslint-plugin-react-refresh": "^0.4.7", "globals": "^15.6.0", "typescript": "^5.5.3", + "typescript-eslint": "^7.18.0", "vite": "^5.3.5" }, "overrides": { From b54b3f08aa09c0c0f63f8965db5e80a25dad1586 Mon Sep 17 00:00:00 2001 From: bluwy Date: Tue, 30 Jul 2024 23:12:36 +0800 Subject: [PATCH 13/14] docs: update readme [skip ci] --- packages/create-vite/template-react-ts/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/create-vite/template-react-ts/README.md b/packages/create-vite/template-react-ts/README.md index 5482ff8469dd7d..f1dfcbea03856a 100644 --- a/packages/create-vite/template-react-ts/README.md +++ b/packages/create-vite/template-react-ts/README.md @@ -25,8 +25,8 @@ export default { } ``` -- Replace `tsPlugin.configs.recommended.rules` to `tsPlugin.configs['recommended-type-checked'].rules` or `tsPlugin.configs['strict-type-checked'].rules` -- Optionally add `tsPlugin.configs['stylistic-type-checked'].rules` +- Replace `tseslint.configs.recommended.rules` to `tseslint.configs['recommended-type-checked'].rules` or `tseslint.configs['strict-type-checked'].rules` +- Optionally add `tseslint.configs['stylistic-type-checked'].rules` - Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config: ```js From 9f6a6897ca44fb7df1d290b82b8bb33722d1413a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnaud=20Barr=C3=A9?= Date: Tue, 30 Jul 2024 19:19:11 +0200 Subject: [PATCH 14/14] fix config & doc --- .../create-vite/template-react-ts/README.md | 28 ++++++++++--------- .../template-react-ts/eslint.config.js | 5 +--- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/packages/create-vite/template-react-ts/README.md b/packages/create-vite/template-react-ts/README.md index f1dfcbea03856a..74872fd4af60fb 100644 --- a/packages/create-vite/template-react-ts/README.md +++ b/packages/create-vite/template-react-ts/README.md @@ -14,35 +14,37 @@ If you are developing a production application, we recommend updating the config - Configure the top-level `parserOptions` property like this: ```js -export default { - // other rules... - parserOptions: { - ecmaVersion: 'latest', - sourceType: 'module', - project: ['./tsconfig.json', './tsconfig.node.json', './tsconfig.app.json'], - tsconfigRootDir: __dirname, +export default tseslint.config({ + languageOptions: { + // other options... + parserOptions: { + project: ['./tsconfig.node.json', './tsconfig.app.json'], + tsconfigRootDir: import.meta.dirname, + }, }, -} +}) ``` -- Replace `tseslint.configs.recommended.rules` to `tseslint.configs['recommended-type-checked'].rules` or `tseslint.configs['strict-type-checked'].rules` -- Optionally add `tseslint.configs['stylistic-type-checked'].rules` +- Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked` +- Optionally add `...tseslint.configs.stylisticTypeChecked` - Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config: ```js // eslint.config.js import react from 'eslint-plugin-react' -export default { - // other rules... +export default tseslint.config({ + // Set the react version + settings: { react: { version: '18.3' } }, plugins: { // Add the react plugin react, }, rules: { + // other rules... // Enable its recommended rules ...react.configs.recommended.rules, ...react.configs['jsx-runtime'].rules, }, -} +}) ``` diff --git a/packages/create-vite/template-react-ts/eslint.config.js b/packages/create-vite/template-react-ts/eslint.config.js index 760861802100bd..c4bc8f33c0b03e 100644 --- a/packages/create-vite/template-react-ts/eslint.config.js +++ b/packages/create-vite/template-react-ts/eslint.config.js @@ -5,21 +5,18 @@ import reactRefresh from 'eslint-plugin-react-refresh' import tseslint from 'typescript-eslint' export default tseslint.config({ + extends: [js.configs.recommended, ...tseslint.configs.recommended], files: ['**/*.{ts,tsx}'], ignores: ['dist'], languageOptions: { ecmaVersion: 2020, globals: globals.browser, - parser: tseslint.parser, }, plugins: { 'react-hooks': reactHooks, 'react-refresh': reactRefresh, - '@typescript-eslint': tseslint.plugin, }, rules: { - ...js.configs.recommended.rules, - ...tseslint.configs.recommended.rules, ...reactHooks.configs.recommended.rules, 'react-refresh/only-export-components': [ 'warn',