Skip to content

Commit 3d8bda7

Browse files
NMinhNguyengaearon
authored andcommitted
Refactor ESLint configuration to enable better IDE integration (facebook#13914)
* Refactor ESLint configuration to enable better IDE integration * Minor tweaks
1 parent 051272f commit 3d8bda7

11 files changed

+58
-98
lines changed

.eslintrc.js

+48
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
'use strict';
22

3+
const {
4+
es5Paths,
5+
esNextPaths,
6+
} = require('./scripts/shared/pathsByLanguageVersion');
7+
38
const OFF = 0;
49
const ERROR = 2;
510

@@ -16,6 +21,15 @@ module.exports = {
1621
'react-internal',
1722
],
1823

24+
parser: 'espree',
25+
parserOptions: {
26+
ecmaVersion: 2017,
27+
sourceType: 'script',
28+
ecmaFeatures: {
29+
experimentalObjectRestSpread: true,
30+
},
31+
},
32+
1933
// We're stricter than the default config, mostly. We'll override a few rules
2034
// and then enable some React specific ones.
2135
rules: {
@@ -44,6 +58,13 @@ module.exports = {
4458
'space-before-function-paren': OFF,
4559
'valid-typeof': [ERROR, {requireStringLiterals: true}],
4660

61+
// We apply these settings to files that should run on Node.
62+
// They can't use JSX or ES6 modules, and must be in strict mode.
63+
// They can, however, use other ES6 features.
64+
// (Note these rules are overridden later for source files.)
65+
'no-var': ERROR,
66+
strict: ERROR,
67+
4768
// React & JSX
4869
// Our transforms set this automatically
4970
'react/jsx-boolean-value': [ERROR, 'always'],
@@ -71,6 +92,33 @@ module.exports = {
7192
},
7293

7394
overrides: [
95+
{
96+
// We apply these settings to files that we ship through npm.
97+
// They must be ES5.
98+
files: es5Paths,
99+
parser: 'espree',
100+
parserOptions: {
101+
ecmaVersion: 5,
102+
sourceType: 'script',
103+
},
104+
rules: {
105+
'no-var': OFF,
106+
strict: ERROR,
107+
},
108+
},
109+
{
110+
// We apply these settings to the source files that get compiled.
111+
// They can use all features including JSX (but shouldn't use `var`).
112+
files: esNextPaths,
113+
parser: 'babel-eslint',
114+
parserOptions: {
115+
sourceType: 'module',
116+
},
117+
rules: {
118+
'no-var': ERROR,
119+
strict: OFF,
120+
},
121+
},
74122
{
75123
files: ['**/__tests__/*.js'],
76124
rules: {

packages/scheduler/npm/umd/scheduler-tracing.development.js

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
'use strict';
1111

1212
(function(global, factory) {
13+
// eslint-disable-next-line no-unused-expressions
1314
typeof exports === 'object' && typeof module !== 'undefined'
1415
? (module.exports = factory(require('react')))
1516
: typeof define === 'function' && define.amd // eslint-disable-line no-undef

packages/scheduler/npm/umd/scheduler-tracing.production.min.js

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
'use strict';
1111

1212
(function(global, factory) {
13+
// eslint-disable-next-line no-unused-expressions
1314
typeof exports === 'object' && typeof module !== 'undefined'
1415
? (module.exports = factory(require('react')))
1516
: typeof define === 'function' && define.amd // eslint-disable-line no-undef

packages/scheduler/npm/umd/scheduler-tracing.profiling.min.js

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
'use strict';
1111

1212
(function(global, factory) {
13+
// eslint-disable-next-line no-unused-expressions
1314
typeof exports === 'object' && typeof module !== 'undefined'
1415
? (module.exports = factory(require('react')))
1516
: typeof define === 'function' && define.amd // eslint-disable-line no-undef

packages/scheduler/npm/umd/scheduler.development.js

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
'use strict';
1313

1414
(function(global, factory) {
15+
// eslint-disable-next-line no-unused-expressions
1516
typeof exports === 'object' && typeof module !== 'undefined'
1617
? (module.exports = factory(require('react')))
1718
: typeof define === 'function' && define.amd // eslint-disable-line no-undef

packages/scheduler/npm/umd/scheduler.production.min.js

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
'use strict';
1313

1414
(function(global, factory) {
15+
// eslint-disable-next-line no-unused-expressions
1516
typeof exports === 'object' && typeof module !== 'undefined'
1617
? (module.exports = factory(require('react')))
1718
: typeof define === 'function' && define.amd // eslint-disable-line no-undef

packages/scheduler/npm/umd/scheduler.profiling.min.js

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
'use strict';
1313

1414
(function(global, factory) {
15+
// eslint-disable-next-line no-unused-expressions
1516
typeof exports === 'object' && typeof module !== 'undefined'
1617
? (module.exports = factory(require('react')))
1718
: typeof define === 'function' && define.amd // eslint-disable-line no-undef

scripts/eslint/eslintrc.default.js

-31
This file was deleted.

scripts/eslint/eslintrc.es5.js

-26
This file was deleted.

scripts/eslint/eslintrc.esnext.js

-21
This file was deleted.

scripts/eslint/index.js

+4-20
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
const minimatch = require('minimatch');
1111
const CLIEngine = require('eslint').CLIEngine;
1212
const listChangedFiles = require('../shared/listChangedFiles');
13-
const {es5Paths, esNextPaths} = require('../shared/pathsByLanguageVersion');
1413

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

@@ -65,25 +64,10 @@ function runESLint({onlyChanged}) {
6564
if (typeof onlyChanged !== 'boolean') {
6665
throw new Error('Pass options.onlyChanged as a boolean.');
6766
}
68-
let errorCount = 0;
69-
let warningCount = 0;
70-
let output = '';
71-
[
72-
runESLintOnFilesWithOptions(allPaths, onlyChanged, {
73-
configFile: `${__dirname}/eslintrc.default.js`,
74-
ignorePattern: [...es5Paths, ...esNextPaths],
75-
}),
76-
runESLintOnFilesWithOptions(esNextPaths, onlyChanged, {
77-
configFile: `${__dirname}/eslintrc.esnext.js`,
78-
}),
79-
runESLintOnFilesWithOptions(es5Paths, onlyChanged, {
80-
configFile: `${__dirname}/eslintrc.es5.js`,
81-
}),
82-
].forEach(result => {
83-
errorCount += result.errorCount;
84-
warningCount += result.warningCount;
85-
output += result.output;
86-
});
67+
const {errorCount, warningCount, output} = runESLintOnFilesWithOptions(
68+
allPaths,
69+
onlyChanged
70+
);
8771
console.log(output);
8872
return errorCount === 0 && warningCount === 0;
8973
}

0 commit comments

Comments
 (0)