From d84460a5fcc553d71ce1d4962d22ab53419d2b10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnaud=20Barr=C3=A9?= Date: Thu, 20 Apr 2023 09:56:12 +0200 Subject: [PATCH] feat(create-vite): add eslint to React templates (#12801) --- .eslintrc.cjs | 1 + .../create-vite/template-react-ts/.eslintrc.cjs | 14 ++++++++++++++ .../create-vite/template-react-ts/package.json | 6 ++++++ packages/create-vite/template-react/.eslintrc.cjs | 15 +++++++++++++++ packages/create-vite/template-react/package.json | 5 +++++ 5 files changed, 41 insertions(+) create mode 100644 packages/create-vite/template-react-ts/.eslintrc.cjs create mode 100644 packages/create-vite/template-react/.eslintrc.cjs diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 6f10675c2f33ce..3128e91c9df364 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -10,6 +10,7 @@ module.exports = defineConfig({ 'plugin:@typescript-eslint/recommended', 'plugin:regexp/recommended', ], + ignorePatterns: ['packages/create-vite/template-**'], plugins: ['import', 'regexp'], parser: '@typescript-eslint/parser', parserOptions: { diff --git a/packages/create-vite/template-react-ts/.eslintrc.cjs b/packages/create-vite/template-react-ts/.eslintrc.cjs new file mode 100644 index 00000000000000..4020bcbf409dd2 --- /dev/null +++ b/packages/create-vite/template-react-ts/.eslintrc.cjs @@ -0,0 +1,14 @@ +module.exports = { + env: { browser: true, es2020: true }, + extends: [ + 'eslint:recommended', + 'plugin:@typescript-eslint/recommended', + 'plugin:react-hooks/recommended', + ], + parser: '@typescript-eslint/parser', + parserOptions: { ecmaVersion: 'latest', sourceType: 'module' }, + plugins: ['react-refresh'], + rules: { + 'react-refresh/only-export-components': 'warn', + }, +} diff --git a/packages/create-vite/template-react-ts/package.json b/packages/create-vite/template-react-ts/package.json index 700ce50d85d129..5a2d6f9fd7e067 100644 --- a/packages/create-vite/template-react-ts/package.json +++ b/packages/create-vite/template-react-ts/package.json @@ -6,6 +6,7 @@ "scripts": { "dev": "vite", "build": "tsc && vite build", + "lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0", "preview": "vite preview" }, "dependencies": { @@ -15,7 +16,12 @@ "devDependencies": { "@types/react": "^18.0.28", "@types/react-dom": "^18.0.11", + "@typescript-eslint/eslint-plugin": "^5.57.1", + "@typescript-eslint/parser": "^5.57.1", "@vitejs/plugin-react": "^4.0.0-beta.0", + "eslint": "^8.38.0", + "eslint-plugin-react-hooks": "^4.6.0", + "eslint-plugin-react-refresh": "^0.3.4", "typescript": "^5.0.2", "vite": "^4.3.0-beta.2" } diff --git a/packages/create-vite/template-react/.eslintrc.cjs b/packages/create-vite/template-react/.eslintrc.cjs new file mode 100644 index 00000000000000..ec601b2ceaac71 --- /dev/null +++ b/packages/create-vite/template-react/.eslintrc.cjs @@ -0,0 +1,15 @@ +module.exports = { + env: { browser: true, es2020: true }, + extends: [ + 'eslint:recommended', + 'plugin:react/recommended', + 'plugin:react/jsx-runtime', + 'plugin:react-hooks/recommended', + ], + parserOptions: { ecmaVersion: 'latest', sourceType: 'module' }, + settings: { react: { version: '18.2' } }, + plugins: ['react-refresh'], + rules: { + 'react-refresh/only-export-components': 'warn', + }, +} diff --git a/packages/create-vite/template-react/package.json b/packages/create-vite/template-react/package.json index 08c96622385dd5..017eebb3b2ee69 100644 --- a/packages/create-vite/template-react/package.json +++ b/packages/create-vite/template-react/package.json @@ -6,6 +6,7 @@ "scripts": { "dev": "vite", "build": "vite build", + "lint": "eslint src --ext js,jsx --report-unused-disable-directives --max-warnings 0", "preview": "vite preview" }, "dependencies": { @@ -16,6 +17,10 @@ "@types/react": "^18.0.28", "@types/react-dom": "^18.0.11", "@vitejs/plugin-react": "^4.0.0-beta.0", + "eslint": "^8.38.0", + "eslint-plugin-react": "^7.32.2", + "eslint-plugin-react-hooks": "^4.6.0", + "eslint-plugin-react-refresh": "^0.3.4", "vite": "^4.3.0-beta.2" } }