eslint 10.0.0-alpha.0 → 10.0.0-beta.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/README.md +1 -1
- package/lib/api.js +2 -2
- package/lib/cli-engine/formatters/stylish.js +65 -34
- package/lib/cli.js +18 -8
- package/lib/eslint/eslint.js +4 -2
- package/lib/languages/js/index.js +1 -0
- package/lib/languages/js/source-code/source-code.js +27 -165
- package/lib/languages/js/source-code/token-store/index.js +0 -26
- package/lib/linter/linter.js +1 -0
- package/lib/rule-tester/rule-tester.js +117 -43
- package/lib/rules/array-bracket-spacing.js +4 -4
- package/lib/rules/block-spacing.js +1 -1
- package/lib/rules/comma-spacing.js +2 -5
- package/lib/rules/computed-property-spacing.js +4 -4
- package/lib/rules/keyword-spacing.js +4 -4
- package/lib/rules/no-extra-parens.js +1 -1
- package/lib/rules/no-restricted-imports.js +56 -14
- package/lib/rules/no-spaced-func.js +1 -1
- package/lib/rules/no-useless-assignment.js +8 -5
- package/lib/rules/no-useless-constructor.js +13 -3
- package/lib/rules/no-whitespace-before-property.js +1 -1
- package/lib/rules/object-curly-spacing.js +2 -8
- package/lib/rules/require-yield.js +11 -1
- package/lib/rules/rest-spread-spacing.js +1 -4
- package/lib/rules/semi-spacing.js +2 -2
- package/lib/rules/space-before-blocks.js +1 -1
- package/lib/rules/space-before-function-paren.js +1 -4
- package/lib/rules/space-in-parens.js +4 -4
- package/lib/rules/space-infix-ops.js +4 -7
- package/lib/rules/switch-colon-spacing.js +1 -1
- package/lib/rules/template-tag-spacing.js +1 -1
- package/lib/rules/utils/ast-utils.js +117 -22
- package/lib/rules/yield-star-spacing.js +1 -2
- package/lib/types/index.d.ts +59 -36
- package/lib/types/use-at-your-own-risk.d.ts +1 -1
- package/package.json +5 -6
package/README.md
CHANGED
|
@@ -343,7 +343,7 @@ to get your logo on our READMEs and [website](https://eslint.org/sponsors).
|
|
|
343
343
|
<p><a href="https://automattic.com"><img src="https://images.opencollective.com/automattic/d0ef3e1/logo.png" alt="Automattic" height="128"></a> <a href="https://www.airbnb.com/"><img src="https://images.opencollective.com/airbnb/d327d66/logo.png" alt="Airbnb" height="128"></a></p><h3>Gold Sponsors</h3>
|
|
344
344
|
<p><a href="https://qlty.sh/"><img src="https://images.opencollective.com/qltysh/33d157d/logo.png" alt="Qlty Software" height="96"></a> <a href="https://shopify.engineering/"><img src="https://avatars.githubusercontent.com/u/8085" alt="Shopify" height="96"></a></p><h3>Silver Sponsors</h3>
|
|
345
345
|
<p><a href="https://vite.dev/"><img src="https://images.opencollective.com/vite/e6d15e1/logo.png" alt="Vite" height="64"></a> <a href="https://liftoff.io/"><img src="https://images.opencollective.com/liftoff/2d6c3b6/logo.png" alt="Liftoff" height="64"></a> <a href="https://americanexpress.io"><img src="https://avatars.githubusercontent.com/u/3853301" alt="American Express" height="64"></a> <a href="https://stackblitz.com"><img src="https://avatars.githubusercontent.com/u/28635252" alt="StackBlitz" height="64"></a></p><h3>Bronze Sponsors</h3>
|
|
346
|
-
<p><a href="https://cybozu.co.jp/"><img src="https://images.opencollective.com/cybozu/933e46d/logo.png" alt="Cybozu" height="32"></a> <a href="https://syntax.fm"><img src="https://github.com/syntaxfm.png" alt="Syntax" height="32"></a> <a href="https://
|
|
346
|
+
<p><a href="https://cybozu.co.jp/"><img src="https://images.opencollective.com/cybozu/933e46d/logo.png" alt="Cybozu" height="32"></a> <a href="https://www.crawljobs.com/"><img src="https://images.opencollective.com/crawljobs-poland/fa43a17/logo.png" alt="CrawlJobs" height="32"></a> <a href="https://syntax.fm"><img src="https://github.com/syntaxfm.png" alt="Syntax" height="32"></a> <a href="https://www.n-ix.com/"><img src="https://images.opencollective.com/n-ix-ltd/575a7a5/logo.png" alt="N-iX Ltd" height="32"></a> <a href="https://icons8.com/"><img src="https://images.opencollective.com/icons8/7fa1641/logo.png" alt="Icons8" height="32"></a> <a href="https://discord.com"><img src="https://images.opencollective.com/discordapp/f9645d9/logo.png" alt="Discord" height="32"></a> <a href="https://www.gitbook.com"><img src="https://avatars.githubusercontent.com/u/7111340" alt="GitBook" height="32"></a> <a href="https://nx.dev"><img src="https://avatars.githubusercontent.com/u/23692104" alt="Nx" height="32"></a> <a href="https://herocoders.com"><img src="https://avatars.githubusercontent.com/u/37549774" alt="HeroCoders" height="32"></a> <a href="https://www.lambdatest.com"><img src="https://avatars.githubusercontent.com/u/171592363" alt="LambdaTest" height="32"></a></p>
|
|
347
347
|
<h3>Technology Sponsors</h3>
|
|
348
348
|
Technology sponsors allow us to use their products and services for free as part of a contribution to the open source ecosystem and our work.
|
|
349
349
|
<p><a href="https://netlify.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/netlify-icon.svg" alt="Netlify" height="32"></a> <a href="https://algolia.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/algolia-icon.svg" alt="Algolia" height="32"></a> <a href="https://1password.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/1password-icon.svg" alt="1Password" height="32"></a></p>
|
package/lib/api.js
CHANGED
|
@@ -19,8 +19,8 @@ const { SourceCode } = require("./languages/js/source-code");
|
|
|
19
19
|
//-----------------------------------------------------------------------------
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
* Loads the correct ESLint constructor
|
|
23
|
-
* @returns {Promise<ESLint>} The ESLint constructor
|
|
22
|
+
* Loads the correct `ESLint` constructor.
|
|
23
|
+
* @returns {Promise<ESLint>} The ESLint constructor.
|
|
24
24
|
*/
|
|
25
25
|
async function loadESLint() {
|
|
26
26
|
return ESLint;
|
|
@@ -4,14 +4,30 @@
|
|
|
4
4
|
*/
|
|
5
5
|
"use strict";
|
|
6
6
|
|
|
7
|
-
const
|
|
8
|
-
util = require("node:util"),
|
|
7
|
+
const util = require("node:util"),
|
|
9
8
|
table = require("../../shared/text-table");
|
|
10
9
|
|
|
11
10
|
//------------------------------------------------------------------------------
|
|
12
11
|
// Helpers
|
|
13
12
|
//------------------------------------------------------------------------------
|
|
14
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Returns a styling function based on the color option.
|
|
16
|
+
* @param {boolean|undefined} color Indicates whether to use colors.
|
|
17
|
+
* @returns {Function} A function that styles text.
|
|
18
|
+
*/
|
|
19
|
+
function getStyleText(color) {
|
|
20
|
+
if (typeof color === "undefined") {
|
|
21
|
+
return (format, text) =>
|
|
22
|
+
util.styleText(format, text, { validateStream: true });
|
|
23
|
+
}
|
|
24
|
+
if (color) {
|
|
25
|
+
return (format, text) =>
|
|
26
|
+
util.styleText(format, text, { validateStream: false });
|
|
27
|
+
}
|
|
28
|
+
return (_, text) => text;
|
|
29
|
+
}
|
|
30
|
+
|
|
15
31
|
/**
|
|
16
32
|
* Given a word and a count, append an s if count is not one.
|
|
17
33
|
* @param {string} word A word in its singular form.
|
|
@@ -26,7 +42,9 @@ function pluralize(word, count) {
|
|
|
26
42
|
// Public Interface
|
|
27
43
|
//------------------------------------------------------------------------------
|
|
28
44
|
|
|
29
|
-
module.exports = function (results) {
|
|
45
|
+
module.exports = function (results, data) {
|
|
46
|
+
const styleText = getStyleText(data?.color);
|
|
47
|
+
|
|
30
48
|
let output = "\n",
|
|
31
49
|
errorCount = 0,
|
|
32
50
|
warningCount = 0,
|
|
@@ -46,17 +64,17 @@ module.exports = function (results) {
|
|
|
46
64
|
fixableErrorCount += result.fixableErrorCount;
|
|
47
65
|
fixableWarningCount += result.fixableWarningCount;
|
|
48
66
|
|
|
49
|
-
output += `${
|
|
67
|
+
output += `${styleText("underline", result.filePath)}\n`;
|
|
50
68
|
|
|
51
69
|
output += `${table(
|
|
52
70
|
messages.map(message => {
|
|
53
71
|
let messageType;
|
|
54
72
|
|
|
55
73
|
if (message.fatal || message.severity === 2) {
|
|
56
|
-
messageType =
|
|
74
|
+
messageType = styleText("red", "error");
|
|
57
75
|
summaryColor = "red";
|
|
58
76
|
} else {
|
|
59
|
-
messageType =
|
|
77
|
+
messageType = styleText("yellow", "warning");
|
|
60
78
|
}
|
|
61
79
|
|
|
62
80
|
return [
|
|
@@ -65,7 +83,7 @@ module.exports = function (results) {
|
|
|
65
83
|
String(message.column || 0),
|
|
66
84
|
messageType,
|
|
67
85
|
message.message.replace(/([^ ])\.$/u, "$1"),
|
|
68
|
-
|
|
86
|
+
message.ruleId ? styleText("dim", message.ruleId) : "",
|
|
69
87
|
];
|
|
70
88
|
}),
|
|
71
89
|
{
|
|
@@ -78,7 +96,7 @@ module.exports = function (results) {
|
|
|
78
96
|
.split("\n")
|
|
79
97
|
.map(el =>
|
|
80
98
|
el.replace(/(\d+)\s+(\d+)/u, (m, p1, p2) =>
|
|
81
|
-
|
|
99
|
+
styleText("dim", `${p1}:${p2}`),
|
|
82
100
|
),
|
|
83
101
|
)
|
|
84
102
|
.join("\n")}\n\n`;
|
|
@@ -86,37 +104,50 @@ module.exports = function (results) {
|
|
|
86
104
|
|
|
87
105
|
const total = errorCount + warningCount;
|
|
88
106
|
|
|
107
|
+
/*
|
|
108
|
+
* We can't use a single `styleText` call like `styleText([summaryColor, "bold"], text)` here.
|
|
109
|
+
* This is a bug in `util.styleText` in Node.js versions earlier than v22.15.0 (https://github.com/nodejs/node/issues/56717).
|
|
110
|
+
* As a workaround, we use nested `styleText` calls.
|
|
111
|
+
*/
|
|
89
112
|
if (total > 0) {
|
|
90
|
-
output +=
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
pluralize(" problem", total),
|
|
95
|
-
" (",
|
|
96
|
-
errorCount,
|
|
97
|
-
pluralize(" error", errorCount),
|
|
98
|
-
", ",
|
|
99
|
-
warningCount,
|
|
100
|
-
pluralize(" warning", warningCount),
|
|
101
|
-
")\n",
|
|
102
|
-
].join(""),
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
if (fixableErrorCount > 0 || fixableWarningCount > 0) {
|
|
106
|
-
output += chalk[summaryColor].bold(
|
|
113
|
+
output += `${styleText(
|
|
114
|
+
summaryColor,
|
|
115
|
+
styleText(
|
|
116
|
+
"bold",
|
|
107
117
|
[
|
|
108
|
-
"
|
|
109
|
-
|
|
110
|
-
pluralize("
|
|
111
|
-
"
|
|
112
|
-
|
|
113
|
-
pluralize("
|
|
114
|
-
"
|
|
118
|
+
"\u2716 ",
|
|
119
|
+
total,
|
|
120
|
+
pluralize(" problem", total),
|
|
121
|
+
" (",
|
|
122
|
+
errorCount,
|
|
123
|
+
pluralize(" error", errorCount),
|
|
124
|
+
", ",
|
|
125
|
+
warningCount,
|
|
126
|
+
pluralize(" warning", warningCount),
|
|
127
|
+
")",
|
|
115
128
|
].join(""),
|
|
116
|
-
)
|
|
129
|
+
),
|
|
130
|
+
)}\n`;
|
|
131
|
+
|
|
132
|
+
if (fixableErrorCount > 0 || fixableWarningCount > 0) {
|
|
133
|
+
output += `${styleText(
|
|
134
|
+
summaryColor,
|
|
135
|
+
styleText(
|
|
136
|
+
"bold",
|
|
137
|
+
[
|
|
138
|
+
" ",
|
|
139
|
+
fixableErrorCount,
|
|
140
|
+
pluralize(" error", fixableErrorCount),
|
|
141
|
+
" and ",
|
|
142
|
+
fixableWarningCount,
|
|
143
|
+
pluralize(" warning", fixableWarningCount),
|
|
144
|
+
" potentially fixable with the `--fix` option.",
|
|
145
|
+
].join(""),
|
|
146
|
+
),
|
|
147
|
+
)}\n`;
|
|
117
148
|
}
|
|
118
149
|
}
|
|
119
150
|
|
|
120
151
|
// Resets output color, for prevent change on top level
|
|
121
|
-
return total > 0 ?
|
|
152
|
+
return total > 0 ? styleText("reset", output) : "";
|
|
122
153
|
};
|
package/lib/cli.js
CHANGED
|
@@ -454,14 +454,24 @@ const cli = {
|
|
|
454
454
|
const tooManyWarnings =
|
|
455
455
|
options.maxWarnings >= 0 &&
|
|
456
456
|
resultCounts.warningCount > options.maxWarnings;
|
|
457
|
-
const resultsMeta =
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
457
|
+
const resultsMeta = /** @type {ResultsMeta} */ ({});
|
|
458
|
+
|
|
459
|
+
/*
|
|
460
|
+
* `--color` was set, `options.color` is `true`.
|
|
461
|
+
* `--no-color` was set, `options.color` is `false`.
|
|
462
|
+
* Neither option was provided, `options.color` is omitted, so `undefined`.
|
|
463
|
+
*/
|
|
464
|
+
if (options.color !== void 0) {
|
|
465
|
+
debug(`Color setting for output: ${options.color}`);
|
|
466
|
+
resultsMeta.color = options.color;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
if (tooManyWarnings) {
|
|
470
|
+
resultsMeta.maxWarningsExceeded = {
|
|
471
|
+
maxWarnings: options.maxWarnings,
|
|
472
|
+
foundWarnings: resultCounts.warningCount,
|
|
473
|
+
};
|
|
474
|
+
}
|
|
465
475
|
|
|
466
476
|
if (
|
|
467
477
|
await printResults(
|
package/lib/eslint/eslint.js
CHANGED
|
@@ -1207,6 +1207,7 @@ class ESLint {
|
|
|
1207
1207
|
const { cwd } = privateMembers.get(this).options;
|
|
1208
1208
|
|
|
1209
1209
|
let formatterPath;
|
|
1210
|
+
let isBuiltInFormatter = false;
|
|
1210
1211
|
|
|
1211
1212
|
// if there's a slash, then it's a file (TODO: this check seems dubious for scoped npm packages)
|
|
1212
1213
|
if (!namespace && normalizedFormatName.includes("/")) {
|
|
@@ -1228,6 +1229,7 @@ class ESLint {
|
|
|
1228
1229
|
"formatters",
|
|
1229
1230
|
`${normalizedFormatName}.js`,
|
|
1230
1231
|
);
|
|
1232
|
+
isBuiltInFormatter = true;
|
|
1231
1233
|
}
|
|
1232
1234
|
}
|
|
1233
1235
|
|
|
@@ -1237,7 +1239,7 @@ class ESLint {
|
|
|
1237
1239
|
formatter = (await import(pathToFileURL(formatterPath))).default;
|
|
1238
1240
|
} catch (ex) {
|
|
1239
1241
|
// check for formatters that have been removed
|
|
1240
|
-
if (removedFormatters.has(name)) {
|
|
1242
|
+
if (isBuiltInFormatter && removedFormatters.has(name)) {
|
|
1241
1243
|
ex.message = `The ${name} formatter is no longer part of core ESLint. Install it manually with \`npm install -D eslint-formatter-${name}\``;
|
|
1242
1244
|
} else {
|
|
1243
1245
|
ex.message = `There was a problem loading formatter: ${formatterPath}\nError: ${ex.message}`;
|
|
@@ -1344,7 +1346,7 @@ class ESLint {
|
|
|
1344
1346
|
|
|
1345
1347
|
/**
|
|
1346
1348
|
* Returns whether flat config should be used.
|
|
1347
|
-
* @returns {Promise<
|
|
1349
|
+
* @returns {Promise<true>} Whether flat config should be used.
|
|
1348
1350
|
*/
|
|
1349
1351
|
async function shouldUseFlatConfig() {
|
|
1350
1352
|
return true;
|
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
// Requirements
|
|
9
9
|
//------------------------------------------------------------------------------
|
|
10
10
|
|
|
11
|
-
const
|
|
12
|
-
TokenStore = require("./token-store"),
|
|
11
|
+
const TokenStore = require("./token-store"),
|
|
13
12
|
astUtils = require("../../../shared/ast-utils"),
|
|
14
13
|
Traverser = require("../../../shared/traverser"),
|
|
15
14
|
globals = require("../../../../conf/globals"),
|
|
@@ -90,21 +89,6 @@ function getGlobalsForEcmaVersion(ecmaVersion) {
|
|
|
90
89
|
}
|
|
91
90
|
}
|
|
92
91
|
|
|
93
|
-
/**
|
|
94
|
-
* Check to see if its a ES6 export declaration.
|
|
95
|
-
* @param {ASTNode} astNode An AST node.
|
|
96
|
-
* @returns {boolean} whether the given node represents an export declaration.
|
|
97
|
-
* @private
|
|
98
|
-
*/
|
|
99
|
-
function looksLikeExport(astNode) {
|
|
100
|
-
return (
|
|
101
|
-
astNode.type === "ExportDefaultDeclaration" ||
|
|
102
|
-
astNode.type === "ExportNamedDeclaration" ||
|
|
103
|
-
astNode.type === "ExportAllDeclaration" ||
|
|
104
|
-
astNode.type === "ExportSpecifier"
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
92
|
/**
|
|
109
93
|
* Merges two sorted lists into a larger sorted list in O(n) time.
|
|
110
94
|
* @param {Token[]} tokens The list of tokens.
|
|
@@ -179,56 +163,6 @@ function nodesOrTokensOverlap(first, second) {
|
|
|
179
163
|
);
|
|
180
164
|
}
|
|
181
165
|
|
|
182
|
-
/**
|
|
183
|
-
* Determines if two nodes or tokens have at least one whitespace character
|
|
184
|
-
* between them. Order does not matter. Returns false if the given nodes or
|
|
185
|
-
* tokens overlap.
|
|
186
|
-
* @param {SourceCode} sourceCode The source code object.
|
|
187
|
-
* @param {ASTNode|Token} first The first node or token to check between.
|
|
188
|
-
* @param {ASTNode|Token} second The second node or token to check between.
|
|
189
|
-
* @param {boolean} checkInsideOfJSXText If `true` is present, check inside of JSXText tokens for backward compatibility.
|
|
190
|
-
* @returns {boolean} True if there is a whitespace character between
|
|
191
|
-
* any of the tokens found between the two given nodes or tokens.
|
|
192
|
-
* @public
|
|
193
|
-
*/
|
|
194
|
-
function isSpaceBetween(sourceCode, first, second, checkInsideOfJSXText) {
|
|
195
|
-
if (nodesOrTokensOverlap(first, second)) {
|
|
196
|
-
return false;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
const [startingNodeOrToken, endingNodeOrToken] =
|
|
200
|
-
first.range[1] <= second.range[0] ? [first, second] : [second, first];
|
|
201
|
-
const firstToken =
|
|
202
|
-
sourceCode.getLastToken(startingNodeOrToken) || startingNodeOrToken;
|
|
203
|
-
const finalToken =
|
|
204
|
-
sourceCode.getFirstToken(endingNodeOrToken) || endingNodeOrToken;
|
|
205
|
-
let currentToken = firstToken;
|
|
206
|
-
|
|
207
|
-
while (currentToken !== finalToken) {
|
|
208
|
-
const nextToken = sourceCode.getTokenAfter(currentToken, {
|
|
209
|
-
includeComments: true,
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
if (
|
|
213
|
-
currentToken.range[1] !== nextToken.range[0] ||
|
|
214
|
-
/*
|
|
215
|
-
* For backward compatibility, check spaces in JSXText.
|
|
216
|
-
* https://github.com/eslint/eslint/issues/12614
|
|
217
|
-
*/
|
|
218
|
-
(checkInsideOfJSXText &&
|
|
219
|
-
nextToken !== finalToken &&
|
|
220
|
-
nextToken.type === "JSXText" &&
|
|
221
|
-
/\s/u.test(nextToken.value))
|
|
222
|
-
) {
|
|
223
|
-
return true;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
currentToken = nextToken;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
return false;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
166
|
/**
|
|
233
167
|
* Performs binary search to find the line number containing a given character index.
|
|
234
168
|
* Returns the lower bound - the index of the first element greater than the target.
|
|
@@ -529,87 +463,6 @@ class SourceCode extends TokenStore {
|
|
|
529
463
|
return this.ast.comments;
|
|
530
464
|
}
|
|
531
465
|
|
|
532
|
-
/**
|
|
533
|
-
* Retrieves the JSDoc comment for a given node.
|
|
534
|
-
* @param {ASTNode} node The AST node to get the comment for.
|
|
535
|
-
* @returns {Token|null} The Block comment token containing the JSDoc comment
|
|
536
|
-
* for the given node or null if not found.
|
|
537
|
-
* @public
|
|
538
|
-
* @deprecated
|
|
539
|
-
*/
|
|
540
|
-
getJSDocComment(node) {
|
|
541
|
-
/**
|
|
542
|
-
* Checks for the presence of a JSDoc comment for the given node and returns it.
|
|
543
|
-
* @param {ASTNode} astNode The AST node to get the comment for.
|
|
544
|
-
* @returns {Token|null} The Block comment token containing the JSDoc comment
|
|
545
|
-
* for the given node or null if not found.
|
|
546
|
-
* @private
|
|
547
|
-
*/
|
|
548
|
-
const findJSDocComment = astNode => {
|
|
549
|
-
const tokenBefore = this.getTokenBefore(astNode, {
|
|
550
|
-
includeComments: true,
|
|
551
|
-
});
|
|
552
|
-
|
|
553
|
-
if (
|
|
554
|
-
tokenBefore &&
|
|
555
|
-
isCommentToken(tokenBefore) &&
|
|
556
|
-
tokenBefore.type === "Block" &&
|
|
557
|
-
tokenBefore.value.charAt(0) === "*" &&
|
|
558
|
-
astNode.loc.start.line - tokenBefore.loc.end.line <= 1
|
|
559
|
-
) {
|
|
560
|
-
return tokenBefore;
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
return null;
|
|
564
|
-
};
|
|
565
|
-
let parent = node.parent;
|
|
566
|
-
|
|
567
|
-
switch (node.type) {
|
|
568
|
-
case "ClassDeclaration":
|
|
569
|
-
case "FunctionDeclaration":
|
|
570
|
-
return findJSDocComment(
|
|
571
|
-
looksLikeExport(parent) ? parent : node,
|
|
572
|
-
);
|
|
573
|
-
|
|
574
|
-
case "ClassExpression":
|
|
575
|
-
return findJSDocComment(parent.parent);
|
|
576
|
-
|
|
577
|
-
case "ArrowFunctionExpression":
|
|
578
|
-
case "FunctionExpression":
|
|
579
|
-
if (
|
|
580
|
-
parent.type !== "CallExpression" &&
|
|
581
|
-
parent.type !== "NewExpression"
|
|
582
|
-
) {
|
|
583
|
-
while (
|
|
584
|
-
!this.getCommentsBefore(parent).length &&
|
|
585
|
-
!/Function/u.test(parent.type) &&
|
|
586
|
-
parent.type !== "MethodDefinition" &&
|
|
587
|
-
parent.type !== "Property"
|
|
588
|
-
) {
|
|
589
|
-
parent = parent.parent;
|
|
590
|
-
|
|
591
|
-
if (!parent) {
|
|
592
|
-
break;
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
if (
|
|
597
|
-
parent &&
|
|
598
|
-
parent.type !== "FunctionDeclaration" &&
|
|
599
|
-
parent.type !== "Program"
|
|
600
|
-
) {
|
|
601
|
-
return findJSDocComment(parent);
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
return findJSDocComment(node);
|
|
606
|
-
|
|
607
|
-
// falls through
|
|
608
|
-
default:
|
|
609
|
-
return null;
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
|
|
613
466
|
/**
|
|
614
467
|
* Gets the deepest node containing a range index.
|
|
615
468
|
* @param {number} index Range index of the desired node.
|
|
@@ -649,24 +502,33 @@ class SourceCode extends TokenStore {
|
|
|
649
502
|
* @public
|
|
650
503
|
*/
|
|
651
504
|
isSpaceBetween(first, second) {
|
|
652
|
-
|
|
653
|
-
|
|
505
|
+
if (nodesOrTokensOverlap(first, second)) {
|
|
506
|
+
return false;
|
|
507
|
+
}
|
|
654
508
|
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
509
|
+
const [startingNodeOrToken, endingNodeOrToken] =
|
|
510
|
+
first.range[1] <= second.range[0]
|
|
511
|
+
? [first, second]
|
|
512
|
+
: [second, first];
|
|
513
|
+
const firstToken =
|
|
514
|
+
this.getLastToken(startingNodeOrToken) || startingNodeOrToken;
|
|
515
|
+
const finalToken =
|
|
516
|
+
this.getFirstToken(endingNodeOrToken) || endingNodeOrToken;
|
|
517
|
+
let currentToken = firstToken;
|
|
518
|
+
|
|
519
|
+
while (currentToken !== finalToken) {
|
|
520
|
+
const nextToken = this.getTokenAfter(currentToken, {
|
|
521
|
+
includeComments: true,
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
if (currentToken.range[1] !== nextToken.range[0]) {
|
|
525
|
+
return true;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
currentToken = nextToken;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
return false;
|
|
670
532
|
}
|
|
671
533
|
|
|
672
534
|
/**
|
|
@@ -444,32 +444,6 @@ module.exports = class TokenStore {
|
|
|
444
444
|
).getOneToken();
|
|
445
445
|
}
|
|
446
446
|
|
|
447
|
-
/**
|
|
448
|
-
* Gets the token that precedes a given node or token in the token stream.
|
|
449
|
-
* This is defined for backward compatibility. Use `includeComments` option instead.
|
|
450
|
-
* TODO: We have a plan to remove this in a future major version.
|
|
451
|
-
* @param {ASTNode|Token|Comment} node The AST node or token.
|
|
452
|
-
* @param {number} [skip=0] A number of tokens to skip.
|
|
453
|
-
* @returns {Token|null} An object representing the token.
|
|
454
|
-
* @deprecated
|
|
455
|
-
*/
|
|
456
|
-
getTokenOrCommentBefore(node, skip) {
|
|
457
|
-
return this.getTokenBefore(node, { includeComments: true, skip });
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
/**
|
|
461
|
-
* Gets the token that follows a given node or token in the token stream.
|
|
462
|
-
* This is defined for backward compatibility. Use `includeComments` option instead.
|
|
463
|
-
* TODO: We have a plan to remove this in a future major version.
|
|
464
|
-
* @param {ASTNode|Token|Comment} node The AST node or token.
|
|
465
|
-
* @param {number} [skip=0] A number of tokens to skip.
|
|
466
|
-
* @returns {Token|null} An object representing the token.
|
|
467
|
-
* @deprecated
|
|
468
|
-
*/
|
|
469
|
-
getTokenOrCommentAfter(node, skip) {
|
|
470
|
-
return this.getTokenAfter(node, { includeComments: true, skip });
|
|
471
|
-
}
|
|
472
|
-
|
|
473
447
|
//--------------------------------------------------------------------------
|
|
474
448
|
// Gets multiple tokens.
|
|
475
449
|
//--------------------------------------------------------------------------
|
package/lib/linter/linter.js
CHANGED