Skip to content

Commit

Permalink
Refactor ESLint configuration to enable better IDE integration (faceb…
Browse files Browse the repository at this point in the history
…ook#13914)

* Refactor ESLint configuration to enable better IDE integration

* Minor tweaks
  • Loading branch information
NMinhNguyen authored and gaearon committed Nov 8, 2018
1 parent 051272f commit 3d8bda7
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 98 deletions.
48 changes: 48 additions & 0 deletions .eslintrc.js
@@ -1,5 +1,10 @@
'use strict';

const {
es5Paths,
esNextPaths,
} = require('./scripts/shared/pathsByLanguageVersion');

const OFF = 0;
const ERROR = 2;

Expand All @@ -16,6 +21,15 @@ module.exports = {
'react-internal',
],

parser: 'espree',
parserOptions: {
ecmaVersion: 2017,
sourceType: 'script',
ecmaFeatures: {
experimentalObjectRestSpread: true,
},
},

// We're stricter than the default config, mostly. We'll override a few rules
// and then enable some React specific ones.
rules: {
Expand Down Expand Up @@ -44,6 +58,13 @@ module.exports = {
'space-before-function-paren': OFF,
'valid-typeof': [ERROR, {requireStringLiterals: true}],

// We apply these settings to files that should run on Node.
// They can't use JSX or ES6 modules, and must be in strict mode.
// They can, however, use other ES6 features.
// (Note these rules are overridden later for source files.)
'no-var': ERROR,
strict: ERROR,

// React & JSX
// Our transforms set this automatically
'react/jsx-boolean-value': [ERROR, 'always'],
Expand Down Expand Up @@ -71,6 +92,33 @@ module.exports = {
},

overrides: [
{
// We apply these settings to files that we ship through npm.
// They must be ES5.
files: es5Paths,
parser: 'espree',
parserOptions: {
ecmaVersion: 5,
sourceType: 'script',
},
rules: {
'no-var': OFF,
strict: ERROR,
},
},
{
// We apply these settings to the source files that get compiled.
// They can use all features including JSX (but shouldn't use `var`).
files: esNextPaths,
parser: 'babel-eslint',
parserOptions: {
sourceType: 'module',
},
rules: {
'no-var': ERROR,
strict: OFF,
},
},
{
files: ['**/__tests__/*.js'],
rules: {
Expand Down
Expand Up @@ -10,6 +10,7 @@
'use strict';

(function(global, factory) {
// eslint-disable-next-line no-unused-expressions
typeof exports === 'object' && typeof module !== 'undefined'
? (module.exports = factory(require('react')))
: typeof define === 'function' && define.amd // eslint-disable-line no-undef
Expand Down
Expand Up @@ -10,6 +10,7 @@
'use strict';

(function(global, factory) {
// eslint-disable-next-line no-unused-expressions
typeof exports === 'object' && typeof module !== 'undefined'
? (module.exports = factory(require('react')))
: typeof define === 'function' && define.amd // eslint-disable-line no-undef
Expand Down
Expand Up @@ -10,6 +10,7 @@
'use strict';

(function(global, factory) {
// eslint-disable-next-line no-unused-expressions
typeof exports === 'object' && typeof module !== 'undefined'
? (module.exports = factory(require('react')))
: typeof define === 'function' && define.amd // eslint-disable-line no-undef
Expand Down
1 change: 1 addition & 0 deletions packages/scheduler/npm/umd/scheduler.development.js
Expand Up @@ -12,6 +12,7 @@
'use strict';

(function(global, factory) {
// eslint-disable-next-line no-unused-expressions
typeof exports === 'object' && typeof module !== 'undefined'
? (module.exports = factory(require('react')))
: typeof define === 'function' && define.amd // eslint-disable-line no-undef
Expand Down
1 change: 1 addition & 0 deletions packages/scheduler/npm/umd/scheduler.production.min.js
Expand Up @@ -12,6 +12,7 @@
'use strict';

(function(global, factory) {
// eslint-disable-next-line no-unused-expressions
typeof exports === 'object' && typeof module !== 'undefined'
? (module.exports = factory(require('react')))
: typeof define === 'function' && define.amd // eslint-disable-line no-undef
Expand Down
1 change: 1 addition & 0 deletions packages/scheduler/npm/umd/scheduler.profiling.min.js
Expand Up @@ -12,6 +12,7 @@
'use strict';

(function(global, factory) {
// eslint-disable-next-line no-unused-expressions
typeof exports === 'object' && typeof module !== 'undefined'
? (module.exports = factory(require('react')))
: typeof define === 'function' && define.amd // eslint-disable-line no-undef
Expand Down
31 changes: 0 additions & 31 deletions scripts/eslint/eslintrc.default.js

This file was deleted.

26 changes: 0 additions & 26 deletions scripts/eslint/eslintrc.es5.js

This file was deleted.

21 changes: 0 additions & 21 deletions scripts/eslint/eslintrc.esnext.js

This file was deleted.

24 changes: 4 additions & 20 deletions scripts/eslint/index.js
Expand Up @@ -10,7 +10,6 @@
const minimatch = require('minimatch');
const CLIEngine = require('eslint').CLIEngine;
const listChangedFiles = require('../shared/listChangedFiles');
const {es5Paths, esNextPaths} = require('../shared/pathsByLanguageVersion');

const allPaths = ['**/*.js'];

Expand Down Expand Up @@ -65,25 +64,10 @@ function runESLint({onlyChanged}) {
if (typeof onlyChanged !== 'boolean') {
throw new Error('Pass options.onlyChanged as a boolean.');
}
let errorCount = 0;
let warningCount = 0;
let output = '';
[
runESLintOnFilesWithOptions(allPaths, onlyChanged, {
configFile: `${__dirname}/eslintrc.default.js`,
ignorePattern: [...es5Paths, ...esNextPaths],
}),
runESLintOnFilesWithOptions(esNextPaths, onlyChanged, {
configFile: `${__dirname}/eslintrc.esnext.js`,
}),
runESLintOnFilesWithOptions(es5Paths, onlyChanged, {
configFile: `${__dirname}/eslintrc.es5.js`,
}),
].forEach(result => {
errorCount += result.errorCount;
warningCount += result.warningCount;
output += result.output;
});
const {errorCount, warningCount, output} = runESLintOnFilesWithOptions(
allPaths,
onlyChanged
);
console.log(output);
return errorCount === 0 && warningCount === 0;
}
Expand Down

0 comments on commit 3d8bda7

Please sign in to comment.