eslint 6.1.0 → 6.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/README.md +1 -3
- package/conf/config-schema.js +1 -0
- package/conf/environments.js +72 -15
- package/lib/cli-engine/config-array/config-array.js +7 -0
- package/lib/cli-engine/config-array/extracted-config.js +16 -1
- package/lib/cli-engine/config-array-factory.js +2 -0
- package/lib/init/npm-utils.js +2 -2
- package/lib/linter/code-path-analysis/code-path-analyzer.js +1 -0
- package/lib/linter/linter.js +48 -15
- package/lib/rules/accessor-pairs.js +195 -35
- package/lib/rules/class-methods-use-this.js +10 -3
- package/lib/rules/dot-notation.js +6 -2
- package/lib/rules/func-call-spacing.js +30 -20
- package/lib/rules/func-names.js +4 -0
- package/lib/rules/function-call-argument-newline.js +120 -0
- package/lib/rules/function-paren-newline.js +34 -22
- package/lib/rules/indent.js +13 -2
- package/lib/rules/index.js +1 -0
- package/lib/rules/new-cap.js +2 -1
- package/lib/rules/no-dupe-keys.js +1 -1
- package/lib/rules/no-duplicate-case.js +10 -8
- package/lib/rules/no-extra-bind.js +1 -0
- package/lib/rules/no-extra-boolean-cast.js +44 -5
- package/lib/rules/no-extra-parens.js +54 -22
- package/lib/rules/no-mixed-operators.js +48 -13
- package/lib/rules/no-restricted-syntax.js +2 -2
- package/lib/rules/no-unused-vars.js +1 -1
- package/lib/rules/prefer-template.js +1 -10
- package/lib/rules/sort-keys.js +11 -3
- package/lib/rules/utils/ast-utils.js +19 -2
- package/lib/rules/yoda.js +1 -1
- package/lib/shared/types.js +2 -0
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,37 @@
|
|
1
|
+
v6.2.0 - August 18, 2019
|
2
|
+
|
3
|
+
* [`fee6acb`](https://github.com/eslint/eslint/commit/fee6acbe13cecd4c028e681e185fc6a6d6ba9452) Update: support bigint and dynamic import (refs #11803) (#11983) (Toru Nagashima)
|
4
|
+
* [`afd8012`](https://github.com/eslint/eslint/commit/afd8012c2797f2f5bf3c360cb241ea2ba6e1a489) New: noInlineConfig setting (refs eslint/rfcs#22) (#12091) (Toru Nagashima)
|
5
|
+
* [`3d12378`](https://github.com/eslint/eslint/commit/3d12378221961439c27ddae0ecda9845ac575107) Update: Fix accessor-pairs to enforce pairs per property in literals (#12062) (Milos Djermanovic)
|
6
|
+
* [`8cd00b3`](https://github.com/eslint/eslint/commit/8cd00b308987e0db0bdb2e242bf13b2b07b350bd) New: function-call-argument-newline (#12024) (finico)
|
7
|
+
* [`30ebf92`](https://github.com/eslint/eslint/commit/30ebf929f60684520b1201c1adfd86214c19d614) Fix: prefer-template autofix produces syntax error with octal escapes (#12085) (Milos Djermanovic)
|
8
|
+
* [`13c3988`](https://github.com/eslint/eslint/commit/13c3988a4001ae368ea7b6c8d3dd0abfa7c6cf64) Fix: Check literal type explicitly in dot-notation (#12095) (Milos Djermanovic)
|
9
|
+
* [`3e5ceca`](https://github.com/eslint/eslint/commit/3e5ceca4d2284b55a2292a1d3de9aa4cdf6fa213) Fix: Handle empty string property names in getFunctionNameWithKind (#12104) (Milos Djermanovic)
|
10
|
+
* [`9a043ff`](https://github.com/eslint/eslint/commit/9a043ffbb864fc65baeb16fe5668435e3b7cfe34) Fix: no-duplicate-case false positives on Object.prototype keys (#12107) (Milos Djermanovic)
|
11
|
+
* [`fe631af`](https://github.com/eslint/eslint/commit/fe631afee59641876598d19b1935967099cc6fa0) Chore: minor typo fix (#12112) (James George)
|
12
|
+
* [`4cb7877`](https://github.com/eslint/eslint/commit/4cb78774f6cc687a3c8701462f8c7f7b587ecaf0) Fix: fix no-extra-parens ignores some nodes (#11909) (Pig Fang)
|
13
|
+
* [`2dc23b8`](https://github.com/eslint/eslint/commit/2dc23b81e54defbce7a70a7f26c2e4c7b692cf58) Update: fix no-dupe-keys false negatives on empty string names (#12069) (Milos Djermanovic)
|
14
|
+
* [`19ab666`](https://github.com/eslint/eslint/commit/19ab6666e8e4142a183bdee2be96e5bafbac0e21) Fix: yoda exceptRange false positives on empty string property names (#12071) (Milos Djermanovic)
|
15
|
+
* [`d642150`](https://github.com/eslint/eslint/commit/d642150fe016608e71a1df2a72960e915b3cfbad) Update: Check empty string property names in sort-keys (#12073) (Milos Djermanovic)
|
16
|
+
* [`acce6de`](https://github.com/eslint/eslint/commit/acce6de940e2b089ff5ba59e4518a54af1682d5e) Fix: class-methods-use-this reports 'undefined' names (#12103) (Milos Djermanovic)
|
17
|
+
* [`92ec2cb`](https://github.com/eslint/eslint/commit/92ec2cb1731b7b6e0ac66336d583fbb782504290) Fix: Allow bind call with a single spread element in no-extra-bind (#12088) (Milos Djermanovic)
|
18
|
+
* [`bfdb0c9`](https://github.com/eslint/eslint/commit/bfdb0c97003fc0e045aa6ed10b177c35305a6e46) Fix: no-extra-boolean-cast invalid autofix for Boolean() without args (#12076) (Milos Djermanovic)
|
19
|
+
* [`34ccc0c`](https://github.com/eslint/eslint/commit/34ccc0cd81f495190e585c6efa8ae233d45bd3ed) Chore: Remove TDZ scope type condition from no-unused-vars (#12055) (Milos Djermanovic)
|
20
|
+
* [`01d38ce`](https://github.com/eslint/eslint/commit/01d38ce2faf0abbc9dd5d25694baeee131036165) Docs: Remove TDZ scope from the scope manager interface documentation (#12054) (Milos Djermanovic)
|
21
|
+
* [`1aff8fc`](https://github.com/eslint/eslint/commit/1aff8fc4f9394cd9126654a55f7f3a43ab1cf8f0) Update: warn about mixing ternary and logical operators (fixes #11704) (#12001) (Karthik Priyadarshan)
|
22
|
+
* [`11be2f8`](https://github.com/eslint/eslint/commit/11be2f8513bd61499f6247392a33ac0a26901c90) Docs: do not recommend global-installed usage (#12016) (薛定谔的猫)
|
23
|
+
* [`cf31dab`](https://github.com/eslint/eslint/commit/cf31dab5d5982151e0cfcc32879e69a83180ec70) Fix: no-restricted-syntax - correct the schema (#12051) (Brad Zacher)
|
24
|
+
* [`fbec99e`](https://github.com/eslint/eslint/commit/fbec99ea3e39316791685652c66e522d698f52d8) Update: fix class-methods-use-this false negatives with exceptMethods (#12077) (Milos Djermanovic)
|
25
|
+
* [`fb08b7c`](https://github.com/eslint/eslint/commit/fb08b7c9d28bc68864eb940e26df274059228b6a) Docs: Remove readonly/writable global logic from no-undef (fixes #11963) (#12053) (Milos Djermanovic)
|
26
|
+
* [`5b5934b`](https://github.com/eslint/eslint/commit/5b5934b9513f9114f5bf8e12ff4f4981590d64d3) Sponsors: Sync README with website (ESLint Jenkins)
|
27
|
+
* [`9156760`](https://github.com/eslint/eslint/commit/915676022a100ae5dba788fa3329d34b3c1f18d3) Sponsors: Sync README with website (ESLint Jenkins)
|
28
|
+
* [`f5e0cc4`](https://github.com/eslint/eslint/commit/f5e0cc40795f175692acb05daaadb91e9e5ae5d3) Update: Check computed method keys in no-extra-parens (#11973) (Milos Djermanovic)
|
29
|
+
* [`d961438`](https://github.com/eslint/eslint/commit/d9614388df8cfb977842ed7ac4725d76a3e05df3) Docs: Fix Incorrect Documentation (#12045) (Michael Miceli)
|
30
|
+
* [`887d08c`](https://github.com/eslint/eslint/commit/887d08c244e32f1fc18359e63380e2cdb0cb3797) Sponsors: Sync README with website (ESLint Jenkins)
|
31
|
+
* [`d90183f`](https://github.com/eslint/eslint/commit/d90183ff6757cff854f4ca4d25b835143dfb4b21) Docs: add a case to func-names (#12038) (Chiawen Chen)
|
32
|
+
* [`8a5b62d`](https://github.com/eslint/eslint/commit/8a5b62de2ae574f416c0f8ad91205da9b1837275) Docs: no use eslint.linter in code example (#12037) (薛定谔的猫)
|
33
|
+
* [`5831767`](https://github.com/eslint/eslint/commit/58317673210e48be3975e317c2c566fae155c94f) Update: report location of func-names (fixes #12022) (#12028) (Pig Fang)
|
34
|
+
|
1
35
|
v6.1.0 - July 20, 2019
|
2
36
|
|
3
37
|
* [`8f86cca`](https://github.com/eslint/eslint/commit/8f86ccaa89daf10123370868c5dcb48c1fcbef7d) Upgrade: eslint-scope@^5.0.0 (#12011) (Kevin Partington)
|
package/README.md
CHANGED
@@ -59,8 +59,6 @@ After that, you can run ESLint on any file or directory like this:
|
|
59
59
|
$ ./node_modules/.bin/eslint yourfile.js
|
60
60
|
```
|
61
61
|
|
62
|
-
It is also possible to install ESLint globally rather than locally (using `npm install eslint --global`). However, any plugins or shareable configs that you use must be installed locally in either case.
|
63
|
-
|
64
62
|
## <a name="configuration"></a>Configuration
|
65
63
|
|
66
64
|
After running `eslint --init`, you'll have a `.eslintrc` file in your directory. In it, you'll see some rules configured like this:
|
@@ -260,7 +258,7 @@ The following companies, organizations, and individuals support ESLint's ongoing
|
|
260
258
|
<h3>Gold Sponsors</h3>
|
261
259
|
<p><a href="https://www.shopify.com"><img src="https://images.opencollective.com/shopify/eeb91aa/logo.png" alt="Shopify" height="96"></a> <a href="http://salesforce.com"><img src="https://images.opencollective.com/salesforce/853ecef/logo.png" alt="Salesforce" height="96"></a> <a href="https://badoo.com/team?utm_source=eslint"><img src="https://images.opencollective.com/badoo/2826a3b/logo.png" alt="Badoo" height="96"></a> <a href="https://www.airbnb.com/"><img src="https://images.opencollective.com/airbnb/001a341/logo.png" alt="Airbnb" height="96"></a> <a href="https://code.facebook.com/projects/"><img src="https://images.opencollective.com/fbopensource/fbb8a5b/logo.png" alt="Facebook Open Source" height="96"></a></p><h3>Silver Sponsors</h3>
|
262
260
|
<p><a href="https://www.ampproject.org/"><img src="https://images.opencollective.com/amp/c8a3b25/logo.png" alt="AMP Project" height="64"></a></p><h3>Bronze Sponsors</h3>
|
263
|
-
<p><a href="https://clay.global"><img src="https://images.opencollective.com/clayglobal/2468f34/logo.png" alt="clay" height="32"></a> <a href="https://discordapp.com"><img src="https://images.opencollective.com/discordapp/7e3d9a9/logo.png" alt="Discord" height="32"></a> <a href="https://themeisle.com"><img src="https://images.opencollective.com/themeisle/logo.png" alt="ThemeIsle" height="32"></a> <a href="https://tekhattan.com"><img src="https://images.opencollective.com/tekhattan/bc73c28/logo.png" alt="TekHattan" height="32"></a> <a href="https://www.marfeel.com/"><img src="https://images.opencollective.com/marfeel/4b88e30/logo.png" alt="Marfeel" height="32"></a> <a href="http://www.firesticktricks.com"><img src="https://images.opencollective.com/fire-stick-tricks/b8fbe2c/logo.png" alt="Fire Stick Tricks" height="32"></a> <a href="https://jsheroes.io/"><img src="https://images.opencollective.com/jsheroes1/9fedf0b/logo.png" alt="JSHeroes " height="32"></a> <a href="https://faithlife.com/ref/about"><img src="https://images.opencollective.com/faithlife/534b832/logo.png" alt="Faithlife" height="32"></a></p>
|
261
|
+
<p><a href="https://icons8.com"><img src="https://images.opencollective.com/icons8/0b37d14/logo.png" alt="Free Icons by Icons8" height="32"></a> <a href="https://uxplanet.org/top-ui-ux-design-agencies-user-experience-firms-8c54697e290"><img src="https://images.opencollective.com/ui-ux-design-agencies/cae5dfe/logo.png" alt="UI UX Design Agencies" height="32"></a> <a href="https://clay.global"><img src="https://images.opencollective.com/clayglobal/2468f34/logo.png" alt="clay" height="32"></a> <a href="https://discordapp.com"><img src="https://images.opencollective.com/discordapp/7e3d9a9/logo.png" alt="Discord" height="32"></a> <a href="https://themeisle.com"><img src="https://images.opencollective.com/themeisle/logo.png" alt="ThemeIsle" height="32"></a> <a href="https://tekhattan.com"><img src="https://images.opencollective.com/tekhattan/bc73c28/logo.png" alt="TekHattan" height="32"></a> <a href="https://www.marfeel.com/"><img src="https://images.opencollective.com/marfeel/4b88e30/logo.png" alt="Marfeel" height="32"></a> <a href="http://www.firesticktricks.com"><img src="https://images.opencollective.com/fire-stick-tricks/b8fbe2c/logo.png" alt="Fire Stick Tricks" height="32"></a> <a href="https://jsheroes.io/"><img src="https://images.opencollective.com/jsheroes1/9fedf0b/logo.png" alt="JSHeroes " height="32"></a> <a href="https://faithlife.com/ref/about"><img src="https://images.opencollective.com/faithlife/534b832/logo.png" alt="Faithlife" height="32"></a></p>
|
264
262
|
<!--sponsorsend-->
|
265
263
|
|
266
264
|
## <a name="technology-sponsors"></a>Technology Sponsors
|
package/conf/config-schema.js
CHANGED
package/conf/environments.js
CHANGED
@@ -10,15 +10,76 @@
|
|
10
10
|
|
11
11
|
const globals = require("globals");
|
12
12
|
|
13
|
+
//------------------------------------------------------------------------------
|
14
|
+
// Helpers
|
15
|
+
//------------------------------------------------------------------------------
|
16
|
+
|
17
|
+
/**
|
18
|
+
* Get the object that has differentce.
|
19
|
+
* @param {Record<string,boolean>} current The newer object.
|
20
|
+
* @param {Record<string,boolean>} prev The older object.
|
21
|
+
* @returns {Record<string,boolean>} The difference object.
|
22
|
+
*/
|
23
|
+
function getDiff(current, prev) {
|
24
|
+
const retv = {};
|
25
|
+
|
26
|
+
for (const [key, value] of Object.entries(current)) {
|
27
|
+
if (!Object.hasOwnProperty.call(prev, key)) {
|
28
|
+
retv[key] = value;
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
return retv;
|
33
|
+
}
|
34
|
+
|
35
|
+
const newGlobals2015 = getDiff(globals.es2015, globals.es5); // 19 variables such as Promise, Map, ...
|
36
|
+
const newGlobals2017 = {
|
37
|
+
Atomics: false,
|
38
|
+
SharedArrayBuffer: false
|
39
|
+
};
|
40
|
+
const newGlobals2020 = {
|
41
|
+
BigInt: false,
|
42
|
+
BigInt64Array: false,
|
43
|
+
BigUint64Array: false
|
44
|
+
};
|
45
|
+
|
13
46
|
//------------------------------------------------------------------------------
|
14
47
|
// Public Interface
|
15
48
|
//------------------------------------------------------------------------------
|
16
49
|
|
17
50
|
/** @type {Map<string, import("../lib/shared/types").Environment>} */
|
18
51
|
module.exports = new Map(Object.entries({
|
52
|
+
|
53
|
+
// Language
|
19
54
|
builtin: {
|
20
55
|
globals: globals.es5
|
21
56
|
},
|
57
|
+
es6: {
|
58
|
+
globals: newGlobals2015,
|
59
|
+
parserOptions: {
|
60
|
+
ecmaVersion: 6
|
61
|
+
}
|
62
|
+
},
|
63
|
+
es2015: {
|
64
|
+
globals: newGlobals2015,
|
65
|
+
parserOptions: {
|
66
|
+
ecmaVersion: 6
|
67
|
+
}
|
68
|
+
},
|
69
|
+
es2017: {
|
70
|
+
globals: { ...newGlobals2015, ...newGlobals2017 },
|
71
|
+
parserOptions: {
|
72
|
+
ecmaVersion: 8
|
73
|
+
}
|
74
|
+
},
|
75
|
+
es2020: {
|
76
|
+
globals: { ...newGlobals2015, ...newGlobals2017, ...newGlobals2020 },
|
77
|
+
parserOptions: {
|
78
|
+
ecmaVersion: 11
|
79
|
+
}
|
80
|
+
},
|
81
|
+
|
82
|
+
// Platforms
|
22
83
|
browser: {
|
23
84
|
globals: globals.browser
|
24
85
|
},
|
@@ -30,6 +91,17 @@ module.exports = new Map(Object.entries({
|
|
30
91
|
}
|
31
92
|
}
|
32
93
|
},
|
94
|
+
"shared-node-browser": {
|
95
|
+
globals: globals["shared-node-browser"]
|
96
|
+
},
|
97
|
+
worker: {
|
98
|
+
globals: globals.worker
|
99
|
+
},
|
100
|
+
serviceworker: {
|
101
|
+
globals: globals.serviceworker
|
102
|
+
},
|
103
|
+
|
104
|
+
// Frameworks
|
33
105
|
commonjs: {
|
34
106
|
globals: globals.commonjs,
|
35
107
|
parserOptions: {
|
@@ -38,12 +110,6 @@ module.exports = new Map(Object.entries({
|
|
38
110
|
}
|
39
111
|
}
|
40
112
|
},
|
41
|
-
"shared-node-browser": {
|
42
|
-
globals: globals["shared-node-browser"]
|
43
|
-
},
|
44
|
-
worker: {
|
45
|
-
globals: globals.worker
|
46
|
-
},
|
47
113
|
amd: {
|
48
114
|
globals: globals.amd
|
49
115
|
},
|
@@ -86,9 +152,6 @@ module.exports = new Map(Object.entries({
|
|
86
152
|
nashorn: {
|
87
153
|
globals: globals.nashorn
|
88
154
|
},
|
89
|
-
serviceworker: {
|
90
|
-
globals: globals.serviceworker
|
91
|
-
},
|
92
155
|
atomtest: {
|
93
156
|
globals: globals.atomtest
|
94
157
|
},
|
@@ -98,12 +161,6 @@ module.exports = new Map(Object.entries({
|
|
98
161
|
webextensions: {
|
99
162
|
globals: globals.webextensions
|
100
163
|
},
|
101
|
-
es6: {
|
102
|
-
globals: globals.es2015,
|
103
|
-
parserOptions: {
|
104
|
-
ecmaVersion: 6
|
105
|
-
}
|
106
|
-
},
|
107
164
|
greasemonkey: {
|
108
165
|
globals: globals.greasemonkey
|
109
166
|
}
|
@@ -54,6 +54,7 @@ const { ExtractedConfig } = require("./extracted-config");
|
|
54
54
|
* @property {InstanceType<OverrideTester>|null} criteria The tester for the `files` and `excludedFiles` of this config element.
|
55
55
|
* @property {Record<string, boolean>|undefined} env The environment settings.
|
56
56
|
* @property {Record<string, GlobalConf>|undefined} globals The global variable settings.
|
57
|
+
* @property {boolean|undefined} noInlineConfig The flag that disables directive comments.
|
57
58
|
* @property {DependentParser|undefined} parser The parser loader.
|
58
59
|
* @property {Object|undefined} parserOptions The parser options.
|
59
60
|
* @property {Record<string, DependentPlugin>|undefined} plugins The plugin loaders.
|
@@ -250,6 +251,12 @@ function createConfig(instance, indices) {
|
|
250
251
|
config.processor = element.processor;
|
251
252
|
}
|
252
253
|
|
254
|
+
// Adopt the noInlineConfig which was found at first.
|
255
|
+
if (config.noInlineConfig === void 0 && element.noInlineConfig !== void 0) {
|
256
|
+
config.noInlineConfig = element.noInlineConfig;
|
257
|
+
config.configNameOfNoInlineConfig = element.name;
|
258
|
+
}
|
259
|
+
|
253
260
|
// Merge others.
|
254
261
|
mergeWithoutOverwrite(config.env, element.env);
|
255
262
|
mergeWithoutOverwrite(config.globals, element.globals);
|
@@ -29,6 +29,12 @@
|
|
29
29
|
class ExtractedConfig {
|
30
30
|
constructor() {
|
31
31
|
|
32
|
+
/**
|
33
|
+
* The config name what `noInlineConfig` setting came from.
|
34
|
+
* @type {string}
|
35
|
+
*/
|
36
|
+
this.configNameOfNoInlineConfig = "";
|
37
|
+
|
32
38
|
/**
|
33
39
|
* Environments.
|
34
40
|
* @type {Record<string, boolean>}
|
@@ -41,6 +47,12 @@ class ExtractedConfig {
|
|
41
47
|
*/
|
42
48
|
this.globals = {};
|
43
49
|
|
50
|
+
/**
|
51
|
+
* The flag that disables directive comments.
|
52
|
+
* @type {boolean|undefined}
|
53
|
+
*/
|
54
|
+
this.noInlineConfig = void 0;
|
55
|
+
|
44
56
|
/**
|
45
57
|
* Parser definition.
|
46
58
|
* @type {DependentParser|null}
|
@@ -84,7 +96,10 @@ class ExtractedConfig {
|
|
84
96
|
*/
|
85
97
|
toCompatibleObjectAsConfigFileContent() {
|
86
98
|
const {
|
87
|
-
|
99
|
+
/* eslint-disable no-unused-vars */
|
100
|
+
configNameOfNoInlineConfig: _ignore1,
|
101
|
+
processor: _ignore2,
|
102
|
+
/* eslint-enable no-unused-vars */
|
88
103
|
...config
|
89
104
|
} = this;
|
90
105
|
|
@@ -526,6 +526,7 @@ class ConfigArrayFactory {
|
|
526
526
|
env,
|
527
527
|
extends: extend,
|
528
528
|
globals,
|
529
|
+
noInlineConfig,
|
529
530
|
parser: parserName,
|
530
531
|
parserOptions,
|
531
532
|
plugins: pluginList,
|
@@ -567,6 +568,7 @@ class ConfigArrayFactory {
|
|
567
568
|
criteria: null,
|
568
569
|
env,
|
569
570
|
globals,
|
571
|
+
noInlineConfig,
|
570
572
|
parser,
|
571
573
|
parserOptions,
|
572
574
|
plugins,
|
package/lib/init/npm-utils.js
CHANGED
@@ -135,7 +135,7 @@ function check(packages, opt) {
|
|
135
135
|
* Check whether node modules are included in the dependencies of a project's
|
136
136
|
* package.json.
|
137
137
|
*
|
138
|
-
*
|
138
|
+
* Convenience wrapper around check().
|
139
139
|
*
|
140
140
|
* @param {string[]} packages Array of node modules to check.
|
141
141
|
* @param {string} rootDir The directory contianing a package.json
|
@@ -150,7 +150,7 @@ function checkDeps(packages, rootDir) {
|
|
150
150
|
* Check whether node modules are included in the devDependencies of a project's
|
151
151
|
* package.json.
|
152
152
|
*
|
153
|
-
*
|
153
|
+
* Convenience wrapper around check().
|
154
154
|
*
|
155
155
|
* @param {string[]} packages Array of node modules to check.
|
156
156
|
* @returns {Object} An object whose keys are the module names
|
package/lib/linter/linter.js
CHANGED
@@ -198,14 +198,20 @@ function createMissingRuleMessage(ruleId) {
|
|
198
198
|
/**
|
199
199
|
* creates a linting problem
|
200
200
|
* @param {Object} options to create linting error
|
201
|
-
* @param {string} options.ruleId the ruleId to report
|
202
|
-
* @param {Object} options.loc the loc to report
|
203
|
-
* @param {string} options.message the error message to report
|
204
|
-
* @
|
201
|
+
* @param {string} [options.ruleId] the ruleId to report
|
202
|
+
* @param {Object} [options.loc] the loc to report
|
203
|
+
* @param {string} [options.message] the error message to report
|
204
|
+
* @param {string} [options.severity] the error message to report
|
205
|
+
* @returns {LintMessage} created problem, returns a missing-rule problem if only provided ruleId.
|
205
206
|
* @private
|
206
207
|
*/
|
207
208
|
function createLintingProblem(options) {
|
208
|
-
const {
|
209
|
+
const {
|
210
|
+
ruleId = null,
|
211
|
+
loc = DEFAULT_ERROR_LOC,
|
212
|
+
message = createMissingRuleMessage(options.ruleId),
|
213
|
+
severity = 2
|
214
|
+
} = options;
|
209
215
|
|
210
216
|
return {
|
211
217
|
ruleId,
|
@@ -214,7 +220,7 @@ function createLintingProblem(options) {
|
|
214
220
|
column: loc.start.column + 1,
|
215
221
|
endLine: loc.end.line,
|
216
222
|
endColumn: loc.end.column + 1,
|
217
|
-
severity
|
223
|
+
severity,
|
218
224
|
nodeType: null
|
219
225
|
};
|
220
226
|
}
|
@@ -257,10 +263,11 @@ function createDisableDirectives(options) {
|
|
257
263
|
* @param {string} filename The file being checked.
|
258
264
|
* @param {ASTNode} ast The top node of the AST.
|
259
265
|
* @param {function(string): {create: Function}} ruleMapper A map from rule IDs to defined rules
|
266
|
+
* @param {string|null} warnInlineConfig If a string then it should warn directive comments as disabled. The string value is the config name what the setting came from.
|
260
267
|
* @returns {{configuredRules: Object, enabledGlobals: {value:string,comment:Token}[], exportedVariables: Object, problems: Problem[], disableDirectives: DisableDirective[]}}
|
261
268
|
* A collection of the directive comments that were found, along with any problems that occurred when parsing
|
262
269
|
*/
|
263
|
-
function getDirectiveComments(filename, ast, ruleMapper) {
|
270
|
+
function getDirectiveComments(filename, ast, ruleMapper, warnInlineConfig) {
|
264
271
|
const configuredRules = {};
|
265
272
|
const enabledGlobals = Object.create(null);
|
266
273
|
const exportedVariables = {};
|
@@ -269,16 +276,29 @@ function getDirectiveComments(filename, ast, ruleMapper) {
|
|
269
276
|
|
270
277
|
ast.comments.filter(token => token.type !== "Shebang").forEach(comment => {
|
271
278
|
const trimmedCommentText = comment.value.trim();
|
272
|
-
const match = /^(eslint(
|
279
|
+
const match = /^(eslint(?:-env|-enable|-disable(?:(?:-next)?-line)?)?|exported|globals?)(?:\s|$)/u.exec(trimmedCommentText);
|
273
280
|
|
274
281
|
if (!match) {
|
275
282
|
return;
|
276
283
|
}
|
284
|
+
const lineCommentSupported = /^eslint-disable-(next-)?line$/u.test(match[1]);
|
285
|
+
|
286
|
+
if (warnInlineConfig && (lineCommentSupported || comment.type === "Block")) {
|
287
|
+
const kind = comment.type === "Block" ? `/*${match[1]}*/` : `//${match[1]}`;
|
288
|
+
|
289
|
+
problems.push(createLintingProblem({
|
290
|
+
ruleId: null,
|
291
|
+
message: `'${kind}' has no effect because you have 'noInlineConfig' setting in ${warnInlineConfig}.`,
|
292
|
+
loc: comment.loc,
|
293
|
+
severity: 1
|
294
|
+
}));
|
295
|
+
return;
|
296
|
+
}
|
277
297
|
|
278
298
|
const directiveValue = trimmedCommentText.slice(match.index + match[1].length);
|
279
299
|
let directiveType = "";
|
280
300
|
|
281
|
-
if (
|
301
|
+
if (lineCommentSupported) {
|
282
302
|
if (comment.loc.start.line === comment.loc.end.line) {
|
283
303
|
directiveType = match[1].slice("eslint-".length);
|
284
304
|
} else {
|
@@ -441,16 +461,27 @@ function normalizeFilename(filename) {
|
|
441
461
|
return index === -1 ? filename : parts.slice(index).join(path.sep);
|
442
462
|
}
|
443
463
|
|
464
|
+
// eslint-disable-next-line valid-jsdoc
|
444
465
|
/**
|
445
466
|
* Normalizes the possible options for `linter.verify` and `linter.verifyAndFix` to a
|
446
467
|
* consistent shape.
|
447
468
|
* @param {VerifyOptions} providedOptions Options
|
448
|
-
* @
|
469
|
+
* @param {ConfigData} config Config.
|
470
|
+
* @returns {Required<VerifyOptions> & { warnInlineConfig: string|null }} Normalized options
|
449
471
|
*/
|
450
|
-
function normalizeVerifyOptions(providedOptions) {
|
472
|
+
function normalizeVerifyOptions(providedOptions, config) {
|
473
|
+
const disableInlineConfig = config.noInlineConfig === true;
|
474
|
+
const ignoreInlineConfig = providedOptions.allowInlineConfig === false;
|
475
|
+
const configNameOfNoInlineConfig = config.configNameOfNoInlineConfig
|
476
|
+
? ` (${config.configNameOfNoInlineConfig})`
|
477
|
+
: "";
|
478
|
+
|
451
479
|
return {
|
452
480
|
filename: normalizeFilename(providedOptions.filename || "<input>"),
|
453
|
-
allowInlineConfig:
|
481
|
+
allowInlineConfig: !ignoreInlineConfig,
|
482
|
+
warnInlineConfig: disableInlineConfig && !ignoreInlineConfig
|
483
|
+
? `your config${configNameOfNoInlineConfig}`
|
484
|
+
: null,
|
454
485
|
reportUnusedDisableDirectives: Boolean(providedOptions.reportUnusedDisableDirectives),
|
455
486
|
disableFixes: Boolean(providedOptions.disableFixes)
|
456
487
|
};
|
@@ -984,7 +1015,7 @@ class Linter {
|
|
984
1015
|
_verifyWithoutProcessors(textOrSourceCode, providedConfig, providedOptions) {
|
985
1016
|
const slots = internalSlotsMap.get(this);
|
986
1017
|
const config = providedConfig || {};
|
987
|
-
const options = normalizeVerifyOptions(providedOptions);
|
1018
|
+
const options = normalizeVerifyOptions(providedOptions, config);
|
988
1019
|
let text;
|
989
1020
|
|
990
1021
|
// evaluate arguments
|
@@ -1019,7 +1050,9 @@ class Linter {
|
|
1019
1050
|
}
|
1020
1051
|
|
1021
1052
|
// search and apply "eslint-env *".
|
1022
|
-
const envInFile =
|
1053
|
+
const envInFile = options.allowInlineConfig && !options.warnInlineConfig
|
1054
|
+
? findEslintEnv(text)
|
1055
|
+
: {};
|
1023
1056
|
const resolvedEnvConfig = Object.assign({ builtin: true }, config.env, envInFile);
|
1024
1057
|
const enabledEnvs = Object.keys(resolvedEnvConfig)
|
1025
1058
|
.filter(envName => resolvedEnvConfig[envName])
|
@@ -1062,7 +1095,7 @@ class Linter {
|
|
1062
1095
|
|
1063
1096
|
const sourceCode = slots.lastSourceCode;
|
1064
1097
|
const commentDirectives = options.allowInlineConfig
|
1065
|
-
? getDirectiveComments(options.filename, sourceCode.ast, ruleId => getRule(slots, ruleId))
|
1098
|
+
? getDirectiveComments(options.filename, sourceCode.ast, ruleId => getRule(slots, ruleId), options.warnInlineConfig)
|
1066
1099
|
: { configuredRules: {}, enabledGlobals: {}, exportedVariables: {}, problems: [], disableDirectives: [] };
|
1067
1100
|
|
1068
1101
|
// augment global scope with declared global variables
|