eslint 9.0.0-beta.0 → 9.0.0-beta.2
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 +19 -7
- package/lib/config/rule-validator.js +15 -2
- package/lib/eslint/eslint.js +8 -1
- package/lib/linter/linter.js +121 -110
- package/lib/rules/complexity.js +13 -0
- package/lib/rules/no-constant-binary-expression.js +2 -3
- package/lib/rules/no-extend-native.js +1 -2
- package/lib/rules/no-misleading-character-class.js +110 -63
- package/lib/rules/no-restricted-imports.js +183 -47
- package/lib/rules/no-unused-vars.js +14 -1
- package/lib/rules/use-isnan.js +33 -4
- package/lib/rules/utils/ast-utils.js +9 -0
- package/lib/rules/utils/char-source.js +240 -0
- package/package.json +5 -5
@@ -19,6 +19,8 @@ const {
|
|
19
19
|
lineBreakPattern,
|
20
20
|
shebangPattern
|
21
21
|
} = require("../../shared/ast-utils");
|
22
|
+
const globals = require("../../../conf/globals");
|
23
|
+
const { LATEST_ECMA_VERSION } = require("../../../conf/ecma-version");
|
22
24
|
|
23
25
|
//------------------------------------------------------------------------------
|
24
26
|
// Helpers
|
@@ -46,6 +48,12 @@ const OCTAL_OR_NON_OCTAL_DECIMAL_ESCAPE_PATTERN = /^(?:[^\\]|\\.)*\\(?:[1-9]|0[0
|
|
46
48
|
|
47
49
|
const LOGICAL_ASSIGNMENT_OPERATORS = new Set(["&&=", "||=", "??="]);
|
48
50
|
|
51
|
+
/**
|
52
|
+
* All builtin global variables defined in the latest ECMAScript specification.
|
53
|
+
* @type {Record<string,boolean>} Key is the name of the variable. Value is `true` if the variable is considered writable, `false` otherwise.
|
54
|
+
*/
|
55
|
+
const ECMASCRIPT_GLOBALS = globals[`es${LATEST_ECMA_VERSION}`];
|
56
|
+
|
49
57
|
/**
|
50
58
|
* Checks reference if is non initializer and writable.
|
51
59
|
* @param {Reference} reference A reference to check.
|
@@ -1133,6 +1141,7 @@ module.exports = {
|
|
1133
1141
|
LINEBREAK_MATCHER: lineBreakPattern,
|
1134
1142
|
SHEBANG_MATCHER: shebangPattern,
|
1135
1143
|
STATEMENT_LIST_PARENTS,
|
1144
|
+
ECMASCRIPT_GLOBALS,
|
1136
1145
|
|
1137
1146
|
/**
|
1138
1147
|
* Determines whether two adjacent tokens are on the same line.
|
@@ -0,0 +1,240 @@
|
|
1
|
+
/**
|
2
|
+
* @fileoverview Utility functions to locate the source text of each code unit in the value of a string literal or template token.
|
3
|
+
* @author Francesco Trotta
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
/**
|
9
|
+
* Represents a code unit produced by the evaluation of a JavaScript common token like a string
|
10
|
+
* literal or template token.
|
11
|
+
*/
|
12
|
+
class CodeUnit {
|
13
|
+
constructor(start, source) {
|
14
|
+
this.start = start;
|
15
|
+
this.source = source;
|
16
|
+
}
|
17
|
+
|
18
|
+
get end() {
|
19
|
+
return this.start + this.length;
|
20
|
+
}
|
21
|
+
|
22
|
+
get length() {
|
23
|
+
return this.source.length;
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
/**
|
28
|
+
* An object used to keep track of the position in a source text where the next characters will be read.
|
29
|
+
*/
|
30
|
+
class TextReader {
|
31
|
+
constructor(source) {
|
32
|
+
this.source = source;
|
33
|
+
this.pos = 0;
|
34
|
+
}
|
35
|
+
|
36
|
+
/**
|
37
|
+
* Advances the reading position of the specified number of characters.
|
38
|
+
* @param {number} length Number of characters to advance.
|
39
|
+
* @returns {void}
|
40
|
+
*/
|
41
|
+
advance(length) {
|
42
|
+
this.pos += length;
|
43
|
+
}
|
44
|
+
|
45
|
+
/**
|
46
|
+
* Reads characters from the source.
|
47
|
+
* @param {number} [offset=0] The offset where reading starts, relative to the current position.
|
48
|
+
* @param {number} [length=1] Number of characters to read.
|
49
|
+
* @returns {string} A substring of source characters.
|
50
|
+
*/
|
51
|
+
read(offset = 0, length = 1) {
|
52
|
+
const start = offset + this.pos;
|
53
|
+
|
54
|
+
return this.source.slice(start, start + length);
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
const SIMPLE_ESCAPE_SEQUENCES =
|
59
|
+
{ __proto__: null, b: "\b", f: "\f", n: "\n", r: "\r", t: "\t", v: "\v" };
|
60
|
+
|
61
|
+
/**
|
62
|
+
* Reads a hex escape sequence.
|
63
|
+
* @param {TextReader} reader The reader should be positioned on the first hexadecimal digit.
|
64
|
+
* @param {number} length The number of hexadecimal digits.
|
65
|
+
* @returns {string} A code unit.
|
66
|
+
*/
|
67
|
+
function readHexSequence(reader, length) {
|
68
|
+
const str = reader.read(0, length);
|
69
|
+
const charCode = parseInt(str, 16);
|
70
|
+
|
71
|
+
reader.advance(length);
|
72
|
+
return String.fromCharCode(charCode);
|
73
|
+
}
|
74
|
+
|
75
|
+
/**
|
76
|
+
* Reads a Unicode escape sequence.
|
77
|
+
* @param {TextReader} reader The reader should be positioned after the "u".
|
78
|
+
* @returns {string} A code unit.
|
79
|
+
*/
|
80
|
+
function readUnicodeSequence(reader) {
|
81
|
+
const regExp = /\{(?<hexDigits>[\dA-Fa-f]+)\}/uy;
|
82
|
+
|
83
|
+
regExp.lastIndex = reader.pos;
|
84
|
+
const match = regExp.exec(reader.source);
|
85
|
+
|
86
|
+
if (match) {
|
87
|
+
const codePoint = parseInt(match.groups.hexDigits, 16);
|
88
|
+
|
89
|
+
reader.pos = regExp.lastIndex;
|
90
|
+
return String.fromCodePoint(codePoint);
|
91
|
+
}
|
92
|
+
return readHexSequence(reader, 4);
|
93
|
+
}
|
94
|
+
|
95
|
+
/**
|
96
|
+
* Reads an octal escape sequence.
|
97
|
+
* @param {TextReader} reader The reader should be positioned after the first octal digit.
|
98
|
+
* @param {number} maxLength The maximum number of octal digits.
|
99
|
+
* @returns {string} A code unit.
|
100
|
+
*/
|
101
|
+
function readOctalSequence(reader, maxLength) {
|
102
|
+
const [octalStr] = reader.read(-1, maxLength).match(/^[0-7]+/u);
|
103
|
+
|
104
|
+
reader.advance(octalStr.length - 1);
|
105
|
+
const octal = parseInt(octalStr, 8);
|
106
|
+
|
107
|
+
return String.fromCharCode(octal);
|
108
|
+
}
|
109
|
+
|
110
|
+
/**
|
111
|
+
* Reads an escape sequence or line continuation.
|
112
|
+
* @param {TextReader} reader The reader should be positioned on the backslash.
|
113
|
+
* @returns {string} A string of zero, one or two code units.
|
114
|
+
*/
|
115
|
+
function readEscapeSequenceOrLineContinuation(reader) {
|
116
|
+
const char = reader.read(1);
|
117
|
+
|
118
|
+
reader.advance(2);
|
119
|
+
const unitChar = SIMPLE_ESCAPE_SEQUENCES[char];
|
120
|
+
|
121
|
+
if (unitChar) {
|
122
|
+
return unitChar;
|
123
|
+
}
|
124
|
+
switch (char) {
|
125
|
+
case "x":
|
126
|
+
return readHexSequence(reader, 2);
|
127
|
+
case "u":
|
128
|
+
return readUnicodeSequence(reader);
|
129
|
+
case "\r":
|
130
|
+
if (reader.read() === "\n") {
|
131
|
+
reader.advance(1);
|
132
|
+
}
|
133
|
+
|
134
|
+
// fallthrough
|
135
|
+
case "\n":
|
136
|
+
case "\u2028":
|
137
|
+
case "\u2029":
|
138
|
+
return "";
|
139
|
+
case "0":
|
140
|
+
case "1":
|
141
|
+
case "2":
|
142
|
+
case "3":
|
143
|
+
return readOctalSequence(reader, 3);
|
144
|
+
case "4":
|
145
|
+
case "5":
|
146
|
+
case "6":
|
147
|
+
case "7":
|
148
|
+
return readOctalSequence(reader, 2);
|
149
|
+
default:
|
150
|
+
return char;
|
151
|
+
}
|
152
|
+
}
|
153
|
+
|
154
|
+
/**
|
155
|
+
* Reads an escape sequence or line continuation and generates the respective `CodeUnit` elements.
|
156
|
+
* @param {TextReader} reader The reader should be positioned on the backslash.
|
157
|
+
* @returns {Generator<CodeUnit>} Zero, one or two `CodeUnit` elements.
|
158
|
+
*/
|
159
|
+
function *mapEscapeSequenceOrLineContinuation(reader) {
|
160
|
+
const start = reader.pos;
|
161
|
+
const str = readEscapeSequenceOrLineContinuation(reader);
|
162
|
+
const end = reader.pos;
|
163
|
+
const source = reader.source.slice(start, end);
|
164
|
+
|
165
|
+
switch (str.length) {
|
166
|
+
case 0:
|
167
|
+
break;
|
168
|
+
case 1:
|
169
|
+
yield new CodeUnit(start, source);
|
170
|
+
break;
|
171
|
+
default:
|
172
|
+
yield new CodeUnit(start, source);
|
173
|
+
yield new CodeUnit(start, source);
|
174
|
+
break;
|
175
|
+
}
|
176
|
+
}
|
177
|
+
|
178
|
+
/**
|
179
|
+
* Parses a string literal.
|
180
|
+
* @param {string} source The string literal to parse, including the delimiting quotes.
|
181
|
+
* @returns {CodeUnit[]} A list of code units produced by the string literal.
|
182
|
+
*/
|
183
|
+
function parseStringLiteral(source) {
|
184
|
+
const reader = new TextReader(source);
|
185
|
+
const quote = reader.read();
|
186
|
+
|
187
|
+
reader.advance(1);
|
188
|
+
const codeUnits = [];
|
189
|
+
|
190
|
+
for (;;) {
|
191
|
+
const char = reader.read();
|
192
|
+
|
193
|
+
if (char === quote) {
|
194
|
+
break;
|
195
|
+
}
|
196
|
+
if (char === "\\") {
|
197
|
+
codeUnits.push(...mapEscapeSequenceOrLineContinuation(reader));
|
198
|
+
} else {
|
199
|
+
codeUnits.push(new CodeUnit(reader.pos, char));
|
200
|
+
reader.advance(1);
|
201
|
+
}
|
202
|
+
}
|
203
|
+
return codeUnits;
|
204
|
+
}
|
205
|
+
|
206
|
+
/**
|
207
|
+
* Parses a template token.
|
208
|
+
* @param {string} source The template token to parse, including the delimiting sequences `` ` ``, `${` and `}`.
|
209
|
+
* @returns {CodeUnit[]} A list of code units produced by the template token.
|
210
|
+
*/
|
211
|
+
function parseTemplateToken(source) {
|
212
|
+
const reader = new TextReader(source);
|
213
|
+
|
214
|
+
reader.advance(1);
|
215
|
+
const codeUnits = [];
|
216
|
+
|
217
|
+
for (;;) {
|
218
|
+
const char = reader.read();
|
219
|
+
|
220
|
+
if (char === "`" || char === "$" && reader.read(1) === "{") {
|
221
|
+
break;
|
222
|
+
}
|
223
|
+
if (char === "\\") {
|
224
|
+
codeUnits.push(...mapEscapeSequenceOrLineContinuation(reader));
|
225
|
+
} else {
|
226
|
+
let unitSource;
|
227
|
+
|
228
|
+
if (char === "\r" && reader.read(1) === "\n") {
|
229
|
+
unitSource = "\r\n";
|
230
|
+
} else {
|
231
|
+
unitSource = char;
|
232
|
+
}
|
233
|
+
codeUnits.push(new CodeUnit(reader.pos, unitSource));
|
234
|
+
reader.advance(unitSource.length);
|
235
|
+
}
|
236
|
+
}
|
237
|
+
return codeUnits;
|
238
|
+
}
|
239
|
+
|
240
|
+
module.exports = { parseStringLiteral, parseTemplateToken };
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "eslint",
|
3
|
-
"version": "9.0.0-beta.
|
3
|
+
"version": "9.0.0-beta.2",
|
4
4
|
"author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
|
5
5
|
"description": "An AST-based pattern checker for JavaScript.",
|
6
6
|
"bin": {
|
@@ -65,8 +65,8 @@
|
|
65
65
|
"dependencies": {
|
66
66
|
"@eslint-community/eslint-utils": "^4.2.0",
|
67
67
|
"@eslint-community/regexpp": "^4.6.1",
|
68
|
-
"@eslint/eslintrc": "^3.0.
|
69
|
-
"@eslint/js": "9.0.0-beta.
|
68
|
+
"@eslint/eslintrc": "^3.0.2",
|
69
|
+
"@eslint/js": "9.0.0-beta.2",
|
70
70
|
"@humanwhocodes/config-array": "^0.11.14",
|
71
71
|
"@humanwhocodes/module-importer": "^1.0.1",
|
72
72
|
"@nodelib/fs.walk": "^1.2.8",
|
@@ -84,7 +84,6 @@
|
|
84
84
|
"file-entry-cache": "^8.0.0",
|
85
85
|
"find-up": "^5.0.0",
|
86
86
|
"glob-parent": "^6.0.2",
|
87
|
-
"globals": "^13.19.0",
|
88
87
|
"graphemer": "^1.4.0",
|
89
88
|
"ignore": "^5.2.0",
|
90
89
|
"imurmurhash": "^0.1.4",
|
@@ -122,12 +121,13 @@
|
|
122
121
|
"eslint-plugin-jsdoc": "^46.9.0",
|
123
122
|
"eslint-plugin-n": "^16.6.0",
|
124
123
|
"eslint-plugin-unicorn": "^49.0.0",
|
125
|
-
"eslint-release": "^3.2.
|
124
|
+
"eslint-release": "^3.2.2",
|
126
125
|
"eslump": "^3.0.0",
|
127
126
|
"esprima": "^4.0.1",
|
128
127
|
"fast-glob": "^3.2.11",
|
129
128
|
"fs-teardown": "^0.1.3",
|
130
129
|
"glob": "^10.0.0",
|
130
|
+
"globals": "^14.0.0",
|
131
131
|
"got": "^11.8.3",
|
132
132
|
"gray-matter": "^4.0.3",
|
133
133
|
"js-yaml": "^4.1.0",
|