eslint-plugin-n 14.0.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/LICENSE +22 -0
- package/README.md +189 -0
- package/lib/configs/_commons.js +76 -0
- package/lib/configs/recommended-module.js +27 -0
- package/lib/configs/recommended-script.js +24 -0
- package/lib/configs/recommended.js +18 -0
- package/lib/index.js +55 -0
- package/lib/rules/callback-return.js +185 -0
- package/lib/rules/exports-style.js +297 -0
- package/lib/rules/file-extension-in-import.js +129 -0
- package/lib/rules/global-require.js +91 -0
- package/lib/rules/handle-callback-err.js +94 -0
- package/lib/rules/no-callback-literal.js +82 -0
- package/lib/rules/no-deprecated-api.js +782 -0
- package/lib/rules/no-exports-assign.js +75 -0
- package/lib/rules/no-extraneous-import.js +49 -0
- package/lib/rules/no-extraneous-require.js +49 -0
- package/lib/rules/no-hide-core-modules.js +157 -0
- package/lib/rules/no-missing-import.js +47 -0
- package/lib/rules/no-missing-require.js +47 -0
- package/lib/rules/no-mixed-requires.js +255 -0
- package/lib/rules/no-new-require.js +39 -0
- package/lib/rules/no-path-concat.js +212 -0
- package/lib/rules/no-process-env.js +45 -0
- package/lib/rules/no-process-exit.js +36 -0
- package/lib/rules/no-restricted-import.js +61 -0
- package/lib/rules/no-restricted-require.js +61 -0
- package/lib/rules/no-sync.js +53 -0
- package/lib/rules/no-unpublished-bin.js +97 -0
- package/lib/rules/no-unpublished-import.js +49 -0
- package/lib/rules/no-unpublished-require.js +49 -0
- package/lib/rules/no-unsupported-features/es-builtins.js +181 -0
- package/lib/rules/no-unsupported-features/es-syntax.js +659 -0
- package/lib/rules/no-unsupported-features/node-builtins.js +417 -0
- package/lib/rules/no-unsupported-features.js +1542 -0
- package/lib/rules/prefer-global/buffer.js +49 -0
- package/lib/rules/prefer-global/console.js +46 -0
- package/lib/rules/prefer-global/process.js +46 -0
- package/lib/rules/prefer-global/text-decoder.js +49 -0
- package/lib/rules/prefer-global/text-encoder.js +49 -0
- package/lib/rules/prefer-global/url-search-params.js +49 -0
- package/lib/rules/prefer-global/url.js +48 -0
- package/lib/rules/prefer-promises/dns.js +74 -0
- package/lib/rules/prefer-promises/fs.js +76 -0
- package/lib/rules/process-exit-as-throw.js +164 -0
- package/lib/rules/shebang.js +170 -0
- package/lib/util/cache.js +58 -0
- package/lib/util/check-existence.js +40 -0
- package/lib/util/check-extraneous.js +52 -0
- package/lib/util/check-prefer-global.js +63 -0
- package/lib/util/check-publish.js +71 -0
- package/lib/util/check-restricted.js +109 -0
- package/lib/util/check-unsupported-builtins.js +108 -0
- package/lib/util/enumerate-property-names.js +39 -0
- package/lib/util/exists.js +58 -0
- package/lib/util/get-allow-modules.js +47 -0
- package/lib/util/get-configured-node-version.js +39 -0
- package/lib/util/get-convert-path.js +189 -0
- package/lib/util/get-npmignore.js +184 -0
- package/lib/util/get-package-json.js +75 -0
- package/lib/util/get-resolve-paths.js +44 -0
- package/lib/util/get-semver-range.js +30 -0
- package/lib/util/get-try-extensions.js +47 -0
- package/lib/util/import-target.js +85 -0
- package/lib/util/merge-visitors-in-place.js +46 -0
- package/lib/util/strip-import-path-params.js +10 -0
- package/lib/util/visit-import.js +66 -0
- package/lib/util/visit-require.js +60 -0
- package/package.json +91 -0
|
@@ -0,0 +1,659 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author Toru Nagashima
|
|
3
|
+
* See LICENSE file in root directory for full license.
|
|
4
|
+
*/
|
|
5
|
+
"use strict"
|
|
6
|
+
|
|
7
|
+
const { rules: esRules } = require("eslint-plugin-es")
|
|
8
|
+
const { getInnermostScope } = require("eslint-utils")
|
|
9
|
+
const { Range } = require("semver") //eslint-disable-line no-unused-vars
|
|
10
|
+
const getConfiguredNodeVersion = require("../../util/get-configured-node-version")
|
|
11
|
+
const getSemverRange = require("../../util/get-semver-range")
|
|
12
|
+
const mergeVisitorsInPlace = require("../../util/merge-visitors-in-place")
|
|
13
|
+
|
|
14
|
+
const getOrSet = /^(?:g|s)et$/u
|
|
15
|
+
const features = {
|
|
16
|
+
//--------------------------------------------------------------------------
|
|
17
|
+
// ES2015
|
|
18
|
+
//--------------------------------------------------------------------------
|
|
19
|
+
arrowFunctions: {
|
|
20
|
+
ruleId: "no-arrow-functions",
|
|
21
|
+
cases: [
|
|
22
|
+
{
|
|
23
|
+
supported: "4.0.0",
|
|
24
|
+
messageId: "no-arrow-functions",
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
binaryNumericLiterals: {
|
|
29
|
+
ruleId: "no-binary-numeric-literals",
|
|
30
|
+
cases: [
|
|
31
|
+
{
|
|
32
|
+
supported: "4.0.0",
|
|
33
|
+
messageId: "no-binary-numeric-literals",
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
|
+
blockScopedFunctions: {
|
|
38
|
+
ruleId: "no-block-scoped-functions",
|
|
39
|
+
cases: [
|
|
40
|
+
{
|
|
41
|
+
supported: "6.0.0",
|
|
42
|
+
test: info => !info.isStrict,
|
|
43
|
+
messageId: "no-block-scoped-functions-sloppy",
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
supported: "4.0.0",
|
|
47
|
+
messageId: "no-block-scoped-functions-strict",
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
blockScopedVariables: {
|
|
52
|
+
ruleId: "no-block-scoped-variables",
|
|
53
|
+
cases: [
|
|
54
|
+
{
|
|
55
|
+
supported: "6.0.0",
|
|
56
|
+
test: info => !info.isStrict,
|
|
57
|
+
messageId: "no-block-scoped-variables-sloppy",
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
supported: "4.0.0",
|
|
61
|
+
messageId: "no-block-scoped-variables-strict",
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
classes: {
|
|
66
|
+
ruleId: "no-classes",
|
|
67
|
+
cases: [
|
|
68
|
+
{
|
|
69
|
+
supported: "6.0.0",
|
|
70
|
+
test: info => !info.isStrict,
|
|
71
|
+
messageId: "no-classes-sloppy",
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
supported: "4.0.0",
|
|
75
|
+
messageId: "no-classes-strict",
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
computedProperties: {
|
|
80
|
+
ruleId: "no-computed-properties",
|
|
81
|
+
cases: [
|
|
82
|
+
{
|
|
83
|
+
supported: "4.0.0",
|
|
84
|
+
messageId: "no-computed-properties",
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
},
|
|
88
|
+
defaultParameters: {
|
|
89
|
+
ruleId: "no-default-parameters",
|
|
90
|
+
cases: [
|
|
91
|
+
{
|
|
92
|
+
supported: "6.0.0",
|
|
93
|
+
messageId: "no-default-parameters",
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
},
|
|
97
|
+
destructuring: {
|
|
98
|
+
ruleId: "no-destructuring",
|
|
99
|
+
cases: [
|
|
100
|
+
{
|
|
101
|
+
supported: "6.0.0",
|
|
102
|
+
messageId: "no-destructuring",
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
forOfLoops: {
|
|
107
|
+
ruleId: "no-for-of-loops",
|
|
108
|
+
cases: [
|
|
109
|
+
{
|
|
110
|
+
supported: "0.12.0",
|
|
111
|
+
messageId: "no-for-of-loops",
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
},
|
|
115
|
+
generators: {
|
|
116
|
+
ruleId: "no-generators",
|
|
117
|
+
cases: [
|
|
118
|
+
{
|
|
119
|
+
supported: "4.0.0",
|
|
120
|
+
messageId: "no-generators",
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
},
|
|
124
|
+
modules: {
|
|
125
|
+
ruleId: "no-modules",
|
|
126
|
+
cases: [
|
|
127
|
+
{
|
|
128
|
+
supported: null,
|
|
129
|
+
messageId: "no-modules",
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
},
|
|
133
|
+
"new.target": {
|
|
134
|
+
ruleId: "no-new-target",
|
|
135
|
+
cases: [
|
|
136
|
+
{
|
|
137
|
+
supported: "5.0.0",
|
|
138
|
+
messageId: "no-new-target",
|
|
139
|
+
},
|
|
140
|
+
],
|
|
141
|
+
},
|
|
142
|
+
objectSuperProperties: {
|
|
143
|
+
ruleId: "no-object-super-properties",
|
|
144
|
+
cases: [
|
|
145
|
+
{
|
|
146
|
+
supported: "4.0.0",
|
|
147
|
+
messageId: "no-object-super-properties",
|
|
148
|
+
},
|
|
149
|
+
],
|
|
150
|
+
},
|
|
151
|
+
octalNumericLiterals: {
|
|
152
|
+
ruleId: "no-octal-numeric-literals",
|
|
153
|
+
cases: [
|
|
154
|
+
{
|
|
155
|
+
supported: "4.0.0",
|
|
156
|
+
messageId: "no-octal-numeric-literals",
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
},
|
|
160
|
+
propertyShorthands: {
|
|
161
|
+
ruleId: "no-property-shorthands",
|
|
162
|
+
cases: [
|
|
163
|
+
{
|
|
164
|
+
supported: "6.0.0",
|
|
165
|
+
test: info =>
|
|
166
|
+
info.node.shorthand && getOrSet.test(info.node.key.name),
|
|
167
|
+
messageId: "no-property-shorthands-getset",
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
supported: "4.0.0",
|
|
171
|
+
messageId: "no-property-shorthands",
|
|
172
|
+
},
|
|
173
|
+
],
|
|
174
|
+
},
|
|
175
|
+
regexpU: {
|
|
176
|
+
ruleId: "no-regexp-u-flag",
|
|
177
|
+
cases: [
|
|
178
|
+
{
|
|
179
|
+
supported: "6.0.0",
|
|
180
|
+
messageId: "no-regexp-u-flag",
|
|
181
|
+
},
|
|
182
|
+
],
|
|
183
|
+
},
|
|
184
|
+
regexpY: {
|
|
185
|
+
ruleId: "no-regexp-y-flag",
|
|
186
|
+
cases: [
|
|
187
|
+
{
|
|
188
|
+
supported: "6.0.0",
|
|
189
|
+
messageId: "no-regexp-y-flag",
|
|
190
|
+
},
|
|
191
|
+
],
|
|
192
|
+
},
|
|
193
|
+
restParameters: {
|
|
194
|
+
ruleId: "no-rest-parameters",
|
|
195
|
+
cases: [
|
|
196
|
+
{
|
|
197
|
+
supported: "6.0.0",
|
|
198
|
+
messageId: "no-rest-parameters",
|
|
199
|
+
},
|
|
200
|
+
],
|
|
201
|
+
},
|
|
202
|
+
spreadElements: {
|
|
203
|
+
ruleId: "no-spread-elements",
|
|
204
|
+
cases: [
|
|
205
|
+
{
|
|
206
|
+
supported: "5.0.0",
|
|
207
|
+
messageId: "no-spread-elements",
|
|
208
|
+
},
|
|
209
|
+
],
|
|
210
|
+
},
|
|
211
|
+
templateLiterals: {
|
|
212
|
+
ruleId: "no-template-literals",
|
|
213
|
+
cases: [
|
|
214
|
+
{
|
|
215
|
+
supported: "4.0.0",
|
|
216
|
+
messageId: "no-template-literals",
|
|
217
|
+
},
|
|
218
|
+
],
|
|
219
|
+
},
|
|
220
|
+
unicodeCodePointEscapes: {
|
|
221
|
+
ruleId: "no-unicode-codepoint-escapes",
|
|
222
|
+
cases: [
|
|
223
|
+
{
|
|
224
|
+
supported: "4.0.0",
|
|
225
|
+
messageId: "no-unicode-codepoint-escapes",
|
|
226
|
+
},
|
|
227
|
+
],
|
|
228
|
+
},
|
|
229
|
+
|
|
230
|
+
//--------------------------------------------------------------------------
|
|
231
|
+
// ES2016
|
|
232
|
+
//--------------------------------------------------------------------------
|
|
233
|
+
exponentialOperators: {
|
|
234
|
+
ruleId: "no-exponential-operators",
|
|
235
|
+
cases: [
|
|
236
|
+
{
|
|
237
|
+
supported: "7.0.0",
|
|
238
|
+
messageId: "no-exponential-operators",
|
|
239
|
+
},
|
|
240
|
+
],
|
|
241
|
+
},
|
|
242
|
+
|
|
243
|
+
//--------------------------------------------------------------------------
|
|
244
|
+
// ES2017
|
|
245
|
+
//--------------------------------------------------------------------------
|
|
246
|
+
asyncFunctions: {
|
|
247
|
+
ruleId: "no-async-functions",
|
|
248
|
+
cases: [
|
|
249
|
+
{
|
|
250
|
+
supported: "7.6.0",
|
|
251
|
+
messageId: "no-async-functions",
|
|
252
|
+
},
|
|
253
|
+
],
|
|
254
|
+
},
|
|
255
|
+
trailingCommasInFunctions: {
|
|
256
|
+
ruleId: "no-trailing-function-commas",
|
|
257
|
+
cases: [
|
|
258
|
+
{
|
|
259
|
+
supported: "8.0.0",
|
|
260
|
+
messageId: "no-trailing-function-commas",
|
|
261
|
+
},
|
|
262
|
+
],
|
|
263
|
+
},
|
|
264
|
+
|
|
265
|
+
//--------------------------------------------------------------------------
|
|
266
|
+
// ES2018
|
|
267
|
+
//--------------------------------------------------------------------------
|
|
268
|
+
asyncIteration: {
|
|
269
|
+
ruleId: "no-async-iteration",
|
|
270
|
+
cases: [
|
|
271
|
+
{
|
|
272
|
+
supported: "10.0.0",
|
|
273
|
+
messageId: "no-async-iteration",
|
|
274
|
+
},
|
|
275
|
+
],
|
|
276
|
+
},
|
|
277
|
+
malformedTemplateLiterals: {
|
|
278
|
+
ruleId: "no-malformed-template-literals",
|
|
279
|
+
cases: [
|
|
280
|
+
{
|
|
281
|
+
supported: "8.10.0",
|
|
282
|
+
messageId: "no-malformed-template-literals",
|
|
283
|
+
},
|
|
284
|
+
],
|
|
285
|
+
},
|
|
286
|
+
regexpLookbehind: {
|
|
287
|
+
ruleId: "no-regexp-lookbehind-assertions",
|
|
288
|
+
cases: [
|
|
289
|
+
{
|
|
290
|
+
supported: "8.10.0",
|
|
291
|
+
messageId: "no-regexp-lookbehind-assertions",
|
|
292
|
+
},
|
|
293
|
+
],
|
|
294
|
+
},
|
|
295
|
+
regexpNamedCaptureGroups: {
|
|
296
|
+
ruleId: "no-regexp-named-capture-groups",
|
|
297
|
+
cases: [
|
|
298
|
+
{
|
|
299
|
+
supported: "10.0.0",
|
|
300
|
+
messageId: "no-regexp-named-capture-groups",
|
|
301
|
+
},
|
|
302
|
+
],
|
|
303
|
+
},
|
|
304
|
+
regexpS: {
|
|
305
|
+
ruleId: "no-regexp-s-flag",
|
|
306
|
+
cases: [
|
|
307
|
+
{
|
|
308
|
+
supported: "8.10.0",
|
|
309
|
+
messageId: "no-regexp-s-flag",
|
|
310
|
+
},
|
|
311
|
+
],
|
|
312
|
+
},
|
|
313
|
+
regexpUnicodeProperties: {
|
|
314
|
+
ruleId: "no-regexp-unicode-property-escapes",
|
|
315
|
+
cases: [
|
|
316
|
+
{
|
|
317
|
+
supported: "10.0.0",
|
|
318
|
+
messageId: "no-regexp-unicode-property-escapes",
|
|
319
|
+
},
|
|
320
|
+
],
|
|
321
|
+
},
|
|
322
|
+
restSpreadProperties: {
|
|
323
|
+
ruleId: "no-rest-spread-properties",
|
|
324
|
+
cases: [
|
|
325
|
+
{
|
|
326
|
+
supported: "8.3.0",
|
|
327
|
+
messageId: "no-rest-spread-properties",
|
|
328
|
+
},
|
|
329
|
+
],
|
|
330
|
+
},
|
|
331
|
+
|
|
332
|
+
//--------------------------------------------------------------------------
|
|
333
|
+
// ES2019
|
|
334
|
+
//--------------------------------------------------------------------------
|
|
335
|
+
jsonSuperset: {
|
|
336
|
+
ruleId: "no-json-superset",
|
|
337
|
+
cases: [
|
|
338
|
+
{
|
|
339
|
+
supported: "10.0.0",
|
|
340
|
+
messageId: "no-json-superset",
|
|
341
|
+
},
|
|
342
|
+
],
|
|
343
|
+
},
|
|
344
|
+
optionalCatchBinding: {
|
|
345
|
+
ruleId: "no-optional-catch-binding",
|
|
346
|
+
cases: [
|
|
347
|
+
{
|
|
348
|
+
supported: "10.0.0",
|
|
349
|
+
messageId: "no-optional-catch-binding",
|
|
350
|
+
},
|
|
351
|
+
],
|
|
352
|
+
},
|
|
353
|
+
|
|
354
|
+
//--------------------------------------------------------------------------
|
|
355
|
+
// ES2020
|
|
356
|
+
//--------------------------------------------------------------------------
|
|
357
|
+
bigint: {
|
|
358
|
+
ruleId: "no-bigint",
|
|
359
|
+
cases: [
|
|
360
|
+
{
|
|
361
|
+
supported: "10.4.0",
|
|
362
|
+
test: info => info.node.type === "Literal",
|
|
363
|
+
messageId: "no-bigint",
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
supported: null,
|
|
367
|
+
test: ({ node }) =>
|
|
368
|
+
node.type === "Literal" &&
|
|
369
|
+
(node.parent.type === "Property" ||
|
|
370
|
+
node.parent.type === "MethodDefinition") &&
|
|
371
|
+
!node.parent.computed &&
|
|
372
|
+
node.parent.key === node,
|
|
373
|
+
messageId: "no-bigint-property-names",
|
|
374
|
+
},
|
|
375
|
+
],
|
|
376
|
+
},
|
|
377
|
+
dynamicImport: {
|
|
378
|
+
ruleId: "no-dynamic-import",
|
|
379
|
+
cases: [
|
|
380
|
+
{
|
|
381
|
+
supported: null,
|
|
382
|
+
messageId: "no-dynamic-import",
|
|
383
|
+
},
|
|
384
|
+
],
|
|
385
|
+
},
|
|
386
|
+
optionalChaining: {
|
|
387
|
+
ruleId: "no-optional-chaining",
|
|
388
|
+
cases: [
|
|
389
|
+
{
|
|
390
|
+
supported: "14.0.0",
|
|
391
|
+
messageId: "no-optional-chaining",
|
|
392
|
+
},
|
|
393
|
+
],
|
|
394
|
+
},
|
|
395
|
+
nullishCoalescingOperators: {
|
|
396
|
+
ruleId: "no-nullish-coalescing-operators",
|
|
397
|
+
cases: [
|
|
398
|
+
{
|
|
399
|
+
supported: "14.0.0",
|
|
400
|
+
messageId: "no-nullish-coalescing-operators",
|
|
401
|
+
},
|
|
402
|
+
],
|
|
403
|
+
},
|
|
404
|
+
}
|
|
405
|
+
const keywords = Object.keys(features)
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Parses the options.
|
|
409
|
+
* @param {RuleContext} context The rule context.
|
|
410
|
+
* @returns {{version:Range,ignores:Set<string>}} Parsed value.
|
|
411
|
+
*/
|
|
412
|
+
function parseOptions(context) {
|
|
413
|
+
const raw = context.options[0] || {}
|
|
414
|
+
const filePath = context.getFilename()
|
|
415
|
+
const version = getConfiguredNodeVersion(raw.version, filePath)
|
|
416
|
+
const ignores = new Set(raw.ignores || [])
|
|
417
|
+
|
|
418
|
+
return Object.freeze({ version, ignores })
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Find the scope that a given node belongs to.
|
|
423
|
+
* @param {Scope} initialScope The initial scope to find.
|
|
424
|
+
* @param {Node} node The AST node.
|
|
425
|
+
* @returns {Scope} The scope that the node belongs to.
|
|
426
|
+
*/
|
|
427
|
+
function normalizeScope(initialScope, node) {
|
|
428
|
+
let scope = getInnermostScope(initialScope, node)
|
|
429
|
+
|
|
430
|
+
while (scope && scope.block === node) {
|
|
431
|
+
scope = scope.upper
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
return scope
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Define the visitor object as merging the rules of eslint-plugin-es.
|
|
439
|
+
* @param {RuleContext} context The rule context.
|
|
440
|
+
* @param {{version:Range,ignores:Set<string>}} options The options.
|
|
441
|
+
* @returns {object} The defined visitor.
|
|
442
|
+
*/
|
|
443
|
+
function defineVisitor(context, options) {
|
|
444
|
+
const testInfoPrototype = {
|
|
445
|
+
get isStrict() {
|
|
446
|
+
return normalizeScope(context.getScope(), this.node).isStrict
|
|
447
|
+
},
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* Check whether a given case object is full-supported on the configured node version.
|
|
452
|
+
* @param {{supported:string}} aCase The case object to check.
|
|
453
|
+
* @returns {boolean} `true` if it's supporting.
|
|
454
|
+
*/
|
|
455
|
+
function isNotSupportingVersion(aCase) {
|
|
456
|
+
return (
|
|
457
|
+
!aCase.supported ||
|
|
458
|
+
options.version.intersects(getSemverRange(`<${aCase.supported}`))
|
|
459
|
+
)
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* Define the predicate function to check whether a given case object is supported on the configured node version.
|
|
464
|
+
* @param {Node} node The node which is reported.
|
|
465
|
+
* @returns {function(aCase:{supported:string}):boolean} The predicate function.
|
|
466
|
+
*/
|
|
467
|
+
function isNotSupportingOn(node) {
|
|
468
|
+
return aCase =>
|
|
469
|
+
isNotSupportingVersion(aCase) &&
|
|
470
|
+
(!aCase.test || aCase.test({ node, __proto__: testInfoPrototype }))
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
return (
|
|
474
|
+
keywords
|
|
475
|
+
// Omit full-supported features and ignored features by options
|
|
476
|
+
// because this rule never reports those.
|
|
477
|
+
.filter(
|
|
478
|
+
keyword =>
|
|
479
|
+
!options.ignores.has(keyword) &&
|
|
480
|
+
features[keyword].cases.some(isNotSupportingVersion)
|
|
481
|
+
)
|
|
482
|
+
// Merge remaining features with overriding `context.report()`.
|
|
483
|
+
.reduce((visitor, keyword) => {
|
|
484
|
+
const { ruleId, cases } = features[keyword]
|
|
485
|
+
const rule = esRules[ruleId]
|
|
486
|
+
const thisContext = {
|
|
487
|
+
__proto__: context,
|
|
488
|
+
|
|
489
|
+
// Override `context.report()` then:
|
|
490
|
+
// - ignore if it's supported.
|
|
491
|
+
// - override reporting messages.
|
|
492
|
+
report(descriptor) {
|
|
493
|
+
// Set additional information.
|
|
494
|
+
if (descriptor.data) {
|
|
495
|
+
descriptor.data.version = options.version.raw
|
|
496
|
+
} else {
|
|
497
|
+
descriptor.data = { version: options.version.raw }
|
|
498
|
+
}
|
|
499
|
+
descriptor.fix = undefined
|
|
500
|
+
|
|
501
|
+
// Test and report.
|
|
502
|
+
const node = descriptor.node
|
|
503
|
+
const hitCase = cases.find(isNotSupportingOn(node))
|
|
504
|
+
if (hitCase) {
|
|
505
|
+
descriptor.messageId = hitCase.messageId
|
|
506
|
+
descriptor.data.supported = hitCase.supported
|
|
507
|
+
super.report(descriptor)
|
|
508
|
+
}
|
|
509
|
+
},
|
|
510
|
+
}
|
|
511
|
+
return mergeVisitorsInPlace(visitor, rule.create(thisContext))
|
|
512
|
+
}, {})
|
|
513
|
+
)
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
module.exports = {
|
|
517
|
+
meta: {
|
|
518
|
+
docs: {
|
|
519
|
+
description:
|
|
520
|
+
"disallow unsupported ECMAScript syntax on the specified version",
|
|
521
|
+
category: "Possible Errors",
|
|
522
|
+
recommended: true,
|
|
523
|
+
url:
|
|
524
|
+
"https://github.com/mysticatea/eslint-plugin-node/blob/HEAD/docs/rules/no-unsupported-features/es-syntax.md",
|
|
525
|
+
},
|
|
526
|
+
type: "problem",
|
|
527
|
+
fixable: null,
|
|
528
|
+
schema: [
|
|
529
|
+
{
|
|
530
|
+
type: "object",
|
|
531
|
+
properties: {
|
|
532
|
+
version: {
|
|
533
|
+
type: "string",
|
|
534
|
+
},
|
|
535
|
+
ignores: {
|
|
536
|
+
type: "array",
|
|
537
|
+
items: {
|
|
538
|
+
enum: Object.keys(features),
|
|
539
|
+
},
|
|
540
|
+
uniqueItems: true,
|
|
541
|
+
},
|
|
542
|
+
},
|
|
543
|
+
additionalProperties: false,
|
|
544
|
+
},
|
|
545
|
+
],
|
|
546
|
+
messages: {
|
|
547
|
+
//------------------------------------------------------------------
|
|
548
|
+
// ES2015
|
|
549
|
+
//------------------------------------------------------------------
|
|
550
|
+
"no-arrow-functions":
|
|
551
|
+
"Arrow functions are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
552
|
+
"no-binary-numeric-literals":
|
|
553
|
+
"Binary numeric literals are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
554
|
+
"no-block-scoped-functions-strict":
|
|
555
|
+
"Block-scoped functions in strict mode are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
556
|
+
"no-block-scoped-functions-sloppy":
|
|
557
|
+
"Block-scoped functions in non-strict mode are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
558
|
+
"no-block-scoped-variables-strict":
|
|
559
|
+
"Block-scoped variables in strict mode are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
560
|
+
"no-block-scoped-variables-sloppy":
|
|
561
|
+
"Block-scoped variables in non-strict mode are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
562
|
+
"no-classes-strict":
|
|
563
|
+
"Classes in strict mode are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
564
|
+
"no-classes-sloppy":
|
|
565
|
+
"Classes in non-strict mode are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
566
|
+
"no-computed-properties":
|
|
567
|
+
"Computed properties are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
568
|
+
"no-default-parameters":
|
|
569
|
+
"Default parameters are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
570
|
+
"no-destructuring":
|
|
571
|
+
"Destructuring is not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
572
|
+
"no-for-of-loops":
|
|
573
|
+
"'for-of' loops are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
574
|
+
"no-generators":
|
|
575
|
+
"Generator functions are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
576
|
+
"no-modules":
|
|
577
|
+
"Import and export declarations are not supported yet.",
|
|
578
|
+
"no-new-target":
|
|
579
|
+
"'new.target' is not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
580
|
+
"no-object-super-properties":
|
|
581
|
+
"'super' in object literals is not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
582
|
+
"no-octal-numeric-literals":
|
|
583
|
+
"Octal numeric literals are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
584
|
+
"no-property-shorthands":
|
|
585
|
+
"Property shorthands are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
586
|
+
"no-property-shorthands-getset":
|
|
587
|
+
"Property shorthands of 'get' and 'set' are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
588
|
+
"no-regexp-u-flag":
|
|
589
|
+
"RegExp 'u' flag is not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
590
|
+
"no-regexp-y-flag":
|
|
591
|
+
"RegExp 'y' flag is not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
592
|
+
"no-rest-parameters":
|
|
593
|
+
"Rest parameters are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
594
|
+
"no-spread-elements":
|
|
595
|
+
"Spread elements are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
596
|
+
"no-template-literals":
|
|
597
|
+
"Template literals are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
598
|
+
"no-unicode-codepoint-escapes":
|
|
599
|
+
"Unicode code point escapes are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
600
|
+
|
|
601
|
+
//------------------------------------------------------------------
|
|
602
|
+
// ES2016
|
|
603
|
+
//------------------------------------------------------------------
|
|
604
|
+
"no-exponential-operators":
|
|
605
|
+
"Exponential operators are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
606
|
+
|
|
607
|
+
//------------------------------------------------------------------
|
|
608
|
+
// ES2017
|
|
609
|
+
//------------------------------------------------------------------
|
|
610
|
+
"no-async-functions":
|
|
611
|
+
"Async functions are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
612
|
+
"no-trailing-function-commas":
|
|
613
|
+
"Trailing commas in function syntax are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
614
|
+
|
|
615
|
+
//------------------------------------------------------------------
|
|
616
|
+
// ES2018
|
|
617
|
+
//------------------------------------------------------------------
|
|
618
|
+
"no-async-iteration":
|
|
619
|
+
"Async iteration is not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
620
|
+
"no-malformed-template-literals":
|
|
621
|
+
"Malformed template literals are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
622
|
+
"no-regexp-lookbehind-assertions":
|
|
623
|
+
"RegExp lookbehind assertions are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
624
|
+
"no-regexp-named-capture-groups":
|
|
625
|
+
"RegExp named capture groups are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
626
|
+
"no-regexp-s-flag":
|
|
627
|
+
"RegExp 's' flag is not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
628
|
+
"no-regexp-unicode-property-escapes":
|
|
629
|
+
"RegExp Unicode property escapes are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
630
|
+
"no-rest-spread-properties":
|
|
631
|
+
"Rest/spread properties are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
632
|
+
|
|
633
|
+
//------------------------------------------------------------------
|
|
634
|
+
// ES2019
|
|
635
|
+
//------------------------------------------------------------------
|
|
636
|
+
"no-json-superset":
|
|
637
|
+
"'\\u{{code}}' in string literals is not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
638
|
+
"no-optional-catch-binding":
|
|
639
|
+
"The omission of 'catch' binding is not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
640
|
+
|
|
641
|
+
//------------------------------------------------------------------
|
|
642
|
+
// ES2020
|
|
643
|
+
//------------------------------------------------------------------
|
|
644
|
+
"no-bigint":
|
|
645
|
+
"Bigint literals are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
646
|
+
"no-bigint-property-names":
|
|
647
|
+
"Bigint literal property names are not supported yet.",
|
|
648
|
+
"no-dynamic-import":
|
|
649
|
+
"'import()' expressions are not supported yet.",
|
|
650
|
+
"no-optional-chaining":
|
|
651
|
+
"Optional chainings are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
652
|
+
"no-nullish-coalescing-operators":
|
|
653
|
+
"Nullish coalescing operators are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
|
|
654
|
+
},
|
|
655
|
+
},
|
|
656
|
+
create(context) {
|
|
657
|
+
return defineVisitor(context, parseOptions(context))
|
|
658
|
+
},
|
|
659
|
+
}
|