eslint 8.20.0 → 8.21.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/lib/config/default-config.js +16 -7
- package/lib/config/flat-config-array.js +41 -2
- package/lib/config/flat-config-helpers.js +9 -1
- package/lib/eslint/eslint-helpers.js +621 -0
- package/lib/eslint/flat-eslint.js +1164 -0
- package/lib/eslint/index.js +3 -1
- package/lib/linter/linter.js +18 -1
- package/lib/rule-tester/flat-rule-tester.js +41 -38
- package/lib/rule-tester/rule-tester.js +42 -0
- package/lib/rules/key-spacing.js +4 -1
- package/lib/rules/lines-around-comment.js +11 -4
- package/lib/rules/sort-keys.js +43 -0
- package/lib/unsupported-api.js +4 -0
- package/package.json +9 -5
package/lib/eslint/index.js
CHANGED
package/lib/linter/linter.js
CHANGED
@@ -1608,6 +1608,11 @@ class Linter {
|
|
1608
1608
|
...languageOptions.globals
|
1609
1609
|
};
|
1610
1610
|
|
1611
|
+
// double check that there is a parser to avoid mysterious error messages
|
1612
|
+
if (!languageOptions.parser) {
|
1613
|
+
throw new TypeError(`No parser specified for ${options.filename}`);
|
1614
|
+
}
|
1615
|
+
|
1611
1616
|
// Espree expects this information to be passed in
|
1612
1617
|
if (isEspree(languageOptions.parser)) {
|
1613
1618
|
const parserOptions = languageOptions.parserOptions;
|
@@ -1770,12 +1775,24 @@ class Linter {
|
|
1770
1775
|
debug("With flat config: %s", options.filename);
|
1771
1776
|
|
1772
1777
|
// we need a filename to match configs against
|
1773
|
-
const filename = options.filename || "
|
1778
|
+
const filename = options.filename || "__placeholder__.js";
|
1774
1779
|
|
1775
1780
|
// Store the config array in order to get plugin envs and rules later.
|
1776
1781
|
internalSlotsMap.get(this).lastConfigArray = configArray;
|
1777
1782
|
const config = configArray.getConfig(filename);
|
1778
1783
|
|
1784
|
+
if (!config) {
|
1785
|
+
return [
|
1786
|
+
{
|
1787
|
+
ruleId: null,
|
1788
|
+
severity: 1,
|
1789
|
+
message: `No matching configuration found for ${filename}.`,
|
1790
|
+
line: 0,
|
1791
|
+
column: 0
|
1792
|
+
}
|
1793
|
+
];
|
1794
|
+
}
|
1795
|
+
|
1779
1796
|
// Verify.
|
1780
1797
|
if (config.processor) {
|
1781
1798
|
debug("Apply the processor: %o", config.processor);
|
@@ -480,51 +480,54 @@ class FlatRuleTester {
|
|
480
480
|
].concat(scenarioErrors).join("\n"));
|
481
481
|
}
|
482
482
|
|
483
|
-
const baseConfig =
|
484
|
-
|
485
|
-
|
486
|
-
// copy root plugin over
|
487
|
-
"@": {
|
488
|
-
|
489
|
-
/*
|
490
|
-
* Parsers are wrapped to detect more errors, so this needs
|
491
|
-
* to be a new object for each call to run(), otherwise the
|
492
|
-
* parsers will be wrapped multiple times.
|
493
|
-
*/
|
494
|
-
parsers: {
|
495
|
-
...defaultConfig[0].plugins["@"].parsers
|
496
|
-
},
|
483
|
+
const baseConfig = [
|
484
|
+
{
|
485
|
+
plugins: {
|
497
486
|
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
487
|
+
// copy root plugin over
|
488
|
+
"@": {
|
489
|
+
|
490
|
+
/*
|
491
|
+
* Parsers are wrapped to detect more errors, so this needs
|
492
|
+
* to be a new object for each call to run(), otherwise the
|
493
|
+
* parsers will be wrapped multiple times.
|
494
|
+
*/
|
495
|
+
parsers: {
|
496
|
+
...defaultConfig[0].plugins["@"].parsers
|
497
|
+
},
|
498
|
+
|
499
|
+
/*
|
500
|
+
* The rules key on the default plugin is a proxy to lazy-load
|
501
|
+
* just the rules that are needed. So, don't create a new object
|
502
|
+
* here, just use the default one to keep that performance
|
503
|
+
* enhancement.
|
504
|
+
*/
|
505
|
+
rules: defaultConfig[0].plugins["@"].rules
|
506
|
+
},
|
507
|
+
"rule-to-test": {
|
508
|
+
rules: {
|
509
|
+
[ruleName]: Object.assign({}, rule, {
|
509
510
|
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
511
|
+
// Create a wrapper rule that freezes the `context` properties.
|
512
|
+
create(context) {
|
513
|
+
freezeDeeply(context.options);
|
514
|
+
freezeDeeply(context.settings);
|
515
|
+
freezeDeeply(context.parserOptions);
|
515
516
|
|
516
|
-
|
517
|
+
// freezeDeeply(context.languageOptions);
|
517
518
|
|
518
|
-
|
519
|
-
|
520
|
-
|
519
|
+
return (typeof rule === "function" ? rule : rule.create)(context);
|
520
|
+
}
|
521
|
+
})
|
522
|
+
}
|
521
523
|
}
|
524
|
+
},
|
525
|
+
languageOptions: {
|
526
|
+
...defaultConfig[0].languageOptions
|
522
527
|
}
|
523
528
|
},
|
524
|
-
|
525
|
-
|
526
|
-
}
|
527
|
-
};
|
529
|
+
...defaultConfig.slice(1)
|
530
|
+
];
|
528
531
|
|
529
532
|
/**
|
530
533
|
* Run the rule for the given item
|
@@ -305,6 +305,36 @@ function getCommentsDeprecation() {
|
|
305
305
|
);
|
306
306
|
}
|
307
307
|
|
308
|
+
/**
|
309
|
+
* Emit a deprecation warning if function-style format is being used.
|
310
|
+
* @param {string} ruleName Name of the rule.
|
311
|
+
* @returns {void}
|
312
|
+
*/
|
313
|
+
function emitLegacyRuleAPIWarning(ruleName) {
|
314
|
+
if (!emitLegacyRuleAPIWarning[`warned-${ruleName}`]) {
|
315
|
+
emitLegacyRuleAPIWarning[`warned-${ruleName}`] = true;
|
316
|
+
process.emitWarning(
|
317
|
+
`"${ruleName}" rule is using the deprecated function-style format and will stop working in ESLint v9. Please use object-style format: https://eslint.org/docs/developer-guide/working-with-rules`,
|
318
|
+
"DeprecationWarning"
|
319
|
+
);
|
320
|
+
}
|
321
|
+
}
|
322
|
+
|
323
|
+
/**
|
324
|
+
* Emit a deprecation warning if rule has options but is missing the "meta.schema" property
|
325
|
+
* @param {string} ruleName Name of the rule.
|
326
|
+
* @returns {void}
|
327
|
+
*/
|
328
|
+
function emitMissingSchemaWarning(ruleName) {
|
329
|
+
if (!emitMissingSchemaWarning[`warned-${ruleName}`]) {
|
330
|
+
emitMissingSchemaWarning[`warned-${ruleName}`] = true;
|
331
|
+
process.emitWarning(
|
332
|
+
`"${ruleName}" rule has options but is missing the "meta.schema" property and will stop working in ESLint v9. Please add a schema: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas`,
|
333
|
+
"DeprecationWarning"
|
334
|
+
);
|
335
|
+
}
|
336
|
+
}
|
337
|
+
|
308
338
|
//------------------------------------------------------------------------------
|
309
339
|
// Public Interface
|
310
340
|
//------------------------------------------------------------------------------
|
@@ -521,6 +551,9 @@ class RuleTester {
|
|
521
551
|
].concat(scenarioErrors).join("\n"));
|
522
552
|
}
|
523
553
|
|
554
|
+
if (typeof rule === "function") {
|
555
|
+
emitLegacyRuleAPIWarning(ruleName);
|
556
|
+
}
|
524
557
|
|
525
558
|
linter.defineRule(ruleName, Object.assign({}, rule, {
|
526
559
|
|
@@ -578,6 +611,15 @@ class RuleTester {
|
|
578
611
|
|
579
612
|
if (hasOwnProperty(item, "options")) {
|
580
613
|
assert(Array.isArray(item.options), "options must be an array");
|
614
|
+
if (
|
615
|
+
item.options.length > 0 &&
|
616
|
+
typeof rule === "object" &&
|
617
|
+
(
|
618
|
+
!rule.meta || (rule.meta && (typeof rule.meta.schema === "undefined" || rule.meta.schema === null))
|
619
|
+
)
|
620
|
+
) {
|
621
|
+
emitMissingSchemaWarning(ruleName);
|
622
|
+
}
|
581
623
|
config.rules[ruleName] = [1].concat(item.options);
|
582
624
|
} else {
|
583
625
|
config.rules[ruleName] = 1;
|
package/lib/rules/key-spacing.js
CHANGED
@@ -9,6 +9,9 @@
|
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
11
|
const astUtils = require("./utils/ast-utils");
|
12
|
+
const GraphemeSplitter = require("grapheme-splitter");
|
13
|
+
|
14
|
+
const splitter = new GraphemeSplitter();
|
12
15
|
|
13
16
|
//------------------------------------------------------------------------------
|
14
17
|
// Helpers
|
@@ -508,7 +511,7 @@ module.exports = {
|
|
508
511
|
const startToken = sourceCode.getFirstToken(property);
|
509
512
|
const endToken = getLastTokenBeforeColon(property.key);
|
510
513
|
|
511
|
-
return
|
514
|
+
return splitter.countGraphemes(sourceCode.getText().slice(startToken.range[0], endToken.range[1]));
|
512
515
|
}
|
513
516
|
|
514
517
|
/**
|
@@ -231,9 +231,15 @@ module.exports = {
|
|
231
231
|
const parent = getParentNodeOfToken(token);
|
232
232
|
|
233
233
|
if (parent && isParentNodeType(parent, nodeType)) {
|
234
|
-
|
235
|
-
|
236
|
-
|
234
|
+
let parentStartNodeOrToken = parent;
|
235
|
+
|
236
|
+
if (parent.type === "StaticBlock") {
|
237
|
+
parentStartNodeOrToken = sourceCode.getFirstToken(parent, { skip: 1 }); // opening brace of the static block
|
238
|
+
} else if (parent.type === "SwitchStatement") {
|
239
|
+
parentStartNodeOrToken = sourceCode.getTokenAfter(parent.discriminant, {
|
240
|
+
filter: astUtils.isOpeningBraceToken
|
241
|
+
}); // opening brace of the switch statement
|
242
|
+
}
|
237
243
|
|
238
244
|
return token.loc.start.line - parentStartNodeOrToken.loc.start.line === 1;
|
239
245
|
}
|
@@ -264,7 +270,8 @@ module.exports = {
|
|
264
270
|
isCommentAtParentStart(token, "ClassBody") ||
|
265
271
|
isCommentAtParentStart(token, "BlockStatement") ||
|
266
272
|
isCommentAtParentStart(token, "StaticBlock") ||
|
267
|
-
isCommentAtParentStart(token, "SwitchCase")
|
273
|
+
isCommentAtParentStart(token, "SwitchCase") ||
|
274
|
+
isCommentAtParentStart(token, "SwitchStatement")
|
268
275
|
);
|
269
276
|
}
|
270
277
|
|
package/lib/rules/sort-keys.js
CHANGED
@@ -105,6 +105,10 @@ module.exports = {
|
|
105
105
|
type: "integer",
|
106
106
|
minimum: 2,
|
107
107
|
default: 2
|
108
|
+
},
|
109
|
+
allowLineSeparatedGroups: {
|
110
|
+
type: "boolean",
|
111
|
+
default: false
|
108
112
|
}
|
109
113
|
},
|
110
114
|
additionalProperties: false
|
@@ -124,17 +128,21 @@ module.exports = {
|
|
124
128
|
const insensitive = options && options.caseSensitive === false;
|
125
129
|
const natural = options && options.natural;
|
126
130
|
const minKeys = options && options.minKeys;
|
131
|
+
const allowLineSeparatedGroups = options && options.allowLineSeparatedGroups || false;
|
127
132
|
const isValidOrder = isValidOrders[
|
128
133
|
order + (insensitive ? "I" : "") + (natural ? "N" : "")
|
129
134
|
];
|
130
135
|
|
131
136
|
// The stack to save the previous property's name for each object literals.
|
132
137
|
let stack = null;
|
138
|
+
const sourceCode = context.getSourceCode();
|
133
139
|
|
134
140
|
return {
|
135
141
|
ObjectExpression(node) {
|
136
142
|
stack = {
|
137
143
|
upper: stack,
|
144
|
+
prevNode: null,
|
145
|
+
prevBlankLine: false,
|
138
146
|
prevName: null,
|
139
147
|
numKeys: node.properties.length
|
140
148
|
};
|
@@ -159,10 +167,45 @@ module.exports = {
|
|
159
167
|
const numKeys = stack.numKeys;
|
160
168
|
const thisName = getPropertyName(node);
|
161
169
|
|
170
|
+
// Get tokens between current node and previous node
|
171
|
+
const tokens = stack.prevNode && sourceCode
|
172
|
+
.getTokensBetween(stack.prevNode, node, { includeComments: true });
|
173
|
+
|
174
|
+
let isBlankLineBetweenNodes = stack.prevBlankLine;
|
175
|
+
|
176
|
+
if (tokens) {
|
177
|
+
|
178
|
+
// check blank line between tokens
|
179
|
+
tokens.forEach((token, index) => {
|
180
|
+
const previousToken = tokens[index - 1];
|
181
|
+
|
182
|
+
if (previousToken && (token.loc.start.line - previousToken.loc.end.line > 1)) {
|
183
|
+
isBlankLineBetweenNodes = true;
|
184
|
+
}
|
185
|
+
});
|
186
|
+
|
187
|
+
// check blank line between the current node and the last token
|
188
|
+
if (!isBlankLineBetweenNodes && (node.loc.start.line - tokens[tokens.length - 1].loc.end.line > 1)) {
|
189
|
+
isBlankLineBetweenNodes = true;
|
190
|
+
}
|
191
|
+
|
192
|
+
// check blank line between the first token and the previous node
|
193
|
+
if (!isBlankLineBetweenNodes && (tokens[0].loc.start.line - stack.prevNode.loc.end.line > 1)) {
|
194
|
+
isBlankLineBetweenNodes = true;
|
195
|
+
}
|
196
|
+
}
|
197
|
+
|
198
|
+
stack.prevNode = node;
|
199
|
+
|
162
200
|
if (thisName !== null) {
|
163
201
|
stack.prevName = thisName;
|
164
202
|
}
|
165
203
|
|
204
|
+
if (allowLineSeparatedGroups && isBlankLineBetweenNodes) {
|
205
|
+
stack.prevBlankLine = thisName === null;
|
206
|
+
return;
|
207
|
+
}
|
208
|
+
|
166
209
|
if (prevName === null || thisName === null || numKeys < minKeys) {
|
167
210
|
return;
|
168
211
|
}
|
package/lib/unsupported-api.js
CHANGED
@@ -12,6 +12,8 @@
|
|
12
12
|
//-----------------------------------------------------------------------------
|
13
13
|
|
14
14
|
const { FileEnumerator } = require("./cli-engine/file-enumerator");
|
15
|
+
const { FlatESLint } = require("./eslint/flat-eslint");
|
16
|
+
const FlatRuleTester = require("./rule-tester/flat-rule-tester");
|
15
17
|
|
16
18
|
//-----------------------------------------------------------------------------
|
17
19
|
// Exports
|
@@ -19,5 +21,7 @@ const { FileEnumerator } = require("./cli-engine/file-enumerator");
|
|
19
21
|
|
20
22
|
module.exports = {
|
21
23
|
builtinRules: require("./rules"),
|
24
|
+
FlatESLint,
|
25
|
+
FlatRuleTester,
|
22
26
|
FileEnumerator
|
23
27
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "eslint",
|
3
|
-
"version": "8.
|
3
|
+
"version": "8.21.0",
|
4
4
|
"author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
|
5
5
|
"description": "An AST-based pattern checker for JavaScript.",
|
6
6
|
"bin": {
|
@@ -55,7 +55,8 @@
|
|
55
55
|
"bugs": "https://github.com/eslint/eslint/issues/",
|
56
56
|
"dependencies": {
|
57
57
|
"@eslint/eslintrc": "^1.3.0",
|
58
|
-
"@humanwhocodes/config-array": "^0.
|
58
|
+
"@humanwhocodes/config-array": "^0.10.4",
|
59
|
+
"@humanwhocodes/gitignore-to-minimatch": "^1.0.2",
|
59
60
|
"ajv": "^6.10.0",
|
60
61
|
"chalk": "^4.0.0",
|
61
62
|
"cross-spawn": "^7.0.2",
|
@@ -65,14 +66,17 @@
|
|
65
66
|
"eslint-scope": "^7.1.1",
|
66
67
|
"eslint-utils": "^3.0.0",
|
67
68
|
"eslint-visitor-keys": "^3.3.0",
|
68
|
-
"espree": "^9.3.
|
69
|
+
"espree": "^9.3.3",
|
69
70
|
"esquery": "^1.4.0",
|
70
71
|
"esutils": "^2.0.2",
|
71
72
|
"fast-deep-equal": "^3.1.3",
|
72
73
|
"file-entry-cache": "^6.0.1",
|
74
|
+
"find-up": "^5.0.0",
|
73
75
|
"functional-red-black-tree": "^1.0.1",
|
74
76
|
"glob-parent": "^6.0.1",
|
75
77
|
"globals": "^13.15.0",
|
78
|
+
"globby": "^11.1.0",
|
79
|
+
"grapheme-splitter": "^1.0.4",
|
76
80
|
"ignore": "^5.2.0",
|
77
81
|
"import-fresh": "^3.0.0",
|
78
82
|
"imurmurhash": "^0.1.4",
|
@@ -105,7 +109,7 @@
|
|
105
109
|
"eslint-plugin-eslint-plugin": "^4.4.0",
|
106
110
|
"eslint-plugin-internal-rules": "file:tools/internal-rules",
|
107
111
|
"eslint-plugin-jsdoc": "^38.1.6",
|
108
|
-
"eslint-plugin-
|
112
|
+
"eslint-plugin-n": "^15.2.4",
|
109
113
|
"eslint-plugin-unicorn": "^42.0.0",
|
110
114
|
"eslint-release": "^3.2.0",
|
111
115
|
"eslump": "^3.0.0",
|
@@ -141,7 +145,7 @@
|
|
141
145
|
"pirates": "^4.0.5",
|
142
146
|
"progress": "^2.0.3",
|
143
147
|
"proxyquire": "^2.0.1",
|
144
|
-
"puppeteer": "^
|
148
|
+
"puppeteer": "^13.7.0",
|
145
149
|
"recast": "^0.20.4",
|
146
150
|
"regenerator-runtime": "^0.13.2",
|
147
151
|
"semver": "^7.3.5",
|