Skip to content

Commit 6547b31

Browse files
committed
Add ESLint extend support to eslint-loader
1 parent e2f43a0 commit 6547b31

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ const getCacheIdentifier = require('react-dev-utils/getCacheIdentifier');
3838
// @remove-on-eject-end
3939
const postcssNormalize = require('postcss-normalize');
4040

41+
// Get the app's `package.json`.
42+
const appPackageJson = require(paths.appPackageJson);
43+
4144
// Source maps are resource heavy and can cause out of memory issue for large source files.
4245
const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';
4346
// Some apps do not need the benefits of saving a web request, so not inlining the chunk
@@ -319,9 +322,13 @@ module.exports = function(webpackEnv) {
319322
formatter: require.resolve('react-dev-utils/eslintFormatter'),
320323
eslintPath: require.resolve('eslint'),
321324
// @remove-on-eject-begin
322-
baseConfig: {
323-
extends: [require.resolve('eslint-config-react-app')],
324-
},
325+
baseConfig:
326+
// We allow overriding the config, only if it extends our config
327+
// (`extends` can be a string or array of strings).
328+
appPackageJson.eslintConfig &&
329+
appPackageJson.eslintConfig.extends.includes('react-app')
330+
? appPackageJson.eslintConfig
331+
: { extends: [require.resolve('eslint-config-react-app')] },
325332
ignore: false,
326333
useEslintrc: false,
327334
// @remove-on-eject-end

packages/react-scripts/scripts/eject.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,12 @@ inquirer
236236
};
237237

238238
// Add ESlint config
239-
console.log(` Adding ${cyan('ESLint')} configuration`);
240-
appPackage.eslintConfig = {
241-
extends: 'react-app',
242-
};
239+
if (!appPackage.eslintConfig) {
240+
console.log(` Adding ${cyan('ESLint')} configuration`);
241+
appPackage.eslintConfig = {
242+
extends: 'react-app',
243+
};
244+
}
243245

244246
fs.writeFileSync(
245247
path.join(appPath, 'package.json'),

0 commit comments

Comments
 (0)