@odg/eslint-config 1.0.0 β 1.1.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 +1313 -717
- package/index.js +1 -0
- package/package.json +2 -1
- package/rules/javascript/best-practices.js +65 -21
- package/rules/javascript/errors.js +19 -0
- package/rules/javascript/possible-errors.js +25 -0
- package/rules/json/base.js +5 -0
- package/rules/typescript/best-practices.js +2 -7
- package/rules/typescript/errors.js +8 -0
- package/src/test.ts +0 -11
package/README.md
CHANGED
|
@@ -69,11 +69,6 @@
|
|
|
69
69
|
- [Arrow Function No Break Line](#arrow-function-no-break-line)
|
|
70
70
|
- [No Empty Block](#no-empty-block)
|
|
71
71
|
- [No Long Syntax](#no-long-syntax)
|
|
72
|
-
- [Useless Call Code](#useless-call-code)
|
|
73
|
-
- [Useless Catch Code](#useless-catch-code)
|
|
74
|
-
- [Useless Expression Code](#useless-expression-code)
|
|
75
|
-
- [Useless Return Code](#useless-return-code)
|
|
76
|
-
- [Useless Construct Code](#useless-construct-code)
|
|
77
72
|
- [Useless Parens](#useless-parens)
|
|
78
73
|
- [Useless Boolean](#useless-boolean)
|
|
79
74
|
- [Useless Alias](#useless-alias)
|
|
@@ -86,6 +81,8 @@
|
|
|
86
81
|
- [Disallow Script Url](#disallow-script-url)
|
|
87
82
|
- [Disallow Undefined](#disallow-undefined)
|
|
88
83
|
- [Function Name](#function-name)
|
|
84
|
+
- [Function Name Match](#function-name-match)
|
|
85
|
+
- [Get And Setters](#get-and-setters)
|
|
89
86
|
- [Function Style](#function-style)
|
|
90
87
|
- [No Else Return](#no-else-return)
|
|
91
88
|
- [No Console Spaces](#no-console-spaces)
|
|
@@ -128,7 +125,6 @@
|
|
|
128
125
|
- [No Delete Var](#no-delete-var)
|
|
129
126
|
- [No Lone Blocks](#no-lone-blocks)
|
|
130
127
|
- [No Proto](#no-proto)
|
|
131
|
-
- [No Useless Computed Key](#no-useless-computed-key)
|
|
132
128
|
- [No Declare in Block](#no-declare-in-block)
|
|
133
129
|
- [No Nonoctal Decimal Escape](#no-nonoctal-decimal-escape)
|
|
134
130
|
- [No Import Absolute Path](#no-import-absolute-path)
|
|
@@ -196,7 +192,9 @@
|
|
|
196
192
|
- [Quote Props](#quote-props)
|
|
197
193
|
- [Brace Style](#brace-style)
|
|
198
194
|
- [Comma Style](#comma-style)
|
|
199
|
-
- [Object
|
|
195
|
+
- [Object Break Line](#object-break-line)
|
|
196
|
+
- [Object Curly Newline](#object-curly-newline)
|
|
197
|
+
- [No Negative Condition](#no-negated-condition)
|
|
200
198
|
- [No Shadow](#no-shadow)
|
|
201
199
|
- [Parentheses New Line](#parentheses-new-line)
|
|
202
200
|
- [No Func Call Spacing](#no-func-call-spacing)
|
|
@@ -207,6 +205,7 @@
|
|
|
207
205
|
- [Inline IF](#inline-if)
|
|
208
206
|
- [New Instance Use Parentheses](#new-instance-use-parentheses)
|
|
209
207
|
- [Logical Assignment Operators](#logical-assignment-operators)
|
|
208
|
+
- [No With](#no-with)
|
|
210
209
|
- [Promise Rules](#promise-rules)
|
|
211
210
|
- [No New Statics](#no-new-statics)
|
|
212
211
|
- [No Return Wrap](#no-return-wrap)
|
|
@@ -230,7 +229,8 @@
|
|
|
230
229
|
- [Import Order](#import-order)
|
|
231
230
|
- [No Anonymous Default Export](#no-anonymous-default-export)
|
|
232
231
|
- [Prefer Node Protocol](#prefer-node-protocol)
|
|
233
|
-
- [Prefer export
|
|
232
|
+
- [Prefer export from](#prefer-export-from)
|
|
233
|
+
- [No Empty Import](#no-empty-import)
|
|
234
234
|
- [Documentation](#documentation)
|
|
235
235
|
- [Space Comment](#spaced-comment)
|
|
236
236
|
- [Capitalized Comments](#capitalized-comments)
|
|
@@ -395,6 +395,13 @@
|
|
|
395
395
|
- [No This Before Super](#no-this-before-super)
|
|
396
396
|
- [No Obj Calls](#no-obj-calls)
|
|
397
397
|
- [No Empty Pattern](#no-empty-pattern)
|
|
398
|
+
- [No Useless Computed Key](#no-useless-computed-key)
|
|
399
|
+
- [Useless Call Code](#useless-call-code)
|
|
400
|
+
- [Useless Catch Code](#useless-catch-code)
|
|
401
|
+
- [Useless Expression Code](#useless-expression-code)
|
|
402
|
+
- [Useless Return Code](#useless-return-code)
|
|
403
|
+
- [Useless Construct Code](#useless-construct-code)
|
|
404
|
+
- [No Use Before Define](#no-use-before-define)
|
|
398
405
|
- [Possible Errors](#possible-errors)
|
|
399
406
|
- [For Direction](#for-direction)
|
|
400
407
|
- [No Extra Bind](#no-extra-bind)
|
|
@@ -411,6 +418,10 @@
|
|
|
411
418
|
- [No Disable Timeout](#no-disable-timeout)
|
|
412
419
|
- [No Empty Static Block](#no-empty-static-block)
|
|
413
420
|
- [No Fallthrough](#no-fallthrough)
|
|
421
|
+
- [No Octal](#no-octal)
|
|
422
|
+
- [Octal Scape](#octal-scape)
|
|
423
|
+
- [No Global Assign](#no-global-assign)
|
|
424
|
+
- [No Case Declarations](#no-case-declarations)
|
|
414
425
|
- [YAML / JSON](#yaml-json)
|
|
415
426
|
|
|
416
427
|
## Introduction
|
|
@@ -466,6 +477,7 @@ export default class Foo {
|
|
|
466
477
|
Requires semicolons at the end of statements
|
|
467
478
|
|
|
468
479
|
<https://eslint.org/docs/rules/semi#semi>
|
|
480
|
+
<https://eslint.org/docs/rules/semi-style>
|
|
469
481
|
|
|
470
482
|
π Examples of correct code
|
|
471
483
|
|
|
@@ -479,6 +491,23 @@ object.method = function() {
|
|
|
479
491
|
class Foo {
|
|
480
492
|
bar = 1;
|
|
481
493
|
}
|
|
494
|
+
|
|
495
|
+
foo();
|
|
496
|
+
[1, 2, 3].forEach(bar);
|
|
497
|
+
|
|
498
|
+
for (
|
|
499
|
+
var i = 0;
|
|
500
|
+
i < 10;
|
|
501
|
+
++i
|
|
502
|
+
) {
|
|
503
|
+
foo();
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
class C {
|
|
507
|
+
static {
|
|
508
|
+
foo();
|
|
509
|
+
}
|
|
510
|
+
}
|
|
482
511
|
```
|
|
483
512
|
|
|
484
513
|
π Examples of incorrect code
|
|
@@ -493,6 +522,25 @@ object.method = function() {
|
|
|
493
522
|
class Foo {
|
|
494
523
|
bar = 1
|
|
495
524
|
}
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
foo()
|
|
528
|
+
;[1, 2, 3].forEach(bar)
|
|
529
|
+
|
|
530
|
+
for (
|
|
531
|
+
var i = 0
|
|
532
|
+
; i < 10
|
|
533
|
+
; ++i
|
|
534
|
+
) {
|
|
535
|
+
foo()
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
class C {
|
|
539
|
+
static {
|
|
540
|
+
foo()
|
|
541
|
+
;bar()
|
|
542
|
+
}
|
|
543
|
+
}
|
|
496
544
|
```
|
|
497
545
|
|
|
498
546
|
## Quotes Rule
|
|
@@ -533,6 +581,7 @@ Tabs Disallow
|
|
|
533
581
|
<https://eslint.org/docs/rules/indent#indent>
|
|
534
582
|
<https://sonarsource.github.io/rspec/#/rspec/S3973/javascript>
|
|
535
583
|
<https://eslint.org/docs/latest/rules/no-tabs>
|
|
584
|
+
<https://eslint.org/docs/latest/rules/no-mixed-spaces-and-tabs>
|
|
536
585
|
|
|
537
586
|
π Examples of correct code
|
|
538
587
|
|
|
@@ -1842,853 +1891,734 @@ const arr = Array(0, 1, 2);
|
|
|
1842
1891
|
const arr = new Array(0, 1, 2);
|
|
1843
1892
|
```
|
|
1844
1893
|
|
|
1845
|
-
## Useless
|
|
1894
|
+
## Useless Parens
|
|
1846
1895
|
|
|
1847
1896
|
----------
|
|
1848
1897
|
|
|
1849
|
-
|
|
1898
|
+
Disallows unnecessary parentheses.
|
|
1850
1899
|
|
|
1851
|
-
<https://
|
|
1900
|
+
<https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/no-extra-parens.md>
|
|
1901
|
+
<https://eslint.org/docs/rules/no-extra-parens#no-extra-parens>
|
|
1852
1902
|
|
|
1853
1903
|
π Examples of correct code
|
|
1854
1904
|
|
|
1855
1905
|
```typescript
|
|
1856
|
-
|
|
1857
|
-
foo.apply(obj, [1, 2, 3]);
|
|
1858
|
-
obj.foo.call(null, 1, 2, 3);
|
|
1859
|
-
obj.foo.apply(null, [1, 2, 3]);
|
|
1860
|
-
obj.foo.call(otherObj, 1, 2, 3);
|
|
1861
|
-
obj.foo.apply(otherObj, [1, 2, 3]);
|
|
1906
|
+
a = (b * c);
|
|
1862
1907
|
|
|
1863
|
-
|
|
1864
|
-
// Those are warned by the `prefer-spread` rule.
|
|
1865
|
-
foo.apply(undefined, args);
|
|
1866
|
-
foo.apply(null, args);
|
|
1867
|
-
obj.foo.apply(obj, args);
|
|
1908
|
+
(a * b) + c;
|
|
1868
1909
|
|
|
1869
|
-
|
|
1910
|
+
for (a in (b, c));
|
|
1911
|
+
|
|
1912
|
+
for (a in (b));
|
|
1913
|
+
|
|
1914
|
+
for (a of (b));
|
|
1915
|
+
|
|
1916
|
+
typeof (a);
|
|
1917
|
+
|
|
1918
|
+
(function(){} ? a() : b());
|
|
1919
|
+
|
|
1920
|
+
class A {
|
|
1921
|
+
[(x)] = 1;
|
|
1922
|
+
}
|
|
1923
|
+
|
|
1924
|
+
class B {
|
|
1925
|
+
x = (y + z);
|
|
1926
|
+
}
|
|
1870
1927
|
```
|
|
1871
1928
|
|
|
1872
1929
|
π Examples of incorrect code
|
|
1873
1930
|
|
|
1874
1931
|
```typescript
|
|
1875
|
-
|
|
1876
|
-
foo.apply(undefined, [1, 2, 3]);
|
|
1877
|
-
foo.call(null, 1, 2, 3);
|
|
1878
|
-
foo.apply(null, [1, 2, 3]);
|
|
1932
|
+
a = (b * c);
|
|
1879
1933
|
|
|
1880
|
-
|
|
1881
|
-
obj.foo.call(obj, 1, 2, 3);
|
|
1882
|
-
obj.foo.apply(obj, [1, 2, 3]);
|
|
1934
|
+
(a * b) + c;
|
|
1883
1935
|
|
|
1884
|
-
|
|
1936
|
+
for (a in (b, c));
|
|
1937
|
+
|
|
1938
|
+
for (a in (b));
|
|
1939
|
+
|
|
1940
|
+
for (a of (b));
|
|
1941
|
+
|
|
1942
|
+
typeof (a);
|
|
1943
|
+
|
|
1944
|
+
(function(){} ? a() : b());
|
|
1945
|
+
|
|
1946
|
+
class A {
|
|
1947
|
+
[(x)] = 1;
|
|
1948
|
+
}
|
|
1949
|
+
|
|
1950
|
+
class B {
|
|
1951
|
+
x = (y + z);
|
|
1952
|
+
}
|
|
1885
1953
|
```
|
|
1886
1954
|
|
|
1887
|
-
## Useless
|
|
1955
|
+
## Useless Boolean
|
|
1888
1956
|
|
|
1889
1957
|
----------
|
|
1890
1958
|
|
|
1891
1959
|
Disallow useless code
|
|
1892
1960
|
|
|
1893
|
-
<https://eslint.org/docs/rules/no-useless-
|
|
1961
|
+
<https://eslint.org/docs/rules/no-useless-constructor#options>
|
|
1894
1962
|
|
|
1895
1963
|
π Examples of correct code
|
|
1896
1964
|
|
|
1897
1965
|
```typescript
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
} catch (e) {
|
|
1901
|
-
doSomethingBeforeRethrow();
|
|
1902
|
-
throw e;
|
|
1903
|
-
}
|
|
1966
|
+
var foo = !!bar;
|
|
1967
|
+
var foo = Boolean(bar);
|
|
1904
1968
|
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
} catch (e) {
|
|
1908
|
-
handleError(e);
|
|
1969
|
+
function foo() {
|
|
1970
|
+
return !!bar;
|
|
1909
1971
|
}
|
|
1910
1972
|
|
|
1911
|
-
|
|
1912
|
-
doSomethingThatMightThrow();
|
|
1913
|
-
} finally {
|
|
1914
|
-
cleanUp();
|
|
1915
|
-
}
|
|
1973
|
+
var foo = bar ? !!baz : !!bat;
|
|
1916
1974
|
```
|
|
1917
1975
|
|
|
1918
1976
|
π Examples of incorrect code
|
|
1919
1977
|
|
|
1920
1978
|
```typescript
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1979
|
+
var foo = !!!bar;
|
|
1980
|
+
|
|
1981
|
+
var foo = !!bar ? baz : bat;
|
|
1982
|
+
|
|
1983
|
+
var foo = Boolean(!!bar);
|
|
1984
|
+
|
|
1985
|
+
var foo = new Boolean(!!bar);
|
|
1986
|
+
|
|
1987
|
+
if (!!foo) {
|
|
1988
|
+
// ...
|
|
1925
1989
|
}
|
|
1926
1990
|
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
}
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1991
|
+
if (Boolean(foo)) {
|
|
1992
|
+
// ...
|
|
1993
|
+
}
|
|
1994
|
+
|
|
1995
|
+
while (!!foo) {
|
|
1996
|
+
// ...
|
|
1997
|
+
}
|
|
1998
|
+
|
|
1999
|
+
do {
|
|
2000
|
+
// ...
|
|
2001
|
+
} while (Boolean(foo));
|
|
2002
|
+
|
|
2003
|
+
for ( ;!!foo; ) {
|
|
2004
|
+
// ...
|
|
1933
2005
|
}
|
|
1934
2006
|
```
|
|
1935
2007
|
|
|
1936
|
-
## Useless
|
|
2008
|
+
## Useless Alias
|
|
1937
2009
|
|
|
1938
2010
|
----------
|
|
1939
2011
|
|
|
1940
|
-
|
|
2012
|
+
Disallows renaming import, export, and destructured assignments to the same name.
|
|
1941
2013
|
|
|
1942
|
-
<https://eslint.org/docs/rules/no-
|
|
2014
|
+
<https://eslint.org/docs/rules/no-useless-rename>
|
|
1943
2015
|
|
|
1944
2016
|
π Examples of correct code
|
|
1945
2017
|
|
|
1946
2018
|
```typescript
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
{
|
|
1950
|
-
|
|
1951
|
-
function namedFunctionDeclaration () {}
|
|
1952
|
-
|
|
1953
|
-
(function aGenuineIIFE () {}());
|
|
1954
|
-
|
|
1955
|
-
f()
|
|
1956
|
-
|
|
1957
|
-
a = 0
|
|
2019
|
+
import * as foo from "foo";
|
|
2020
|
+
import { foo } from "bar";
|
|
2021
|
+
import { foo as bar } from "baz";
|
|
2022
|
+
import { "foo" as bar } from "baz";
|
|
1958
2023
|
|
|
1959
|
-
|
|
2024
|
+
export { foo };
|
|
2025
|
+
export { foo as bar };
|
|
2026
|
+
export { foo as bar } from "foo";
|
|
1960
2027
|
|
|
1961
|
-
|
|
2028
|
+
let { foo } = bar;
|
|
2029
|
+
let { foo: bar } = baz;
|
|
2030
|
+
let { [foo]: foo } = bar;
|
|
1962
2031
|
|
|
1963
|
-
|
|
2032
|
+
function foo({ bar }) {}
|
|
2033
|
+
function foo({ bar: baz }) {}
|
|
1964
2034
|
|
|
1965
|
-
|
|
1966
|
-
|
|
2035
|
+
({ foo }) => {}
|
|
2036
|
+
({ foo: bar }) => {}
|
|
1967
2037
|
```
|
|
1968
2038
|
|
|
1969
2039
|
π Examples of incorrect code
|
|
1970
2040
|
|
|
1971
2041
|
```typescript
|
|
1972
|
-
|
|
2042
|
+
import { foo as foo } from "bar";
|
|
2043
|
+
import { "foo" as foo } from "bar";
|
|
2044
|
+
export { foo as foo };
|
|
2045
|
+
export { foo as "foo" };
|
|
2046
|
+
export { foo as foo } from "bar";
|
|
2047
|
+
export { "foo" as "foo" } from "bar";
|
|
2048
|
+
let { foo: foo } = bar;
|
|
2049
|
+
let { 'foo': foo } = bar;
|
|
2050
|
+
function foo({ bar: bar }) {}
|
|
2051
|
+
({ foo: foo }) => {}
|
|
2052
|
+
```
|
|
1973
2053
|
|
|
1974
|
-
|
|
2054
|
+
## Return New line
|
|
1975
2055
|
|
|
1976
|
-
|
|
2056
|
+
----------
|
|
1977
2057
|
|
|
1978
|
-
|
|
2058
|
+
Force new line before return
|
|
1979
2059
|
|
|
1980
|
-
|
|
2060
|
+
<https://eslint.org/docs/rules/newline-before-return#newline-before-return>
|
|
1981
2061
|
|
|
1982
|
-
|
|
2062
|
+
π Examples of correct code
|
|
1983
2063
|
|
|
1984
|
-
|
|
2064
|
+
```typescript
|
|
2065
|
+
function foo(bar) {
|
|
2066
|
+
var baz = 'baz';
|
|
1985
2067
|
|
|
1986
|
-
|
|
2068
|
+
if (bar()) {
|
|
2069
|
+
return true;
|
|
2070
|
+
}
|
|
1987
2071
|
|
|
1988
|
-
|
|
2072
|
+
if (!bar) {
|
|
2073
|
+
bar = baz;
|
|
1989
2074
|
|
|
1990
|
-
|
|
2075
|
+
return baz;
|
|
2076
|
+
}
|
|
1991
2077
|
|
|
1992
|
-
|
|
1993
|
-
"bar" + 1;
|
|
2078
|
+
return bar;
|
|
1994
2079
|
}
|
|
2080
|
+
```
|
|
1995
2081
|
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2082
|
+
π Examples of incorrect code
|
|
2083
|
+
|
|
2084
|
+
```typescript
|
|
2085
|
+
function foo(bar) {
|
|
2086
|
+
var baz = 'baz';
|
|
2087
|
+
if (bar()) {
|
|
2088
|
+
return true;
|
|
2089
|
+
}
|
|
2090
|
+
if (!bar) {
|
|
2091
|
+
bar = baz;
|
|
2092
|
+
return bar;
|
|
2093
|
+
}
|
|
2094
|
+
return bar;
|
|
2000
2095
|
}
|
|
2001
2096
|
```
|
|
2002
2097
|
|
|
2003
|
-
##
|
|
2098
|
+
## Comment Multi Line Prefer
|
|
2004
2099
|
|
|
2005
2100
|
----------
|
|
2006
2101
|
|
|
2007
|
-
|
|
2102
|
+
Prefer Multi-line comment formated
|
|
2008
2103
|
|
|
2009
|
-
<https://eslint.org/docs/rules/
|
|
2104
|
+
<https://eslint.org/docs/rules/newline-before-return#newline-before-return>
|
|
2010
2105
|
|
|
2011
2106
|
π Examples of correct code
|
|
2012
2107
|
|
|
2013
2108
|
```typescript
|
|
2014
|
-
|
|
2109
|
+
/*
|
|
2110
|
+
* this line
|
|
2111
|
+
* calls foo()
|
|
2112
|
+
*/
|
|
2113
|
+
foo();
|
|
2015
2114
|
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
}
|
|
2115
|
+
// single-line comment
|
|
2116
|
+
```
|
|
2019
2117
|
|
|
2020
|
-
|
|
2021
|
-
if (condition) {
|
|
2022
|
-
bar();
|
|
2023
|
-
return;
|
|
2024
|
-
} else {
|
|
2025
|
-
baz();
|
|
2026
|
-
}
|
|
2027
|
-
qux();
|
|
2028
|
-
}
|
|
2118
|
+
π Examples of incorrect code
|
|
2029
2119
|
|
|
2030
|
-
|
|
2031
|
-
switch (bar) {
|
|
2032
|
-
case 1:
|
|
2033
|
-
doSomething();
|
|
2034
|
-
return;
|
|
2035
|
-
default:
|
|
2036
|
-
doSomethingElse();
|
|
2037
|
-
}
|
|
2038
|
-
}
|
|
2120
|
+
```typescript
|
|
2039
2121
|
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
}
|
|
2044
|
-
}
|
|
2045
|
-
```
|
|
2122
|
+
// this line
|
|
2123
|
+
// calls foo()
|
|
2124
|
+
foo();
|
|
2046
2125
|
|
|
2047
|
-
|
|
2126
|
+
/* this line
|
|
2127
|
+
calls foo() */
|
|
2128
|
+
foo();
|
|
2048
2129
|
|
|
2049
|
-
|
|
2050
|
-
|
|
2130
|
+
/* this comment
|
|
2131
|
+
* is missing a newline after /*
|
|
2132
|
+
*/
|
|
2051
2133
|
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
}
|
|
2134
|
+
/*
|
|
2135
|
+
* this comment
|
|
2136
|
+
* is missing a newline at the end */
|
|
2056
2137
|
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
return;
|
|
2061
|
-
} else {
|
|
2062
|
-
baz();
|
|
2063
|
-
}
|
|
2064
|
-
}
|
|
2138
|
+
/*
|
|
2139
|
+
* the star in this line should have a space before it
|
|
2140
|
+
*/
|
|
2065
2141
|
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
doSomething();
|
|
2070
|
-
default:
|
|
2071
|
-
doSomethingElse();
|
|
2072
|
-
return;
|
|
2073
|
-
}
|
|
2074
|
-
}
|
|
2142
|
+
/*
|
|
2143
|
+
* the star on the following line should have a space before it
|
|
2144
|
+
*/
|
|
2075
2145
|
```
|
|
2076
2146
|
|
|
2077
|
-
##
|
|
2147
|
+
## No throw Literal
|
|
2078
2148
|
|
|
2079
2149
|
----------
|
|
2080
2150
|
|
|
2081
|
-
|
|
2151
|
+
Create custom class to Throw
|
|
2082
2152
|
|
|
2083
|
-
<https://
|
|
2153
|
+
<https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/no-throw-literal.md>
|
|
2154
|
+
<https://eslint.org/docs/rules/prefer-promise-reject-errors#prefer-promise-reject-errors>
|
|
2084
2155
|
|
|
2085
2156
|
π Examples of correct code
|
|
2086
2157
|
|
|
2087
2158
|
```typescript
|
|
2159
|
+
class CustomError extends Error {
|
|
2160
|
+
// ...
|
|
2161
|
+
};
|
|
2088
2162
|
|
|
2089
|
-
|
|
2163
|
+
const e = new CustomError("error");
|
|
2164
|
+
throw e;
|
|
2090
2165
|
|
|
2091
|
-
|
|
2092
|
-
constructor () {
|
|
2093
|
-
doSomething();
|
|
2094
|
-
}
|
|
2095
|
-
}
|
|
2166
|
+
throw new CustomError("error");
|
|
2096
2167
|
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
super('foo');
|
|
2100
|
-
}
|
|
2168
|
+
function err() {
|
|
2169
|
+
return new CustomError();
|
|
2101
2170
|
}
|
|
2171
|
+
throw err();
|
|
2102
2172
|
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
super();
|
|
2106
|
-
doSomething();
|
|
2107
|
-
}
|
|
2173
|
+
const foo = {
|
|
2174
|
+
bar: new CustomError();
|
|
2108
2175
|
}
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
π Examples of incorrect code
|
|
2176
|
+
throw foo.bar;
|
|
2112
2177
|
|
|
2113
|
-
|
|
2114
|
-
class A {
|
|
2115
|
-
constructor () {
|
|
2116
|
-
}
|
|
2117
|
-
}
|
|
2178
|
+
// promises
|
|
2118
2179
|
|
|
2119
|
-
|
|
2120
|
-
constructor (...args) {
|
|
2121
|
-
super(...args);
|
|
2122
|
-
}
|
|
2123
|
-
}
|
|
2124
|
-
```
|
|
2180
|
+
Promise.reject(new CustomError("something bad happened"));
|
|
2125
2181
|
|
|
2126
|
-
|
|
2182
|
+
Promise.reject(new TypeError("something bad happened"));
|
|
2127
2183
|
|
|
2128
|
-
|
|
2184
|
+
new Promise(function(resolve, reject) {
|
|
2185
|
+
reject(new CustomError("something bad happened"));
|
|
2186
|
+
});
|
|
2129
2187
|
|
|
2130
|
-
|
|
2188
|
+
var foo = getUnknownValue();
|
|
2189
|
+
Promise.reject(foo);
|
|
2131
2190
|
|
|
2132
|
-
|
|
2133
|
-
<https://eslint.org/docs/rules/no-extra-parens#no-extra-parens>
|
|
2191
|
+
```
|
|
2134
2192
|
|
|
2135
|
-
|
|
2193
|
+
π Examples of incorrect code
|
|
2136
2194
|
|
|
2137
2195
|
```typescript
|
|
2138
|
-
|
|
2196
|
+
throw new Error();
|
|
2139
2197
|
|
|
2140
|
-
|
|
2198
|
+
throw 'error';
|
|
2141
2199
|
|
|
2142
|
-
|
|
2200
|
+
throw 0;
|
|
2143
2201
|
|
|
2144
|
-
|
|
2202
|
+
throw undefined;
|
|
2145
2203
|
|
|
2146
|
-
|
|
2204
|
+
throw null;
|
|
2147
2205
|
|
|
2148
|
-
|
|
2206
|
+
const err = new Error();
|
|
2207
|
+
throw 'an ' + err;
|
|
2149
2208
|
|
|
2150
|
-
|
|
2209
|
+
const err = new Error();
|
|
2210
|
+
throw `${err}`;
|
|
2151
2211
|
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
}
|
|
2212
|
+
const err = '';
|
|
2213
|
+
throw err;
|
|
2155
2214
|
|
|
2156
|
-
|
|
2157
|
-
|
|
2215
|
+
function err() {
|
|
2216
|
+
return '';
|
|
2158
2217
|
}
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
π Examples of incorrect code
|
|
2162
|
-
|
|
2163
|
-
```typescript
|
|
2164
|
-
a = (b * c);
|
|
2165
|
-
|
|
2166
|
-
(a * b) + c;
|
|
2218
|
+
throw err();
|
|
2167
2219
|
|
|
2168
|
-
|
|
2220
|
+
const foo = {
|
|
2221
|
+
bar: '',
|
|
2222
|
+
};
|
|
2223
|
+
throw foo.bar;
|
|
2169
2224
|
|
|
2170
|
-
|
|
2225
|
+
// Promise
|
|
2171
2226
|
|
|
2172
|
-
|
|
2227
|
+
Promise.reject("something bad happened");
|
|
2173
2228
|
|
|
2174
|
-
|
|
2229
|
+
Promise.reject(5);
|
|
2175
2230
|
|
|
2176
|
-
(
|
|
2231
|
+
Promise.reject();
|
|
2177
2232
|
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
}
|
|
2233
|
+
new Promise(function(resolve, reject) {
|
|
2234
|
+
reject("something bad happened");
|
|
2235
|
+
});
|
|
2181
2236
|
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
}
|
|
2237
|
+
new Promise(function(resolve, reject) {
|
|
2238
|
+
reject();
|
|
2239
|
+
});
|
|
2185
2240
|
```
|
|
2186
2241
|
|
|
2187
|
-
##
|
|
2242
|
+
## No Unreachable
|
|
2188
2243
|
|
|
2189
2244
|
----------
|
|
2190
2245
|
|
|
2191
|
-
|
|
2246
|
+
No Unreachable code
|
|
2192
2247
|
|
|
2193
|
-
<https://eslint.org/docs/rules/no-
|
|
2248
|
+
<https://eslint.org/docs/rules/no-unreachable>
|
|
2194
2249
|
|
|
2195
2250
|
π Examples of correct code
|
|
2196
2251
|
|
|
2197
2252
|
```typescript
|
|
2198
|
-
var foo = !!bar;
|
|
2199
|
-
var foo = Boolean(bar);
|
|
2200
|
-
|
|
2201
2253
|
function foo() {
|
|
2202
|
-
|
|
2254
|
+
function bar() {
|
|
2255
|
+
return 1;
|
|
2256
|
+
}
|
|
2257
|
+
|
|
2258
|
+
return bar();
|
|
2259
|
+
|
|
2203
2260
|
}
|
|
2204
2261
|
|
|
2205
|
-
|
|
2262
|
+
function bar() {
|
|
2263
|
+
var x;
|
|
2264
|
+
return x;
|
|
2265
|
+
}
|
|
2266
|
+
|
|
2267
|
+
switch (foo) {
|
|
2268
|
+
case 1:
|
|
2269
|
+
break;
|
|
2270
|
+
}
|
|
2206
2271
|
```
|
|
2207
2272
|
|
|
2208
2273
|
π Examples of incorrect code
|
|
2209
2274
|
|
|
2210
2275
|
```typescript
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
var foo = Boolean(!!bar);
|
|
2216
|
-
|
|
2217
|
-
var foo = new Boolean(!!bar);
|
|
2218
|
-
|
|
2219
|
-
if (!!foo) {
|
|
2220
|
-
// ...
|
|
2276
|
+
function foo() {
|
|
2277
|
+
return true;
|
|
2278
|
+
console.log("done");
|
|
2221
2279
|
}
|
|
2222
2280
|
|
|
2223
|
-
|
|
2224
|
-
|
|
2281
|
+
function bar() {
|
|
2282
|
+
throw new Error("Oops!");
|
|
2283
|
+
console.log("done");
|
|
2225
2284
|
}
|
|
2226
2285
|
|
|
2227
|
-
while
|
|
2228
|
-
|
|
2286
|
+
while(value) {
|
|
2287
|
+
break;
|
|
2288
|
+
console.log("done");
|
|
2229
2289
|
}
|
|
2230
2290
|
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
} while (Boolean(foo));
|
|
2291
|
+
throw new Error("Oops!");
|
|
2292
|
+
console.log("done");
|
|
2234
2293
|
|
|
2235
|
-
|
|
2236
|
-
|
|
2294
|
+
function baz() {
|
|
2295
|
+
if (Math.random() < 0.5) {
|
|
2296
|
+
return;
|
|
2297
|
+
} else {
|
|
2298
|
+
throw new Error();
|
|
2299
|
+
}
|
|
2300
|
+
console.log("done");
|
|
2237
2301
|
}
|
|
2302
|
+
|
|
2303
|
+
for (;;) {}
|
|
2304
|
+
console.log("done");
|
|
2238
2305
|
```
|
|
2239
2306
|
|
|
2240
|
-
##
|
|
2307
|
+
## No Multiline String
|
|
2241
2308
|
|
|
2242
2309
|
----------
|
|
2243
2310
|
|
|
2244
|
-
|
|
2311
|
+
Prevent break line in string
|
|
2245
2312
|
|
|
2246
|
-
<https://eslint.org/docs/rules/no-
|
|
2313
|
+
<https://eslint.org/docs/rules/no-multi-str#no-multi-str>
|
|
2247
2314
|
|
|
2248
2315
|
π Examples of correct code
|
|
2249
2316
|
|
|
2250
2317
|
```typescript
|
|
2251
|
-
|
|
2252
|
-
import { foo } from "bar";
|
|
2253
|
-
import { foo as bar } from "baz";
|
|
2254
|
-
import { "foo" as bar } from "baz";
|
|
2255
|
-
|
|
2256
|
-
export { foo };
|
|
2257
|
-
export { foo as bar };
|
|
2258
|
-
export { foo as bar } from "foo";
|
|
2259
|
-
|
|
2260
|
-
let { foo } = bar;
|
|
2261
|
-
let { foo: bar } = baz;
|
|
2262
|
-
let { [foo]: foo } = bar;
|
|
2263
|
-
|
|
2264
|
-
function foo({ bar }) {}
|
|
2265
|
-
function foo({ bar: baz }) {}
|
|
2318
|
+
var x = "some very\nlong text";
|
|
2266
2319
|
|
|
2267
|
-
|
|
2268
|
-
|
|
2320
|
+
var x = "some very " +
|
|
2321
|
+
"long text";
|
|
2269
2322
|
```
|
|
2270
2323
|
|
|
2271
2324
|
π Examples of incorrect code
|
|
2272
2325
|
|
|
2273
2326
|
```typescript
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
export { foo as foo };
|
|
2277
|
-
export { foo as "foo" };
|
|
2278
|
-
export { foo as foo } from "bar";
|
|
2279
|
-
export { "foo" as "foo" } from "bar";
|
|
2280
|
-
let { foo: foo } = bar;
|
|
2281
|
-
let { 'foo': foo } = bar;
|
|
2282
|
-
function foo({ bar: bar }) {}
|
|
2283
|
-
({ foo: foo }) => {}
|
|
2327
|
+
var x = "some very \
|
|
2328
|
+
long text";
|
|
2284
2329
|
```
|
|
2285
2330
|
|
|
2286
|
-
##
|
|
2331
|
+
## No Unsafe Assign
|
|
2287
2332
|
|
|
2288
2333
|
----------
|
|
2289
2334
|
|
|
2290
|
-
|
|
2335
|
+
Disallows assigning any to variables and properties.
|
|
2291
2336
|
|
|
2292
|
-
<https://
|
|
2337
|
+
<https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/no-unsafe-assignment.md>
|
|
2293
2338
|
|
|
2294
2339
|
π Examples of correct code
|
|
2295
2340
|
|
|
2296
2341
|
```typescript
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
return true;
|
|
2302
|
-
}
|
|
2303
|
-
|
|
2304
|
-
if (!bar) {
|
|
2305
|
-
bar = baz;
|
|
2306
|
-
|
|
2307
|
-
return baz;
|
|
2308
|
-
}
|
|
2342
|
+
const x = 1,
|
|
2343
|
+
y = 1;
|
|
2344
|
+
const [x] = [1];
|
|
2345
|
+
[x] = [1] as [number];
|
|
2309
2346
|
|
|
2310
|
-
|
|
2347
|
+
function foo(a = 1) {}
|
|
2348
|
+
class Foo {
|
|
2349
|
+
constructor(private a = 1) {}
|
|
2350
|
+
}
|
|
2351
|
+
class Foo {
|
|
2352
|
+
private a = 1;
|
|
2311
2353
|
}
|
|
2354
|
+
|
|
2355
|
+
// generic position examples
|
|
2356
|
+
const x: Set<string> = new Set<string>();
|
|
2357
|
+
const x: Map<string, string> = new Map<string, string>();
|
|
2358
|
+
const x: Set<string[]> = new Set<string[]>();
|
|
2359
|
+
const x: Set<Set<Set<string>>> = new Set<Set<Set<string>>>();
|
|
2312
2360
|
```
|
|
2313
2361
|
|
|
2314
2362
|
π Examples of incorrect code
|
|
2315
2363
|
|
|
2316
2364
|
```typescript
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2365
|
+
const x = 1 as any,
|
|
2366
|
+
y = 1 as any;
|
|
2367
|
+
const [x] = 1 as any;
|
|
2368
|
+
const [x] = [] as any[];
|
|
2369
|
+
const [x] = [1 as any];
|
|
2370
|
+
[x] = [1] as [any];
|
|
2371
|
+
|
|
2372
|
+
function foo(a = 1 as any) {}
|
|
2373
|
+
class Foo {
|
|
2374
|
+
constructor(private a = 1 as any) {}
|
|
2327
2375
|
}
|
|
2376
|
+
class Foo {
|
|
2377
|
+
private a = 1 as any;
|
|
2378
|
+
}
|
|
2379
|
+
|
|
2380
|
+
// generic position examples
|
|
2381
|
+
const x: Set<string> = new Set<any>();
|
|
2382
|
+
const x: Map<string, string> = new Map<string, any>();
|
|
2383
|
+
const x: Set<string[]> = new Set<any[]>();
|
|
2384
|
+
const x: Set<Set<Set<string>>> = new Set<Set<Set<any>>>();
|
|
2328
2385
|
```
|
|
2329
2386
|
|
|
2330
|
-
##
|
|
2387
|
+
## Disallow Script Url
|
|
2331
2388
|
|
|
2332
2389
|
----------
|
|
2333
2390
|
|
|
2334
|
-
|
|
2391
|
+
Using javascript: URLs is considered by some as a form of eval.
|
|
2335
2392
|
|
|
2336
|
-
<https://eslint.org/docs/rules/
|
|
2393
|
+
<https://eslint.org/docs/rules/no-script-url>
|
|
2337
2394
|
|
|
2338
2395
|
π Examples of correct code
|
|
2339
2396
|
|
|
2340
2397
|
```typescript
|
|
2341
|
-
|
|
2342
|
-
* this line
|
|
2343
|
-
* calls foo()
|
|
2344
|
-
*/
|
|
2345
|
-
foo();
|
|
2346
|
-
|
|
2347
|
-
// single-line comment
|
|
2398
|
+
location.href = "#";
|
|
2348
2399
|
```
|
|
2349
2400
|
|
|
2350
2401
|
π Examples of incorrect code
|
|
2351
2402
|
|
|
2352
2403
|
```typescript
|
|
2404
|
+
location.href = "javascript:void(0)";
|
|
2353
2405
|
|
|
2354
|
-
|
|
2355
|
-
// calls foo()
|
|
2356
|
-
foo();
|
|
2357
|
-
|
|
2358
|
-
/* this line
|
|
2359
|
-
calls foo() */
|
|
2360
|
-
foo();
|
|
2361
|
-
|
|
2362
|
-
/* this comment
|
|
2363
|
-
* is missing a newline after /*
|
|
2364
|
-
*/
|
|
2365
|
-
|
|
2366
|
-
/*
|
|
2367
|
-
* this comment
|
|
2368
|
-
* is missing a newline at the end */
|
|
2369
|
-
|
|
2370
|
-
/*
|
|
2371
|
-
* the star in this line should have a space before it
|
|
2372
|
-
*/
|
|
2373
|
-
|
|
2374
|
-
/*
|
|
2375
|
-
* the star on the following line should have a space before it
|
|
2376
|
-
*/
|
|
2406
|
+
location.href = `javascript:void(0)`;
|
|
2377
2407
|
```
|
|
2378
2408
|
|
|
2379
|
-
##
|
|
2409
|
+
## Disallow Undefined
|
|
2380
2410
|
|
|
2381
2411
|
----------
|
|
2382
2412
|
|
|
2383
|
-
|
|
2413
|
+
Disallows the use of undeclared variables unless mentioned in /\*global\*/ comments.
|
|
2384
2414
|
|
|
2385
|
-
<https://
|
|
2386
|
-
<https://eslint.org/docs/rules/prefer-promise-reject-errors#prefer-promise-reject-errors>
|
|
2415
|
+
<https://eslint.org/docs/rules/no-undef>
|
|
2387
2416
|
|
|
2388
2417
|
π Examples of correct code
|
|
2389
2418
|
|
|
2390
2419
|
```typescript
|
|
2391
|
-
|
|
2392
|
-
// ...
|
|
2393
|
-
};
|
|
2420
|
+
/* global someFunction, a */
|
|
2394
2421
|
|
|
2395
|
-
|
|
2396
|
-
|
|
2422
|
+
var foo = someFunction();
|
|
2423
|
+
var bar = a + 1;
|
|
2424
|
+
```
|
|
2397
2425
|
|
|
2398
|
-
|
|
2426
|
+
π Examples of incorrect code
|
|
2399
2427
|
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2428
|
+
```typescript
|
|
2429
|
+
var foo = someFunction();
|
|
2430
|
+
var bar = a + 1;
|
|
2431
|
+
```
|
|
2404
2432
|
|
|
2405
|
-
|
|
2406
|
-
bar: new CustomError();
|
|
2407
|
-
}
|
|
2408
|
-
throw foo.bar;
|
|
2433
|
+
## Function Name
|
|
2409
2434
|
|
|
2410
|
-
|
|
2435
|
+
----------
|
|
2411
2436
|
|
|
2412
|
-
|
|
2437
|
+
Requires function expressions to have a name, if the name isn't assigned automatically per the ECMAScript specification.
|
|
2413
2438
|
|
|
2414
|
-
|
|
2439
|
+
<https://eslint.org/docs/rules/func-names>
|
|
2415
2440
|
|
|
2416
|
-
|
|
2417
|
-
reject(new CustomError("something bad happened"));
|
|
2418
|
-
});
|
|
2441
|
+
π Examples of correct code
|
|
2419
2442
|
|
|
2420
|
-
|
|
2421
|
-
|
|
2443
|
+
```typescript
|
|
2444
|
+
/* global someFunction, a */
|
|
2422
2445
|
|
|
2446
|
+
var foo = someFunction();
|
|
2447
|
+
var bar = a + 1;
|
|
2423
2448
|
```
|
|
2424
2449
|
|
|
2425
2450
|
π Examples of incorrect code
|
|
2426
2451
|
|
|
2427
2452
|
```typescript
|
|
2428
|
-
|
|
2453
|
+
Foo.prototype.bar = function() {};
|
|
2429
2454
|
|
|
2430
|
-
|
|
2455
|
+
(function() {
|
|
2456
|
+
// ...
|
|
2457
|
+
}())
|
|
2431
2458
|
|
|
2432
|
-
|
|
2459
|
+
export default function() {}
|
|
2460
|
+
```
|
|
2433
2461
|
|
|
2434
|
-
|
|
2462
|
+
## Function Name Match
|
|
2435
2463
|
|
|
2436
|
-
|
|
2464
|
+
----------
|
|
2437
2465
|
|
|
2438
|
-
|
|
2439
|
-
|
|
2466
|
+
This rule requires function names to match the name of the variable or property to which they are assigned.
|
|
2467
|
+
The rule will ignore property assignments where the property name is a literal that
|
|
2468
|
+
is not a valid identifier in the ECMAScript version specified in your configuration (default ES5).
|
|
2440
2469
|
|
|
2441
|
-
|
|
2442
|
-
throw `${err}`;
|
|
2470
|
+
<https://eslint.org/docs/latest/rules/func-name-matching>
|
|
2443
2471
|
|
|
2444
|
-
|
|
2445
|
-
throw err;
|
|
2472
|
+
π Examples of correct code
|
|
2446
2473
|
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
}
|
|
2450
|
-
|
|
2474
|
+
```typescript
|
|
2475
|
+
var foo = function foo() {};
|
|
2476
|
+
var foo = function() {};
|
|
2477
|
+
var foo = () => {};
|
|
2478
|
+
foo = function foo() {};
|
|
2451
2479
|
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
};
|
|
2455
|
-
|
|
2480
|
+
obj.foo = function foo() {};
|
|
2481
|
+
obj['foo'] = function foo() {};
|
|
2482
|
+
obj['foo//bar'] = function foo() {};
|
|
2483
|
+
obj[foo] = function bar() {};
|
|
2456
2484
|
|
|
2457
|
-
|
|
2485
|
+
var obj = {foo: function foo() {}};
|
|
2486
|
+
var obj = {[foo]: function bar() {}};
|
|
2487
|
+
var obj = {'foo//bar': function foo() {}};
|
|
2488
|
+
var obj = {foo: function() {}};
|
|
2458
2489
|
|
|
2459
|
-
|
|
2490
|
+
obj['x' + 2] = function bar(){};
|
|
2491
|
+
var [ bar ] = [ function bar(){} ];
|
|
2492
|
+
({[foo]: function bar() {}})
|
|
2460
2493
|
|
|
2461
|
-
|
|
2494
|
+
class C {
|
|
2495
|
+
foo = function foo() {};
|
|
2496
|
+
baz = function() {};
|
|
2497
|
+
}
|
|
2462
2498
|
|
|
2463
|
-
|
|
2499
|
+
// private names are ignored
|
|
2500
|
+
class D {
|
|
2501
|
+
#foo = function foo() {};
|
|
2502
|
+
#bar = function foo() {};
|
|
2503
|
+
baz() {
|
|
2504
|
+
this.#foo = function foo() {};
|
|
2505
|
+
this.#foo = function bar() {};
|
|
2506
|
+
}
|
|
2507
|
+
}
|
|
2464
2508
|
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2509
|
+
module.exports = function foo(name) {};
|
|
2510
|
+
module['exports'] = function foo(name) {};
|
|
2511
|
+
```
|
|
2468
2512
|
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2513
|
+
π Examples of incorrect code
|
|
2514
|
+
|
|
2515
|
+
```typescript
|
|
2516
|
+
var foo = function bar() {};
|
|
2517
|
+
foo = function bar() {};
|
|
2518
|
+
obj.foo = function bar() {};
|
|
2519
|
+
obj['foo'] = function bar() {};
|
|
2520
|
+
var obj = {foo: function bar() {}};
|
|
2521
|
+
({['foo']: function bar() {}});
|
|
2522
|
+
|
|
2523
|
+
class C {
|
|
2524
|
+
foo = function bar() {};
|
|
2525
|
+
}
|
|
2472
2526
|
```
|
|
2473
2527
|
|
|
2474
|
-
##
|
|
2528
|
+
## Get And Setters
|
|
2475
2529
|
|
|
2476
2530
|
----------
|
|
2477
2531
|
|
|
2478
|
-
|
|
2532
|
+
A getter and setter for the same property donβt necessarily have to be defined adjacent to each other.
|
|
2479
2533
|
|
|
2480
|
-
<https://eslint.org/docs/rules/
|
|
2534
|
+
<https://eslint.org/docs/latest/rules/grouped-accessor-pairs>
|
|
2481
2535
|
|
|
2482
2536
|
π Examples of correct code
|
|
2483
2537
|
|
|
2484
2538
|
```typescript
|
|
2485
|
-
function foo() {
|
|
2486
|
-
function bar() {
|
|
2487
|
-
return 1;
|
|
2488
|
-
}
|
|
2489
2539
|
|
|
2490
|
-
|
|
2540
|
+
var foo = {
|
|
2541
|
+
get a() {
|
|
2542
|
+
return this.val;
|
|
2543
|
+
},
|
|
2544
|
+
set a(value) {
|
|
2545
|
+
this.val = value;
|
|
2546
|
+
},
|
|
2547
|
+
b: 1
|
|
2548
|
+
};
|
|
2491
2549
|
|
|
2550
|
+
var bar = {
|
|
2551
|
+
set b(value) {
|
|
2552
|
+
this.val = value;
|
|
2553
|
+
},
|
|
2554
|
+
get b() {
|
|
2555
|
+
return this.val;
|
|
2556
|
+
},
|
|
2557
|
+
a: 1
|
|
2492
2558
|
}
|
|
2493
2559
|
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2560
|
+
class Foo {
|
|
2561
|
+
set a(value) {
|
|
2562
|
+
this.val = value;
|
|
2563
|
+
}
|
|
2564
|
+
get a() {
|
|
2565
|
+
return this.val;
|
|
2566
|
+
}
|
|
2567
|
+
b(){}
|
|
2497
2568
|
}
|
|
2498
2569
|
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2570
|
+
const Bar = class {
|
|
2571
|
+
static get a() {
|
|
2572
|
+
return this.val;
|
|
2573
|
+
}
|
|
2574
|
+
static set a(value) {
|
|
2575
|
+
this.val = value;
|
|
2576
|
+
}
|
|
2502
2577
|
}
|
|
2503
2578
|
```
|
|
2504
2579
|
|
|
2505
2580
|
π Examples of incorrect code
|
|
2506
2581
|
|
|
2507
2582
|
```typescript
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
}
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
}
|
|
2517
|
-
|
|
2518
|
-
while(value) {
|
|
2519
|
-
break;
|
|
2520
|
-
console.log("done");
|
|
2521
|
-
}
|
|
2522
|
-
|
|
2523
|
-
throw new Error("Oops!");
|
|
2524
|
-
console.log("done");
|
|
2583
|
+
var foo = {
|
|
2584
|
+
get a() {
|
|
2585
|
+
return this.val;
|
|
2586
|
+
},
|
|
2587
|
+
b: 1,
|
|
2588
|
+
set a(value) {
|
|
2589
|
+
this.val = value;
|
|
2590
|
+
}
|
|
2591
|
+
};
|
|
2525
2592
|
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
}
|
|
2530
|
-
|
|
2593
|
+
var bar = {
|
|
2594
|
+
set b(value) {
|
|
2595
|
+
this.val = value;
|
|
2596
|
+
},
|
|
2597
|
+
a: 1,
|
|
2598
|
+
get b() {
|
|
2599
|
+
return this.val;
|
|
2531
2600
|
}
|
|
2532
|
-
console.log("done");
|
|
2533
2601
|
}
|
|
2534
2602
|
|
|
2535
|
-
for (;;) {}
|
|
2536
|
-
console.log("done");
|
|
2537
|
-
```
|
|
2538
|
-
|
|
2539
|
-
## No Multiline String
|
|
2540
|
-
|
|
2541
|
-
----------
|
|
2542
|
-
|
|
2543
|
-
Prevent break line in string
|
|
2544
|
-
|
|
2545
|
-
<https://eslint.org/docs/rules/no-multi-str#no-multi-str>
|
|
2546
|
-
|
|
2547
|
-
π Examples of correct code
|
|
2548
|
-
|
|
2549
|
-
```typescript
|
|
2550
|
-
var x = "some very\nlong text";
|
|
2551
|
-
|
|
2552
|
-
var x = "some very " +
|
|
2553
|
-
"long text";
|
|
2554
|
-
```
|
|
2555
|
-
|
|
2556
|
-
π Examples of incorrect code
|
|
2557
|
-
|
|
2558
|
-
```typescript
|
|
2559
|
-
var x = "some very \
|
|
2560
|
-
long text";
|
|
2561
|
-
```
|
|
2562
|
-
|
|
2563
|
-
## No Unsafe Assign
|
|
2564
|
-
|
|
2565
|
-
----------
|
|
2566
|
-
|
|
2567
|
-
Disallows assigning any to variables and properties.
|
|
2568
|
-
|
|
2569
|
-
<https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/no-unsafe-assignment.md>
|
|
2570
|
-
|
|
2571
|
-
π Examples of correct code
|
|
2572
|
-
|
|
2573
|
-
```typescript
|
|
2574
|
-
const x = 1,
|
|
2575
|
-
y = 1;
|
|
2576
|
-
const [x] = [1];
|
|
2577
|
-
[x] = [1] as [number];
|
|
2578
|
-
|
|
2579
|
-
function foo(a = 1) {}
|
|
2580
2603
|
class Foo {
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2604
|
+
set a(value) {
|
|
2605
|
+
this.val = value;
|
|
2606
|
+
}
|
|
2607
|
+
b(){}
|
|
2608
|
+
get a() {
|
|
2609
|
+
return this.val;
|
|
2610
|
+
}
|
|
2585
2611
|
}
|
|
2586
2612
|
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
```typescript
|
|
2597
|
-
const x = 1 as any,
|
|
2598
|
-
y = 1 as any;
|
|
2599
|
-
const [x] = 1 as any;
|
|
2600
|
-
const [x] = [] as any[];
|
|
2601
|
-
const [x] = [1 as any];
|
|
2602
|
-
[x] = [1] as [any];
|
|
2603
|
-
|
|
2604
|
-
function foo(a = 1 as any) {}
|
|
2605
|
-
class Foo {
|
|
2606
|
-
constructor(private a = 1 as any) {}
|
|
2607
|
-
}
|
|
2608
|
-
class Foo {
|
|
2609
|
-
private a = 1 as any;
|
|
2613
|
+
const Bar = class {
|
|
2614
|
+
static get a() {
|
|
2615
|
+
return this.val;
|
|
2616
|
+
}
|
|
2617
|
+
b(){}
|
|
2618
|
+
static set a(value) {
|
|
2619
|
+
this.val = value;
|
|
2620
|
+
}
|
|
2610
2621
|
}
|
|
2611
|
-
|
|
2612
|
-
// generic position examples
|
|
2613
|
-
const x: Set<string> = new Set<any>();
|
|
2614
|
-
const x: Map<string, string> = new Map<string, any>();
|
|
2615
|
-
const x: Set<string[]> = new Set<any[]>();
|
|
2616
|
-
const x: Set<Set<Set<string>>> = new Set<Set<Set<any>>>();
|
|
2617
|
-
```
|
|
2618
|
-
|
|
2619
|
-
## Disallow Script Url
|
|
2620
|
-
|
|
2621
|
-
----------
|
|
2622
|
-
|
|
2623
|
-
Using javascript: URLs is considered by some as a form of eval.
|
|
2624
|
-
|
|
2625
|
-
<https://eslint.org/docs/rules/no-script-url>
|
|
2626
|
-
|
|
2627
|
-
π Examples of correct code
|
|
2628
|
-
|
|
2629
|
-
```typescript
|
|
2630
|
-
location.href = "#";
|
|
2631
|
-
```
|
|
2632
|
-
|
|
2633
|
-
π Examples of incorrect code
|
|
2634
|
-
|
|
2635
|
-
```typescript
|
|
2636
|
-
location.href = "javascript:void(0)";
|
|
2637
|
-
|
|
2638
|
-
location.href = `javascript:void(0)`;
|
|
2639
|
-
```
|
|
2640
|
-
|
|
2641
|
-
## Disallow Undefined
|
|
2642
|
-
|
|
2643
|
-
----------
|
|
2644
|
-
|
|
2645
|
-
Disallows the use of undeclared variables unless mentioned in /\*global\*/ comments.
|
|
2646
|
-
|
|
2647
|
-
<https://eslint.org/docs/rules/no-undef>
|
|
2648
|
-
|
|
2649
|
-
π Examples of correct code
|
|
2650
|
-
|
|
2651
|
-
```typescript
|
|
2652
|
-
/* global someFunction, a */
|
|
2653
|
-
|
|
2654
|
-
var foo = someFunction();
|
|
2655
|
-
var bar = a + 1;
|
|
2656
|
-
```
|
|
2657
|
-
|
|
2658
|
-
π Examples of incorrect code
|
|
2659
|
-
|
|
2660
|
-
```typescript
|
|
2661
|
-
var foo = someFunction();
|
|
2662
|
-
var bar = a + 1;
|
|
2663
|
-
```
|
|
2664
|
-
|
|
2665
|
-
## Function Name
|
|
2666
|
-
|
|
2667
|
-
----------
|
|
2668
|
-
|
|
2669
|
-
Requires function expressions to have a name, if the name isn't assigned automatically per the ECMAScript specification.
|
|
2670
|
-
|
|
2671
|
-
<https://eslint.org/docs/rules/func-names>
|
|
2672
|
-
|
|
2673
|
-
π Examples of correct code
|
|
2674
|
-
|
|
2675
|
-
```typescript
|
|
2676
|
-
/* global someFunction, a */
|
|
2677
|
-
|
|
2678
|
-
var foo = someFunction();
|
|
2679
|
-
var bar = a + 1;
|
|
2680
|
-
```
|
|
2681
|
-
|
|
2682
|
-
π Examples of incorrect code
|
|
2683
|
-
|
|
2684
|
-
```typescript
|
|
2685
|
-
Foo.prototype.bar = function() {};
|
|
2686
|
-
|
|
2687
|
-
(function() {
|
|
2688
|
-
// ...
|
|
2689
|
-
}())
|
|
2690
|
-
|
|
2691
|
-
export default function() {}
|
|
2692
2622
|
```
|
|
2693
2623
|
|
|
2694
2624
|
## Function Style
|
|
@@ -4337,7 +4267,7 @@ class C {
|
|
|
4337
4267
|
}
|
|
4338
4268
|
```
|
|
4339
4269
|
|
|
4340
|
-
|
|
4270
|
+
## No Proto
|
|
4341
4271
|
|
|
4342
4272
|
----------
|
|
4343
4273
|
|
|
@@ -4367,34 +4297,6 @@ obj.__proto__ = b;
|
|
|
4367
4297
|
obj["__proto__"] = b;
|
|
4368
4298
|
```
|
|
4369
4299
|
|
|
4370
|
-
### No Useless Computed Key
|
|
4371
|
-
|
|
4372
|
-
----------
|
|
4373
|
-
|
|
4374
|
-
Disallow unnecessary computed property keys in objects and classes
|
|
4375
|
-
|
|
4376
|
-
<https://eslint.org/docs/latest/rules/no-useless-computed-key>
|
|
4377
|
-
|
|
4378
|
-
π Examples of correct code
|
|
4379
|
-
|
|
4380
|
-
```typescript
|
|
4381
|
-
var c = { 'a': 0 };
|
|
4382
|
-
var c = { 0: 0 };
|
|
4383
|
-
var a = { x() {} };
|
|
4384
|
-
var c = { a: 0 };
|
|
4385
|
-
var c = { '0+1,234': 0 };
|
|
4386
|
-
```
|
|
4387
|
-
|
|
4388
|
-
π Examples of incorrect code
|
|
4389
|
-
|
|
4390
|
-
```typescript
|
|
4391
|
-
var a = { ['0']: 0 };
|
|
4392
|
-
var a = { ['0+1,234']: 0 };
|
|
4393
|
-
var a = { [0]: 0 };
|
|
4394
|
-
var a = { ['x']: 0 };
|
|
4395
|
-
var a = { ['x']() {} };
|
|
4396
|
-
```
|
|
4397
|
-
|
|
4398
4300
|
## No Declare in Block
|
|
4399
4301
|
|
|
4400
4302
|
----------
|
|
@@ -7276,27 +7178,23 @@ Enforces placing object properties on separate lines.
|
|
|
7276
7178
|
π Examples of correct code
|
|
7277
7179
|
|
|
7278
7180
|
```typescript
|
|
7279
|
-
const obj1 = {
|
|
7280
|
-
foo: "foo",
|
|
7281
|
-
bar: "bar",
|
|
7282
|
-
baz: "baz"
|
|
7283
|
-
};
|
|
7181
|
+
const obj1 = { foo: "foo", bar: "bar", baz: "baz" };
|
|
7284
7182
|
|
|
7285
7183
|
const obj2 = {
|
|
7286
|
-
foo: "foo"
|
|
7287
|
-
|
|
7288
|
-
|
|
7184
|
+
foo: "foo",
|
|
7185
|
+
bar: "bar",
|
|
7186
|
+
baz: "baz",
|
|
7289
7187
|
};
|
|
7290
7188
|
|
|
7291
7189
|
const user = process.argv[2];
|
|
7292
7190
|
const obj3 = {
|
|
7293
7191
|
user,
|
|
7294
|
-
[process.argv[3] ? "foo" : "bar"]: 0,
|
|
7192
|
+
[ process.argv[3] ? "foo" : "bar" ]: 0,
|
|
7295
7193
|
baz: [
|
|
7296
7194
|
1,
|
|
7297
7195
|
2,
|
|
7298
7196
|
4,
|
|
7299
|
-
8
|
|
7197
|
+
8,
|
|
7300
7198
|
]
|
|
7301
7199
|
};
|
|
7302
7200
|
```
|
|
@@ -7323,17 +7221,120 @@ const obj3 = {
|
|
|
7323
7221
|
};
|
|
7324
7222
|
```
|
|
7325
7223
|
|
|
7326
|
-
##
|
|
7224
|
+
## Object Curly Newline
|
|
7327
7225
|
|
|
7328
7226
|
----------
|
|
7329
7227
|
|
|
7330
|
-
|
|
7228
|
+
A number of style guides require or disallow line breaks inside of object braces and other tokens.
|
|
7331
7229
|
|
|
7332
|
-
|
|
7333
|
-
but rather the local version with a very different meaning.
|
|
7230
|
+
<https://eslint.org/docs/latest/rules/object-curly-newline>
|
|
7334
7231
|
|
|
7335
|
-
|
|
7336
|
-
|
|
7232
|
+
π Examples of correct code
|
|
7233
|
+
|
|
7234
|
+
```typescript
|
|
7235
|
+
let a = {};
|
|
7236
|
+
let b = { foo: 1 };
|
|
7237
|
+
let c = { foo: 1, bar: 2 };
|
|
7238
|
+
let d = {
|
|
7239
|
+
foo: 1,
|
|
7240
|
+
bar: 2,
|
|
7241
|
+
};
|
|
7242
|
+
let e = {
|
|
7243
|
+
foo: function() {
|
|
7244
|
+
dosomething();
|
|
7245
|
+
}
|
|
7246
|
+
};
|
|
7247
|
+
|
|
7248
|
+
let { f } = obj;
|
|
7249
|
+
let { g, h } = obj;
|
|
7250
|
+
let {
|
|
7251
|
+
i,
|
|
7252
|
+
j
|
|
7253
|
+
} = obj;
|
|
7254
|
+
let { k = () => dosomething() } = obj;
|
|
7255
|
+
```
|
|
7256
|
+
|
|
7257
|
+
π Examples of incorrect code
|
|
7258
|
+
|
|
7259
|
+
```typescript
|
|
7260
|
+
let b = {
|
|
7261
|
+
foo: 1
|
|
7262
|
+
};
|
|
7263
|
+
let c = { foo: 1,
|
|
7264
|
+
bar: 2 };
|
|
7265
|
+
let d = {foo: 1
|
|
7266
|
+
, bar: 2};
|
|
7267
|
+
let e = { foo: function() {
|
|
7268
|
+
dosomething();
|
|
7269
|
+
} };
|
|
7270
|
+
|
|
7271
|
+
let {i,
|
|
7272
|
+
j} = obj;
|
|
7273
|
+
```
|
|
7274
|
+
|
|
7275
|
+
## No Negative Condition
|
|
7276
|
+
|
|
7277
|
+
----------
|
|
7278
|
+
|
|
7279
|
+
Negated conditions are more difficult to understand. Code can be made more readable by inverting the condition instead.
|
|
7280
|
+
|
|
7281
|
+
<https://eslint.org/docs/latest/rules/no-negated-condition>
|
|
7282
|
+
|
|
7283
|
+
π Examples of correct code
|
|
7284
|
+
|
|
7285
|
+
```typescript
|
|
7286
|
+
if (!a) {
|
|
7287
|
+
doSomething();
|
|
7288
|
+
}
|
|
7289
|
+
|
|
7290
|
+
if (!a) {
|
|
7291
|
+
doSomething();
|
|
7292
|
+
} else if (b) {
|
|
7293
|
+
doSomething();
|
|
7294
|
+
}
|
|
7295
|
+
|
|
7296
|
+
if (a != b) {
|
|
7297
|
+
doSomething();
|
|
7298
|
+
}
|
|
7299
|
+
|
|
7300
|
+
a ? b : c
|
|
7301
|
+
```
|
|
7302
|
+
|
|
7303
|
+
π Examples of incorrect code
|
|
7304
|
+
|
|
7305
|
+
```typescript
|
|
7306
|
+
if (!a) {
|
|
7307
|
+
doSomething();
|
|
7308
|
+
} else {
|
|
7309
|
+
doSomethingElse();
|
|
7310
|
+
}
|
|
7311
|
+
|
|
7312
|
+
if (a != b) {
|
|
7313
|
+
doSomething();
|
|
7314
|
+
} else {
|
|
7315
|
+
doSomethingElse();
|
|
7316
|
+
}
|
|
7317
|
+
|
|
7318
|
+
if (a !== b) {
|
|
7319
|
+
doSomething();
|
|
7320
|
+
} else {
|
|
7321
|
+
doSomethingElse();
|
|
7322
|
+
}
|
|
7323
|
+
|
|
7324
|
+
!a ? c : b
|
|
7325
|
+
```
|
|
7326
|
+
|
|
7327
|
+
## No Shadow
|
|
7328
|
+
|
|
7329
|
+
----------
|
|
7330
|
+
|
|
7331
|
+
Enforces placing object properties on separate lines.
|
|
7332
|
+
|
|
7333
|
+
Then any code used within the same scope would not get the global undefined,
|
|
7334
|
+
but rather the local version with a very different meaning.
|
|
7335
|
+
|
|
7336
|
+
<https://eslint.org/docs/rules/no-shadow>
|
|
7337
|
+
<https://eslint.org/docs/rules/no-shadow-restricted-names>
|
|
7337
7338
|
|
|
7338
7339
|
π Examples of correct code
|
|
7339
7340
|
|
|
@@ -7747,6 +7748,29 @@ a && (a = b)
|
|
|
7747
7748
|
a ?? (a = b)
|
|
7748
7749
|
```
|
|
7749
7750
|
|
|
7751
|
+
## No With
|
|
7752
|
+
|
|
7753
|
+
----------
|
|
7754
|
+
|
|
7755
|
+
The with statement is potentially problematic because it adds members of an object to the current scope,
|
|
7756
|
+
making it impossible to tell what a variable inside the block actually refers to.
|
|
7757
|
+
|
|
7758
|
+
<https://eslint.org/docs/rules/no-with>
|
|
7759
|
+
|
|
7760
|
+
π Examples of correct code
|
|
7761
|
+
|
|
7762
|
+
```typescript
|
|
7763
|
+
const r = ({x, y}) => Math.sqrt(x * x + y * y);
|
|
7764
|
+
```
|
|
7765
|
+
|
|
7766
|
+
π Examples of incorrect code
|
|
7767
|
+
|
|
7768
|
+
```typescript
|
|
7769
|
+
with (point) {
|
|
7770
|
+
r = Math.sqrt(x * x + y * y); // is r a member of point?
|
|
7771
|
+
}
|
|
7772
|
+
```
|
|
7773
|
+
|
|
7750
7774
|
## Promise Rules
|
|
7751
7775
|
|
|
7752
7776
|
### No New Statics
|
|
@@ -8449,7 +8473,7 @@ import fs from 'fs/promises';
|
|
|
8449
8473
|
const fs = require('fs/promises');
|
|
8450
8474
|
```
|
|
8451
8475
|
|
|
8452
|
-
### Prefer export
|
|
8476
|
+
### Prefer export from
|
|
8453
8477
|
|
|
8454
8478
|
----------
|
|
8455
8479
|
|
|
@@ -8501,6 +8525,28 @@ export {
|
|
|
8501
8525
|
};
|
|
8502
8526
|
```
|
|
8503
8527
|
|
|
8528
|
+
### No Empty Import
|
|
8529
|
+
|
|
8530
|
+
----------
|
|
8531
|
+
|
|
8532
|
+
Prevent import empty
|
|
8533
|
+
|
|
8534
|
+
<https://github.com/ODGodinho/ODG-Linter-Js>
|
|
8535
|
+
|
|
8536
|
+
π Examples of correct code
|
|
8537
|
+
|
|
8538
|
+
```typescript
|
|
8539
|
+
import { a } from './foo.js';
|
|
8540
|
+
import a from './foo.js';
|
|
8541
|
+
```
|
|
8542
|
+
|
|
8543
|
+
π Examples of incorrect code
|
|
8544
|
+
|
|
8545
|
+
```typescript
|
|
8546
|
+
import { } from './foo.js';
|
|
8547
|
+
import t, { } from './foo.js';
|
|
8548
|
+
```
|
|
8549
|
+
|
|
8504
8550
|
## Documentation
|
|
8505
8551
|
|
|
8506
8552
|
### Spaced Comment
|
|
@@ -11601,7 +11647,7 @@ if (foo) {
|
|
|
11601
11647
|
Improved version of the no-nested-ternary ESLint rule,
|
|
11602
11648
|
which allows cases where the nested ternary is only one level and wrapped in Parentheses.
|
|
11603
11649
|
|
|
11604
|
-
<https://eslint.org/docs/latest/rules/no-nested-ternary
|
|
11650
|
+
<https://eslint.org/docs/latest/rules/no-nested-ternary>
|
|
11605
11651
|
<https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-nested-ternary.md>
|
|
11606
11652
|
|
|
11607
11653
|
π Examples of correct code
|
|
@@ -13731,49 +13777,450 @@ foo(function() {
|
|
|
13731
13777
|
baz(() => this);
|
|
13732
13778
|
});
|
|
13733
13779
|
|
|
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
|
-
};
|
|
13780
|
+
var obj = {
|
|
13781
|
+
aaa: function() {
|
|
13782
|
+
return function foo() {
|
|
13783
|
+
// There is in a method `aaa`, but `foo` is not a method.
|
|
13784
|
+
this.a = 0;
|
|
13785
|
+
baz(() => this);
|
|
13786
|
+
};
|
|
13787
|
+
}
|
|
13788
|
+
};
|
|
13789
|
+
|
|
13790
|
+
foo.forEach(function() {
|
|
13791
|
+
this.a = 0;
|
|
13792
|
+
baz(() => this);
|
|
13793
|
+
});
|
|
13794
|
+
```
|
|
13795
|
+
|
|
13796
|
+
### No This Before Super
|
|
13797
|
+
|
|
13798
|
+
----------
|
|
13799
|
+
|
|
13800
|
+
In the constructor of derived classes, if this/super are used before super() calls, it raises a reference error.
|
|
13801
|
+
|
|
13802
|
+
<https://eslint.org/docs/latest/rules/no-this-before-super>
|
|
13803
|
+
|
|
13804
|
+
π Examples of correct code
|
|
13805
|
+
|
|
13806
|
+
```typescript
|
|
13807
|
+
class A {
|
|
13808
|
+
constructor() {
|
|
13809
|
+
this.a = 0; // OK, this class doesn't have an `extends` clause.
|
|
13810
|
+
}
|
|
13811
|
+
}
|
|
13812
|
+
|
|
13813
|
+
class A extends B {
|
|
13814
|
+
constructor() {
|
|
13815
|
+
super();
|
|
13816
|
+
this.a = 0; // OK, this is after `super()`.
|
|
13817
|
+
}
|
|
13818
|
+
}
|
|
13819
|
+
|
|
13820
|
+
class A extends B {
|
|
13821
|
+
foo() {
|
|
13822
|
+
this.a = 0; // OK. this is not in a constructor.
|
|
13823
|
+
}
|
|
13824
|
+
}
|
|
13825
|
+
```
|
|
13826
|
+
|
|
13827
|
+
π Examples of incorrect code
|
|
13828
|
+
|
|
13829
|
+
```typescript
|
|
13830
|
+
class A extends B {
|
|
13831
|
+
constructor() {
|
|
13832
|
+
this.a = 0;
|
|
13833
|
+
super();
|
|
13834
|
+
}
|
|
13835
|
+
}
|
|
13836
|
+
|
|
13837
|
+
class A extends B {
|
|
13838
|
+
constructor() {
|
|
13839
|
+
this.foo();
|
|
13840
|
+
super();
|
|
13841
|
+
}
|
|
13842
|
+
}
|
|
13843
|
+
|
|
13844
|
+
class A extends B {
|
|
13845
|
+
constructor() {
|
|
13846
|
+
super.foo();
|
|
13847
|
+
super();
|
|
13848
|
+
}
|
|
13849
|
+
}
|
|
13850
|
+
|
|
13851
|
+
class A extends B {
|
|
13852
|
+
constructor() {
|
|
13853
|
+
super(this.foo());
|
|
13854
|
+
}
|
|
13855
|
+
}
|
|
13856
|
+
```
|
|
13857
|
+
|
|
13858
|
+
### No Obj Calls
|
|
13859
|
+
|
|
13860
|
+
----------
|
|
13861
|
+
|
|
13862
|
+
Disallow calling global object properties as functions
|
|
13863
|
+
|
|
13864
|
+
<https://eslint.org/docs/latest/rules/no-obj-calls>
|
|
13865
|
+
|
|
13866
|
+
π Examples of correct code
|
|
13867
|
+
|
|
13868
|
+
```typescript
|
|
13869
|
+
function area(r) {
|
|
13870
|
+
return Math.PI * r * r;
|
|
13871
|
+
}
|
|
13872
|
+
|
|
13873
|
+
var object = JSON.parse("{}");
|
|
13874
|
+
|
|
13875
|
+
var value = Reflect.get({ x: 1, y: 2 }, "x");
|
|
13876
|
+
|
|
13877
|
+
var first = Atomics.load(foo, 0);
|
|
13878
|
+
|
|
13879
|
+
var segmenterFr = new Intl.Segmenter("fr", { granularity: "word" });
|
|
13880
|
+
```
|
|
13881
|
+
|
|
13882
|
+
π Examples of incorrect code
|
|
13883
|
+
|
|
13884
|
+
```typescript
|
|
13885
|
+
var math = Math();
|
|
13886
|
+
|
|
13887
|
+
var newMath = new Math();
|
|
13888
|
+
|
|
13889
|
+
var json = JSON();
|
|
13890
|
+
|
|
13891
|
+
var newJSON = new JSON();
|
|
13892
|
+
|
|
13893
|
+
var reflect = Reflect();
|
|
13894
|
+
|
|
13895
|
+
var newReflect = new Reflect();
|
|
13896
|
+
|
|
13897
|
+
var atomics = Atomics();
|
|
13898
|
+
|
|
13899
|
+
var newAtomics = new Atomics();
|
|
13900
|
+
|
|
13901
|
+
var intl = Intl();
|
|
13902
|
+
|
|
13903
|
+
var newIntl = new Intl();
|
|
13904
|
+
```
|
|
13905
|
+
|
|
13906
|
+
### No Empty Pattern
|
|
13907
|
+
|
|
13908
|
+
----------
|
|
13909
|
+
|
|
13910
|
+
Disallow empty destructuring patterns
|
|
13911
|
+
|
|
13912
|
+
<https://eslint.org/docs/latest/rules/no-empty-pattern>
|
|
13913
|
+
|
|
13914
|
+
π Examples of correct code
|
|
13915
|
+
|
|
13916
|
+
```typescript
|
|
13917
|
+
|
|
13918
|
+
```
|
|
13919
|
+
|
|
13920
|
+
π Examples of incorrect code
|
|
13921
|
+
|
|
13922
|
+
```typescript
|
|
13923
|
+
var {} = foo;
|
|
13924
|
+
var [] = foo;
|
|
13925
|
+
var {a: {}} = foo;
|
|
13926
|
+
var {a: []} = foo;
|
|
13927
|
+
function foo({}) {}
|
|
13928
|
+
function foo([]) {}
|
|
13929
|
+
function foo({a: {}}) {}
|
|
13930
|
+
function foo({a: []}) {}
|
|
13931
|
+
```
|
|
13932
|
+
|
|
13933
|
+
### No Useless Computed Key
|
|
13934
|
+
|
|
13935
|
+
----------
|
|
13936
|
+
|
|
13937
|
+
Disallow unnecessary computed property keys in objects and classes
|
|
13938
|
+
|
|
13939
|
+
<https://eslint.org/docs/latest/rules/no-useless-computed-key>
|
|
13940
|
+
|
|
13941
|
+
π Examples of correct code
|
|
13942
|
+
|
|
13943
|
+
```typescript
|
|
13944
|
+
var c = { 'a': 0 };
|
|
13945
|
+
var c = { 0: 0 };
|
|
13946
|
+
var a = { x() {} };
|
|
13947
|
+
var c = { a: 0 };
|
|
13948
|
+
var c = { '0+1,234': 0 };
|
|
13949
|
+
```
|
|
13950
|
+
|
|
13951
|
+
π Examples of incorrect code
|
|
13952
|
+
|
|
13953
|
+
```typescript
|
|
13954
|
+
var a = { ['0']: 0 };
|
|
13955
|
+
var a = { ['0+1,234']: 0 };
|
|
13956
|
+
var a = { [0]: 0 };
|
|
13957
|
+
var a = { ['x']: 0 };
|
|
13958
|
+
var a = { ['x']() {} };
|
|
13959
|
+
```
|
|
13960
|
+
|
|
13961
|
+
|
|
13962
|
+
### Useless Call Code
|
|
13963
|
+
|
|
13964
|
+
----------
|
|
13965
|
+
|
|
13966
|
+
Disallow useless code
|
|
13967
|
+
|
|
13968
|
+
<https://eslint.org/docs/rules/no-useless-call#no-useless-call>
|
|
13969
|
+
|
|
13970
|
+
π Examples of correct code
|
|
13971
|
+
|
|
13972
|
+
```typescript
|
|
13973
|
+
foo.call(obj, 1, 2, 3);
|
|
13974
|
+
foo.apply(obj, [1, 2, 3]);
|
|
13975
|
+
obj.foo.call(null, 1, 2, 3);
|
|
13976
|
+
obj.foo.apply(null, [1, 2, 3]);
|
|
13977
|
+
obj.foo.call(otherObj, 1, 2, 3);
|
|
13978
|
+
obj.foo.apply(otherObj, [1, 2, 3]);
|
|
13979
|
+
|
|
13980
|
+
// The argument list is variadic.
|
|
13981
|
+
// Those are warned by the `prefer-spread` rule.
|
|
13982
|
+
foo.apply(undefined, args);
|
|
13983
|
+
foo.apply(null, args);
|
|
13984
|
+
obj.foo.apply(obj, args);
|
|
13985
|
+
|
|
13986
|
+
a[++i].foo.call(a[i], 1, 2, 3);
|
|
13987
|
+
```
|
|
13988
|
+
|
|
13989
|
+
π Examples of incorrect code
|
|
13990
|
+
|
|
13991
|
+
```typescript
|
|
13992
|
+
foo.call(undefined, 1, 2, 3);
|
|
13993
|
+
foo.apply(undefined, [1, 2, 3]);
|
|
13994
|
+
foo.call(null, 1, 2, 3);
|
|
13995
|
+
foo.apply(null, [1, 2, 3]);
|
|
13996
|
+
|
|
13997
|
+
// These are same as `obj.foo(1, 2, 3);`
|
|
13998
|
+
obj.foo.call(obj, 1, 2, 3);
|
|
13999
|
+
obj.foo.apply(obj, [1, 2, 3]);
|
|
14000
|
+
|
|
14001
|
+
a[i++].foo.call(a[i++], 1, 2, 3);
|
|
14002
|
+
```
|
|
14003
|
+
|
|
14004
|
+
### Useless Catch Code
|
|
14005
|
+
|
|
14006
|
+
----------
|
|
14007
|
+
|
|
14008
|
+
Disallow useless code
|
|
14009
|
+
|
|
14010
|
+
<https://eslint.org/docs/rules/no-useless-catch#no-useless-catch>
|
|
14011
|
+
|
|
14012
|
+
π Examples of correct code
|
|
14013
|
+
|
|
14014
|
+
```typescript
|
|
14015
|
+
try {
|
|
14016
|
+
doSomethingThatMightThrow();
|
|
14017
|
+
} catch (e) {
|
|
14018
|
+
doSomethingBeforeRethrow();
|
|
14019
|
+
throw e;
|
|
14020
|
+
}
|
|
14021
|
+
|
|
14022
|
+
try {
|
|
14023
|
+
doSomethingThatMightThrow();
|
|
14024
|
+
} catch (e) {
|
|
14025
|
+
handleError(e);
|
|
14026
|
+
}
|
|
14027
|
+
|
|
14028
|
+
try {
|
|
14029
|
+
doSomethingThatMightThrow();
|
|
14030
|
+
} finally {
|
|
14031
|
+
cleanUp();
|
|
14032
|
+
}
|
|
14033
|
+
```
|
|
14034
|
+
|
|
14035
|
+
π Examples of incorrect code
|
|
14036
|
+
|
|
14037
|
+
```typescript
|
|
14038
|
+
try {
|
|
14039
|
+
doSomethingThatMightThrow();
|
|
14040
|
+
} catch (e) {
|
|
14041
|
+
throw e;
|
|
14042
|
+
}
|
|
14043
|
+
|
|
14044
|
+
try {
|
|
14045
|
+
doSomethingThatMightThrow();
|
|
14046
|
+
} catch (e) {
|
|
14047
|
+
throw e;
|
|
14048
|
+
} finally {
|
|
14049
|
+
cleanUp();
|
|
14050
|
+
}
|
|
14051
|
+
```
|
|
14052
|
+
|
|
14053
|
+
### Useless Expression Code
|
|
14054
|
+
|
|
14055
|
+
----------
|
|
14056
|
+
|
|
14057
|
+
Disallow useless code
|
|
14058
|
+
|
|
14059
|
+
<https://eslint.org/docs/rules/no-unused-expressions>
|
|
14060
|
+
|
|
14061
|
+
π Examples of correct code
|
|
14062
|
+
|
|
14063
|
+
```typescript
|
|
14064
|
+
{} // In this context, this is a block statement, not an object literal
|
|
14065
|
+
|
|
14066
|
+
{myLabel: someVar} // In this context, this is a block statement with a label and expression, not an object literal
|
|
14067
|
+
|
|
14068
|
+
function namedFunctionDeclaration () {}
|
|
14069
|
+
|
|
14070
|
+
(function aGenuineIIFE () {}());
|
|
14071
|
+
|
|
14072
|
+
f()
|
|
14073
|
+
|
|
14074
|
+
a = 0
|
|
14075
|
+
|
|
14076
|
+
new C
|
|
14077
|
+
|
|
14078
|
+
delete a.b
|
|
14079
|
+
|
|
14080
|
+
void a
|
|
14081
|
+
|
|
14082
|
+
a ? b() : c();
|
|
14083
|
+
a ? (b = c) : d();
|
|
14084
|
+
```
|
|
14085
|
+
|
|
14086
|
+
π Examples of incorrect code
|
|
14087
|
+
|
|
14088
|
+
```typescript
|
|
14089
|
+
0
|
|
14090
|
+
|
|
14091
|
+
if(0) 0
|
|
14092
|
+
|
|
14093
|
+
{0}
|
|
14094
|
+
|
|
14095
|
+
f(0), {}
|
|
14096
|
+
|
|
14097
|
+
a && b()
|
|
14098
|
+
|
|
14099
|
+
a, b()
|
|
14100
|
+
|
|
14101
|
+
c = a, b;
|
|
14102
|
+
|
|
14103
|
+
a() && function namedFunctionInExpressionContext () {f();}
|
|
14104
|
+
|
|
14105
|
+
(function anIncompleteIIFE () {});
|
|
14106
|
+
|
|
14107
|
+
injectGlobal`body{ color: red; }`
|
|
14108
|
+
|
|
14109
|
+
function foo() {
|
|
14110
|
+
"bar" + 1;
|
|
14111
|
+
}
|
|
14112
|
+
|
|
14113
|
+
class Foo {
|
|
14114
|
+
static {
|
|
14115
|
+
"use strict"; // class static blocks do not have directive prologues
|
|
14116
|
+
}
|
|
14117
|
+
}
|
|
14118
|
+
```
|
|
14119
|
+
|
|
14120
|
+
### Useless Return Code
|
|
14121
|
+
|
|
14122
|
+
----------
|
|
14123
|
+
|
|
14124
|
+
Disallow useless code
|
|
14125
|
+
|
|
14126
|
+
<https://eslint.org/docs/rules/no-useless-return#no-useless-return>
|
|
14127
|
+
|
|
14128
|
+
π Examples of correct code
|
|
14129
|
+
|
|
14130
|
+
```typescript
|
|
14131
|
+
function foo() { return 5; }
|
|
14132
|
+
|
|
14133
|
+
function foo() {
|
|
14134
|
+
return doSomething();
|
|
14135
|
+
}
|
|
14136
|
+
|
|
14137
|
+
function foo() {
|
|
14138
|
+
if (condition) {
|
|
14139
|
+
bar();
|
|
14140
|
+
return;
|
|
14141
|
+
} else {
|
|
14142
|
+
baz();
|
|
14143
|
+
}
|
|
14144
|
+
qux();
|
|
14145
|
+
}
|
|
14146
|
+
|
|
14147
|
+
function foo() {
|
|
14148
|
+
switch (bar) {
|
|
14149
|
+
case 1:
|
|
14150
|
+
doSomething();
|
|
14151
|
+
return;
|
|
14152
|
+
default:
|
|
14153
|
+
doSomethingElse();
|
|
14154
|
+
}
|
|
14155
|
+
}
|
|
14156
|
+
|
|
14157
|
+
function foo() {
|
|
14158
|
+
for (const foo of bar) {
|
|
14159
|
+
return;
|
|
14160
|
+
}
|
|
14161
|
+
}
|
|
14162
|
+
```
|
|
14163
|
+
|
|
14164
|
+
π Examples of incorrect code
|
|
14165
|
+
|
|
14166
|
+
```typescript
|
|
14167
|
+
function foo() { return; }
|
|
14168
|
+
|
|
14169
|
+
function foo() {
|
|
14170
|
+
doSomething();
|
|
14171
|
+
return;
|
|
14172
|
+
}
|
|
14173
|
+
|
|
14174
|
+
function foo() {
|
|
14175
|
+
if (condition) {
|
|
14176
|
+
bar();
|
|
14177
|
+
return;
|
|
14178
|
+
} else {
|
|
14179
|
+
baz();
|
|
14180
|
+
}
|
|
14181
|
+
}
|
|
13743
14182
|
|
|
13744
|
-
foo
|
|
13745
|
-
|
|
13746
|
-
|
|
13747
|
-
|
|
14183
|
+
function foo() {
|
|
14184
|
+
switch (bar) {
|
|
14185
|
+
case 1:
|
|
14186
|
+
doSomething();
|
|
14187
|
+
default:
|
|
14188
|
+
doSomethingElse();
|
|
14189
|
+
return;
|
|
14190
|
+
}
|
|
14191
|
+
}
|
|
13748
14192
|
```
|
|
13749
14193
|
|
|
13750
|
-
###
|
|
14194
|
+
### Useless Construct Code
|
|
13751
14195
|
|
|
13752
14196
|
----------
|
|
13753
14197
|
|
|
13754
|
-
|
|
14198
|
+
Disallow useless code
|
|
13755
14199
|
|
|
13756
|
-
<https://eslint.org/docs/
|
|
14200
|
+
<https://eslint.org/docs/rules/no-useless-constructor#options>
|
|
13757
14201
|
|
|
13758
14202
|
π Examples of correct code
|
|
13759
14203
|
|
|
13760
14204
|
```typescript
|
|
14205
|
+
|
|
14206
|
+
class A { }
|
|
14207
|
+
|
|
13761
14208
|
class A {
|
|
13762
|
-
constructor() {
|
|
13763
|
-
|
|
14209
|
+
constructor () {
|
|
14210
|
+
doSomething();
|
|
13764
14211
|
}
|
|
13765
14212
|
}
|
|
13766
14213
|
|
|
13767
|
-
class
|
|
14214
|
+
class B extends A {
|
|
13768
14215
|
constructor() {
|
|
13769
|
-
super();
|
|
13770
|
-
this.a = 0; // OK, this is after `super()`.
|
|
14216
|
+
super('foo');
|
|
13771
14217
|
}
|
|
13772
14218
|
}
|
|
13773
14219
|
|
|
13774
|
-
class
|
|
13775
|
-
|
|
13776
|
-
|
|
14220
|
+
class B extends A {
|
|
14221
|
+
constructor() {
|
|
14222
|
+
super();
|
|
14223
|
+
doSomething();
|
|
13777
14224
|
}
|
|
13778
14225
|
}
|
|
13779
14226
|
```
|
|
@@ -13781,107 +14228,123 @@ class A extends B {
|
|
|
13781
14228
|
π Examples of incorrect code
|
|
13782
14229
|
|
|
13783
14230
|
```typescript
|
|
13784
|
-
class A
|
|
13785
|
-
constructor() {
|
|
13786
|
-
this.a = 0;
|
|
13787
|
-
super();
|
|
13788
|
-
}
|
|
13789
|
-
}
|
|
13790
|
-
|
|
13791
|
-
class A extends B {
|
|
13792
|
-
constructor() {
|
|
13793
|
-
this.foo();
|
|
13794
|
-
super();
|
|
13795
|
-
}
|
|
13796
|
-
}
|
|
13797
|
-
|
|
13798
|
-
class A extends B {
|
|
13799
|
-
constructor() {
|
|
13800
|
-
super.foo();
|
|
13801
|
-
super();
|
|
14231
|
+
class A {
|
|
14232
|
+
constructor () {
|
|
13802
14233
|
}
|
|
13803
14234
|
}
|
|
13804
14235
|
|
|
13805
|
-
class
|
|
13806
|
-
constructor() {
|
|
13807
|
-
|
|
14236
|
+
class B extends A {
|
|
14237
|
+
constructor (...args) {
|
|
14238
|
+
super(...args);
|
|
13808
14239
|
}
|
|
13809
14240
|
}
|
|
13810
14241
|
```
|
|
13811
14242
|
|
|
13812
|
-
### No
|
|
14243
|
+
### No Use Before Define
|
|
13813
14244
|
|
|
13814
14245
|
----------
|
|
13815
14246
|
|
|
13816
|
-
|
|
14247
|
+
In JavaScript, prior to ES6, variable and function declarations are hoisted to the top of a scope,
|
|
14248
|
+
so itβs possible to use identifiers before their formal declarations in code.
|
|
13817
14249
|
|
|
13818
|
-
<https://eslint.org/docs/latest/rules/no-
|
|
14250
|
+
<https://eslint.org/docs/latest/rules/no-use-before-define>
|
|
13819
14251
|
|
|
13820
14252
|
π Examples of correct code
|
|
13821
14253
|
|
|
13822
14254
|
```typescript
|
|
13823
|
-
|
|
13824
|
-
|
|
13825
|
-
|
|
13826
|
-
|
|
13827
|
-
var object = JSON.parse("{}");
|
|
13828
|
-
|
|
13829
|
-
var value = Reflect.get({ x: 1, y: 2 }, "x");
|
|
13830
|
-
|
|
13831
|
-
var first = Atomics.load(foo, 0);
|
|
13832
|
-
|
|
13833
|
-
var segmenterFr = new Intl.Segmenter("fr", { granularity: "word" });
|
|
13834
|
-
```
|
|
13835
|
-
|
|
13836
|
-
π Examples of incorrect code
|
|
13837
|
-
|
|
13838
|
-
```typescript
|
|
13839
|
-
var math = Math();
|
|
13840
|
-
|
|
13841
|
-
var newMath = new Math();
|
|
14255
|
+
var a;
|
|
14256
|
+
a = 10;
|
|
14257
|
+
alert(a);
|
|
13842
14258
|
|
|
13843
|
-
|
|
14259
|
+
function f() {}
|
|
14260
|
+
f(1);
|
|
13844
14261
|
|
|
13845
|
-
var
|
|
14262
|
+
var b = 1;
|
|
14263
|
+
function g() {
|
|
14264
|
+
return b;
|
|
14265
|
+
}
|
|
13846
14266
|
|
|
13847
|
-
|
|
14267
|
+
{
|
|
14268
|
+
let c;
|
|
14269
|
+
c++;
|
|
14270
|
+
}
|
|
13848
14271
|
|
|
13849
|
-
|
|
14272
|
+
{
|
|
14273
|
+
class C {
|
|
14274
|
+
static x = C;
|
|
14275
|
+
}
|
|
14276
|
+
}
|
|
13850
14277
|
|
|
13851
|
-
|
|
14278
|
+
{
|
|
14279
|
+
const C = class C {
|
|
14280
|
+
static x = C;
|
|
14281
|
+
}
|
|
14282
|
+
}
|
|
13852
14283
|
|
|
13853
|
-
|
|
14284
|
+
{
|
|
14285
|
+
const C = class {
|
|
14286
|
+
x = C;
|
|
14287
|
+
}
|
|
14288
|
+
}
|
|
13854
14289
|
|
|
13855
|
-
|
|
14290
|
+
{
|
|
14291
|
+
const C = class C {
|
|
14292
|
+
static {
|
|
14293
|
+
C.x = "foo";
|
|
14294
|
+
}
|
|
14295
|
+
}
|
|
14296
|
+
}
|
|
13856
14297
|
|
|
13857
|
-
|
|
14298
|
+
const foo = 1;
|
|
14299
|
+
export { foo };
|
|
13858
14300
|
```
|
|
13859
14301
|
|
|
13860
|
-
|
|
14302
|
+
π Examples of incorrect code
|
|
13861
14303
|
|
|
13862
|
-
|
|
14304
|
+
```typescript
|
|
14305
|
+
alert(a);
|
|
14306
|
+
var a = 10;
|
|
13863
14307
|
|
|
13864
|
-
|
|
14308
|
+
f();
|
|
14309
|
+
function f() {}
|
|
13865
14310
|
|
|
13866
|
-
|
|
14311
|
+
function g() {
|
|
14312
|
+
return b;
|
|
14313
|
+
}
|
|
14314
|
+
var b = 1;
|
|
13867
14315
|
|
|
13868
|
-
|
|
14316
|
+
{
|
|
14317
|
+
alert(c);
|
|
14318
|
+
let c = 1;
|
|
14319
|
+
}
|
|
13869
14320
|
|
|
13870
|
-
|
|
14321
|
+
{
|
|
14322
|
+
class C extends C {}
|
|
14323
|
+
}
|
|
13871
14324
|
|
|
13872
|
-
|
|
14325
|
+
{
|
|
14326
|
+
class C {
|
|
14327
|
+
static x = "foo";
|
|
14328
|
+
[C.x]() {}
|
|
14329
|
+
}
|
|
14330
|
+
}
|
|
13873
14331
|
|
|
13874
|
-
|
|
14332
|
+
{
|
|
14333
|
+
const C = class {
|
|
14334
|
+
static x = C;
|
|
14335
|
+
}
|
|
14336
|
+
}
|
|
13875
14337
|
|
|
13876
|
-
|
|
13877
|
-
|
|
13878
|
-
|
|
13879
|
-
|
|
13880
|
-
|
|
13881
|
-
|
|
13882
|
-
|
|
13883
|
-
|
|
13884
|
-
|
|
14338
|
+
{
|
|
14339
|
+
const C = class {
|
|
14340
|
+
static {
|
|
14341
|
+
C.x = "foo";
|
|
14342
|
+
}
|
|
14343
|
+
}
|
|
14344
|
+
}
|
|
14345
|
+
|
|
14346
|
+
export { foo };
|
|
14347
|
+
const foo = 1;
|
|
13885
14348
|
```
|
|
13886
14349
|
|
|
13887
14350
|
## Possible Errors
|
|
@@ -14576,6 +15039,139 @@ switch(foo) {
|
|
|
14576
15039
|
}
|
|
14577
15040
|
```
|
|
14578
15041
|
|
|
15042
|
+
### No Octal
|
|
15043
|
+
|
|
15044
|
+
----------
|
|
15045
|
+
|
|
15046
|
+
Octal literals are numerals that begin with a leading zero, such as:
|
|
15047
|
+
|
|
15048
|
+
<https://eslint.org/docs/latest/rules/no-octal>
|
|
15049
|
+
|
|
15050
|
+
π Examples of correct code
|
|
15051
|
+
|
|
15052
|
+
```typescript
|
|
15053
|
+
var test = 71 + 5; // 76
|
|
15054
|
+
```
|
|
15055
|
+
|
|
15056
|
+
π Examples of incorrect code
|
|
15057
|
+
|
|
15058
|
+
```typescript
|
|
15059
|
+
var num = 071; // 57
|
|
15060
|
+
var result = 5 + 07;
|
|
15061
|
+
|
|
15062
|
+
var test = 071 + 5; // 62
|
|
15063
|
+
```
|
|
15064
|
+
|
|
15065
|
+
### Octal Scape
|
|
15066
|
+
|
|
15067
|
+
----------
|
|
15068
|
+
|
|
15069
|
+
As of the ECMAScript 5 specification, octal escape sequences in string literals
|
|
15070
|
+
are deprecated and should not be used. Unicode escape sequences should be used instead.
|
|
15071
|
+
|
|
15072
|
+
<https://eslint.org/docs/latest/rules/no-octal-escape>
|
|
15073
|
+
|
|
15074
|
+
π Examples of correct code
|
|
15075
|
+
|
|
15076
|
+
```typescript
|
|
15077
|
+
var foo = "Copyright \u00A9"; // unicode
|
|
15078
|
+
|
|
15079
|
+
var foo = "Copyright \xA9"; // hexadecimal
|
|
15080
|
+
```
|
|
15081
|
+
|
|
15082
|
+
π Examples of incorrect code
|
|
15083
|
+
|
|
15084
|
+
```typescript
|
|
15085
|
+
var foo = "Copyright \251";
|
|
15086
|
+
```
|
|
15087
|
+
|
|
15088
|
+
### No Global Assign
|
|
15089
|
+
|
|
15090
|
+
----------
|
|
15091
|
+
|
|
15092
|
+
JavaScript environments contain a number of built-in global variables, such as window in browsers
|
|
15093
|
+
and process in Node.js. In almost all cases, you donβt want to assign a value to these global
|
|
15094
|
+
variables as doing so could result in losing access to important functionality.
|
|
15095
|
+
For example, you probably donβt want to do this in browser code:
|
|
15096
|
+
|
|
15097
|
+
<https://eslint.org/docs/latest/rules/no-global-assign>
|
|
15098
|
+
|
|
15099
|
+
π Examples of correct code
|
|
15100
|
+
|
|
15101
|
+
```typescript
|
|
15102
|
+
a = 1
|
|
15103
|
+
const b = 1
|
|
15104
|
+
b = 2
|
|
15105
|
+
```
|
|
15106
|
+
|
|
15107
|
+
π Examples of incorrect code
|
|
15108
|
+
|
|
15109
|
+
```typescript
|
|
15110
|
+
Object = null
|
|
15111
|
+
undefined = 1
|
|
15112
|
+
window = {}
|
|
15113
|
+
length = 1
|
|
15114
|
+
top = 1
|
|
15115
|
+
```
|
|
15116
|
+
|
|
15117
|
+
### No Case Declarations
|
|
15118
|
+
|
|
15119
|
+
----------
|
|
15120
|
+
|
|
15121
|
+
This rule disallows lexical declarations (let, const, function and class) in case/default clauses.
|
|
15122
|
+
The reason is that the lexical declaration is visible in the entire switch block but it only gets
|
|
15123
|
+
initialized when it is assigned, which will only happen if the case where it is defined is reached.
|
|
15124
|
+
|
|
15125
|
+
<https://eslint.org/docs/latest/rules/no-case-declarations>
|
|
15126
|
+
|
|
15127
|
+
π Examples of correct code
|
|
15128
|
+
|
|
15129
|
+
```typescript
|
|
15130
|
+
// Declarations outside switch-statements are valid
|
|
15131
|
+
const a = 0;
|
|
15132
|
+
|
|
15133
|
+
switch (foo) {
|
|
15134
|
+
// The following case clauses are wrapped into blocks using brackets
|
|
15135
|
+
case 1: {
|
|
15136
|
+
let x = 1;
|
|
15137
|
+
break;
|
|
15138
|
+
}
|
|
15139
|
+
case 2: {
|
|
15140
|
+
const y = 2;
|
|
15141
|
+
break;
|
|
15142
|
+
}
|
|
15143
|
+
case 3: {
|
|
15144
|
+
function f() {}
|
|
15145
|
+
break;
|
|
15146
|
+
}
|
|
15147
|
+
case 4:
|
|
15148
|
+
// Declarations using var without brackets are valid due to function-scope hoisting
|
|
15149
|
+
var z = 4;
|
|
15150
|
+
break;
|
|
15151
|
+
default: {
|
|
15152
|
+
class C {}
|
|
15153
|
+
}
|
|
15154
|
+
}
|
|
15155
|
+
```
|
|
15156
|
+
|
|
15157
|
+
π Examples of incorrect code
|
|
15158
|
+
|
|
15159
|
+
```typescript
|
|
15160
|
+
switch (foo) {
|
|
15161
|
+
case 1:
|
|
15162
|
+
let x = 1;
|
|
15163
|
+
break;
|
|
15164
|
+
case 2:
|
|
15165
|
+
const y = 2;
|
|
15166
|
+
break;
|
|
15167
|
+
case 3:
|
|
15168
|
+
function f() {}
|
|
15169
|
+
break;
|
|
15170
|
+
default:
|
|
15171
|
+
class C {}
|
|
15172
|
+
}
|
|
15173
|
+
```
|
|
15174
|
+
|
|
14579
15175
|
## Yaml Json
|
|
14580
15176
|
|
|
14581
15177
|
add suport yaml and json files
|