Skip to content

Commit 9938224

Browse files
authoredJul 16, 2019
Allow extending config used in eslint-loader (facebook#7036)
1 parent 418b44e commit 9938224

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed
 

‎config/webpack.config.js

+25-3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const getClientEnvironment = require('./env');
3333
const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin');
3434
const ForkTsCheckerWebpackPlugin = require('react-dev-utils/ForkTsCheckerWebpackPlugin');
3535
const typescriptFormatter = require('react-dev-utils/typescriptFormatter');
36+
const eslint = require('eslint');
3637
// @remove-on-eject-begin
3738
const getCacheIdentifier = require('react-dev-utils/getCacheIdentifier');
3839
// @remove-on-eject-end
@@ -323,9 +324,30 @@ module.exports = function(webpackEnv) {
323324
formatter: require.resolve('react-dev-utils/eslintFormatter'),
324325
eslintPath: require.resolve('eslint'),
325326
// @remove-on-eject-begin
326-
baseConfig: {
327-
extends: [require.resolve('eslint-config-react-app')],
328-
},
327+
baseConfig: (() => {
328+
const eslintCli = new eslint.CLIEngine();
329+
let eslintConfig;
330+
try {
331+
eslintConfig = eslintCli.getConfigForFile(paths.appIndexJs);
332+
} catch (e) {
333+
// A config couldn't be found.
334+
}
335+
336+
// We allow overriding the config, only if it extends our config
337+
// (`extends` can be a string or array of strings).
338+
if (
339+
process.env.EXTEND_ESLINT &&
340+
eslintConfig &&
341+
eslintConfig.extends &&
342+
eslintConfig.extends.includes('react-app')
343+
) {
344+
return eslintConfig;
345+
} else {
346+
return {
347+
extends: [require.resolve('eslint-config-react-app')],
348+
};
349+
}
350+
})(),
329351
ignore: false,
330352
useEslintrc: false,
331353
// @remove-on-eject-end

‎scripts/eject.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,12 @@ inquirer
239239
};
240240

241241
// Add ESlint config
242-
console.log(` Adding ${cyan('ESLint')} configuration`);
243-
appPackage.eslintConfig = {
244-
extends: 'react-app',
245-
};
242+
if (!appPackage.eslintConfig) {
243+
console.log(` Adding ${cyan('ESLint')} configuration`);
244+
appPackage.eslintConfig = {
245+
extends: 'react-app',
246+
};
247+
}
246248

247249
fs.writeFileSync(
248250
path.join(appPath, 'package.json'),

0 commit comments

Comments
 (0)