eslint 9.37.0 → 9.38.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 +11 -1
- package/lib/eslint/eslint-helpers.js +1 -1
- package/lib/rules/callback-return.js +1 -1
- package/lib/rules/complexity.js +6 -0
- package/lib/rules/global-require.js +1 -1
- package/lib/rules/handle-callback-err.js +1 -1
- package/lib/rules/id-blacklist.js +1 -1
- package/lib/rules/no-buffer-constructor.js +1 -1
- package/lib/rules/no-catch-shadow.js +1 -1
- package/lib/rules/no-loss-of-precision.js +206 -208
- package/lib/rules/no-mixed-requires.js +1 -1
- package/lib/rules/no-native-reassign.js +1 -1
- package/lib/rules/no-negated-in-lhs.js +1 -1
- package/lib/rules/no-new-object.js +1 -1
- package/lib/rules/no-new-require.js +1 -1
- package/lib/rules/no-new-symbol.js +1 -1
- package/lib/rules/no-path-concat.js +1 -1
- package/lib/rules/no-process-env.js +1 -1
- package/lib/rules/no-process-exit.js +1 -1
- package/lib/rules/no-restricted-modules.js +1 -1
- package/lib/rules/no-sync.js +1 -1
- package/lib/shared/serialization.js +1 -1
- package/lib/types/config-api.d.ts +6 -2
- package/lib/types/index.d.ts +85 -403
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -287,6 +287,11 @@ fnx
|
|
|
287
287
|
Josh Goldberg ✨
|
|
288
288
|
</a>
|
|
289
289
|
</td><td align="center" valign="top" width="11%">
|
|
290
|
+
<a href="https://github.com/SwetaTanwar">
|
|
291
|
+
<img src="https://github.com/SwetaTanwar.png?s=75" width="75" height="75" alt="Sweta Tanwar's Avatar"><br />
|
|
292
|
+
Sweta Tanwar
|
|
293
|
+
</a>
|
|
294
|
+
</td><td align="center" valign="top" width="11%">
|
|
290
295
|
<a href="https://github.com/Tanujkanti4441">
|
|
291
296
|
<img src="https://github.com/Tanujkanti4441.png?s=75" width="75" height="75" alt="Tanuj Kanti's Avatar"><br />
|
|
292
297
|
Tanuj Kanti
|
|
@@ -296,6 +301,11 @@ Tanuj Kanti
|
|
|
296
301
|
<img src="https://github.com/lumirlumir.png?s=75" width="75" height="75" alt="루밀LuMir's Avatar"><br />
|
|
297
302
|
루밀LuMir
|
|
298
303
|
</a>
|
|
304
|
+
</td><td align="center" valign="top" width="11%">
|
|
305
|
+
<a href="https://github.com/Pixel998">
|
|
306
|
+
<img src="https://github.com/Pixel998.png?s=75" width="75" height="75" alt="Pixel998's Avatar"><br />
|
|
307
|
+
Pixel998
|
|
308
|
+
</a>
|
|
299
309
|
</td></tr></tbody></table>
|
|
300
310
|
|
|
301
311
|
### Website Team
|
|
@@ -333,7 +343,7 @@ to get your logo on our READMEs and [website](https://eslint.org/sponsors).
|
|
|
333
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>
|
|
334
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://trunk.io/"><img src="https://images.opencollective.com/trunkio/fb92d60/avatar.png" alt="trunk.io" 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>
|
|
335
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/5c4fa84/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>
|
|
336
|
-
<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://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://opensource.mercedes-benz.com/"><img src="https://avatars.githubusercontent.com/u/34240465" alt="Mercedes-Benz Group" 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>
|
|
346
|
+
<p><a href="https://syntax.fm"><img src="https://github.com/syntaxfm.png" alt="Syntax" height="32"></a> <a href="https://cybozu.co.jp/"><img src="https://images.opencollective.com/cybozu/933e46d/logo.png" alt="Cybozu" height="32"></a> <a href="https://sentry.io"><img src="https://github.com/getsentry.png" alt="Sentry" 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://opensource.mercedes-benz.com/"><img src="https://avatars.githubusercontent.com/u/34240465" alt="Mercedes-Benz Group" 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>
|
|
337
347
|
<h3>Technology Sponsors</h3>
|
|
338
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.
|
|
339
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>
|
|
@@ -506,7 +506,7 @@ async function globMultiSearch({
|
|
|
506
506
|
* @param {boolean} args.globInputPaths true to interpret glob patterns,
|
|
507
507
|
* false to not interpret glob patterns.
|
|
508
508
|
* @param {string} args.cwd The current working directory to find from.
|
|
509
|
-
* @param {ConfigLoader|LegacyConfigLoader} args.configLoader The config
|
|
509
|
+
* @param {ConfigLoader|LegacyConfigLoader} args.configLoader The config loader for the current run.
|
|
510
510
|
* @param {boolean} args.errorOnUnmatchedPattern Determines if an unmatched pattern
|
|
511
511
|
* should throw an error.
|
|
512
512
|
* @returns {Promise<Array<string>>} The fully resolved file paths.
|
|
@@ -16,7 +16,7 @@ module.exports = {
|
|
|
16
16
|
message: "Node.js rules were moved out of ESLint core.",
|
|
17
17
|
url: "https://eslint.org/docs/latest/use/migrating-to-7.0.0#deprecate-node-rules",
|
|
18
18
|
deprecatedSince: "7.0.0",
|
|
19
|
-
availableUntil:
|
|
19
|
+
availableUntil: "11.0.0",
|
|
20
20
|
replacedBy: [
|
|
21
21
|
{
|
|
22
22
|
message:
|
package/lib/rules/complexity.js
CHANGED
|
@@ -171,6 +171,7 @@ module.exports = {
|
|
|
171
171
|
|
|
172
172
|
if (complexity > threshold) {
|
|
173
173
|
let name;
|
|
174
|
+
let loc = node.loc;
|
|
174
175
|
|
|
175
176
|
if (codePath.origin === "class-field-initializer") {
|
|
176
177
|
name = "class field initializer";
|
|
@@ -178,10 +179,15 @@ module.exports = {
|
|
|
178
179
|
name = "class static block";
|
|
179
180
|
} else {
|
|
180
181
|
name = astUtils.getFunctionNameWithKind(node);
|
|
182
|
+
loc = astUtils.getFunctionHeadLoc(
|
|
183
|
+
node,
|
|
184
|
+
context.sourceCode,
|
|
185
|
+
);
|
|
181
186
|
}
|
|
182
187
|
|
|
183
188
|
context.report({
|
|
184
189
|
node,
|
|
190
|
+
loc,
|
|
185
191
|
messageId: "complex",
|
|
186
192
|
data: {
|
|
187
193
|
name: upperCaseFirst(name),
|
|
@@ -60,7 +60,7 @@ module.exports = {
|
|
|
60
60
|
message: "Node.js rules were moved out of ESLint core.",
|
|
61
61
|
url: "https://eslint.org/docs/latest/use/migrating-to-7.0.0#deprecate-node-rules",
|
|
62
62
|
deprecatedSince: "7.0.0",
|
|
63
|
-
availableUntil:
|
|
63
|
+
availableUntil: "11.0.0",
|
|
64
64
|
replacedBy: [
|
|
65
65
|
{
|
|
66
66
|
message:
|
|
@@ -17,7 +17,7 @@ module.exports = {
|
|
|
17
17
|
message: "Node.js rules were moved out of ESLint core.",
|
|
18
18
|
url: "https://eslint.org/docs/latest/use/migrating-to-7.0.0#deprecate-node-rules",
|
|
19
19
|
deprecatedSince: "7.0.0",
|
|
20
|
-
availableUntil:
|
|
20
|
+
availableUntil: "11.0.0",
|
|
21
21
|
replacedBy: [
|
|
22
22
|
{
|
|
23
23
|
message:
|
|
@@ -101,7 +101,7 @@ module.exports = {
|
|
|
101
101
|
message: "The rule was renamed.",
|
|
102
102
|
url: "https://eslint.org/blog/2020/07/eslint-v7.5.0-released/#deprecating-id-blacklist",
|
|
103
103
|
deprecatedSince: "7.5.0",
|
|
104
|
-
availableUntil:
|
|
104
|
+
availableUntil: "11.0.0",
|
|
105
105
|
replacedBy: [
|
|
106
106
|
{
|
|
107
107
|
rule: {
|
|
@@ -16,7 +16,7 @@ module.exports = {
|
|
|
16
16
|
message: "Node.js rules were moved out of ESLint core.",
|
|
17
17
|
url: "https://eslint.org/docs/latest/use/migrating-to-7.0.0#deprecate-node-rules",
|
|
18
18
|
deprecatedSince: "7.0.0",
|
|
19
|
-
availableUntil:
|
|
19
|
+
availableUntil: "11.0.0",
|
|
20
20
|
replacedBy: [
|
|
21
21
|
{
|
|
22
22
|
message:
|
|
@@ -5,6 +5,212 @@
|
|
|
5
5
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
|
+
//------------------------------------------------------------------------------
|
|
9
|
+
// Helpers
|
|
10
|
+
//------------------------------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
/** Class representing a number in scientific notation. */
|
|
13
|
+
class ScientificNotation {
|
|
14
|
+
/** @type {string} The digits of the coefficient. A decimal point is implied after the first digit. */
|
|
15
|
+
coefficient;
|
|
16
|
+
|
|
17
|
+
/** @type {number} The order of magnitude. */
|
|
18
|
+
magnitude;
|
|
19
|
+
|
|
20
|
+
constructor(coefficient, magnitude) {
|
|
21
|
+
this.coefficient = coefficient;
|
|
22
|
+
this.magnitude = magnitude;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/* c8 ignore start -- debug only */
|
|
26
|
+
toString() {
|
|
27
|
+
return `${this.coefficient[0]}${this.coefficient.length > 1 ? `.${this.coefficient.slice(1)}` : ""}e${this.magnitude}`;
|
|
28
|
+
}
|
|
29
|
+
/* c8 ignore stop */
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Returns whether the node is number literal
|
|
34
|
+
* @param {Node} node the node literal being evaluated
|
|
35
|
+
* @returns {boolean} true if the node is a number literal
|
|
36
|
+
*/
|
|
37
|
+
function isNumber(node) {
|
|
38
|
+
return typeof node.value === "number";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Gets the source code of the given number literal. Removes `_` numeric separators from the result.
|
|
43
|
+
* @param {Node} node the number `Literal` node
|
|
44
|
+
* @returns {string} raw source code of the literal, without numeric separators
|
|
45
|
+
*/
|
|
46
|
+
function getRaw(node) {
|
|
47
|
+
return node.raw.replace(/_/gu, "");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Checks whether the number is base ten
|
|
52
|
+
* @param {ASTNode} node the node being evaluated
|
|
53
|
+
* @returns {boolean} true if the node is in base ten
|
|
54
|
+
*/
|
|
55
|
+
function isBaseTen(node) {
|
|
56
|
+
const prefixes = ["0x", "0X", "0b", "0B", "0o", "0O"];
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
prefixes.every(prefix => !node.raw.startsWith(prefix)) &&
|
|
60
|
+
!/^0[0-7]+$/u.test(node.raw)
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Checks that the user-intended non-base ten number equals the actual number after is has been converted to the Number type
|
|
66
|
+
* @param {Node} node the node being evaluated
|
|
67
|
+
* @returns {boolean} true if they do not match
|
|
68
|
+
*/
|
|
69
|
+
function notBaseTenLosesPrecision(node) {
|
|
70
|
+
const rawString = getRaw(node).toUpperCase();
|
|
71
|
+
let base;
|
|
72
|
+
|
|
73
|
+
if (rawString.startsWith("0B")) {
|
|
74
|
+
base = 2;
|
|
75
|
+
} else if (rawString.startsWith("0X")) {
|
|
76
|
+
base = 16;
|
|
77
|
+
} else {
|
|
78
|
+
base = 8;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return !rawString.endsWith(node.value.toString(base).toUpperCase());
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Returns the number stripped of leading zeros
|
|
86
|
+
* @param {string} numberAsString the string representation of the number
|
|
87
|
+
* @returns {string} the stripped string
|
|
88
|
+
*/
|
|
89
|
+
function removeLeadingZeros(numberAsString) {
|
|
90
|
+
for (let i = 0; i < numberAsString.length; i++) {
|
|
91
|
+
if (numberAsString[i] !== "0") {
|
|
92
|
+
return numberAsString.slice(i);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return numberAsString;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Returns the number stripped of trailing zeros
|
|
100
|
+
* @param {string} numberAsString the string representation of the number
|
|
101
|
+
* @returns {string} the stripped string
|
|
102
|
+
*/
|
|
103
|
+
function removeTrailingZeros(numberAsString) {
|
|
104
|
+
for (let i = numberAsString.length - 1; i >= 0; i--) {
|
|
105
|
+
if (numberAsString[i] !== "0") {
|
|
106
|
+
return numberAsString.slice(0, i + 1);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return numberAsString;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Converts an integer to an object containing the integer's coefficient and order of magnitude
|
|
114
|
+
* @param {string} stringInteger the string representation of the integer being converted
|
|
115
|
+
* @returns {ScientificNotation} the object containing the integer's coefficient and order of magnitude
|
|
116
|
+
*/
|
|
117
|
+
function normalizeInteger(stringInteger) {
|
|
118
|
+
const trimmedInteger = removeLeadingZeros(stringInteger);
|
|
119
|
+
const significantDigits = removeTrailingZeros(trimmedInteger);
|
|
120
|
+
|
|
121
|
+
return new ScientificNotation(significantDigits, trimmedInteger.length - 1);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Converts a float to an object containing the float's coefficient and order of magnitude
|
|
126
|
+
* @param {string} stringFloat the string representation of the float being converted
|
|
127
|
+
* @returns {ScientificNotation} the object containing the float's coefficient and order of magnitude
|
|
128
|
+
*/
|
|
129
|
+
function normalizeFloat(stringFloat) {
|
|
130
|
+
const trimmedFloat = removeLeadingZeros(stringFloat);
|
|
131
|
+
const indexOfDecimalPoint = trimmedFloat.indexOf(".");
|
|
132
|
+
|
|
133
|
+
switch (indexOfDecimalPoint) {
|
|
134
|
+
case 0: {
|
|
135
|
+
const significantDigits = removeLeadingZeros(trimmedFloat.slice(1));
|
|
136
|
+
|
|
137
|
+
return new ScientificNotation(
|
|
138
|
+
significantDigits,
|
|
139
|
+
significantDigits.length - trimmedFloat.length,
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
case -1:
|
|
143
|
+
return new ScientificNotation(
|
|
144
|
+
trimmedFloat,
|
|
145
|
+
trimmedFloat.length - 1,
|
|
146
|
+
);
|
|
147
|
+
default:
|
|
148
|
+
return new ScientificNotation(
|
|
149
|
+
trimmedFloat.replace(".", ""),
|
|
150
|
+
indexOfDecimalPoint - 1,
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Converts a base ten number to proper scientific notation
|
|
157
|
+
* @param {string} stringNumber the string representation of the base ten number to be converted
|
|
158
|
+
* @param {boolean} parseAsFloat if true, the coefficient will be always parsed as a float, regardless of whether a decimal point is present
|
|
159
|
+
* @returns {ScientificNotation} the object containing the number's coefficient and order of magnitude
|
|
160
|
+
*/
|
|
161
|
+
function convertNumberToScientificNotation(stringNumber, parseAsFloat) {
|
|
162
|
+
const splitNumber = stringNumber.split("e");
|
|
163
|
+
const originalCoefficient = splitNumber[0];
|
|
164
|
+
const normalizedNumber =
|
|
165
|
+
parseAsFloat || stringNumber.includes(".")
|
|
166
|
+
? normalizeFloat(originalCoefficient)
|
|
167
|
+
: normalizeInteger(originalCoefficient);
|
|
168
|
+
if (splitNumber.length > 1) {
|
|
169
|
+
normalizedNumber.magnitude += parseInt(splitNumber[1], 10);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return normalizedNumber;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Checks that the user-intended base ten number equals the actual number after is has been converted to the Number type
|
|
177
|
+
* @param {Node} node the node being evaluated
|
|
178
|
+
* @returns {boolean} true if they do not match
|
|
179
|
+
*/
|
|
180
|
+
function baseTenLosesPrecision(node) {
|
|
181
|
+
const rawNumber = getRaw(node).toLowerCase();
|
|
182
|
+
const normalizedRawNumber = convertNumberToScientificNotation(
|
|
183
|
+
rawNumber,
|
|
184
|
+
false,
|
|
185
|
+
);
|
|
186
|
+
const requestedPrecision = normalizedRawNumber.coefficient.length;
|
|
187
|
+
|
|
188
|
+
if (requestedPrecision > 100) {
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
const storedNumber = node.value.toPrecision(requestedPrecision);
|
|
192
|
+
const normalizedStoredNumber = convertNumberToScientificNotation(
|
|
193
|
+
storedNumber,
|
|
194
|
+
true,
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
return (
|
|
198
|
+
normalizedRawNumber.magnitude !== normalizedStoredNumber.magnitude ||
|
|
199
|
+
normalizedRawNumber.coefficient !== normalizedStoredNumber.coefficient
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Checks that the user-intended number equals the actual number after is has been converted to the Number type
|
|
205
|
+
* @param {Node} node the node being evaluated
|
|
206
|
+
* @returns {boolean} true if they do not match
|
|
207
|
+
*/
|
|
208
|
+
function losesPrecision(node) {
|
|
209
|
+
return isBaseTen(node)
|
|
210
|
+
? baseTenLosesPrecision(node)
|
|
211
|
+
: notBaseTenLosesPrecision(node);
|
|
212
|
+
}
|
|
213
|
+
|
|
8
214
|
//------------------------------------------------------------------------------
|
|
9
215
|
// Rule Definition
|
|
10
216
|
//------------------------------------------------------------------------------
|
|
@@ -29,214 +235,6 @@ module.exports = {
|
|
|
29
235
|
},
|
|
30
236
|
|
|
31
237
|
create(context) {
|
|
32
|
-
/**
|
|
33
|
-
* Returns whether the node is number literal
|
|
34
|
-
* @param {Node} node the node literal being evaluated
|
|
35
|
-
* @returns {boolean} true if the node is a number literal
|
|
36
|
-
*/
|
|
37
|
-
function isNumber(node) {
|
|
38
|
-
return typeof node.value === "number";
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Gets the source code of the given number literal. Removes `_` numeric separators from the result.
|
|
43
|
-
* @param {Node} node the number `Literal` node
|
|
44
|
-
* @returns {string} raw source code of the literal, without numeric separators
|
|
45
|
-
*/
|
|
46
|
-
function getRaw(node) {
|
|
47
|
-
return node.raw.replace(/_/gu, "");
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Checks whether the number is base ten
|
|
52
|
-
* @param {ASTNode} node the node being evaluated
|
|
53
|
-
* @returns {boolean} true if the node is in base ten
|
|
54
|
-
*/
|
|
55
|
-
function isBaseTen(node) {
|
|
56
|
-
const prefixes = ["0x", "0X", "0b", "0B", "0o", "0O"];
|
|
57
|
-
|
|
58
|
-
return (
|
|
59
|
-
prefixes.every(prefix => !node.raw.startsWith(prefix)) &&
|
|
60
|
-
!/^0[0-7]+$/u.test(node.raw)
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Checks that the user-intended non-base ten number equals the actual number after is has been converted to the Number type
|
|
66
|
-
* @param {Node} node the node being evaluated
|
|
67
|
-
* @returns {boolean} true if they do not match
|
|
68
|
-
*/
|
|
69
|
-
function notBaseTenLosesPrecision(node) {
|
|
70
|
-
const rawString = getRaw(node).toUpperCase();
|
|
71
|
-
let base;
|
|
72
|
-
|
|
73
|
-
if (rawString.startsWith("0B")) {
|
|
74
|
-
base = 2;
|
|
75
|
-
} else if (rawString.startsWith("0X")) {
|
|
76
|
-
base = 16;
|
|
77
|
-
} else {
|
|
78
|
-
base = 8;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return !rawString.endsWith(node.value.toString(base).toUpperCase());
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Adds a decimal point to the numeric string at index 1
|
|
86
|
-
* @param {string} stringNumber the numeric string without any decimal point
|
|
87
|
-
* @returns {string} the numeric string with a decimal point in the proper place
|
|
88
|
-
*/
|
|
89
|
-
function addDecimalPointToNumber(stringNumber) {
|
|
90
|
-
return `${stringNumber[0]}.${stringNumber.slice(1)}`;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Returns the number stripped of leading zeros
|
|
95
|
-
* @param {string} numberAsString the string representation of the number
|
|
96
|
-
* @returns {string} the stripped string
|
|
97
|
-
*/
|
|
98
|
-
function removeLeadingZeros(numberAsString) {
|
|
99
|
-
for (let i = 0; i < numberAsString.length; i++) {
|
|
100
|
-
if (numberAsString[i] !== "0") {
|
|
101
|
-
return numberAsString.slice(i);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return numberAsString;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Returns the number stripped of trailing zeros
|
|
109
|
-
* @param {string} numberAsString the string representation of the number
|
|
110
|
-
* @returns {string} the stripped string
|
|
111
|
-
*/
|
|
112
|
-
function removeTrailingZeros(numberAsString) {
|
|
113
|
-
for (let i = numberAsString.length - 1; i >= 0; i--) {
|
|
114
|
-
if (numberAsString[i] !== "0") {
|
|
115
|
-
return numberAsString.slice(0, i + 1);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return numberAsString;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Converts an integer to an object containing the integer's coefficient and order of magnitude
|
|
123
|
-
* @param {string} stringInteger the string representation of the integer being converted
|
|
124
|
-
* @returns {Object} the object containing the integer's coefficient and order of magnitude
|
|
125
|
-
*/
|
|
126
|
-
function normalizeInteger(stringInteger) {
|
|
127
|
-
const trimmedInteger = removeLeadingZeros(stringInteger);
|
|
128
|
-
const significantDigits = removeTrailingZeros(trimmedInteger);
|
|
129
|
-
|
|
130
|
-
return {
|
|
131
|
-
magnitude: trimmedInteger.length - 1,
|
|
132
|
-
coefficient: addDecimalPointToNumber(significantDigits),
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
*
|
|
138
|
-
* Converts a float to an object containing the floats's coefficient and order of magnitude
|
|
139
|
-
* @param {string} stringFloat the string representation of the float being converted
|
|
140
|
-
* @returns {Object} the object containing the float's coefficient and order of magnitude
|
|
141
|
-
*/
|
|
142
|
-
function normalizeFloat(stringFloat) {
|
|
143
|
-
const trimmedFloat = removeLeadingZeros(stringFloat);
|
|
144
|
-
|
|
145
|
-
if (trimmedFloat.startsWith(".")) {
|
|
146
|
-
const decimalDigits = trimmedFloat.slice(1);
|
|
147
|
-
const significantDigits = removeLeadingZeros(decimalDigits);
|
|
148
|
-
|
|
149
|
-
return {
|
|
150
|
-
magnitude:
|
|
151
|
-
significantDigits.length - decimalDigits.length - 1,
|
|
152
|
-
coefficient: addDecimalPointToNumber(significantDigits),
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
return {
|
|
156
|
-
magnitude: trimmedFloat.indexOf(".") - 1,
|
|
157
|
-
coefficient: addDecimalPointToNumber(
|
|
158
|
-
trimmedFloat.replace(".", ""),
|
|
159
|
-
),
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Converts a base ten number to proper scientific notation
|
|
165
|
-
* @param {string} stringNumber the string representation of the base ten number to be converted
|
|
166
|
-
* @returns {string} the number converted to scientific notation
|
|
167
|
-
*/
|
|
168
|
-
function convertNumberToScientificNotation(stringNumber) {
|
|
169
|
-
const splitNumber = stringNumber.split("e");
|
|
170
|
-
const originalCoefficient = splitNumber[0];
|
|
171
|
-
const normalizedNumber = stringNumber.includes(".")
|
|
172
|
-
? normalizeFloat(originalCoefficient)
|
|
173
|
-
: normalizeInteger(originalCoefficient);
|
|
174
|
-
const normalizedCoefficient = normalizedNumber.coefficient;
|
|
175
|
-
const magnitude =
|
|
176
|
-
splitNumber.length > 1
|
|
177
|
-
? parseInt(splitNumber[1], 10) + normalizedNumber.magnitude
|
|
178
|
-
: normalizedNumber.magnitude;
|
|
179
|
-
|
|
180
|
-
return `${normalizedCoefficient}e${magnitude}`;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Checks that the user-intended base ten number equals the actual number after is has been converted to the Number type
|
|
185
|
-
* @param {Node} node the node being evaluated
|
|
186
|
-
* @returns {boolean} true if they do not match
|
|
187
|
-
*/
|
|
188
|
-
function baseTenLosesPrecision(node) {
|
|
189
|
-
const rawNumber = getRaw(node).toLowerCase();
|
|
190
|
-
|
|
191
|
-
/*
|
|
192
|
-
* If trailing zeros equal the exponent, this is a valid representation
|
|
193
|
-
* like "9.00e2" where 00 = 2 (meaning 9.00 * 10^2 = 900)
|
|
194
|
-
* https://github.com/eslint/eslint/issues/19957
|
|
195
|
-
*/
|
|
196
|
-
if (rawNumber.includes(".") && rawNumber.includes("e")) {
|
|
197
|
-
const parts = rawNumber.split("e");
|
|
198
|
-
const coefficient = parts[0];
|
|
199
|
-
const exponent = parseInt(parts[1], 10);
|
|
200
|
-
|
|
201
|
-
// Count trailing zeros after decimal
|
|
202
|
-
const decimalParts = coefficient.split(".");
|
|
203
|
-
if (decimalParts.length === 2) {
|
|
204
|
-
const decimalPart = decimalParts[1];
|
|
205
|
-
const trailingZeros = decimalPart.match(/0*$/u)[0].length;
|
|
206
|
-
|
|
207
|
-
if (trailingZeros === exponent) {
|
|
208
|
-
return false;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
const normalizedRawNumber =
|
|
214
|
-
convertNumberToScientificNotation(rawNumber);
|
|
215
|
-
const requestedPrecision = normalizedRawNumber
|
|
216
|
-
.split("e")[0]
|
|
217
|
-
.replace(".", "").length;
|
|
218
|
-
|
|
219
|
-
if (requestedPrecision > 100) {
|
|
220
|
-
return true;
|
|
221
|
-
}
|
|
222
|
-
const storedNumber = node.value.toPrecision(requestedPrecision);
|
|
223
|
-
const normalizedStoredNumber =
|
|
224
|
-
convertNumberToScientificNotation(storedNumber);
|
|
225
|
-
|
|
226
|
-
return normalizedRawNumber !== normalizedStoredNumber;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* Checks that the user-intended number equals the actual number after is has been converted to the Number type
|
|
231
|
-
* @param {Node} node the node being evaluated
|
|
232
|
-
* @returns {boolean} true if they do not match
|
|
233
|
-
*/
|
|
234
|
-
function losesPrecision(node) {
|
|
235
|
-
return isBaseTen(node)
|
|
236
|
-
? baseTenLosesPrecision(node)
|
|
237
|
-
: notBaseTenLosesPrecision(node);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
238
|
return {
|
|
241
239
|
Literal(node) {
|
|
242
240
|
if (node.value && isNumber(node) && losesPrecision(node)) {
|
|
@@ -17,7 +17,7 @@ module.exports = {
|
|
|
17
17
|
message: "Node.js rules were moved out of ESLint core.",
|
|
18
18
|
url: "https://eslint.org/docs/latest/use/migrating-to-7.0.0#deprecate-node-rules",
|
|
19
19
|
deprecatedSince: "7.0.0",
|
|
20
|
-
availableUntil:
|
|
20
|
+
availableUntil: "11.0.0",
|
|
21
21
|
replacedBy: [
|
|
22
22
|
{
|
|
23
23
|
message:
|
|
@@ -32,7 +32,7 @@ module.exports = {
|
|
|
32
32
|
"The new rule flags more situations where object literal syntax can be used, and it does not report a problem when the `Object` constructor is invoked with an argument.",
|
|
33
33
|
url: "https://eslint.org/blog/2023/09/eslint-v8.50.0-released/",
|
|
34
34
|
deprecatedSince: "8.50.0",
|
|
35
|
-
availableUntil:
|
|
35
|
+
availableUntil: "11.0.0",
|
|
36
36
|
replacedBy: [
|
|
37
37
|
{
|
|
38
38
|
rule: {
|
|
@@ -17,7 +17,7 @@ module.exports = {
|
|
|
17
17
|
message: "Node.js rules were moved out of ESLint core.",
|
|
18
18
|
url: "https://eslint.org/docs/latest/use/migrating-to-7.0.0#deprecate-node-rules",
|
|
19
19
|
deprecatedSince: "7.0.0",
|
|
20
|
-
availableUntil:
|
|
20
|
+
availableUntil: "11.0.0",
|
|
21
21
|
replacedBy: [
|
|
22
22
|
{
|
|
23
23
|
message:
|
|
@@ -25,7 +25,7 @@ module.exports = {
|
|
|
25
25
|
message: "The rule was replaced with a more general rule.",
|
|
26
26
|
url: "https://eslint.org/docs/latest/use/migrate-to-9.0.0#eslint-recommended",
|
|
27
27
|
deprecatedSince: "9.0.0",
|
|
28
|
-
availableUntil:
|
|
28
|
+
availableUntil: "11.0.0",
|
|
29
29
|
replacedBy: [
|
|
30
30
|
{
|
|
31
31
|
rule: {
|
|
@@ -16,7 +16,7 @@ module.exports = {
|
|
|
16
16
|
message: "Node.js rules were moved out of ESLint core.",
|
|
17
17
|
url: "https://eslint.org/docs/latest/use/migrating-to-7.0.0#deprecate-node-rules",
|
|
18
18
|
deprecatedSince: "7.0.0",
|
|
19
|
-
availableUntil:
|
|
19
|
+
availableUntil: "11.0.0",
|
|
20
20
|
replacedBy: [
|
|
21
21
|
{
|
|
22
22
|
message:
|
|
@@ -16,7 +16,7 @@ module.exports = {
|
|
|
16
16
|
message: "Node.js rules were moved out of ESLint core.",
|
|
17
17
|
url: "https://eslint.org/docs/latest/use/migrating-to-7.0.0#deprecate-node-rules",
|
|
18
18
|
deprecatedSince: "7.0.0",
|
|
19
|
-
availableUntil:
|
|
19
|
+
availableUntil: "11.0.0",
|
|
20
20
|
replacedBy: [
|
|
21
21
|
{
|
|
22
22
|
message:
|
|
@@ -16,7 +16,7 @@ module.exports = {
|
|
|
16
16
|
message: "Node.js rules were moved out of ESLint core.",
|
|
17
17
|
url: "https://eslint.org/docs/latest/use/migrating-to-7.0.0#deprecate-node-rules",
|
|
18
18
|
deprecatedSince: "7.0.0",
|
|
19
|
-
availableUntil:
|
|
19
|
+
availableUntil: "11.0.0",
|
|
20
20
|
replacedBy: [
|
|
21
21
|
{
|
|
22
22
|
message:
|
|
@@ -52,7 +52,7 @@ module.exports = {
|
|
|
52
52
|
message: "Node.js rules were moved out of ESLint core.",
|
|
53
53
|
url: "https://eslint.org/docs/latest/use/migrating-to-7.0.0#deprecate-node-rules",
|
|
54
54
|
deprecatedSince: "7.0.0",
|
|
55
|
-
availableUntil:
|
|
55
|
+
availableUntil: "11.0.0",
|
|
56
56
|
replacedBy: [
|
|
57
57
|
{
|
|
58
58
|
message:
|
package/lib/rules/no-sync.js
CHANGED
|
@@ -17,7 +17,7 @@ module.exports = {
|
|
|
17
17
|
message: "Node.js rules were moved out of ESLint core.",
|
|
18
18
|
url: "https://eslint.org/docs/latest/use/migrating-to-7.0.0#deprecate-node-rules",
|
|
19
19
|
deprecatedSince: "7.0.0",
|
|
20
|
-
availableUntil:
|
|
20
|
+
availableUntil: "11.0.0",
|
|
21
21
|
replacedBy: [
|
|
22
22
|
{
|
|
23
23
|
message:
|