@odg/eslint-config 0.9.4 β 1.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/README.md +1264 -208
- package/index.js +26 -0
- package/package.json +4 -2
- package/rules/ini/base.js +5 -0
- package/rules/javascript/best-practices.js +58 -11
- package/rules/javascript/errors.js +4 -0
- package/rules/javascript/performance.js +1 -0
- package/rules/javascript/possible-errors.js +2 -0
- package/rules/javascript/security.js +1 -0
- package/rules/typescript/best-practices.js +29 -5
- package/rules/typescript/errors.js +2 -0
- package/rules/yaml/base.js +23 -0
package/README.md
CHANGED
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
- [EOL last Rule](#eol-last-rule)
|
|
41
41
|
- [Max Line Len Rule](#max-line-len-rule)
|
|
42
42
|
- [Camel Case Rule](#camel-case-rule)
|
|
43
|
+
- [Strict](#strict)
|
|
43
44
|
- [Padded Block Rule](#padded-block-rule)
|
|
44
45
|
- [Lines Between Class Members](#lines-between-class-members)
|
|
45
46
|
- [No Multi Assign Rule](#no-multi-assign-rule)
|
|
@@ -60,10 +61,12 @@
|
|
|
60
61
|
- [Unused Vars](#unused-vars)
|
|
61
62
|
- [Comma Spacing](#comma-spacing)
|
|
62
63
|
- [Comma Dangle](#comma-dangle)
|
|
64
|
+
- [Arrow Spacing](#arrow-spacing)
|
|
63
65
|
- [Prefer Arrow Function](#prefer-arrow-function)
|
|
64
66
|
- [Prefer Destructuring](#prefer-destructuring)
|
|
65
67
|
- [Arrow Function Body](#arrow-function-body)
|
|
66
68
|
- [Arrow Function Parentheses](#arrow-function-parentheses)
|
|
69
|
+
- [Arrow Function No Break Line](#arrow-function-no-break-line)
|
|
67
70
|
- [No Empty Block](#no-empty-block)
|
|
68
71
|
- [No Long Syntax](#no-long-syntax)
|
|
69
72
|
- [Useless Call Code](#useless-call-code)
|
|
@@ -195,6 +198,15 @@
|
|
|
195
198
|
- [Comma Style](#comma-style)
|
|
196
199
|
- [Object BreakLine](#object-break-line)
|
|
197
200
|
- [No Shadow](#no-shadow)
|
|
201
|
+
- [Parentheses New Line](#parentheses-new-line)
|
|
202
|
+
- [No Func Call Spacing](#no-func-call-spacing)
|
|
203
|
+
- [Array Element New Line](#array-element-new-line)
|
|
204
|
+
- [Wrap Iife](#wrap-iife)
|
|
205
|
+
- [Disallow Template Tag Space](#disallow-template-tag-space)
|
|
206
|
+
- [No Space Spread](#no-space-spread)
|
|
207
|
+
- [Inline IF](#inline-if)
|
|
208
|
+
- [New Instance Use Parentheses](#new-instance-use-parentheses)
|
|
209
|
+
- [Logical Assignment Operators](#logical-assignment-operators)
|
|
198
210
|
- [Promise Rules](#promise-rules)
|
|
199
211
|
- [No New Statics](#no-new-statics)
|
|
200
212
|
- [No Return Wrap](#no-return-wrap)
|
|
@@ -310,6 +322,7 @@
|
|
|
310
322
|
- [Protect XSS Render](#protect-xss-render)
|
|
311
323
|
- [Force Integrity](#force-integrity)
|
|
312
324
|
- [DNS prefetching](#dns-prefetching)
|
|
325
|
+
- [No Prototype Builtins](#no-prototype-builtins)
|
|
313
326
|
- [Catch Error Name](#catch-error-name)
|
|
314
327
|
- [Consistent Destructured](#consistent-destructured)
|
|
315
328
|
- [Consistent Function Scope](#consistent-function-scope)
|
|
@@ -351,6 +364,7 @@
|
|
|
351
364
|
- [Prefer String Trim Start End](#prefer-string-trim-start-end)
|
|
352
365
|
- [Prefer Switch](#prefer-switch)
|
|
353
366
|
- [Prefer Ternary](#prefer-ternary)
|
|
367
|
+
- [Multiline Ternary Multiple](#multiline-ternary-multiple)
|
|
354
368
|
- [Prevent Abbreviations](#prevent-abbreviations)
|
|
355
369
|
- [Consistent Relative URL](#consistent-relative-url)
|
|
356
370
|
- [Require Array Join Separator](#require-array-join-separator)
|
|
@@ -377,6 +391,10 @@
|
|
|
377
391
|
- [No Import Resolve](#no-import-resolve)
|
|
378
392
|
- [Import Not Found](#import-not-found)
|
|
379
393
|
- [JS Type](#js-type)
|
|
394
|
+
- [No Invalid This](#no-invalid-this)
|
|
395
|
+
- [No This Before Super](#no-this-before-super)
|
|
396
|
+
- [No Obj Calls](#no-obj-calls)
|
|
397
|
+
- [No Empty Pattern](#no-empty-pattern)
|
|
380
398
|
- [Possible Errors](#possible-errors)
|
|
381
399
|
- [For Direction](#for-direction)
|
|
382
400
|
- [No Extra Bind](#no-extra-bind)
|
|
@@ -391,6 +409,9 @@
|
|
|
391
409
|
- [Assertions In Tests](#assertions-in-tests)
|
|
392
410
|
- [Test Multiple Possible Assert](#test-multiple-possible-assert)
|
|
393
411
|
- [No Disable Timeout](#no-disable-timeout)
|
|
412
|
+
- [No Empty Static Block](#no-empty-static-block)
|
|
413
|
+
- [No Fallthrough](#no-fallthrough)
|
|
414
|
+
- [YAML / JSON](#yaml-json)
|
|
394
415
|
|
|
395
416
|
## Introduction
|
|
396
417
|
|
|
@@ -480,7 +501,10 @@ class Foo {
|
|
|
480
501
|
|
|
481
502
|
Requires the use of double quotes wherever possible
|
|
482
503
|
|
|
483
|
-
|
|
504
|
+
Enforces the use of double quotes for all JSX attribute values that donβt contain a double quote.
|
|
505
|
+
|
|
506
|
+
<https://eslint.org/docs/rules/quotes>
|
|
507
|
+
<https://eslint.org/docs/rules/jsx-quotes>
|
|
484
508
|
|
|
485
509
|
π Examples of correct code
|
|
486
510
|
|
|
@@ -504,9 +528,11 @@ var backtick = `back\ntick`; // you can use \n in single or double quoted string
|
|
|
504
528
|
----------
|
|
505
529
|
|
|
506
530
|
Requires indent with 4 spaces
|
|
531
|
+
Tabs Disallow
|
|
507
532
|
|
|
508
533
|
<https://eslint.org/docs/rules/indent#indent>
|
|
509
534
|
<https://sonarsource.github.io/rspec/#/rspec/S3973/javascript>
|
|
535
|
+
<https://eslint.org/docs/latest/rules/no-tabs>
|
|
510
536
|
|
|
511
537
|
π Examples of correct code
|
|
512
538
|
|
|
@@ -630,6 +656,31 @@ function do_something() {
|
|
|
630
656
|
}
|
|
631
657
|
```
|
|
632
658
|
|
|
659
|
+
## Strict
|
|
660
|
+
|
|
661
|
+
----------
|
|
662
|
+
|
|
663
|
+
A strict mode directive is a "use strict" literal at the beginning of a script or function body.
|
|
664
|
+
It enables strict mode semantics.
|
|
665
|
+
|
|
666
|
+
<https://eslint.org/docs/latest/rules/strict>
|
|
667
|
+
|
|
668
|
+
π Examples of correct code
|
|
669
|
+
|
|
670
|
+
```typescript
|
|
671
|
+
"use strict";
|
|
672
|
+
|
|
673
|
+
function foo() {
|
|
674
|
+
}
|
|
675
|
+
```
|
|
676
|
+
|
|
677
|
+
π Examples of incorrect code
|
|
678
|
+
|
|
679
|
+
```typescript
|
|
680
|
+
function foo() {
|
|
681
|
+
}
|
|
682
|
+
```
|
|
683
|
+
|
|
633
684
|
## Padded Block Rule
|
|
634
685
|
|
|
635
686
|
----------
|
|
@@ -993,6 +1044,7 @@ var c = object[ "foo"];
|
|
|
993
1044
|
Enforces consistent spacing before and after keywords.
|
|
994
1045
|
|
|
995
1046
|
<https://eslint.org/docs/rules/keyword-spacing#keyword-spacing>
|
|
1047
|
+
<https://eslint.org/docs/rules/yield-star-spacing>
|
|
996
1048
|
|
|
997
1049
|
π Examples of correct code
|
|
998
1050
|
|
|
@@ -1010,6 +1062,10 @@ try {
|
|
|
1010
1062
|
} catch(e) {
|
|
1011
1063
|
// code ...
|
|
1012
1064
|
}
|
|
1065
|
+
|
|
1066
|
+
function *generator() {
|
|
1067
|
+
yield *other();
|
|
1068
|
+
}
|
|
1013
1069
|
```
|
|
1014
1070
|
|
|
1015
1071
|
π Examples of incorrect code
|
|
@@ -1028,6 +1084,18 @@ try{
|
|
|
1028
1084
|
}catch(e){
|
|
1029
1085
|
// code ...
|
|
1030
1086
|
}
|
|
1087
|
+
|
|
1088
|
+
function*generator() {
|
|
1089
|
+
yield*other();
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
function* generator() {
|
|
1093
|
+
yield* other();
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
function * generator() {
|
|
1097
|
+
yield * other();
|
|
1098
|
+
}
|
|
1031
1099
|
```
|
|
1032
1100
|
|
|
1033
1101
|
## Space Format
|
|
@@ -1478,6 +1546,35 @@ function baz(
|
|
|
1478
1546
|
}
|
|
1479
1547
|
```
|
|
1480
1548
|
|
|
1549
|
+
## Arrow Spacing
|
|
1550
|
+
|
|
1551
|
+
----------
|
|
1552
|
+
|
|
1553
|
+
This rule normalize style of spacing before/after an arrow functionβs arrow(=>).
|
|
1554
|
+
|
|
1555
|
+
<https://eslint.org/docs/latest/rules/arrow-spacing>
|
|
1556
|
+
|
|
1557
|
+
π Examples of correct code
|
|
1558
|
+
|
|
1559
|
+
```typescript
|
|
1560
|
+
() => {};
|
|
1561
|
+
(a) => {};
|
|
1562
|
+
() => {'\n'};
|
|
1563
|
+
```
|
|
1564
|
+
|
|
1565
|
+
π Examples of incorrect code
|
|
1566
|
+
|
|
1567
|
+
```typescript
|
|
1568
|
+
()=> {};
|
|
1569
|
+
() =>{};
|
|
1570
|
+
(a)=> {};
|
|
1571
|
+
(a) =>{};
|
|
1572
|
+
a =>a;
|
|
1573
|
+
a=> a;
|
|
1574
|
+
()=> {'\n'};
|
|
1575
|
+
() =>{'\n'};
|
|
1576
|
+
```
|
|
1577
|
+
|
|
1481
1578
|
## Prefer Arrow Function
|
|
1482
1579
|
|
|
1483
1580
|
----------
|
|
@@ -1613,6 +1710,58 @@ let foo = () => {
|
|
|
1613
1710
|
};
|
|
1614
1711
|
```
|
|
1615
1712
|
|
|
1713
|
+
## Arrow Function No Break Line
|
|
1714
|
+
|
|
1715
|
+
----------
|
|
1716
|
+
|
|
1717
|
+
Enforces parentheses around arguments in all cases.
|
|
1718
|
+
|
|
1719
|
+
<https://eslint.org/docs/rules/arrow-parens>
|
|
1720
|
+
|
|
1721
|
+
π Examples of correct code
|
|
1722
|
+
|
|
1723
|
+
```typescript
|
|
1724
|
+
(foo) => bar;
|
|
1725
|
+
|
|
1726
|
+
(foo) => (bar);
|
|
1727
|
+
|
|
1728
|
+
(foo) => bar => baz;
|
|
1729
|
+
|
|
1730
|
+
(foo) => (
|
|
1731
|
+
bar()
|
|
1732
|
+
);
|
|
1733
|
+
|
|
1734
|
+
// functions with block bodies allowed with this rule using any style
|
|
1735
|
+
// to enforce a consistent location for this case, see the rule: `brace-style`
|
|
1736
|
+
(foo) => {
|
|
1737
|
+
return bar();
|
|
1738
|
+
}
|
|
1739
|
+
|
|
1740
|
+
(foo) =>
|
|
1741
|
+
{
|
|
1742
|
+
return bar();
|
|
1743
|
+
}
|
|
1744
|
+
```
|
|
1745
|
+
|
|
1746
|
+
π Examples of incorrect code
|
|
1747
|
+
|
|
1748
|
+
```typescript
|
|
1749
|
+
(foo) =>
|
|
1750
|
+
bar;
|
|
1751
|
+
|
|
1752
|
+
(foo) =>
|
|
1753
|
+
(bar);
|
|
1754
|
+
|
|
1755
|
+
(foo) =>
|
|
1756
|
+
bar =>
|
|
1757
|
+
baz;
|
|
1758
|
+
|
|
1759
|
+
(foo) =>
|
|
1760
|
+
(
|
|
1761
|
+
bar()
|
|
1762
|
+
);
|
|
1763
|
+
```
|
|
1764
|
+
|
|
1616
1765
|
## No Empty Block
|
|
1617
1766
|
|
|
1618
1767
|
----------
|
|
@@ -6410,6 +6559,8 @@ Requires using either T[] instead of Array\<T\>.
|
|
|
6410
6559
|
```typescript
|
|
6411
6560
|
const x: string[] = ['a', 'b'];
|
|
6412
6561
|
const y: readonly string[] = ['a', 'b'];
|
|
6562
|
+
|
|
6563
|
+
const a: Array<string | number> = ['a', 'b'];
|
|
6413
6564
|
```
|
|
6414
6565
|
|
|
6415
6566
|
π Examples of incorrect code
|
|
@@ -7178,7 +7329,11 @@ const obj3 = {
|
|
|
7178
7329
|
|
|
7179
7330
|
Enforces placing object properties on separate lines.
|
|
7180
7331
|
|
|
7181
|
-
|
|
7332
|
+
Then any code used within the same scope would not get the global undefined,
|
|
7333
|
+
but rather the local version with a very different meaning.
|
|
7334
|
+
|
|
7335
|
+
<https://eslint.org/docs/rules/no-shadow>
|
|
7336
|
+
<https://eslint.org/docs/rules/no-shadow-restricted-names>
|
|
7182
7337
|
|
|
7183
7338
|
π Examples of correct code
|
|
7184
7339
|
|
|
@@ -7196,6 +7351,8 @@ function b(a) {
|
|
|
7196
7351
|
var c = 10;
|
|
7197
7352
|
}
|
|
7198
7353
|
b(a);
|
|
7354
|
+
|
|
7355
|
+
function f(a, b){}
|
|
7199
7356
|
```
|
|
7200
7357
|
|
|
7201
7358
|
π Examples of incorrect code
|
|
@@ -7218,215 +7375,585 @@ b(a);
|
|
|
7218
7375
|
if (true) {
|
|
7219
7376
|
let a = 5;
|
|
7220
7377
|
}
|
|
7221
|
-
```
|
|
7222
7378
|
|
|
7223
|
-
|
|
7379
|
+
function NaN(){}
|
|
7224
7380
|
|
|
7225
|
-
|
|
7381
|
+
!function(Infinity){};
|
|
7382
|
+
|
|
7383
|
+
var undefined = 5;
|
|
7384
|
+
|
|
7385
|
+
try {} catch(eval){}
|
|
7386
|
+
```
|
|
7387
|
+
|
|
7388
|
+
## Parentheses New Line
|
|
7226
7389
|
|
|
7227
7390
|
----------
|
|
7228
7391
|
|
|
7229
|
-
|
|
7392
|
+
This rule enforces consistent line breaks inside parentheses of function parameters or arguments.
|
|
7230
7393
|
|
|
7231
|
-
<https://
|
|
7394
|
+
<https://eslint.org/docs/latest/rules/function-paren-newline>
|
|
7395
|
+
<https://eslint.org/docs/latest/rules/function-call-argument-newline>
|
|
7232
7396
|
|
|
7233
7397
|
π Examples of correct code
|
|
7234
7398
|
|
|
7235
7399
|
```typescript
|
|
7236
|
-
|
|
7237
|
-
|
|
7238
|
-
|
|
7239
|
-
|
|
7400
|
+
function foo(
|
|
7401
|
+
bar,
|
|
7402
|
+
baz
|
|
7403
|
+
) {}
|
|
7404
|
+
|
|
7405
|
+
var foo = function(bar, baz) {};
|
|
7406
|
+
|
|
7407
|
+
var foo = (
|
|
7408
|
+
bar
|
|
7409
|
+
) => {};
|
|
7410
|
+
|
|
7411
|
+
foo(
|
|
7412
|
+
function() {
|
|
7413
|
+
return baz;
|
|
7414
|
+
}
|
|
7415
|
+
);
|
|
7416
|
+
|
|
7417
|
+
foo("one", "two", "three");
|
|
7418
|
+
// or
|
|
7419
|
+
foo(
|
|
7420
|
+
"one",
|
|
7421
|
+
"two",
|
|
7422
|
+
"three"
|
|
7423
|
+
);
|
|
7424
|
+
|
|
7425
|
+
bar("one", "two", {
|
|
7426
|
+
one: 1,
|
|
7427
|
+
two: 2
|
|
7428
|
+
});
|
|
7429
|
+
// or
|
|
7430
|
+
bar(
|
|
7431
|
+
"one",
|
|
7432
|
+
"two",
|
|
7433
|
+
{ one: 1, two: 2 }
|
|
7434
|
+
);
|
|
7435
|
+
// or
|
|
7436
|
+
bar(
|
|
7437
|
+
"one",
|
|
7438
|
+
"two",
|
|
7439
|
+
{
|
|
7440
|
+
one: 1,
|
|
7441
|
+
two: 2
|
|
7442
|
+
}
|
|
7443
|
+
);
|
|
7444
|
+
|
|
7445
|
+
baz("one", "two", (x) => {
|
|
7446
|
+
console.log(x);
|
|
7447
|
+
});
|
|
7448
|
+
// or
|
|
7449
|
+
baz(
|
|
7450
|
+
"one",
|
|
7451
|
+
"two",
|
|
7452
|
+
(x) => {
|
|
7453
|
+
console.log(x);
|
|
7454
|
+
}
|
|
7455
|
+
);
|
|
7240
7456
|
```
|
|
7241
7457
|
|
|
7242
7458
|
π Examples of incorrect code
|
|
7243
7459
|
|
|
7244
7460
|
```typescript
|
|
7245
|
-
|
|
7246
|
-
|
|
7247
|
-
|
|
7248
|
-
|
|
7461
|
+
function foo(bar,
|
|
7462
|
+
baz
|
|
7463
|
+
) {}
|
|
7464
|
+
|
|
7465
|
+
var foo = function(bar,
|
|
7466
|
+
baz) {};
|
|
7467
|
+
|
|
7468
|
+
var foo = (
|
|
7469
|
+
bar) => {};
|
|
7470
|
+
|
|
7471
|
+
foo(
|
|
7472
|
+
function() {
|
|
7473
|
+
return baz;
|
|
7474
|
+
});
|
|
7475
|
+
|
|
7476
|
+
foo("one", "two",
|
|
7477
|
+
"three");
|
|
7478
|
+
//or
|
|
7479
|
+
foo("one",
|
|
7480
|
+
"two", "three");
|
|
7481
|
+
|
|
7482
|
+
bar("one", "two",
|
|
7483
|
+
{ one: 1, two: 2}
|
|
7484
|
+
);
|
|
7485
|
+
|
|
7486
|
+
baz("one", "two",
|
|
7487
|
+
(x) => { console.log(x); }
|
|
7488
|
+
);
|
|
7249
7489
|
```
|
|
7250
7490
|
|
|
7251
|
-
|
|
7491
|
+
## No Func Call Spacing
|
|
7252
7492
|
|
|
7253
7493
|
----------
|
|
7254
7494
|
|
|
7255
|
-
|
|
7495
|
+
Disallows space between the function name and the opening parenthesis.
|
|
7256
7496
|
|
|
7257
|
-
<https://
|
|
7497
|
+
<https://eslint.org/docs/latest/rules/func-call-spacing>
|
|
7258
7498
|
|
|
7259
7499
|
π Examples of correct code
|
|
7260
7500
|
|
|
7261
7501
|
```typescript
|
|
7262
|
-
|
|
7263
|
-
return val * 2
|
|
7264
|
-
})
|
|
7265
|
-
myPromise.then(function (val) {
|
|
7266
|
-
throw new Exception("Message");
|
|
7267
|
-
})
|
|
7502
|
+
fn();
|
|
7268
7503
|
```
|
|
7269
7504
|
|
|
7270
7505
|
π Examples of incorrect code
|
|
7271
7506
|
|
|
7272
7507
|
```typescript
|
|
7273
|
-
|
|
7274
|
-
|
|
7275
|
-
|
|
7276
|
-
|
|
7277
|
-
return Promise.reject('bad thing')
|
|
7278
|
-
})
|
|
7508
|
+
fn ();
|
|
7509
|
+
|
|
7510
|
+
fn
|
|
7511
|
+
();
|
|
7279
7512
|
```
|
|
7280
7513
|
|
|
7281
|
-
|
|
7514
|
+
## Array Element New Line
|
|
7282
7515
|
|
|
7283
7516
|
----------
|
|
7284
7517
|
|
|
7285
|
-
|
|
7518
|
+
This rule enforces line breaks between array elements.
|
|
7286
7519
|
|
|
7287
|
-
<https://
|
|
7520
|
+
<https://eslint.org/docs/latest/rules/array-element-newline>
|
|
7288
7521
|
|
|
7289
7522
|
π Examples of correct code
|
|
7290
7523
|
|
|
7291
7524
|
```typescript
|
|
7292
|
-
|
|
7293
|
-
|
|
7294
|
-
|
|
7525
|
+
var a = [];
|
|
7526
|
+
var b = [1];
|
|
7527
|
+
var c = [1, 2];
|
|
7528
|
+
var d = [1, 2, 3];
|
|
7529
|
+
var e = [
|
|
7530
|
+
1,
|
|
7531
|
+
2
|
|
7532
|
+
];
|
|
7533
|
+
var f = [
|
|
7534
|
+
1,
|
|
7535
|
+
2,
|
|
7536
|
+
3
|
|
7537
|
+
];
|
|
7538
|
+
var g = [
|
|
7539
|
+
function foo() {
|
|
7540
|
+
dosomething();
|
|
7541
|
+
}, function bar() {
|
|
7542
|
+
dosomething();
|
|
7543
|
+
}, function baz() {
|
|
7544
|
+
dosomething();
|
|
7545
|
+
}
|
|
7546
|
+
];
|
|
7547
|
+
var h = [
|
|
7548
|
+
function foo() {
|
|
7549
|
+
dosomething();
|
|
7550
|
+
},
|
|
7551
|
+
function bar() {
|
|
7552
|
+
dosomething();
|
|
7553
|
+
},
|
|
7554
|
+
function baz() {
|
|
7555
|
+
dosomething();
|
|
7556
|
+
}
|
|
7557
|
+
];
|
|
7295
7558
|
```
|
|
7296
7559
|
|
|
7297
7560
|
π Examples of incorrect code
|
|
7298
7561
|
|
|
7299
7562
|
```typescript
|
|
7300
|
-
|
|
7301
|
-
|
|
7302
|
-
|
|
7563
|
+
var a = [
|
|
7564
|
+
1, 2,
|
|
7565
|
+
3
|
|
7566
|
+
];
|
|
7567
|
+
var b = [
|
|
7568
|
+
function foo() {
|
|
7569
|
+
dosomething();
|
|
7570
|
+
}, function bar() {
|
|
7571
|
+
dosomething();
|
|
7572
|
+
},
|
|
7573
|
+
function baz() {
|
|
7574
|
+
dosomething();
|
|
7575
|
+
}
|
|
7576
|
+
];
|
|
7303
7577
|
```
|
|
7304
7578
|
|
|
7305
|
-
|
|
7579
|
+
## Wrap Iife
|
|
7306
7580
|
|
|
7307
7581
|
----------
|
|
7308
7582
|
|
|
7309
|
-
|
|
7583
|
+
Enforces always wrapping the function expression
|
|
7310
7584
|
|
|
7311
|
-
<https://
|
|
7585
|
+
<https://eslint.org/docs/latest/rules/wrap-iife>
|
|
7312
7586
|
|
|
7313
7587
|
π Examples of correct code
|
|
7314
7588
|
|
|
7315
7589
|
```typescript
|
|
7316
|
-
|
|
7317
|
-
myPromise.then(function(val) { return val * 2; });
|
|
7318
|
-
myPromise.then(doSomething); // could be either
|
|
7319
|
-
myPromise.then((b) => { if (b) { return "yes" } else { return "no" } });
|
|
7590
|
+
var x = (function () { return { y: 1 }; })(); // wrapped function expression
|
|
7320
7591
|
```
|
|
7321
7592
|
|
|
7322
7593
|
π Examples of incorrect code
|
|
7323
7594
|
|
|
7324
7595
|
```typescript
|
|
7325
|
-
|
|
7326
|
-
|
|
7327
|
-
doSomething()
|
|
7328
|
-
})
|
|
7329
|
-
myPromise.then((b) => {
|
|
7330
|
-
if (b) {
|
|
7331
|
-
return 'yes'
|
|
7332
|
-
} else {
|
|
7333
|
-
forgotToReturn()
|
|
7334
|
-
}
|
|
7335
|
-
})
|
|
7596
|
+
var x = function () { return { y: 1 };}(); // unwrapped
|
|
7597
|
+
var x = (function () { return { y: 1 };}()); // wrapped call expression
|
|
7336
7598
|
```
|
|
7337
7599
|
|
|
7338
|
-
|
|
7600
|
+
## Disallow Template Tag Space
|
|
7339
7601
|
|
|
7340
7602
|
----------
|
|
7341
7603
|
|
|
7342
|
-
|
|
7604
|
+
Disallows spaces between a tag function and its template literal.
|
|
7343
7605
|
|
|
7344
|
-
<https://
|
|
7606
|
+
<https://eslint.org/docs/latest/rules/template-tag-spacing>
|
|
7345
7607
|
|
|
7346
7608
|
π Examples of correct code
|
|
7347
7609
|
|
|
7348
7610
|
```typescript
|
|
7349
|
-
|
|
7611
|
+
func`Hello world`;
|
|
7350
7612
|
```
|
|
7351
7613
|
|
|
7352
7614
|
π Examples of incorrect code
|
|
7353
7615
|
|
|
7354
7616
|
```typescript
|
|
7355
|
-
|
|
7356
|
-
|
|
7357
|
-
myPromise.then((val) => doSomething(val).catch(errors))
|
|
7358
|
-
|
|
7359
|
-
myPromise.catch((err) => doSomething(err).then(doSomethingElse))
|
|
7360
|
-
|
|
7361
|
-
myPromise.catch((err) => doSomething(err).catch(errors))
|
|
7617
|
+
func `Hello world`;
|
|
7362
7618
|
```
|
|
7363
7619
|
|
|
7364
|
-
|
|
7620
|
+
## No Space Spread
|
|
7365
7621
|
|
|
7366
7622
|
----------
|
|
7367
7623
|
|
|
7368
|
-
|
|
7624
|
+
Enforce spacing between rest and spread operators and their expressions
|
|
7369
7625
|
|
|
7370
|
-
<https://
|
|
7626
|
+
<https://eslint.org/docs/latest/rules/rest-spread-spacing>
|
|
7371
7627
|
|
|
7372
7628
|
π Examples of correct code
|
|
7373
7629
|
|
|
7374
7630
|
```typescript
|
|
7375
|
-
|
|
7376
|
-
|
|
7377
|
-
|
|
7631
|
+
fn(...args)
|
|
7632
|
+
[...arr, 4, 5, 6]
|
|
7633
|
+
let [a, b, ...arr] = [1, 2, 3, 4, 5];
|
|
7634
|
+
function fn(...args) { console.log(args); }
|
|
7635
|
+
let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };
|
|
7636
|
+
let n = { x, y, ...z };
|
|
7378
7637
|
```
|
|
7379
7638
|
|
|
7380
7639
|
π Examples of incorrect code
|
|
7381
7640
|
|
|
7382
7641
|
```typescript
|
|
7383
|
-
|
|
7384
|
-
|
|
7385
|
-
|
|
7642
|
+
fn(... args)
|
|
7643
|
+
[... arr, 4, 5, 6]
|
|
7644
|
+
let [a, b, ... arr] = [1, 2, 3, 4, 5];
|
|
7645
|
+
function fn(... args) { console.log(args); }
|
|
7646
|
+
let { x, y, ... z } = { x: 1, y: 2, a: 3, b: 4 };
|
|
7647
|
+
let n = { x, y, ... z };
|
|
7386
7648
|
```
|
|
7387
7649
|
|
|
7388
|
-
|
|
7650
|
+
## Inline IF
|
|
7389
7651
|
|
|
7390
7652
|
----------
|
|
7391
7653
|
|
|
7392
|
-
|
|
7654
|
+
Disallows a newline before a single-line statement.
|
|
7393
7655
|
|
|
7394
|
-
<https://
|
|
7656
|
+
<https://eslint.org/docs/latest/rules/nonblock-statement-body-position>
|
|
7395
7657
|
|
|
7396
7658
|
π Examples of correct code
|
|
7397
7659
|
|
|
7398
7660
|
```typescript
|
|
7399
|
-
|
|
7400
|
-
|
|
7401
|
-
Promise.all(iterable)
|
|
7661
|
+
if (foo) bar();
|
|
7662
|
+
else baz();
|
|
7402
7663
|
|
|
7403
|
-
|
|
7404
|
-
Promise.race([p1, p2, p3])
|
|
7405
|
-
Promise.race(iterable)
|
|
7664
|
+
while (foo) bar();
|
|
7406
7665
|
|
|
7407
|
-
|
|
7408
|
-
Promise.resolve()
|
|
7409
|
-
Promise.resolve({})
|
|
7410
|
-
Promise.resolve([1, 2, 3])
|
|
7411
|
-
Promise.resolve(referenceToObject)
|
|
7666
|
+
for (let i = 1; i < foo; i++) bar();
|
|
7412
7667
|
|
|
7413
|
-
|
|
7414
|
-
Promise.reject()
|
|
7415
|
-
Promise.reject(Error())
|
|
7416
|
-
Promise.reject(referenceToError)
|
|
7668
|
+
do bar(); while (foo)
|
|
7417
7669
|
|
|
7418
|
-
|
|
7419
|
-
|
|
7420
|
-
|
|
7670
|
+
if (foo) { // block statements are always allowed with this rule
|
|
7671
|
+
bar();
|
|
7672
|
+
} else {
|
|
7673
|
+
baz();
|
|
7674
|
+
}
|
|
7675
|
+
```
|
|
7421
7676
|
|
|
7422
|
-
|
|
7423
|
-
somePromise().catch((error) => {
|
|
7424
|
-
handleError(error)
|
|
7425
|
-
})
|
|
7426
|
-
somePromise().catch(console.error)
|
|
7677
|
+
π Examples of incorrect code
|
|
7427
7678
|
|
|
7428
|
-
|
|
7429
|
-
|
|
7679
|
+
```typescript
|
|
7680
|
+
if (foo)
|
|
7681
|
+
bar();
|
|
7682
|
+
else
|
|
7683
|
+
baz();
|
|
7684
|
+
|
|
7685
|
+
while (foo)
|
|
7686
|
+
bar();
|
|
7687
|
+
|
|
7688
|
+
for (let i = 1; i < foo; i++)
|
|
7689
|
+
bar();
|
|
7690
|
+
|
|
7691
|
+
do
|
|
7692
|
+
bar();
|
|
7693
|
+
while (foo)
|
|
7694
|
+
```
|
|
7695
|
+
|
|
7696
|
+
## New Instance Use Parentheses
|
|
7697
|
+
|
|
7698
|
+
----------
|
|
7699
|
+
|
|
7700
|
+
This rule can enforce or disallow parentheses when invoking a constructor with no arguments using the new keyword.
|
|
7701
|
+
|
|
7702
|
+
<https://eslint.org/docs/latest/rules/new-parens>
|
|
7703
|
+
|
|
7704
|
+
π Examples of correct code
|
|
7705
|
+
|
|
7706
|
+
```typescript
|
|
7707
|
+
var person = new Person();
|
|
7708
|
+
var person = new Person("name");
|
|
7709
|
+
```
|
|
7710
|
+
|
|
7711
|
+
π Examples of incorrect code
|
|
7712
|
+
|
|
7713
|
+
```typescript
|
|
7714
|
+
var person = new Person;
|
|
7715
|
+
var person = new (Person);
|
|
7716
|
+
```
|
|
7717
|
+
|
|
7718
|
+
## Logical Assignment Operators
|
|
7719
|
+
|
|
7720
|
+
----------
|
|
7721
|
+
|
|
7722
|
+
The shorthand can be used if the assignment target and the left expression of a logical expression are the same.
|
|
7723
|
+
For example `a = a || b` can be shortened to `a ||= b`.
|
|
7724
|
+
|
|
7725
|
+
<https://eslint.org/docs/latest/rules/logical-assignment-operators>
|
|
7726
|
+
|
|
7727
|
+
π Examples of correct code
|
|
7728
|
+
|
|
7729
|
+
```typescript
|
|
7730
|
+
a = b
|
|
7731
|
+
a += b
|
|
7732
|
+
a ||= b
|
|
7733
|
+
a = b || c
|
|
7734
|
+
a || (b = c)
|
|
7735
|
+
|
|
7736
|
+
if (a) a = b
|
|
7737
|
+
```
|
|
7738
|
+
|
|
7739
|
+
π Examples of incorrect code
|
|
7740
|
+
|
|
7741
|
+
```typescript
|
|
7742
|
+
a = a || b
|
|
7743
|
+
a = a && b
|
|
7744
|
+
a = a ?? b
|
|
7745
|
+
a || (a = b)
|
|
7746
|
+
a && (a = b)
|
|
7747
|
+
a ?? (a = b)
|
|
7748
|
+
```
|
|
7749
|
+
|
|
7750
|
+
## Promise Rules
|
|
7751
|
+
|
|
7752
|
+
### No New Statics
|
|
7753
|
+
|
|
7754
|
+
----------
|
|
7755
|
+
|
|
7756
|
+
Calling a Promise static method with new is invalid, resulting in a TypeError at runtime.
|
|
7757
|
+
|
|
7758
|
+
<https://github.com/xjamundx/eslint-plugin-promise/blob/development/docs/rules/no-new-statics.md>
|
|
7759
|
+
|
|
7760
|
+
π Examples of correct code
|
|
7761
|
+
|
|
7762
|
+
```typescript
|
|
7763
|
+
Promise.resolve(value)
|
|
7764
|
+
Promise.reject(error)
|
|
7765
|
+
Promise.race([p1, p2])
|
|
7766
|
+
Promise.all([p1, p2])
|
|
7767
|
+
```
|
|
7768
|
+
|
|
7769
|
+
π Examples of incorrect code
|
|
7770
|
+
|
|
7771
|
+
```typescript
|
|
7772
|
+
new Promise.resolve(value)
|
|
7773
|
+
new Promise.reject(error)
|
|
7774
|
+
new Promise.race([p1, p2])
|
|
7775
|
+
new Promise.all([p1, p2])
|
|
7776
|
+
```
|
|
7777
|
+
|
|
7778
|
+
### No Return Wrap
|
|
7779
|
+
|
|
7780
|
+
----------
|
|
7781
|
+
|
|
7782
|
+
Ensure that inside a then() or a catch() we always return or throw a raw value instead of wrapping in Promise.resolve or Promise.reject
|
|
7783
|
+
|
|
7784
|
+
<https://github.com/xjamundx/eslint-plugin-promise/blob/development/docs/rules/no-new-statics.md>
|
|
7785
|
+
|
|
7786
|
+
π Examples of correct code
|
|
7787
|
+
|
|
7788
|
+
```typescript
|
|
7789
|
+
myPromise.then(function (val) {
|
|
7790
|
+
return val * 2
|
|
7791
|
+
})
|
|
7792
|
+
myPromise.then(function (val) {
|
|
7793
|
+
throw new Exception("Message");
|
|
7794
|
+
})
|
|
7795
|
+
```
|
|
7796
|
+
|
|
7797
|
+
π Examples of incorrect code
|
|
7798
|
+
|
|
7799
|
+
```typescript
|
|
7800
|
+
myPromise.then(function (val) {
|
|
7801
|
+
return Promise.resolve(val * 2)
|
|
7802
|
+
})
|
|
7803
|
+
myPromise.then(function (val) {
|
|
7804
|
+
return Promise.reject('bad thing')
|
|
7805
|
+
})
|
|
7806
|
+
```
|
|
7807
|
+
|
|
7808
|
+
### Param Name
|
|
7809
|
+
|
|
7810
|
+
----------
|
|
7811
|
+
|
|
7812
|
+
Ensure that inside a then() or a catch() we always return or throw a raw value instead of wrapping in Promise.resolve or Promise.reject
|
|
7813
|
+
|
|
7814
|
+
<https://github.com/xjamundx/eslint-plugin-promise/blob/development/docs/rules/param-names.md>
|
|
7815
|
+
|
|
7816
|
+
π Examples of correct code
|
|
7817
|
+
|
|
7818
|
+
```typescript
|
|
7819
|
+
new Promise(function (resolve) { ... })
|
|
7820
|
+
new Promise(function (resolve, reject) { ... })
|
|
7821
|
+
new Promise(function (_resolve, _reject) { ... }) // Unused marker for parameters are allowed
|
|
7822
|
+
```
|
|
7823
|
+
|
|
7824
|
+
π Examples of incorrect code
|
|
7825
|
+
|
|
7826
|
+
```typescript
|
|
7827
|
+
new Promise(function (reject, resolve) { ... }) // incorrect order
|
|
7828
|
+
new Promise(function (ok, fail) { ... }) // non-standard parameter names
|
|
7829
|
+
new Promise(function (_, reject) { ... }) // a simple underscore is not allowed
|
|
7830
|
+
```
|
|
7831
|
+
|
|
7832
|
+
### Always Return
|
|
7833
|
+
|
|
7834
|
+
----------
|
|
7835
|
+
|
|
7836
|
+
Ensure that inside a then() or a catch() we always return or throw a raw value instead of wrapping in Promise.resolve or Promise.reject
|
|
7837
|
+
|
|
7838
|
+
<https://github.com/xjamundx/eslint-plugin-promise/blob/development/docs/rules/always-return.md>
|
|
7839
|
+
|
|
7840
|
+
π Examples of correct code
|
|
7841
|
+
|
|
7842
|
+
```typescript
|
|
7843
|
+
myPromise.then((val) => val * 2);
|
|
7844
|
+
myPromise.then(function(val) { return val * 2; });
|
|
7845
|
+
myPromise.then(doSomething); // could be either
|
|
7846
|
+
myPromise.then((b) => { if (b) { return "yes" } else { return "no" } });
|
|
7847
|
+
```
|
|
7848
|
+
|
|
7849
|
+
π Examples of incorrect code
|
|
7850
|
+
|
|
7851
|
+
```typescript
|
|
7852
|
+
myPromise.then(function (val) {})
|
|
7853
|
+
myPromise.then(() => {
|
|
7854
|
+
doSomething()
|
|
7855
|
+
})
|
|
7856
|
+
myPromise.then((b) => {
|
|
7857
|
+
if (b) {
|
|
7858
|
+
return 'yes'
|
|
7859
|
+
} else {
|
|
7860
|
+
forgotToReturn()
|
|
7861
|
+
}
|
|
7862
|
+
})
|
|
7863
|
+
```
|
|
7864
|
+
|
|
7865
|
+
### No Nesting
|
|
7866
|
+
|
|
7867
|
+
----------
|
|
7868
|
+
|
|
7869
|
+
`Warning` Avoid nested then() or catch() statements (no-nesting)
|
|
7870
|
+
|
|
7871
|
+
<https://github.com/xjamundx/eslint-plugin-promise/blob/development/docs/rules/no-nesting.md>
|
|
7872
|
+
|
|
7873
|
+
π Examples of correct code
|
|
7874
|
+
|
|
7875
|
+
```typescript
|
|
7876
|
+
myPromise.then(doSomething).then(doSomethingElse).catch(errors)
|
|
7877
|
+
```
|
|
7878
|
+
|
|
7879
|
+
π Examples of incorrect code
|
|
7880
|
+
|
|
7881
|
+
```typescript
|
|
7882
|
+
myPromise.then((val) => doSomething(val).then(doSomethingElse))
|
|
7883
|
+
|
|
7884
|
+
myPromise.then((val) => doSomething(val).catch(errors))
|
|
7885
|
+
|
|
7886
|
+
myPromise.catch((err) => doSomething(err).then(doSomethingElse))
|
|
7887
|
+
|
|
7888
|
+
myPromise.catch((err) => doSomething(err).catch(errors))
|
|
7889
|
+
```
|
|
7890
|
+
|
|
7891
|
+
### No Return Finally
|
|
7892
|
+
|
|
7893
|
+
----------
|
|
7894
|
+
|
|
7895
|
+
Disallow return statements inside a callback passed to finally(), since nothing would consume what's returned.
|
|
7896
|
+
|
|
7897
|
+
<https://github.com/xjamundx/eslint-plugin-promise/blob/development/docs/rules/no-return-in-finally.md>
|
|
7898
|
+
|
|
7899
|
+
π Examples of correct code
|
|
7900
|
+
|
|
7901
|
+
```typescript
|
|
7902
|
+
myPromise.finally(function (val) {
|
|
7903
|
+
console.log('value:', val)
|
|
7904
|
+
})
|
|
7905
|
+
```
|
|
7906
|
+
|
|
7907
|
+
π Examples of incorrect code
|
|
7908
|
+
|
|
7909
|
+
```typescript
|
|
7910
|
+
myPromise.finally(function (val) {
|
|
7911
|
+
return val
|
|
7912
|
+
})
|
|
7913
|
+
```
|
|
7914
|
+
|
|
7915
|
+
### Valid Params
|
|
7916
|
+
|
|
7917
|
+
----------
|
|
7918
|
+
|
|
7919
|
+
Disallow return statements inside a callback passed to finally(), since nothing would consume what's returned.
|
|
7920
|
+
|
|
7921
|
+
<https://github.com/xjamundx/eslint-plugin-promise/blob/development/docs/rules/valid-params.md>
|
|
7922
|
+
|
|
7923
|
+
π Examples of correct code
|
|
7924
|
+
|
|
7925
|
+
```typescript
|
|
7926
|
+
// Promise.all() requires 1 argument
|
|
7927
|
+
Promise.all([p1, p2, p3])
|
|
7928
|
+
Promise.all(iterable)
|
|
7929
|
+
|
|
7930
|
+
// Promise.race() requires 1 argument
|
|
7931
|
+
Promise.race([p1, p2, p3])
|
|
7932
|
+
Promise.race(iterable)
|
|
7933
|
+
|
|
7934
|
+
// Promise.resolve() requires 0 or 1 arguments
|
|
7935
|
+
Promise.resolve()
|
|
7936
|
+
Promise.resolve({})
|
|
7937
|
+
Promise.resolve([1, 2, 3])
|
|
7938
|
+
Promise.resolve(referenceToObject)
|
|
7939
|
+
|
|
7940
|
+
// Promise.reject() requires 0 or 1 arguments
|
|
7941
|
+
Promise.reject()
|
|
7942
|
+
Promise.reject(Error())
|
|
7943
|
+
Promise.reject(referenceToError)
|
|
7944
|
+
|
|
7945
|
+
// Promise.then() requires 1 or 2 arguments
|
|
7946
|
+
somePromise().then((value) => doSomething(value))
|
|
7947
|
+
somePromise().then(successCallback, errorCallback)
|
|
7948
|
+
|
|
7949
|
+
// Promise.catch() requires 1 argument
|
|
7950
|
+
somePromise().catch((error) => {
|
|
7951
|
+
handleError(error)
|
|
7952
|
+
})
|
|
7953
|
+
somePromise().catch(console.error)
|
|
7954
|
+
|
|
7955
|
+
// Promise.finally() requires 1 argument
|
|
7956
|
+
somePromise().finally(() => {
|
|
7430
7957
|
console.log('done!')
|
|
7431
7958
|
})
|
|
7432
7959
|
somePromise().finally(console.log)
|
|
@@ -7836,6 +8363,7 @@ import typescript from "typescript"; // exists in dev dependency package.json
|
|
|
7836
8363
|
----------
|
|
7837
8364
|
|
|
7838
8365
|
Enforce a convention in the order of require() / import statements
|
|
8366
|
+
Use: Alphabetic order import
|
|
7839
8367
|
|
|
7840
8368
|
<https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/order.md>
|
|
7841
8369
|
|
|
@@ -7979,9 +8507,13 @@ export {
|
|
|
7979
8507
|
|
|
7980
8508
|
----------
|
|
7981
8509
|
|
|
7982
|
-
Require space after comment block
|
|
8510
|
+
Require space after comment block.
|
|
8511
|
+
|
|
8512
|
+
Many style guides require empty lines before or after comments.
|
|
8513
|
+
The primary goal of these rules is to make the comments easier to read and improve readability of the code.
|
|
7983
8514
|
|
|
7984
8515
|
<https://eslint.org/docs/rules/spaced-comment>
|
|
8516
|
+
<https://eslint.org/docs/latest/rules/lines-around-comment>
|
|
7985
8517
|
|
|
7986
8518
|
π Examples of correct code
|
|
7987
8519
|
|
|
@@ -7993,6 +8525,12 @@ Require space after comment block
|
|
|
7993
8525
|
/*
|
|
7994
8526
|
* This is a comment with a whitespace at the beginning
|
|
7995
8527
|
*/
|
|
8528
|
+
|
|
8529
|
+
|
|
8530
|
+
/**
|
|
8531
|
+
* valid
|
|
8532
|
+
*/
|
|
8533
|
+
function() {}
|
|
7996
8534
|
```
|
|
7997
8535
|
|
|
7998
8536
|
π Examples of incorrect code
|
|
@@ -8001,6 +8539,12 @@ Require space after comment block
|
|
|
8001
8539
|
//This is a comment with no whitespace at the beginning
|
|
8002
8540
|
|
|
8003
8541
|
/*This is a comment with no whitespace at the beginning */
|
|
8542
|
+
|
|
8543
|
+
/**
|
|
8544
|
+
* invalid after space
|
|
8545
|
+
*/
|
|
8546
|
+
|
|
8547
|
+
function() {}
|
|
8004
8548
|
```
|
|
8005
8549
|
|
|
8006
8550
|
### Capitalized Comments
|
|
@@ -10465,28 +11009,61 @@ Allowing browsers to perform DNS prefetching is security-sensitive
|
|
|
10465
11009
|
const express = require('express');
|
|
10466
11010
|
const helmet = require('helmet');
|
|
10467
11011
|
|
|
10468
|
-
let app = express();
|
|
11012
|
+
let app = express();
|
|
11013
|
+
|
|
11014
|
+
app.use(
|
|
11015
|
+
helmet.dnsPrefetchControl({
|
|
11016
|
+
allow: false // Compliant
|
|
11017
|
+
})
|
|
11018
|
+
);
|
|
11019
|
+
```
|
|
11020
|
+
|
|
11021
|
+
π Examples of incorrect code
|
|
11022
|
+
|
|
11023
|
+
```typescript
|
|
11024
|
+
const express = require('express');
|
|
11025
|
+
const helmet = require('helmet');
|
|
11026
|
+
|
|
11027
|
+
let app = express();
|
|
11028
|
+
|
|
11029
|
+
app.use(
|
|
11030
|
+
helmet.dnsPrefetchControl({
|
|
11031
|
+
allow: true // Sensitive: allowing DNS prefetching is security-sensitive
|
|
11032
|
+
})
|
|
11033
|
+
);
|
|
11034
|
+
```
|
|
11035
|
+
|
|
11036
|
+
### No Prototype Builtins
|
|
11037
|
+
|
|
11038
|
+
----------
|
|
11039
|
+
|
|
11040
|
+
Additionally, objects can have properties that shadow the builtins on Object.prototype,
|
|
11041
|
+
potentially causing unintended behavior or denial-of-service security vulnerabilities.
|
|
11042
|
+
For example, it would be unsafe for a webserver to parse JSON input from a client and call hasOwnProperty directly
|
|
11043
|
+
on the resulting object, because a malicious client could send a JSON value like {"hasOwnProperty": 1}
|
|
11044
|
+
and cause the server to crash.
|
|
11045
|
+
|
|
11046
|
+
To avoid subtle bugs like this, itβs better to always call these methods from Object.prototype.
|
|
11047
|
+
For example, foo.hasOwnProperty("bar") should be replaced with Object.prototype.hasOwnProperty.call(foo, "bar").
|
|
11048
|
+
|
|
11049
|
+
<https://eslint.org/docs/latest/rules/No-Prototype-Builtins>
|
|
11050
|
+
|
|
11051
|
+
```typescript
|
|
11052
|
+
var hasBarProperty = Object.prototype.hasOwnProperty.call(foo, "bar");
|
|
11053
|
+
|
|
11054
|
+
var isPrototypeOfBar = Object.prototype.isPrototypeOf.call(foo, bar);
|
|
10469
11055
|
|
|
10470
|
-
|
|
10471
|
-
helmet.dnsPrefetchControl({
|
|
10472
|
-
allow: false // Compliant
|
|
10473
|
-
})
|
|
10474
|
-
);
|
|
11056
|
+
var barIsEnumerable = {}.propertyIsEnumerable.call(foo, "bar");
|
|
10475
11057
|
```
|
|
10476
11058
|
|
|
10477
11059
|
π Examples of incorrect code
|
|
10478
11060
|
|
|
10479
11061
|
```typescript
|
|
10480
|
-
|
|
10481
|
-
const helmet = require('helmet');
|
|
11062
|
+
var hasBarProperty = foo.hasOwnProperty("bar");
|
|
10482
11063
|
|
|
10483
|
-
|
|
11064
|
+
var isPrototypeOfBar = foo.isPrototypeOf(bar);
|
|
10484
11065
|
|
|
10485
|
-
|
|
10486
|
-
helmet.dnsPrefetchControl({
|
|
10487
|
-
allow: true // Sensitive: allowing DNS prefetching is security-sensitive
|
|
10488
|
-
})
|
|
10489
|
-
);
|
|
11066
|
+
var barIsEnumerable = foo.propertyIsEnumerable("bar");
|
|
10490
11067
|
```
|
|
10491
11068
|
|
|
10492
11069
|
## Catch Error Name
|
|
@@ -11938,6 +12515,52 @@ if (test) {
|
|
|
11938
12515
|
}
|
|
11939
12516
|
```
|
|
11940
12517
|
|
|
12518
|
+
## Multiline Ternary Multiple
|
|
12519
|
+
|
|
12520
|
+
----------
|
|
12521
|
+
|
|
12522
|
+
Enforces newlines between the operands of a ternary expression if the expression spans multiple lines.
|
|
12523
|
+
|
|
12524
|
+
<https://eslint.org/docs/latest/rules/multiline-ternary>
|
|
12525
|
+
|
|
12526
|
+
π Examples of correct code
|
|
12527
|
+
|
|
12528
|
+
```tsx
|
|
12529
|
+
foo > bar ? value1 : value2;
|
|
12530
|
+
|
|
12531
|
+
foo > bar ?
|
|
12532
|
+
value1 :
|
|
12533
|
+
value2;
|
|
12534
|
+
|
|
12535
|
+
foo > bar ?
|
|
12536
|
+
(baz > qux ? value1 : value2) :
|
|
12537
|
+
value3;
|
|
12538
|
+
|
|
12539
|
+
foo > bar ?
|
|
12540
|
+
(baz > qux ?
|
|
12541
|
+
value1 :
|
|
12542
|
+
value2) :
|
|
12543
|
+
value3;
|
|
12544
|
+
|
|
12545
|
+
foo > bar &&
|
|
12546
|
+
bar > baz ?
|
|
12547
|
+
value1 :
|
|
12548
|
+
value2;
|
|
12549
|
+
```
|
|
12550
|
+
|
|
12551
|
+
π Examples of incorrect code
|
|
12552
|
+
|
|
12553
|
+
```tsx
|
|
12554
|
+
foo > bar ? value1 :
|
|
12555
|
+
value2;
|
|
12556
|
+
|
|
12557
|
+
foo > bar ?
|
|
12558
|
+
value1 : value2;
|
|
12559
|
+
|
|
12560
|
+
foo > bar &&
|
|
12561
|
+
bar > baz ? value1 : value2;
|
|
12562
|
+
```
|
|
12563
|
+
|
|
11941
12564
|
## Prevent Abbreviations
|
|
11942
12565
|
|
|
11943
12566
|
----------
|
|
@@ -12786,165 +13409,479 @@ function findSomething(arr) {
|
|
|
12786
13409
|
throw new Error("Doesn't exist.");
|
|
12787
13410
|
}
|
|
12788
13411
|
}
|
|
12789
|
-
}
|
|
13412
|
+
}
|
|
13413
|
+
|
|
13414
|
+
for (key in obj) {
|
|
13415
|
+
if (key.startsWith("_")) {
|
|
13416
|
+
break;
|
|
13417
|
+
}
|
|
13418
|
+
firstKey = key;
|
|
13419
|
+
firstValue = obj[key];
|
|
13420
|
+
break;
|
|
13421
|
+
}
|
|
13422
|
+
|
|
13423
|
+
for (foo of bar) {
|
|
13424
|
+
if (foo.id === id) {
|
|
13425
|
+
doSomething(foo);
|
|
13426
|
+
}
|
|
13427
|
+
break;
|
|
13428
|
+
}
|
|
13429
|
+
```
|
|
13430
|
+
|
|
13431
|
+
### No Loss Of Precision
|
|
13432
|
+
|
|
13433
|
+
----------
|
|
13434
|
+
|
|
13435
|
+
Disallow literal numbers that lose precision
|
|
13436
|
+
|
|
13437
|
+
<https://eslint.org/docs/latest/rules/no-loss-of-precision>
|
|
13438
|
+
|
|
13439
|
+
π Examples of correct code
|
|
13440
|
+
|
|
13441
|
+
```typescript
|
|
13442
|
+
const x = 12345
|
|
13443
|
+
const x = 123.456
|
|
13444
|
+
const x = 123e34
|
|
13445
|
+
const x = 12300000000000000000000000
|
|
13446
|
+
const x = 0x1FFFFFFFFFFFFF
|
|
13447
|
+
const x = 9007199254740991
|
|
13448
|
+
const x = 9007_1992547409_91
|
|
13449
|
+
```
|
|
13450
|
+
|
|
13451
|
+
π Examples of incorrect code
|
|
13452
|
+
|
|
13453
|
+
```typescript
|
|
13454
|
+
const x = 9007199254740993
|
|
13455
|
+
const x = 5123000000000000000000000000001
|
|
13456
|
+
const x = 1230000000000000000000000.0
|
|
13457
|
+
const x = .1230000000000000000000000
|
|
13458
|
+
const x = 0X20000000000001
|
|
13459
|
+
const x = 0X2_000000000_0001;
|
|
13460
|
+
```
|
|
13461
|
+
|
|
13462
|
+
### Import Default Not Fount
|
|
13463
|
+
|
|
13464
|
+
----------
|
|
13465
|
+
|
|
13466
|
+
If a default import is requested, report if there is no default export in the imported module.
|
|
13467
|
+
|
|
13468
|
+
<https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/default.md>
|
|
13469
|
+
|
|
13470
|
+
π Examples of correct code
|
|
13471
|
+
|
|
13472
|
+
```typescript
|
|
13473
|
+
// ./foo.js
|
|
13474
|
+
export class Example {}
|
|
13475
|
+
```
|
|
13476
|
+
|
|
13477
|
+
```typescript
|
|
13478
|
+
import foo from './foo'
|
|
13479
|
+
|
|
13480
|
+
// assuming 'node_modules' are ignored (true by default)
|
|
13481
|
+
import someModule from 'some-module'
|
|
13482
|
+
```
|
|
13483
|
+
|
|
13484
|
+
π Examples of incorrect code
|
|
13485
|
+
|
|
13486
|
+
```typescript
|
|
13487
|
+
import bar from './bar' // no default export found in ./bar
|
|
13488
|
+
import baz from './baz' // no default export found in ./baz
|
|
13489
|
+
```
|
|
13490
|
+
|
|
13491
|
+
### Import Namespace
|
|
13492
|
+
|
|
13493
|
+
### No Import Resolve
|
|
13494
|
+
|
|
13495
|
+
----------
|
|
13496
|
+
|
|
13497
|
+
Ensures an imported module can be resolved to a module on the local filesystem, as defined by standard Node require.resolve behavior.
|
|
13498
|
+
|
|
13499
|
+
<https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-unresolved.md>
|
|
13500
|
+
|
|
13501
|
+
π Examples of correct code
|
|
13502
|
+
|
|
13503
|
+
```typescript
|
|
13504
|
+
import x from './bar' // file found
|
|
13505
|
+
```
|
|
13506
|
+
|
|
13507
|
+
π Examples of incorrect code
|
|
13508
|
+
|
|
13509
|
+
```typescript
|
|
13510
|
+
import x from './foo' // File not found
|
|
13511
|
+
```
|
|
13512
|
+
|
|
13513
|
+
### Import Not Found
|
|
13514
|
+
|
|
13515
|
+
----------
|
|
13516
|
+
|
|
13517
|
+
Verifies that all named imports are part of the set of named exports in the referenced module.
|
|
13518
|
+
|
|
13519
|
+
<https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/named.md>
|
|
13520
|
+
|
|
13521
|
+
π Examples of correct code
|
|
13522
|
+
|
|
13523
|
+
```typescript
|
|
13524
|
+
// ./foo.js
|
|
13525
|
+
export const foo = "I'm so foo"
|
|
13526
|
+
|
|
13527
|
+
// -------------------
|
|
13528
|
+
|
|
13529
|
+
// ./bar.js
|
|
13530
|
+
import { foo } from './foo';
|
|
13531
|
+
|
|
13532
|
+
// ES7 proposal
|
|
13533
|
+
export { foo as bar } from './foo';
|
|
13534
|
+
|
|
13535
|
+
// node_modules without jsnext:main are not analyzed by default
|
|
13536
|
+
// (import/ignore setting)
|
|
13537
|
+
import { SomeNonsenseThatDoesntExist } from 'react';
|
|
13538
|
+
```
|
|
13539
|
+
|
|
13540
|
+
π Examples of incorrect code
|
|
13541
|
+
|
|
13542
|
+
```typescript
|
|
13543
|
+
// ./baz.js
|
|
13544
|
+
import { notFoo } from './foo';
|
|
13545
|
+
|
|
13546
|
+
// ES7 proposal
|
|
13547
|
+
export { notFoo as defNotBar } from './foo';
|
|
13548
|
+
|
|
13549
|
+
// will follow 'jsnext:main', if available
|
|
13550
|
+
import { dontCreateStore } from 'redux';
|
|
13551
|
+
```
|
|
13552
|
+
|
|
13553
|
+
### JS Type
|
|
13554
|
+
|
|
13555
|
+
----------
|
|
13556
|
+
|
|
13557
|
+
The types of the arguments to built-in functions are specified in the JavaScript language specifications
|
|
13558
|
+
|
|
13559
|
+
<https://sonarsource.github.io/rspec/#/rspec/S3782/javascript>
|
|
13560
|
+
|
|
13561
|
+
π Examples of correct code
|
|
13562
|
+
|
|
13563
|
+
```typescript
|
|
13564
|
+
const isTooSmall = Math.abs(x) < 0.0042;
|
|
13565
|
+
```
|
|
13566
|
+
|
|
13567
|
+
π Examples of incorrect code
|
|
13568
|
+
|
|
13569
|
+
```typescript
|
|
13570
|
+
const isTooSmall = Math.abs(x < 0.0042); // Type require number no boolean
|
|
13571
|
+
```
|
|
13572
|
+
|
|
13573
|
+
### No Invalid This
|
|
13574
|
+
|
|
13575
|
+
----------
|
|
13576
|
+
|
|
13577
|
+
Under the strict mode, this keywords outside of classes or class-like objects might be undefined and raise a TypeError.
|
|
13578
|
+
|
|
13579
|
+
<https://eslint.org/docs/latest/rules/no-invalid-this#rule-details>
|
|
13580
|
+
<https://typescript-eslint.io/rules/no-invalid-this>
|
|
13581
|
+
|
|
13582
|
+
π Examples of correct code
|
|
13583
|
+
|
|
13584
|
+
```typescript
|
|
13585
|
+
"use strict";
|
|
13586
|
+
|
|
13587
|
+
this.a = 0;
|
|
13588
|
+
baz(() => this);
|
|
13589
|
+
|
|
13590
|
+
function Foo() {
|
|
13591
|
+
// OK, this is in a legacy style constructor.
|
|
13592
|
+
this.a = 0;
|
|
13593
|
+
baz(() => this);
|
|
13594
|
+
}
|
|
13595
|
+
|
|
13596
|
+
class Foo {
|
|
13597
|
+
constructor() {
|
|
13598
|
+
// OK, this is in a constructor.
|
|
13599
|
+
this.a = 0;
|
|
13600
|
+
baz(() => this);
|
|
13601
|
+
}
|
|
13602
|
+
}
|
|
13603
|
+
|
|
13604
|
+
var obj = {
|
|
13605
|
+
foo: function foo() {
|
|
13606
|
+
// OK, this is in a method (this function is on object literal).
|
|
13607
|
+
this.a = 0;
|
|
13608
|
+
}
|
|
13609
|
+
};
|
|
13610
|
+
|
|
13611
|
+
var obj = {
|
|
13612
|
+
foo() {
|
|
13613
|
+
// OK, this is in a method (this function is on object literal).
|
|
13614
|
+
this.a = 0;
|
|
13615
|
+
}
|
|
13616
|
+
};
|
|
13617
|
+
|
|
13618
|
+
var obj = {
|
|
13619
|
+
get foo() {
|
|
13620
|
+
// OK, this is in a method (this function is on object literal).
|
|
13621
|
+
return this.a;
|
|
13622
|
+
}
|
|
13623
|
+
};
|
|
13624
|
+
|
|
13625
|
+
var obj = Object.create(null, {
|
|
13626
|
+
foo: {value: function foo() {
|
|
13627
|
+
// OK, this is in a method (this function is on object literal).
|
|
13628
|
+
this.a = 0;
|
|
13629
|
+
}}
|
|
13630
|
+
});
|
|
13631
|
+
|
|
13632
|
+
Object.defineProperty(obj, "foo", {
|
|
13633
|
+
value: function foo() {
|
|
13634
|
+
// OK, this is in a method (this function is on object literal).
|
|
13635
|
+
this.a = 0;
|
|
13636
|
+
}
|
|
13637
|
+
});
|
|
13638
|
+
|
|
13639
|
+
Object.defineProperties(obj, {
|
|
13640
|
+
foo: {value: function foo() {
|
|
13641
|
+
// OK, this is in a method (this function is on object literal).
|
|
13642
|
+
this.a = 0;
|
|
13643
|
+
}}
|
|
13644
|
+
});
|
|
13645
|
+
|
|
13646
|
+
function Foo() {
|
|
13647
|
+
this.foo = function foo() {
|
|
13648
|
+
// OK, this is in a method (this function assigns to a property).
|
|
13649
|
+
this.a = 0;
|
|
13650
|
+
baz(() => this);
|
|
13651
|
+
};
|
|
13652
|
+
}
|
|
13653
|
+
|
|
13654
|
+
obj.foo = function foo() {
|
|
13655
|
+
// OK, this is in a method (this function assigns to a property).
|
|
13656
|
+
this.a = 0;
|
|
13657
|
+
};
|
|
13658
|
+
|
|
13659
|
+
Foo.prototype.foo = function foo() {
|
|
13660
|
+
// OK, this is in a method (this function assigns to a property).
|
|
13661
|
+
this.a = 0;
|
|
13662
|
+
};
|
|
13663
|
+
|
|
13664
|
+
class Foo {
|
|
13665
|
+
|
|
13666
|
+
// OK, this is in a class field initializer.
|
|
13667
|
+
a = this.b;
|
|
13668
|
+
|
|
13669
|
+
// OK, static initializers also have valid this.
|
|
13670
|
+
static a = this.b;
|
|
13671
|
+
|
|
13672
|
+
foo() {
|
|
13673
|
+
// OK, this is in a method.
|
|
13674
|
+
this.a = 0;
|
|
13675
|
+
baz(() => this);
|
|
13676
|
+
}
|
|
13677
|
+
|
|
13678
|
+
static foo() {
|
|
13679
|
+
// OK, this is in a method (static methods also have valid this).
|
|
13680
|
+
this.a = 0;
|
|
13681
|
+
baz(() => this);
|
|
13682
|
+
}
|
|
12790
13683
|
|
|
12791
|
-
|
|
12792
|
-
|
|
12793
|
-
|
|
13684
|
+
static {
|
|
13685
|
+
// OK, static blocks also have valid this.
|
|
13686
|
+
this.a = 0;
|
|
13687
|
+
baz(() => this);
|
|
12794
13688
|
}
|
|
12795
|
-
firstKey = key;
|
|
12796
|
-
firstValue = obj[key];
|
|
12797
|
-
break;
|
|
12798
13689
|
}
|
|
12799
13690
|
|
|
12800
|
-
|
|
12801
|
-
|
|
12802
|
-
|
|
12803
|
-
|
|
12804
|
-
|
|
13691
|
+
var foo = (function foo() {
|
|
13692
|
+
// OK, the `bind` method of this function is called directly.
|
|
13693
|
+
this.a = 0;
|
|
13694
|
+
}).bind(obj);
|
|
13695
|
+
|
|
13696
|
+
foo.forEach(function() {
|
|
13697
|
+
// OK, `thisArg` of `.forEach()` is given.
|
|
13698
|
+
this.a = 0;
|
|
13699
|
+
baz(() => this);
|
|
13700
|
+
}, thisArg);
|
|
13701
|
+
|
|
13702
|
+
/** @this Foo */
|
|
13703
|
+
function foo() {
|
|
13704
|
+
// OK, this function has a `@this` tag in its JSDoc comment.
|
|
13705
|
+
this.a = 0;
|
|
12805
13706
|
}
|
|
12806
13707
|
```
|
|
12807
13708
|
|
|
12808
|
-
|
|
13709
|
+
π Examples of incorrect code
|
|
12809
13710
|
|
|
12810
|
-
|
|
13711
|
+
```typescript
|
|
13712
|
+
"use strict";
|
|
12811
13713
|
|
|
12812
|
-
|
|
13714
|
+
(function() {
|
|
13715
|
+
this.a = 0;
|
|
13716
|
+
baz(() => this);
|
|
13717
|
+
})();
|
|
12813
13718
|
|
|
12814
|
-
|
|
13719
|
+
function foo() {
|
|
13720
|
+
this.a = 0;
|
|
13721
|
+
baz(() => this);
|
|
13722
|
+
}
|
|
12815
13723
|
|
|
12816
|
-
|
|
13724
|
+
var foo = function() {
|
|
13725
|
+
this.a = 0;
|
|
13726
|
+
baz(() => this);
|
|
13727
|
+
};
|
|
12817
13728
|
|
|
12818
|
-
|
|
12819
|
-
|
|
12820
|
-
|
|
12821
|
-
|
|
12822
|
-
const x = 12300000000000000000000000
|
|
12823
|
-
const x = 0x1FFFFFFFFFFFFF
|
|
12824
|
-
const x = 9007199254740991
|
|
12825
|
-
const x = 9007_1992547409_91
|
|
12826
|
-
```
|
|
13729
|
+
foo(function() {
|
|
13730
|
+
this.a = 0;
|
|
13731
|
+
baz(() => this);
|
|
13732
|
+
});
|
|
12827
13733
|
|
|
12828
|
-
|
|
13734
|
+
var obj = {
|
|
13735
|
+
aaa: function() {
|
|
13736
|
+
return function foo() {
|
|
13737
|
+
// There is in a method `aaa`, but `foo` is not a method.
|
|
13738
|
+
this.a = 0;
|
|
13739
|
+
baz(() => this);
|
|
13740
|
+
};
|
|
13741
|
+
}
|
|
13742
|
+
};
|
|
12829
13743
|
|
|
12830
|
-
|
|
12831
|
-
|
|
12832
|
-
|
|
12833
|
-
|
|
12834
|
-
const x = .1230000000000000000000000
|
|
12835
|
-
const x = 0X20000000000001
|
|
12836
|
-
const x = 0X2_000000000_0001;
|
|
13744
|
+
foo.forEach(function() {
|
|
13745
|
+
this.a = 0;
|
|
13746
|
+
baz(() => this);
|
|
13747
|
+
});
|
|
12837
13748
|
```
|
|
12838
13749
|
|
|
12839
|
-
###
|
|
13750
|
+
### No This Before Super
|
|
12840
13751
|
|
|
12841
13752
|
----------
|
|
12842
13753
|
|
|
12843
|
-
|
|
13754
|
+
In the constructor of derived classes, if this/super are used before super() calls, it raises a reference error.
|
|
12844
13755
|
|
|
12845
|
-
<https://
|
|
13756
|
+
<https://eslint.org/docs/latest/rules/no-this-before-super>
|
|
12846
13757
|
|
|
12847
13758
|
π Examples of correct code
|
|
12848
13759
|
|
|
12849
13760
|
```typescript
|
|
12850
|
-
|
|
12851
|
-
|
|
12852
|
-
|
|
13761
|
+
class A {
|
|
13762
|
+
constructor() {
|
|
13763
|
+
this.a = 0; // OK, this class doesn't have an `extends` clause.
|
|
13764
|
+
}
|
|
13765
|
+
}
|
|
12853
13766
|
|
|
12854
|
-
|
|
12855
|
-
|
|
13767
|
+
class A extends B {
|
|
13768
|
+
constructor() {
|
|
13769
|
+
super();
|
|
13770
|
+
this.a = 0; // OK, this is after `super()`.
|
|
13771
|
+
}
|
|
13772
|
+
}
|
|
12856
13773
|
|
|
12857
|
-
|
|
12858
|
-
|
|
13774
|
+
class A extends B {
|
|
13775
|
+
foo() {
|
|
13776
|
+
this.a = 0; // OK. this is not in a constructor.
|
|
13777
|
+
}
|
|
13778
|
+
}
|
|
12859
13779
|
```
|
|
12860
13780
|
|
|
12861
13781
|
π Examples of incorrect code
|
|
12862
13782
|
|
|
12863
13783
|
```typescript
|
|
12864
|
-
|
|
12865
|
-
|
|
12866
|
-
|
|
13784
|
+
class A extends B {
|
|
13785
|
+
constructor() {
|
|
13786
|
+
this.a = 0;
|
|
13787
|
+
super();
|
|
13788
|
+
}
|
|
13789
|
+
}
|
|
12867
13790
|
|
|
12868
|
-
|
|
13791
|
+
class A extends B {
|
|
13792
|
+
constructor() {
|
|
13793
|
+
this.foo();
|
|
13794
|
+
super();
|
|
13795
|
+
}
|
|
13796
|
+
}
|
|
12869
13797
|
|
|
12870
|
-
|
|
13798
|
+
class A extends B {
|
|
13799
|
+
constructor() {
|
|
13800
|
+
super.foo();
|
|
13801
|
+
super();
|
|
13802
|
+
}
|
|
13803
|
+
}
|
|
12871
13804
|
|
|
12872
|
-
|
|
13805
|
+
class A extends B {
|
|
13806
|
+
constructor() {
|
|
13807
|
+
super(this.foo());
|
|
13808
|
+
}
|
|
13809
|
+
}
|
|
13810
|
+
```
|
|
12873
13811
|
|
|
12874
|
-
|
|
13812
|
+
### No Obj Calls
|
|
12875
13813
|
|
|
12876
|
-
|
|
13814
|
+
----------
|
|
12877
13815
|
|
|
12878
|
-
|
|
13816
|
+
Disallow calling global object properties as functions
|
|
12879
13817
|
|
|
12880
|
-
|
|
12881
|
-
import x from './bar' // file found
|
|
12882
|
-
```
|
|
13818
|
+
<https://eslint.org/docs/latest/rules/no-obj-calls>
|
|
12883
13819
|
|
|
12884
|
-
|
|
13820
|
+
π Examples of correct code
|
|
12885
13821
|
|
|
12886
13822
|
```typescript
|
|
12887
|
-
|
|
12888
|
-
|
|
13823
|
+
function area(r) {
|
|
13824
|
+
return Math.PI * r * r;
|
|
13825
|
+
}
|
|
12889
13826
|
|
|
12890
|
-
|
|
13827
|
+
var object = JSON.parse("{}");
|
|
12891
13828
|
|
|
12892
|
-
|
|
13829
|
+
var value = Reflect.get({ x: 1, y: 2 }, "x");
|
|
12893
13830
|
|
|
12894
|
-
|
|
13831
|
+
var first = Atomics.load(foo, 0);
|
|
12895
13832
|
|
|
12896
|
-
|
|
13833
|
+
var segmenterFr = new Intl.Segmenter("fr", { granularity: "word" });
|
|
13834
|
+
```
|
|
12897
13835
|
|
|
12898
|
-
|
|
13836
|
+
π Examples of incorrect code
|
|
12899
13837
|
|
|
12900
13838
|
```typescript
|
|
12901
|
-
|
|
12902
|
-
export const foo = "I'm so foo"
|
|
13839
|
+
var math = Math();
|
|
12903
13840
|
|
|
12904
|
-
|
|
13841
|
+
var newMath = new Math();
|
|
12905
13842
|
|
|
12906
|
-
|
|
12907
|
-
import { foo } from './foo';
|
|
13843
|
+
var json = JSON();
|
|
12908
13844
|
|
|
12909
|
-
|
|
12910
|
-
export { foo as bar } from './foo';
|
|
13845
|
+
var newJSON = new JSON();
|
|
12911
13846
|
|
|
12912
|
-
|
|
12913
|
-
// (import/ignore setting)
|
|
12914
|
-
import { SomeNonsenseThatDoesntExist } from 'react';
|
|
12915
|
-
```
|
|
13847
|
+
var reflect = Reflect();
|
|
12916
13848
|
|
|
12917
|
-
|
|
13849
|
+
var newReflect = new Reflect();
|
|
12918
13850
|
|
|
12919
|
-
|
|
12920
|
-
// ./baz.js
|
|
12921
|
-
import { notFoo } from './foo';
|
|
13851
|
+
var atomics = Atomics();
|
|
12922
13852
|
|
|
12923
|
-
|
|
12924
|
-
export { notFoo as defNotBar } from './foo';
|
|
13853
|
+
var newAtomics = new Atomics();
|
|
12925
13854
|
|
|
12926
|
-
|
|
12927
|
-
|
|
13855
|
+
var intl = Intl();
|
|
13856
|
+
|
|
13857
|
+
var newIntl = new Intl();
|
|
12928
13858
|
```
|
|
12929
13859
|
|
|
12930
|
-
###
|
|
13860
|
+
### No Empty Pattern
|
|
12931
13861
|
|
|
12932
13862
|
----------
|
|
12933
13863
|
|
|
12934
|
-
|
|
13864
|
+
Disallow empty destructuring patterns
|
|
12935
13865
|
|
|
12936
|
-
<https://
|
|
13866
|
+
<https://eslint.org/docs/latest/rules/no-empty-pattern>
|
|
12937
13867
|
|
|
12938
13868
|
π Examples of correct code
|
|
12939
13869
|
|
|
12940
13870
|
```typescript
|
|
12941
|
-
|
|
13871
|
+
|
|
12942
13872
|
```
|
|
12943
13873
|
|
|
12944
13874
|
π Examples of incorrect code
|
|
12945
13875
|
|
|
12946
13876
|
```typescript
|
|
12947
|
-
|
|
13877
|
+
var {} = foo;
|
|
13878
|
+
var [] = foo;
|
|
13879
|
+
var {a: {}} = foo;
|
|
13880
|
+
var {a: []} = foo;
|
|
13881
|
+
function foo({}) {}
|
|
13882
|
+
function foo([]) {}
|
|
13883
|
+
function foo({a: {}}) {}
|
|
13884
|
+
function foo({a: []}) {}
|
|
12948
13885
|
```
|
|
12949
13886
|
|
|
12950
13887
|
## Possible Errors
|
|
@@ -13523,3 +14460,122 @@ describe("testing this.timeout", function() {
|
|
|
13523
14460
|
});
|
|
13524
14461
|
});
|
|
13525
14462
|
```
|
|
14463
|
+
|
|
14464
|
+
### No Empty Static Block
|
|
14465
|
+
|
|
14466
|
+
----------
|
|
14467
|
+
|
|
14468
|
+
Empty static blocks, while not technically errors, usually occur due to refactoring that wasnβt completed.
|
|
14469
|
+
They can cause confusion when reading code.
|
|
14470
|
+
|
|
14471
|
+
<https://eslint.org/docs/latest/rules/no-empty-static-block>
|
|
14472
|
+
|
|
14473
|
+
π Examples of correct code
|
|
14474
|
+
|
|
14475
|
+
```typescript
|
|
14476
|
+
class Foo {
|
|
14477
|
+
static {
|
|
14478
|
+
bar();
|
|
14479
|
+
}
|
|
14480
|
+
}
|
|
14481
|
+
|
|
14482
|
+
class Foo {
|
|
14483
|
+
static {
|
|
14484
|
+
// comment
|
|
14485
|
+
}
|
|
14486
|
+
}
|
|
14487
|
+
```
|
|
14488
|
+
|
|
14489
|
+
π Examples of incorrect code
|
|
14490
|
+
|
|
14491
|
+
```typescript
|
|
14492
|
+
class Foo {
|
|
14493
|
+
static {}
|
|
14494
|
+
}
|
|
14495
|
+
```
|
|
14496
|
+
|
|
14497
|
+
### No Fallthrough
|
|
14498
|
+
|
|
14499
|
+
----------
|
|
14500
|
+
|
|
14501
|
+
The switch statement in JavaScript is one of the more error-prone constructs of the language
|
|
14502
|
+
thanks in part to the ability to βfall throughβ from one case to the next. For example:
|
|
14503
|
+
|
|
14504
|
+
Use `// falls through` comments to run multiple cases
|
|
14505
|
+
|
|
14506
|
+
<https://eslint.org/docs/latest/rules/no-fallthrough>
|
|
14507
|
+
|
|
14508
|
+
π Examples of correct code
|
|
14509
|
+
|
|
14510
|
+
```typescript
|
|
14511
|
+
switch(foo) {
|
|
14512
|
+
case 1:
|
|
14513
|
+
doSomething();
|
|
14514
|
+
break;
|
|
14515
|
+
|
|
14516
|
+
case 2:
|
|
14517
|
+
doSomething();
|
|
14518
|
+
}
|
|
14519
|
+
|
|
14520
|
+
function bar(foo) {
|
|
14521
|
+
switch(foo) {
|
|
14522
|
+
case 1:
|
|
14523
|
+
doSomething();
|
|
14524
|
+
return;
|
|
14525
|
+
|
|
14526
|
+
case 2:
|
|
14527
|
+
doSomething();
|
|
14528
|
+
}
|
|
14529
|
+
}
|
|
14530
|
+
|
|
14531
|
+
switch(foo) {
|
|
14532
|
+
case 1:
|
|
14533
|
+
doSomething();
|
|
14534
|
+
throw new Error("Boo!");
|
|
14535
|
+
|
|
14536
|
+
case 2:
|
|
14537
|
+
doSomething();
|
|
14538
|
+
}
|
|
14539
|
+
|
|
14540
|
+
switch(foo) {
|
|
14541
|
+
case 1:
|
|
14542
|
+
case 2:
|
|
14543
|
+
doSomething();
|
|
14544
|
+
}
|
|
14545
|
+
|
|
14546
|
+
switch(foo) {
|
|
14547
|
+
case 1:
|
|
14548
|
+
doSomething();
|
|
14549
|
+
// falls through
|
|
14550
|
+
|
|
14551
|
+
case 2:
|
|
14552
|
+
doSomething();
|
|
14553
|
+
}
|
|
14554
|
+
|
|
14555
|
+
switch(foo) {
|
|
14556
|
+
case 1: {
|
|
14557
|
+
doSomething();
|
|
14558
|
+
// falls through
|
|
14559
|
+
}
|
|
14560
|
+
|
|
14561
|
+
case 2: {
|
|
14562
|
+
doSomethingElse();
|
|
14563
|
+
}
|
|
14564
|
+
}
|
|
14565
|
+
```
|
|
14566
|
+
|
|
14567
|
+
π Examples of incorrect code
|
|
14568
|
+
|
|
14569
|
+
```typescript
|
|
14570
|
+
switch(foo) {
|
|
14571
|
+
case 1:
|
|
14572
|
+
doSomething();
|
|
14573
|
+
|
|
14574
|
+
case 2:
|
|
14575
|
+
doSomething();
|
|
14576
|
+
}
|
|
14577
|
+
```
|
|
14578
|
+
|
|
14579
|
+
## Yaml Json
|
|
14580
|
+
|
|
14581
|
+
add suport yaml and json files
|