eslint 4.7.0 → 4.7.1
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 +5 -0
- package/lib/linter.js +9 -7
- package/lib/util/apply-disable-directives.js +58 -42
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
v4.7.1 - September 18, 2017
|
2
|
+
|
3
|
+
* 08656db Fix: Handle nested disable directive correctly (fixes #9318) (#9322) (Gyandeep Singh)
|
4
|
+
* 9226495 Revert "Chore: rewrite parseListConfig for a small perf gain." (#9325) (薛定谔的猫)
|
5
|
+
|
1
6
|
v4.7.0 - September 15, 2017
|
2
7
|
|
3
8
|
* 787b78b Upgrade: Espree v3.5.1 (fixes #9153) (#9314) (Brandon Mills)
|
package/lib/linter.js
CHANGED
@@ -146,15 +146,17 @@ function parseJsonConfig(string, location) {
|
|
146
146
|
*/
|
147
147
|
function parseListConfig(string) {
|
148
148
|
const items = {};
|
149
|
-
const reg = /[\w\-/]+/g;
|
150
|
-
const elementMatches = string.match(reg);
|
151
149
|
|
152
|
-
|
153
|
-
|
154
|
-
items[name] = true;
|
155
|
-
});
|
156
|
-
}
|
150
|
+
// Collapse whitespace around ,
|
151
|
+
string = string.replace(/\s*,\s*/g, ",");
|
157
152
|
|
153
|
+
string.split(/,+/).forEach(name => {
|
154
|
+
name = name.trim();
|
155
|
+
if (!name) {
|
156
|
+
return;
|
157
|
+
}
|
158
|
+
items[name] = true;
|
159
|
+
});
|
158
160
|
return items;
|
159
161
|
}
|
160
162
|
|
@@ -19,46 +19,11 @@ function compareLocations(itemA, itemB) {
|
|
19
19
|
}
|
20
20
|
|
21
21
|
/**
|
22
|
-
*
|
23
|
-
*
|
24
|
-
* @
|
25
|
-
* @param {{
|
26
|
-
* type: ("disable"|"enable"|"disable-line"|"disable-next-line"),
|
27
|
-
* ruleId: (string|null),
|
28
|
-
* line: number,
|
29
|
-
* column: number
|
30
|
-
* }} options.directives Directive comments found in the file, with one-based columns.
|
31
|
-
* Two directive comments can only have the same location if they also have the same type (e.g. a single eslint-disable
|
32
|
-
* comment for two different rules is represented as two directives).
|
33
|
-
* @param {{ruleId: (string|null), line: number, column: number}[]} options.problems
|
34
|
-
* A list of problems reported by rules, sorted by increasing location in the file, with one-based columns.
|
35
|
-
* @returns {{ruleId: (string|null), line: number, column: number}[]}
|
36
|
-
* A list of reported problems that were not disabled by the directive comments.
|
22
|
+
* This is the same as the exported function, except that it doesn't handle disable-line and disable-next-line directives.
|
23
|
+
* @param {Object} options options (see the exported function)
|
24
|
+
* @returns {Problem[]} Filtered problems (see the exported function)
|
37
25
|
*/
|
38
|
-
|
39
|
-
const processedDirectives = lodash.flatMap(options.directives, directive => {
|
40
|
-
switch (directive.type) {
|
41
|
-
case "disable":
|
42
|
-
case "enable":
|
43
|
-
return [directive];
|
44
|
-
|
45
|
-
case "disable-line":
|
46
|
-
return [
|
47
|
-
{ type: "disable", line: directive.line, column: 1, ruleId: directive.ruleId },
|
48
|
-
{ type: "enable", line: directive.line + 1, column: 1, ruleId: directive.ruleId }
|
49
|
-
];
|
50
|
-
|
51
|
-
case "disable-next-line":
|
52
|
-
return [
|
53
|
-
{ type: "disable", line: directive.line + 1, column: 1, ruleId: directive.ruleId },
|
54
|
-
{ type: "enable", line: directive.line + 2, column: 1, ruleId: directive.ruleId }
|
55
|
-
];
|
56
|
-
|
57
|
-
default:
|
58
|
-
throw new TypeError(`Unrecognized directive type '${directive.type}'`);
|
59
|
-
}
|
60
|
-
}).sort(compareLocations);
|
61
|
-
|
26
|
+
function applyDirectives(options) {
|
62
27
|
const problems = [];
|
63
28
|
let nextDirectiveIndex = 0;
|
64
29
|
let globalDisableActive = false;
|
@@ -71,10 +36,10 @@ module.exports = options => {
|
|
71
36
|
|
72
37
|
for (const problem of options.problems) {
|
73
38
|
while (
|
74
|
-
nextDirectiveIndex <
|
75
|
-
compareLocations(
|
39
|
+
nextDirectiveIndex < options.directives.length &&
|
40
|
+
compareLocations(options.directives[nextDirectiveIndex], problem) <= 0
|
76
41
|
) {
|
77
|
-
const directive =
|
42
|
+
const directive = options.directives[nextDirectiveIndex++];
|
78
43
|
|
79
44
|
switch (directive.type) {
|
80
45
|
case "disable":
|
@@ -112,4 +77,55 @@ module.exports = options => {
|
|
112
77
|
}
|
113
78
|
|
114
79
|
return problems;
|
80
|
+
}
|
81
|
+
|
82
|
+
/**
|
83
|
+
* Given a list of directive comments (i.e. metadata about eslint-disable and eslint-enable comments) and a list
|
84
|
+
* of reported problems, determines which problems should be reported.
|
85
|
+
* @param {Object} options Information about directives and problems
|
86
|
+
* @param {{
|
87
|
+
* type: ("disable"|"enable"|"disable-line"|"disable-next-line"),
|
88
|
+
* ruleId: (string|null),
|
89
|
+
* line: number,
|
90
|
+
* column: number
|
91
|
+
* }} options.directives Directive comments found in the file, with one-based columns.
|
92
|
+
* Two directive comments can only have the same location if they also have the same type (e.g. a single eslint-disable
|
93
|
+
* comment for two different rules is represented as two directives).
|
94
|
+
* @param {{ruleId: (string|null), line: number, column: number}[]} options.problems
|
95
|
+
* A list of problems reported by rules, sorted by increasing location in the file, with one-based columns.
|
96
|
+
* @returns {{ruleId: (string|null), line: number, column: number}[]}
|
97
|
+
* A list of reported problems that were not disabled by the directive comments.
|
98
|
+
*/
|
99
|
+
module.exports = options => {
|
100
|
+
const blockDirectives = options.directives
|
101
|
+
.filter(directive => directive.type === "disable" || directive.type === "enable")
|
102
|
+
.sort(compareLocations);
|
103
|
+
|
104
|
+
const lineDirectives = lodash.flatMap(options.directives, directive => {
|
105
|
+
switch (directive.type) {
|
106
|
+
case "disable":
|
107
|
+
case "enable":
|
108
|
+
return [];
|
109
|
+
|
110
|
+
case "disable-line":
|
111
|
+
return [
|
112
|
+
{ type: "disable", line: directive.line, column: 1, ruleId: directive.ruleId },
|
113
|
+
{ type: "enable", line: directive.line + 1, column: 0, ruleId: directive.ruleId }
|
114
|
+
];
|
115
|
+
|
116
|
+
case "disable-next-line":
|
117
|
+
return [
|
118
|
+
{ type: "disable", line: directive.line + 1, column: 1, ruleId: directive.ruleId },
|
119
|
+
{ type: "enable", line: directive.line + 2, column: 0, ruleId: directive.ruleId }
|
120
|
+
];
|
121
|
+
|
122
|
+
default:
|
123
|
+
throw new TypeError(`Unrecognized directive type '${directive.type}'`);
|
124
|
+
}
|
125
|
+
}).sort(compareLocations);
|
126
|
+
|
127
|
+
const problemsAfterBlockDirectives = applyDirectives({ problems: options.problems, directives: blockDirectives });
|
128
|
+
const problemsAfterLineDirectives = applyDirectives({ problems: problemsAfterBlockDirectives, directives: lineDirectives });
|
129
|
+
|
130
|
+
return problemsAfterLineDirectives.sort(compareLocations);
|
115
131
|
};
|