Refactor ESLint configuration to enable better IDE integration (#13914)
* Refactor ESLint configuration to enable better IDE integration * Minor tweaks
Minh Nguyen committed
Nov 8, 2018 at 20:56 UTC
3d8bda70e52a4d90f656cf6bf3021af53bb7ca6f
11 files changed
+58
-98
.eslintrc.js
+48
@@ -1,5 +1,10 @@
1
'use strict';
2
3
+const {
4
+ es5Paths,
5
+ esNextPaths,
6
+} = require('./scripts/shared/pathsByLanguageVersion');
7
+
8
const OFF = 0;
9
const ERROR = 2;
10
@@ -16,6 +21,15 @@ module.exports = {
21
'react-internal',
22
],
23
24
+ parser: 'espree',
25
+ parserOptions: {
26
+ ecmaVersion: 2017,
27
+ sourceType: 'script',
28
+ ecmaFeatures: {
29
+ experimentalObjectRestSpread: true,
30
+ },
31
+ },
32
+
33
// We're stricter than the default config, mostly. We'll override a few rules
34
// and then enable some React specific ones.
35
rules: {
@@ -44,6 +58,13 @@ module.exports = {
58
'space-before-function-paren': OFF,
59
'valid-typeof': [ERROR, {requireStringLiterals: true}],
60
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
+
68
// React & JSX
69
// Our transforms set this automatically
70
'react/jsx-boolean-value': [ERROR, 'always'],
@@ -71,6 +92,33 @@ module.exports = {
92
},
93
94
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
+ },
122
{
123
files: ['**/__tests__/*.js'],
124
rules: {
packages/scheduler/npm/umd/scheduler-tracing.development.js
+1
@@ -10,6 +10,7 @@
10
'use strict';
11
12
(function(global, factory) {
13
+ // eslint-disable-next-line no-unused-expressions
14
typeof exports === 'object' && typeof module !== 'undefined'
15
? (module.exports = factory(require('react')))
16
: typeof define === 'function' && define.amd // eslint-disable-line no-undef
packages/scheduler/npm/umd/scheduler-tracing.production.min.js
+1
@@ -10,6 +10,7 @@
10
'use strict';
11
12
(function(global, factory) {
13
+ // eslint-disable-next-line no-unused-expressions
14
typeof exports === 'object' && typeof module !== 'undefined'
15
? (module.exports = factory(require('react')))
16
: typeof define === 'function' && define.amd // eslint-disable-line no-undef
packages/scheduler/npm/umd/scheduler-tracing.profiling.min.js
+1
@@ -10,6 +10,7 @@
10
'use strict';
11
12
(function(global, factory) {
13
+ // eslint-disable-next-line no-unused-expressions
14
typeof exports === 'object' && typeof module !== 'undefined'
15
? (module.exports = factory(require('react')))
16
: typeof define === 'function' && define.amd // eslint-disable-line no-undef
packages/scheduler/npm/umd/scheduler.development.js
+1
@@ -12,6 +12,7 @@
12
'use strict';
13
14
(function(global, factory) {
15
+ // eslint-disable-next-line no-unused-expressions
16
typeof exports === 'object' && typeof module !== 'undefined'
17
? (module.exports = factory(require('react')))
18
: typeof define === 'function' && define.amd // eslint-disable-line no-undef
packages/scheduler/npm/umd/scheduler.production.min.js
+1
@@ -12,6 +12,7 @@
12
'use strict';
13
14
(function(global, factory) {
15
+ // eslint-disable-next-line no-unused-expressions
16
typeof exports === 'object' && typeof module !== 'undefined'
17
? (module.exports = factory(require('react')))
18
: typeof define === 'function' && define.amd // eslint-disable-line no-undef
packages/scheduler/npm/umd/scheduler.profiling.min.js
+1
@@ -12,6 +12,7 @@
12
'use strict';
13
14
(function(global, factory) {
15
+ // eslint-disable-next-line no-unused-expressions
16
typeof exports === 'object' && typeof module !== 'undefined'
17
? (module.exports = factory(require('react')))
18
: typeof define === 'function' && define.amd // eslint-disable-line no-undef
scripts/eslint/eslintrc.default.js
deleted
-31
@@ -1,31 +0,0 @@
1
-/**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
-'use strict';
9
-
10
-const eslintrc = require('../../.eslintrc');
11
-
12
-const ERROR = 2;
13
-
14
-// We apply these settings to files that should run on Node.
15
-// They can't use JSX or ES6 modules, and must be in strict mode.
16
-// They can, however, use other ES6 features.
17
-
18
-module.exports = Object.assign({}, eslintrc, {
19
- parser: 'espree',
20
- parserOptions: {
21
- ecmaVersion: 2017,
22
- sourceType: 'script',
23
- ecmaFeatures: {
24
- experimentalObjectRestSpread: true,
25
- },
26
- },
27
- rules: Object.assign({}, eslintrc.rules, {
28
- 'no-var': ERROR,
29
- strict: ERROR,
30
- }),
31
-});
scripts/eslint/eslintrc.es5.js
deleted
-26
@@ -1,26 +0,0 @@
1
-/**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
-'use strict';
9
-
10
-const eslintrc = require('../../.eslintrc');
11
-
12
-const ERROR = 2;
13
-
14
-// We apply these settings to files that we ship through npm.
15
-// They must be ES5.
16
-
17
-module.exports = Object.assign({}, eslintrc, {
18
- parser: 'espree',
19
- parserOptions: {
20
- ecmaVersion: 5,
21
- sourceType: 'script',
22
- },
23
- rules: {
24
- strict: ERROR,
25
- },
26
-});
scripts/eslint/eslintrc.esnext.js
deleted
-21
@@ -1,21 +0,0 @@
1
-/**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
-'use strict';
9
-
10
-const eslintrc = require('../../.eslintrc');
11
-
12
-const ERROR = 2;
13
-
14
-// We apply these settings to the source files that get compiled.
15
-// They can use all features including JSX (but shouldn't use `var`).
16
-
17
-module.exports = Object.assign({}, eslintrc, {
18
- rules: Object.assign({}, eslintrc.rules, {
19
- 'no-var': ERROR,
20
- }),
21
-});
scripts/eslint/index.js
+4
-20
@@ -10,7 +10,6 @@
10
const minimatch = require('minimatch');
11
const CLIEngine = require('eslint').CLIEngine;
12
const listChangedFiles = require('../shared/listChangedFiles');
13
-const {es5Paths, esNextPaths} = require('../shared/pathsByLanguageVersion');
13
14
const allPaths = ['**/*.js'];
15
@@ -65,25 +64,10 @@ function runESLint({onlyChanged}) {
64
if (typeof onlyChanged !== 'boolean') {
65
throw new Error('Pass options.onlyChanged as a boolean.');
66
}
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
+ );
71
console.log(output);
72
return errorCount === 0 && warningCount === 0;
73
}