From 694a2a24608733c52acd32ce699da74de02b2925 Mon Sep 17 00:00:00 2001 From: Giuseppe Bandiera <giuseppe.bandiera@live.com> Date: Mon, 11 Nov 2019 11:22:56 +0100 Subject: [PATCH 1/4] Add flag DISABLE_ESLINT_DEV to disable eslint on dev server --- docusaurus/docs/advanced-configuration.md | 1 + .../react-scripts/config/webpack.config.js | 55 ++++++++++++------- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/docusaurus/docs/advanced-configuration.md b/docusaurus/docs/advanced-configuration.md index 958f9ac31..88da32b8a 100644 --- a/docusaurus/docs/advanced-configuration.md +++ b/docusaurus/docs/advanced-configuration.md @@ -27,3 +27,4 @@ You can adjust various development and production settings by setting environmen | EXTEND_ESLINT | ✅ Used | ✅ Used | When set to `true`, user provided ESLint configs will be used by `eslint-loader`. Note that any rules set to `"error"` will stop the application from building. | | FAST_REFRESH | ✅ Used | 🚫 Ignored | When set to `true`, enables experimental support for fast refresh to allow you to tweak your components in real time without reloading the page. | | TSC_COMPILE_ON_ERROR | ✅ Used | ✅ Used | When set to `true`, you can run and properly build TypeScript projects even if there are TypeScript type check errors. These errors are printed as warnings in the terminal and/or browser console. | +| DISABLE_ESLINT_DEV | ✅ Used | 🚫 Ignored | If set to `true`, ESLint will be disabled when compiling the code for running the development server. Useful to allow developers to use non-production-ready code while still developing a feature or inspecting an issue. ESLint will still run on production builds to detect possible problems. | diff --git a/packages/react-scripts/config/webpack.config.js b/packages/react-scripts/config/webpack.config.js index 2c32b66ac..0574d3018 100644 --- a/packages/react-scripts/config/webpack.config.js +++ b/packages/react-scripts/config/webpack.config.js @@ -354,26 +354,43 @@ module.exports = function (webpackEnv) { { test: /\.(js|mjs|jsx|ts|tsx)$/, enforce: 'pre', - use: [ - { - options: { - cache: true, - formatter: require.resolve('react-dev-utils/eslintFormatter'), - eslintPath: require.resolve('eslint'), - resolvePluginsRelativeTo: __dirname, - // @remove-on-eject-begin - ignore: isExtendingEslintConfig, - baseConfig: isExtendingEslintConfig - ? undefined - : { - extends: [require.resolve('eslint-config-react-app')], - }, - useEslintrc: isExtendingEslintConfig, - // @remove-on-eject-end + use: isEnvDevelopment && process.env.DISABLE_ESLINT_DEV === 'true' + ? undefined + : [ + { + options: { + cache: true, + formatter: require.resolve('react-dev-utils/eslintFormatter'), + eslintPath: require.resolve('eslint'), + resolvePluginsRelativeTo: __dirname, + // @remove-on-eject-begin + ignore: process.env.EXTEND_ESLINT === 'true', + baseConfig: (() => { + // We allow overriding the config only if the env variable is set + if (process.env.EXTEND_ESLINT === 'true') { + const eslintCli = new eslint.CLIEngine(); + let eslintConfig; + try { + eslintConfig = eslintCli.getConfigForFile( + paths.appIndexJs + ); + } catch (e) { + console.error(e); + process.exit(1); + } + return eslintConfig; + } else { + return { + extends: [require.resolve('eslint-config-react-app')], + }; + } + })(), + useEslintrc: false, + // @remove-on-eject-end + }, + loader: require.resolve('eslint-loader'), }, - loader: require.resolve('eslint-loader'), - }, - ], + ], include: paths.appSrc, }, { -- GitLab From 91bf5ee6e5c814ffe682f6a0408173572b3a2423 Mon Sep 17 00:00:00 2001 From: Giuseppe Bandiera <giuseppe.bandiera@live.com> Date: Tue, 12 Nov 2019 10:09:27 +0100 Subject: [PATCH 2/4] Change to DISABLE_ESLINT --- docusaurus/docs/advanced-configuration.md | 2 +- packages/react-scripts/config/webpack.config.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docusaurus/docs/advanced-configuration.md b/docusaurus/docs/advanced-configuration.md index 88da32b8a..2663e914d 100644 --- a/docusaurus/docs/advanced-configuration.md +++ b/docusaurus/docs/advanced-configuration.md @@ -27,4 +27,4 @@ You can adjust various development and production settings by setting environmen | EXTEND_ESLINT | ✅ Used | ✅ Used | When set to `true`, user provided ESLint configs will be used by `eslint-loader`. Note that any rules set to `"error"` will stop the application from building. | | FAST_REFRESH | ✅ Used | 🚫 Ignored | When set to `true`, enables experimental support for fast refresh to allow you to tweak your components in real time without reloading the page. | | TSC_COMPILE_ON_ERROR | ✅ Used | ✅ Used | When set to `true`, you can run and properly build TypeScript projects even if there are TypeScript type check errors. These errors are printed as warnings in the terminal and/or browser console. | -| DISABLE_ESLINT_DEV | ✅ Used | 🚫 Ignored | If set to `true`, ESLint will be disabled when compiling the code for running the development server. Useful to allow developers to use non-production-ready code while still developing a feature or inspecting an issue. ESLint will still run on production builds to detect possible problems. | +| DISABLE_ESLINT | ✅ Used | ✅ Used | When set to `true`, ESLint won't run when compiling the code. | diff --git a/packages/react-scripts/config/webpack.config.js b/packages/react-scripts/config/webpack.config.js index 0574d3018..0a591448a 100644 --- a/packages/react-scripts/config/webpack.config.js +++ b/packages/react-scripts/config/webpack.config.js @@ -354,7 +354,7 @@ module.exports = function (webpackEnv) { { test: /\.(js|mjs|jsx|ts|tsx)$/, enforce: 'pre', - use: isEnvDevelopment && process.env.DISABLE_ESLINT_DEV === 'true' + use: process.env.DISABLE_ESLINT === 'true' ? undefined : [ { -- GitLab From 70fd32da0dfa8ce6b07af1cd1aed07db04cc7987 Mon Sep 17 00:00:00 2001 From: Andy Crow <andy.crow@travelperk.com> Date: Tue, 31 Mar 2020 12:40:24 +0200 Subject: [PATCH 3/4] Fix conflicts --- .../react-scripts/config/webpack.config.js | 29 +++++-------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/packages/react-scripts/config/webpack.config.js b/packages/react-scripts/config/webpack.config.js index 0a591448a..190798881 100644 --- a/packages/react-scripts/config/webpack.config.js +++ b/packages/react-scripts/config/webpack.config.js @@ -364,27 +364,14 @@ module.exports = function (webpackEnv) { eslintPath: require.resolve('eslint'), resolvePluginsRelativeTo: __dirname, // @remove-on-eject-begin - ignore: process.env.EXTEND_ESLINT === 'true', - baseConfig: (() => { - // We allow overriding the config only if the env variable is set - if (process.env.EXTEND_ESLINT === 'true') { - const eslintCli = new eslint.CLIEngine(); - let eslintConfig; - try { - eslintConfig = eslintCli.getConfigForFile( - paths.appIndexJs - ); - } catch (e) { - console.error(e); - process.exit(1); - } - return eslintConfig; - } else { - return { - extends: [require.resolve('eslint-config-react-app')], - }; - } - })(), + ignore: isExtendingEslintConfig, + baseConfig: isExtendingEslintConfig + ? undefined + : { + extends: [ + require.resolve('eslint-config-react-app'), + ], + }, useEslintrc: false, // @remove-on-eject-end }, -- GitLab From 83e2264a63e2f882aefe6e7c06805de0a9093576 Mon Sep 17 00:00:00 2001 From: Andy Crow <andy.crow@travelperk.com> Date: Tue, 31 Mar 2020 12:50:22 +0200 Subject: [PATCH 4/4] Formatting + use constant --- packages/react-scripts/config/webpack.config.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/react-scripts/config/webpack.config.js b/packages/react-scripts/config/webpack.config.js index 190798881..96a38a3c6 100644 --- a/packages/react-scripts/config/webpack.config.js +++ b/packages/react-scripts/config/webpack.config.js @@ -366,13 +366,11 @@ module.exports = function (webpackEnv) { // @remove-on-eject-begin ignore: isExtendingEslintConfig, baseConfig: isExtendingEslintConfig - ? undefined - : { - extends: [ - require.resolve('eslint-config-react-app'), - ], - }, - useEslintrc: false, + ? undefined + : { + extends: [require.resolve('eslint-config-react-app'),], + }, + useEslintrc: isExtendingEslintConfig, // @remove-on-eject-end }, loader: require.resolve('eslint-loader'), -- GitLab