Skip to content

Commit b9963ab

Browse files
authoredFeb 3, 2021
Add opt-out for eslint-webpack-plugin (#10170)
1 parent 8fa0a26 commit b9963ab

File tree

3 files changed

+34
-23
lines changed

3 files changed

+34
-23
lines changed
 

‎docusaurus/docs/advanced-configuration.md

+2
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ You can adjust various development and production settings by setting environmen
2727
| IMAGE_INLINE_SIZE_LIMIT | 🚫 Ignored | ✅ Used | By default, images smaller than 10,000 bytes are encoded as a data URI in base64 and inlined in the CSS or JS build artifact. Set this to control the size limit in bytes. Setting it to 0 will disable the inlining of images. |
2828
| FAST_REFRESH | ✅ Used | 🚫 Ignored | When set to `false`, disables experimental support for Fast Refresh to allow you to tweak your components in real time without reloading the page. |
2929
| 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. |
30+
| ESLINT_NO_DEV_ERRORS | ✅ Used | 🚫 Ignored | When set to `true`, ESLint errors are converted to warnings during development. As a result, ESLint output will no longer appear in the error overlay. |
31+
| DISABLE_ESLINT_PLUGIN | ✅ Used | ✅ Used | When set to `true`, [eslint-webpack-plugin](https://github.com/webpack-contrib/eslint-webpack-plugin) will be completely disabled. |
3032
| DISABLE_NEW_JSX_TRANSFORM | ✅ Used | ✅ Used | When set to `true`, disables the [new JSX transform](https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html) introduced in React 17 and backported to React 16.14.0, 15.7.0, and 0.14.10. New projects will use a version of React that supports this by default but you may need to disable it in existing projects if you can't upgrade React. |

‎packages/react-dev-utils/eslintFormatter.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ const table = require('text-table');
1414

1515
const cwd = process.cwd();
1616

17+
const emitErrorsAsWarnings =
18+
process.env.NODE_ENV === 'development' &&
19+
process.env.ESLINT_NO_DEV_ERRORS === 'true';
20+
1721
function isError(message) {
1822
if (message.fatal || message.severity === 2) {
1923
return true;
@@ -38,7 +42,7 @@ function formatter(results) {
3842

3943
messages = messages.map(message => {
4044
let messageType;
41-
if (isError(message)) {
45+
if (isError(message) && !emitErrorsAsWarnings) {
4246
messageType = 'error';
4347
hasErrors = true;
4448
if (message.ruleId) {

‎packages/react-scripts/config/webpack.config.js

+27-22
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ const reactRefreshOverlayEntry = require.resolve(
5555
// makes for a smoother build process.
5656
const shouldInlineRuntimeChunk = process.env.INLINE_RUNTIME_CHUNK !== 'false';
5757

58+
const emitErrorsAsWarnings = process.env.ESLINT_NO_DEV_ERRORS === 'true';
59+
const disableESLintPlugin = process.env.DISABLE_ESLINT_PLUGIN === 'true';
60+
5861
const imageInlineSizeLimit = parseInt(
5962
process.env.IMAGE_INLINE_SIZE_LIMIT || '10000'
6063
);
@@ -750,29 +753,31 @@ module.exports = function (webpackEnv) {
750753
// The formatter is invoked directly in WebpackDevServerUtils during development
751754
formatter: isEnvProduction ? typescriptFormatter : undefined,
752755
}),
753-
new ESLintPlugin({
754-
// Plugin options
755-
extensions: ['js', 'mjs', 'jsx', 'ts', 'tsx'],
756-
formatter: require.resolve('react-dev-utils/eslintFormatter'),
757-
eslintPath: require.resolve('eslint'),
758-
context: paths.appSrc,
759-
cache: true,
760-
cacheLocation: path.resolve(
761-
paths.appNodeModules,
762-
'.cache/.eslintcache'
763-
),
764-
// ESLint class options
765-
cwd: paths.appPath,
766-
resolvePluginsRelativeTo: __dirname,
767-
baseConfig: {
768-
extends: [require.resolve('eslint-config-react-app/base')],
769-
rules: {
770-
...(!hasJsxRuntime && {
771-
'react/react-in-jsx-scope': 'error',
772-
}),
756+
!disableESLintPlugin &&
757+
new ESLintPlugin({
758+
// Plugin options
759+
extensions: ['js', 'mjs', 'jsx', 'ts', 'tsx'],
760+
formatter: require.resolve('react-dev-utils/eslintFormatter'),
761+
eslintPath: require.resolve('eslint'),
762+
emitWarning: isEnvDevelopment && emitErrorsAsWarnings,
763+
context: paths.appSrc,
764+
cache: true,
765+
cacheLocation: path.resolve(
766+
paths.appNodeModules,
767+
'.cache/.eslintcache'
768+
),
769+
// ESLint class options
770+
cwd: paths.appPath,
771+
resolvePluginsRelativeTo: __dirname,
772+
baseConfig: {
773+
extends: [require.resolve('eslint-config-react-app/base')],
774+
rules: {
775+
...(!hasJsxRuntime && {
776+
'react/react-in-jsx-scope': 'error',
777+
}),
778+
},
773779
},
774-
},
775-
}),
780+
}),
776781
].filter(Boolean),
777782
// Some libraries import Node modules but don't use them in the browser.
778783
// Tell webpack to provide empty mocks for them so importing them works.

0 commit comments

Comments
 (0)
Please sign in to comment.