@typescript-eslint/eslint-plugin 6.8.1-alpha.30 → 6.8.1-alpha.33
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/docs/rules/array-type.md +6 -6
- package/docs/rules/ban-ts-comment.md +10 -8
- package/docs/rules/class-literal-property-style.md +4 -12
- package/docs/rules/class-methods-use-this.md +2 -2
- package/docs/rules/consistent-generic-constructors.md +4 -4
- package/docs/rules/consistent-indexed-object-style.md +4 -12
- package/docs/rules/consistent-type-assertions.md +4 -4
- package/docs/rules/consistent-type-definitions.md +4 -12
- package/docs/rules/consistent-type-exports.md +2 -2
- package/docs/rules/consistent-type-imports.md +5 -5
- package/docs/rules/dot-notation.md +3 -3
- package/docs/rules/explicit-function-return-type.md +14 -14
- package/docs/rules/explicit-member-accessibility.md +15 -15
- package/docs/rules/explicit-module-boundary-types.md +8 -8
- package/docs/rules/lines-between-class-members.md +2 -6
- package/docs/rules/member-ordering.md +34 -34
- package/docs/rules/method-signature-style.md +4 -4
- package/docs/rules/no-array-constructor.md +0 -4
- package/docs/rules/no-base-to-string.md +1 -1
- package/docs/rules/no-confusing-void-expression.md +2 -2
- package/docs/rules/no-empty-function.md +4 -4
- package/docs/rules/no-explicit-any.md +1 -3
- package/docs/rules/no-extraneous-class.md +8 -8
- package/docs/rules/no-floating-promises.md +2 -2
- package/docs/rules/no-inferrable-types.md +2 -2
- package/docs/rules/no-invalid-void-type.md +4 -4
- package/docs/rules/no-magic-numbers.md +8 -24
- package/docs/rules/no-misused-promises.md +6 -6
- package/docs/rules/no-namespace.md +6 -6
- package/docs/rules/no-redeclare.md +2 -2
- package/docs/rules/no-restricted-imports.md +2 -2
- package/docs/rules/no-shadow.md +2 -2
- package/docs/rules/no-type-alias.md +33 -33
- package/docs/rules/no-unnecessary-boolean-literal-compare.md +4 -4
- package/docs/rules/no-unnecessary-condition.md +1 -1
- package/docs/rules/no-unnecessary-type-assertion.md +2 -2
- package/docs/rules/no-unsafe-argument.md +2 -2
- package/docs/rules/no-unsafe-assignment.md +1 -1
- package/docs/rules/no-unsafe-return.md +1 -1
- package/docs/rules/no-use-before-define.md +4 -12
- package/docs/rules/parameter-properties.md +16 -16
- package/docs/rules/prefer-literal-enum-member.md +2 -2
- package/docs/rules/prefer-nullish-coalescing.md +8 -8
- package/docs/rules/prefer-optional-chain.md +15 -15
- package/docs/rules/prefer-readonly-parameter-types.md +46 -27
- package/docs/rules/prefer-readonly.md +2 -2
- package/docs/rules/require-array-sort-compare.md +2 -2
- package/docs/rules/restrict-plus-operands.md +12 -12
- package/docs/rules/restrict-template-expressions.md +7 -7
- package/docs/rules/return-await.md +6 -6
- package/docs/rules/triple-slash-reference.md +6 -6
- package/docs/rules/type-annotation-spacing.md +8 -8
- package/docs/rules/typedef.md +16 -16
- package/docs/rules/unbound-method.md +1 -1
- package/docs/rules/unified-signatures.md +2 -2
- package/package.json +7 -7
package/docs/rules/array-type.md
CHANGED
|
@@ -22,14 +22,14 @@ Always use `T[]` or `readonly T[]` for all array types.
|
|
|
22
22
|
|
|
23
23
|
#### ❌ Incorrect
|
|
24
24
|
|
|
25
|
-
```ts
|
|
25
|
+
```ts option='{ "default": "array" }'
|
|
26
26
|
const x: Array<string> = ['a', 'b'];
|
|
27
27
|
const y: ReadonlyArray<string> = ['a', 'b'];
|
|
28
28
|
```
|
|
29
29
|
|
|
30
30
|
#### ✅ Correct
|
|
31
31
|
|
|
32
|
-
```ts
|
|
32
|
+
```ts option='{ "default": "array" }'
|
|
33
33
|
const x: string[] = ['a', 'b'];
|
|
34
34
|
const y: readonly string[] = ['a', 'b'];
|
|
35
35
|
```
|
|
@@ -42,14 +42,14 @@ Always use `Array<T>` or `ReadonlyArray<T>` for all array types.
|
|
|
42
42
|
|
|
43
43
|
#### ❌ Incorrect
|
|
44
44
|
|
|
45
|
-
```ts
|
|
45
|
+
```ts option='{ "default": "generic" }'
|
|
46
46
|
const x: string[] = ['a', 'b'];
|
|
47
47
|
const y: readonly string[] = ['a', 'b'];
|
|
48
48
|
```
|
|
49
49
|
|
|
50
50
|
#### ✅ Correct
|
|
51
51
|
|
|
52
|
-
```ts
|
|
52
|
+
```ts option='{ "default": "generic" }'
|
|
53
53
|
const x: Array<string> = ['a', 'b'];
|
|
54
54
|
const y: ReadonlyArray<string> = ['a', 'b'];
|
|
55
55
|
```
|
|
@@ -63,7 +63,7 @@ Use `Array<T>` or `ReadonlyArray<T>` for all other types (union types, intersect
|
|
|
63
63
|
|
|
64
64
|
#### ❌ Incorrect
|
|
65
65
|
|
|
66
|
-
```ts
|
|
66
|
+
```ts option='{ "default": "array-simple" }'
|
|
67
67
|
const a: (string | number)[] = ['a', 'b'];
|
|
68
68
|
const b: { prop: string }[] = [{ prop: 'a' }];
|
|
69
69
|
const c: (() => void)[] = [() => {}];
|
|
@@ -74,7 +74,7 @@ const f: ReadonlyArray<string> = ['a', 'b'];
|
|
|
74
74
|
|
|
75
75
|
#### ✅ Correct
|
|
76
76
|
|
|
77
|
-
```ts
|
|
77
|
+
```ts option='{ "default": "array-simple" }'
|
|
78
78
|
const a: Array<string | number> = ['a', 'b'];
|
|
79
79
|
const b: Array<{ prop: string }> = [{ prop: 'a' }];
|
|
80
80
|
const c: Array<() => void> = [() => {}];
|
|
@@ -33,7 +33,7 @@ A value of `true` for a particular directive means that this rule will report if
|
|
|
33
33
|
|
|
34
34
|
#### ❌ Incorrect
|
|
35
35
|
|
|
36
|
-
```ts
|
|
36
|
+
```ts option='{ "ts-ignore": true }'
|
|
37
37
|
if (false) {
|
|
38
38
|
// @ts-ignore: Unreachable code error
|
|
39
39
|
console.log('hello');
|
|
@@ -48,7 +48,7 @@ if (false) {
|
|
|
48
48
|
|
|
49
49
|
#### ✅ Correct
|
|
50
50
|
|
|
51
|
-
```ts
|
|
51
|
+
```ts option='{ "ts-ignore": true }'
|
|
52
52
|
if (false) {
|
|
53
53
|
// Compiler warns about unreachable code error
|
|
54
54
|
console.log('hello');
|
|
@@ -65,7 +65,7 @@ For example, with `{ 'ts-expect-error': 'allow-with-description' }`:
|
|
|
65
65
|
|
|
66
66
|
#### ❌ Incorrect
|
|
67
67
|
|
|
68
|
-
```ts
|
|
68
|
+
```ts option='{ "ts-expect-error": "allow-with-description" }'
|
|
69
69
|
if (false) {
|
|
70
70
|
// @ts-expect-error
|
|
71
71
|
console.log('hello');
|
|
@@ -78,7 +78,7 @@ if (false) {
|
|
|
78
78
|
|
|
79
79
|
#### ✅ Correct
|
|
80
80
|
|
|
81
|
-
```ts
|
|
81
|
+
```ts option='{ "ts-expect-error": "allow-with-description" }'
|
|
82
82
|
if (false) {
|
|
83
83
|
// @ts-expect-error: Unreachable code error
|
|
84
84
|
console.log('hello');
|
|
@@ -101,14 +101,16 @@ For example, with `{ 'ts-expect-error': { descriptionFormat: '^: TS\\d+ because
|
|
|
101
101
|
|
|
102
102
|
#### ❌ Incorrect
|
|
103
103
|
|
|
104
|
-
|
|
104
|
+
<!-- prettier-ignore -->
|
|
105
|
+
```ts option='{ "ts-expect-error": { "descriptionFormat": "^: TS\\\\d+ because .+$" } }'
|
|
105
106
|
// @ts-expect-error: the library definition is wrong
|
|
106
107
|
const a = doSomething('hello');
|
|
107
108
|
```
|
|
108
109
|
|
|
109
110
|
#### ✅ Correct
|
|
110
111
|
|
|
111
|
-
|
|
112
|
+
<!-- prettier-ignore -->
|
|
113
|
+
```ts option='{ "ts-expect-error": { "descriptionFormat": "^: TS\\\\d+ because .+$" } }'
|
|
112
114
|
// @ts-expect-error: TS1234 because the library definition is wrong
|
|
113
115
|
const a = doSomething('hello');
|
|
114
116
|
```
|
|
@@ -123,7 +125,7 @@ For example, with `{ 'ts-expect-error': 'allow-with-description', minimumDescrip
|
|
|
123
125
|
|
|
124
126
|
#### ❌ Incorrect
|
|
125
127
|
|
|
126
|
-
```ts
|
|
128
|
+
```ts option='{ "ts-expect-error": "allow-with-description", "minimumDescriptionLength": 10 }'
|
|
127
129
|
if (false) {
|
|
128
130
|
// @ts-expect-error: TODO
|
|
129
131
|
console.log('hello');
|
|
@@ -132,7 +134,7 @@ if (false) {
|
|
|
132
134
|
|
|
133
135
|
#### ✅ Correct
|
|
134
136
|
|
|
135
|
-
```ts
|
|
137
|
+
```ts option='{ "ts-expect-error": "allow-with-description", "minimumDescriptionLength": 10 }'
|
|
136
138
|
if (false) {
|
|
137
139
|
// @ts-expect-error The rationale for this override is described in issue #1337 on GitLab
|
|
138
140
|
console.log('hello');
|
|
@@ -31,9 +31,7 @@ Examples of code with the `fields` style:
|
|
|
31
31
|
|
|
32
32
|
#### ❌ Incorrect
|
|
33
33
|
|
|
34
|
-
```ts
|
|
35
|
-
/* eslint @typescript-eslint/class-literal-property-style: ["error", "fields"] */
|
|
36
|
-
|
|
34
|
+
```ts option='"fields"'
|
|
37
35
|
class Mx {
|
|
38
36
|
public static get myField1() {
|
|
39
37
|
return 1;
|
|
@@ -47,9 +45,7 @@ class Mx {
|
|
|
47
45
|
|
|
48
46
|
#### ✅ Correct
|
|
49
47
|
|
|
50
|
-
```ts
|
|
51
|
-
/* eslint @typescript-eslint/class-literal-property-style: ["error", "fields"] */
|
|
52
|
-
|
|
48
|
+
```ts option='"fields"'
|
|
53
49
|
class Mx {
|
|
54
50
|
public readonly myField1 = 1;
|
|
55
51
|
|
|
@@ -76,9 +72,7 @@ Examples of code with the `getters` style:
|
|
|
76
72
|
|
|
77
73
|
#### ❌ Incorrect
|
|
78
74
|
|
|
79
|
-
```ts
|
|
80
|
-
/* eslint @typescript-eslint/class-literal-property-style: ["error", "getters"] */
|
|
81
|
-
|
|
75
|
+
```ts option='"getters"'
|
|
82
76
|
class Mx {
|
|
83
77
|
readonly myField1 = 1;
|
|
84
78
|
readonly myField2 = `hello world`;
|
|
@@ -88,9 +82,7 @@ class Mx {
|
|
|
88
82
|
|
|
89
83
|
#### ✅ Correct
|
|
90
84
|
|
|
91
|
-
```ts
|
|
92
|
-
/* eslint @typescript-eslint/class-literal-property-style: ["error", "getters"] */
|
|
93
|
-
|
|
85
|
+
```ts option='"getters"'
|
|
94
86
|
class Mx {
|
|
95
87
|
// no readonly modifier
|
|
96
88
|
public myField1 = 'hello';
|
|
@@ -32,7 +32,7 @@ Makes the rule to ignores any class member explicitly marked with `override`.
|
|
|
32
32
|
|
|
33
33
|
Example of a correct code when `ignoreOverrideMethods` is set to `true`:
|
|
34
34
|
|
|
35
|
-
```ts
|
|
35
|
+
```ts option='{ "ignoreOverrideMethods": true }' showPlaygroundButton
|
|
36
36
|
class X {
|
|
37
37
|
override method() {}
|
|
38
38
|
override property = () => {};
|
|
@@ -47,7 +47,7 @@ It's important to note that this option does not only apply to members defined i
|
|
|
47
47
|
|
|
48
48
|
Example of a correct code when `ignoreClassesThatImplementAnInterface` is set to `true`:
|
|
49
49
|
|
|
50
|
-
```ts
|
|
50
|
+
```ts option='{ "ignoreClassesThatImplementAnInterface": true }' showPlaygroundButton
|
|
51
51
|
class X implements Y {
|
|
52
52
|
method() {}
|
|
53
53
|
property = () => {};
|
|
@@ -33,14 +33,14 @@ Keeping to one side consistently improve code readability.
|
|
|
33
33
|
|
|
34
34
|
#### ❌ Incorrect
|
|
35
35
|
|
|
36
|
-
```ts
|
|
36
|
+
```ts option='"constructor"'
|
|
37
37
|
const map: Map<string, number> = new Map();
|
|
38
38
|
const set: Set<string> = new Set();
|
|
39
39
|
```
|
|
40
40
|
|
|
41
41
|
#### ✅ Correct
|
|
42
42
|
|
|
43
|
-
```ts
|
|
43
|
+
```ts option='"constructor"'
|
|
44
44
|
const map = new Map<string, number>();
|
|
45
45
|
const map: Map<string, number> = new MyMap();
|
|
46
46
|
const set = new Set<string>();
|
|
@@ -54,14 +54,14 @@ const set: Set<string> = new Set<string>();
|
|
|
54
54
|
|
|
55
55
|
#### ❌ Incorrect
|
|
56
56
|
|
|
57
|
-
```ts
|
|
57
|
+
```ts option='"type-annotation"'
|
|
58
58
|
const map = new Map<string, number>();
|
|
59
59
|
const set = new Set<string>();
|
|
60
60
|
```
|
|
61
61
|
|
|
62
62
|
#### ✅ Correct
|
|
63
63
|
|
|
64
|
-
```ts
|
|
64
|
+
```ts option='"type-annotation"'
|
|
65
65
|
const map: Map<string, number> = new Map();
|
|
66
66
|
const set: Set<string> = new Set();
|
|
67
67
|
const set = new Set();
|
|
@@ -33,9 +33,7 @@ Keeping to one declaration form consistently improve code readability.
|
|
|
33
33
|
|
|
34
34
|
#### ❌ Incorrect
|
|
35
35
|
|
|
36
|
-
```ts
|
|
37
|
-
/* eslint @typescript-eslint/consistent-indexed-object-style: ["error", "record"] */
|
|
38
|
-
|
|
36
|
+
```ts option='"record"'
|
|
39
37
|
interface Foo {
|
|
40
38
|
[key: string]: unknown;
|
|
41
39
|
}
|
|
@@ -47,9 +45,7 @@ type Foo = {
|
|
|
47
45
|
|
|
48
46
|
#### ✅ Correct
|
|
49
47
|
|
|
50
|
-
```ts
|
|
51
|
-
/* eslint @typescript-eslint/consistent-indexed-object-style: ["error", "record"] */
|
|
52
|
-
|
|
48
|
+
```ts option='"record"'
|
|
53
49
|
type Foo = Record<string, unknown>;
|
|
54
50
|
```
|
|
55
51
|
|
|
@@ -59,17 +55,13 @@ type Foo = Record<string, unknown>;
|
|
|
59
55
|
|
|
60
56
|
#### ❌ Incorrect
|
|
61
57
|
|
|
62
|
-
```ts
|
|
63
|
-
/* eslint @typescript-eslint/consistent-indexed-object-style: ["error", "index-signature"] */
|
|
64
|
-
|
|
58
|
+
```ts option='"index-signature"'
|
|
65
59
|
type Foo = Record<string, unknown>;
|
|
66
60
|
```
|
|
67
61
|
|
|
68
62
|
#### ✅ Correct
|
|
69
63
|
|
|
70
|
-
```ts
|
|
71
|
-
/* eslint @typescript-eslint/consistent-indexed-object-style: ["error", "index-signature"] */
|
|
72
|
-
|
|
64
|
+
```ts option='"index-signature"'
|
|
73
65
|
interface Foo {
|
|
74
66
|
[key: string]: unknown;
|
|
75
67
|
}
|
|
@@ -53,7 +53,7 @@ Examples of code for `{ assertionStyle: 'as', objectLiteralTypeAssertions: 'neve
|
|
|
53
53
|
|
|
54
54
|
#### ❌ Incorrect
|
|
55
55
|
|
|
56
|
-
```ts
|
|
56
|
+
```ts option='{ "assertionStyle": "as", "objectLiteralTypeAssertions": "never" }'
|
|
57
57
|
const x = { ... } as T;
|
|
58
58
|
|
|
59
59
|
function foo() {
|
|
@@ -63,7 +63,7 @@ function foo() {
|
|
|
63
63
|
|
|
64
64
|
#### ✅ Correct
|
|
65
65
|
|
|
66
|
-
```ts
|
|
66
|
+
```ts option='{ "assertionStyle": "as", "objectLiteralTypeAssertions": "never" }'
|
|
67
67
|
const x: T = { ... };
|
|
68
68
|
const y = { ... } as any;
|
|
69
69
|
const z = { ... } as unknown;
|
|
@@ -81,7 +81,7 @@ Examples of code for `{ assertionStyle: 'as', objectLiteralTypeAssertions: 'allo
|
|
|
81
81
|
|
|
82
82
|
#### ❌ Incorrect
|
|
83
83
|
|
|
84
|
-
```ts
|
|
84
|
+
```ts option='{ "assertionStyle": "as", "objectLiteralTypeAssertions": "allow-as-parameter" }'
|
|
85
85
|
const x = { ... } as T;
|
|
86
86
|
|
|
87
87
|
function foo() {
|
|
@@ -91,7 +91,7 @@ function foo() {
|
|
|
91
91
|
|
|
92
92
|
#### ✅ Correct
|
|
93
93
|
|
|
94
|
-
```tsx
|
|
94
|
+
```tsx option='{ "assertionStyle": "as", "objectLiteralTypeAssertions": "allow-as-parameter" }'
|
|
95
95
|
const x: T = { ... };
|
|
96
96
|
const y = { ... } as any;
|
|
97
97
|
const z = { ... } as unknown;
|
|
@@ -36,17 +36,13 @@ Using the same type declaration style consistently helps with code readability.
|
|
|
36
36
|
|
|
37
37
|
#### ❌ Incorrect
|
|
38
38
|
|
|
39
|
-
```ts
|
|
40
|
-
/* eslint @typescript-eslint/consistent-type-definitions: ["error", "interface"] */
|
|
41
|
-
|
|
39
|
+
```ts option='"interface"'
|
|
42
40
|
type T = { x: number };
|
|
43
41
|
```
|
|
44
42
|
|
|
45
43
|
#### ✅ Correct
|
|
46
44
|
|
|
47
|
-
```ts
|
|
48
|
-
/* eslint @typescript-eslint/consistent-type-definitions: ["error", "interface"] */
|
|
49
|
-
|
|
45
|
+
```ts option='"interface"'
|
|
50
46
|
type T = string;
|
|
51
47
|
type Foo = string | {};
|
|
52
48
|
|
|
@@ -61,9 +57,7 @@ interface T {
|
|
|
61
57
|
|
|
62
58
|
#### ❌ Incorrect
|
|
63
59
|
|
|
64
|
-
```ts
|
|
65
|
-
/* eslint @typescript-eslint/consistent-type-definitions: ["error", "type"] */
|
|
66
|
-
|
|
60
|
+
```ts option='"type"'
|
|
67
61
|
interface T {
|
|
68
62
|
x: number;
|
|
69
63
|
}
|
|
@@ -71,9 +65,7 @@ interface T {
|
|
|
71
65
|
|
|
72
66
|
#### ✅ Correct
|
|
73
67
|
|
|
74
|
-
```ts
|
|
75
|
-
/* eslint @typescript-eslint/consistent-type-definitions: ["error", "type"] */
|
|
76
|
-
|
|
68
|
+
```ts option='"type"'
|
|
77
69
|
type T = { x: number };
|
|
78
70
|
```
|
|
79
71
|
|
|
@@ -83,14 +83,14 @@ export { x };
|
|
|
83
83
|
|
|
84
84
|
### ❌ Incorrect
|
|
85
85
|
|
|
86
|
-
```ts
|
|
86
|
+
```ts option='{ "fixMixedExportsWithInlineTypeSpecifier": true }'
|
|
87
87
|
export { Button } from 'some-library';
|
|
88
88
|
export type { ButtonProps } from 'some-library';
|
|
89
89
|
```
|
|
90
90
|
|
|
91
91
|
### ✅ Correct
|
|
92
92
|
|
|
93
|
-
```ts
|
|
93
|
+
```ts option='{ "fixMixedExportsWithInlineTypeSpecifier": true }'
|
|
94
94
|
export { Button, type ButtonProps } from 'some-library';
|
|
95
95
|
```
|
|
96
96
|
|
|
@@ -22,7 +22,7 @@ This option defines the expected import kind for type-only imports. Valid values
|
|
|
22
22
|
|
|
23
23
|
Examples of **correct** code with `{prefer: 'type-imports'}`, and **incorrect** code with `{prefer: 'no-type-imports'}`.
|
|
24
24
|
|
|
25
|
-
```ts
|
|
25
|
+
```ts option='{ "prefer": "type-imports" }' showPlaygroundButton
|
|
26
26
|
import type { Foo } from 'Foo';
|
|
27
27
|
import type Bar from 'Bar';
|
|
28
28
|
type T = Foo;
|
|
@@ -31,7 +31,7 @@ const x: Bar = 1;
|
|
|
31
31
|
|
|
32
32
|
Examples of **incorrect** code with `{prefer: 'type-imports'}`, and **correct** code with `{prefer: 'no-type-imports'}`.
|
|
33
33
|
|
|
34
|
-
```ts
|
|
34
|
+
```ts option='{ "prefer": "type-imports" }' showPlaygroundButton
|
|
35
35
|
import { Foo } from 'Foo';
|
|
36
36
|
import Bar from 'Bar';
|
|
37
37
|
type T = Foo;
|
|
@@ -58,7 +58,7 @@ const x: Bar = 1;
|
|
|
58
58
|
|
|
59
59
|
#### ✅ With `separate-type-imports`
|
|
60
60
|
|
|
61
|
-
```ts
|
|
61
|
+
```ts option='{ "fixStyle": "separate-type-imports" }'
|
|
62
62
|
import type { Foo } from 'Foo';
|
|
63
63
|
import type Bar from 'Bar';
|
|
64
64
|
type T = Foo;
|
|
@@ -67,7 +67,7 @@ const x: Bar = 1;
|
|
|
67
67
|
|
|
68
68
|
#### ✅ With `inline-type-imports`
|
|
69
69
|
|
|
70
|
-
```ts
|
|
70
|
+
```ts option='{ "fixStyle": "inline-type-imports" }'
|
|
71
71
|
import { type Foo } from 'Foo';
|
|
72
72
|
import type Bar from 'Bar';
|
|
73
73
|
type T = Foo;
|
|
@@ -83,7 +83,7 @@ Default is `true`.
|
|
|
83
83
|
|
|
84
84
|
Examples of **incorrect** code with `{disallowTypeAnnotations: true}`:
|
|
85
85
|
|
|
86
|
-
```ts
|
|
86
|
+
```ts option='{ "disallowTypeAnnotations": true }' showPlaygroundButton
|
|
87
87
|
type T = import('Foo').Foo;
|
|
88
88
|
const x: import('Bar') = 1;
|
|
89
89
|
```
|
|
@@ -37,7 +37,7 @@ If the TypeScript compiler option `noPropertyAccessFromIndexSignature` is set to
|
|
|
37
37
|
|
|
38
38
|
Example of a correct code when `allowPrivateClassPropertyAccess` is set to `true`:
|
|
39
39
|
|
|
40
|
-
```ts
|
|
40
|
+
```ts option='{ "allowPrivateClassPropertyAccess": true }' showPlaygroundButton
|
|
41
41
|
class X {
|
|
42
42
|
private priv_prop = 123;
|
|
43
43
|
}
|
|
@@ -50,7 +50,7 @@ x['priv_prop'] = 123;
|
|
|
50
50
|
|
|
51
51
|
Example of a correct code when `allowProtectedClassPropertyAccess` is set to `true`:
|
|
52
52
|
|
|
53
|
-
```ts
|
|
53
|
+
```ts option='{ "allowProtectedClassPropertyAccess": true }' showPlaygroundButton
|
|
54
54
|
class X {
|
|
55
55
|
protected protected_prop = 123;
|
|
56
56
|
}
|
|
@@ -63,7 +63,7 @@ x['protected_prop'] = 123;
|
|
|
63
63
|
|
|
64
64
|
Example of correct code when `allowIndexSignaturePropertyAccess` is set to `true`:
|
|
65
65
|
|
|
66
|
-
```ts
|
|
66
|
+
```ts option='{ "allowIndexSignaturePropertyAccess": true }' showPlaygroundButton
|
|
67
67
|
class X {
|
|
68
68
|
[key: string]: number;
|
|
69
69
|
}
|
|
@@ -98,7 +98,7 @@ Examples of code for this rule with `{ allowExpressions: true }`:
|
|
|
98
98
|
|
|
99
99
|
#### ❌ Incorrect
|
|
100
100
|
|
|
101
|
-
```ts
|
|
101
|
+
```ts option='{ "allowExpressions": true }'
|
|
102
102
|
function test() {}
|
|
103
103
|
|
|
104
104
|
const fn = () => {};
|
|
@@ -108,7 +108,7 @@ export default () => {};
|
|
|
108
108
|
|
|
109
109
|
#### ✅ Correct
|
|
110
110
|
|
|
111
|
-
```ts
|
|
111
|
+
```ts option='{ "allowExpressions": true }'
|
|
112
112
|
node.addEventListener('click', () => {});
|
|
113
113
|
|
|
114
114
|
node.addEventListener('click', function () {});
|
|
@@ -124,7 +124,7 @@ Examples of code for this rule with `{ allowTypedFunctionExpressions: true }`:
|
|
|
124
124
|
|
|
125
125
|
#### ❌ Incorrect
|
|
126
126
|
|
|
127
|
-
```ts
|
|
127
|
+
```ts option='{ "allowTypedFunctionExpressions": true }'
|
|
128
128
|
let arrowFn = () => 'test';
|
|
129
129
|
|
|
130
130
|
let funcExpr = function () {
|
|
@@ -138,7 +138,7 @@ let objectProp = {
|
|
|
138
138
|
|
|
139
139
|
#### ✅ Correct
|
|
140
140
|
|
|
141
|
-
```ts
|
|
141
|
+
```ts option='{ "allowTypedFunctionExpressions": true }'
|
|
142
142
|
type FuncType = () => string;
|
|
143
143
|
|
|
144
144
|
let arrowFn: FuncType = () => 'test';
|
|
@@ -182,7 +182,7 @@ Examples of code for this rule with `{ allowHigherOrderFunctions: true }`:
|
|
|
182
182
|
|
|
183
183
|
#### ❌ Incorrect
|
|
184
184
|
|
|
185
|
-
```ts
|
|
185
|
+
```ts option='{ "allowHigherOrderFunctions": true }'
|
|
186
186
|
var arrowFn = () => () => {};
|
|
187
187
|
|
|
188
188
|
function fn() {
|
|
@@ -192,7 +192,7 @@ function fn() {
|
|
|
192
192
|
|
|
193
193
|
#### ✅ Correct
|
|
194
194
|
|
|
195
|
-
```ts
|
|
195
|
+
```ts option='{ "allowHigherOrderFunctions": true }'
|
|
196
196
|
var arrowFn = () => (): void => {};
|
|
197
197
|
|
|
198
198
|
function fn() {
|
|
@@ -208,14 +208,14 @@ Examples of code for this rule with `{ allowDirectConstAssertionInArrowFunctions
|
|
|
208
208
|
|
|
209
209
|
#### ❌ Incorrect
|
|
210
210
|
|
|
211
|
-
```ts
|
|
211
|
+
```ts option='{ "allowDirectConstAssertionInArrowFunctions": true }'
|
|
212
212
|
const func = (value: number) => ({ type: 'X', value }) as any;
|
|
213
213
|
const func = (value: number) => ({ type: 'X', value }) as Action;
|
|
214
214
|
```
|
|
215
215
|
|
|
216
216
|
#### ✅ Correct
|
|
217
217
|
|
|
218
|
-
```ts
|
|
218
|
+
```ts option='{ "allowDirectConstAssertionInArrowFunctions": true }'
|
|
219
219
|
const func = (value: number) => ({ foo: 'bar', value }) as const;
|
|
220
220
|
const func = () => x as const;
|
|
221
221
|
```
|
|
@@ -228,7 +228,7 @@ Examples of code for this rule with `{ allowConciseArrowFunctionExpressionsStart
|
|
|
228
228
|
|
|
229
229
|
#### ❌ Incorrect
|
|
230
230
|
|
|
231
|
-
```ts
|
|
231
|
+
```ts option='{ "allowConciseArrowFunctionExpressionsStartingWithVoid": true }'
|
|
232
232
|
var join = (a: string, b: string) => `${a}${b}`;
|
|
233
233
|
|
|
234
234
|
const log = (message: string) => {
|
|
@@ -238,7 +238,7 @@ const log = (message: string) => {
|
|
|
238
238
|
|
|
239
239
|
#### ✅ Correct
|
|
240
240
|
|
|
241
|
-
```ts
|
|
241
|
+
```ts option='{ "allowConciseArrowFunctionExpressionsStartingWithVoid": true }'
|
|
242
242
|
var log = (message: string) => void console.log(message);
|
|
243
243
|
```
|
|
244
244
|
|
|
@@ -250,7 +250,7 @@ Examples of code for this rule with `{ allowFunctionsWithoutTypeParameters: true
|
|
|
250
250
|
|
|
251
251
|
#### ❌ Incorrect
|
|
252
252
|
|
|
253
|
-
```ts
|
|
253
|
+
```ts option='{ "allowFunctionsWithoutTypeParameters": true }'
|
|
254
254
|
function foo<T>(t: T) {
|
|
255
255
|
return t;
|
|
256
256
|
}
|
|
@@ -260,7 +260,7 @@ const bar = <T>(t: T) => t;
|
|
|
260
260
|
|
|
261
261
|
#### ✅ Correct
|
|
262
262
|
|
|
263
|
-
```ts
|
|
263
|
+
```ts option='{ "allowFunctionsWithoutTypeParameters": true }'
|
|
264
264
|
function foo<T>(t: T): T {
|
|
265
265
|
return t;
|
|
266
266
|
}
|
|
@@ -297,13 +297,13 @@ Examples of code for this rule with `{ allowIIFEs: true }`:
|
|
|
297
297
|
|
|
298
298
|
#### ❌ Incorrect
|
|
299
299
|
|
|
300
|
-
```ts
|
|
300
|
+
```ts option='{ "allowIIFEs": true }'
|
|
301
301
|
var func = () => 'foo';
|
|
302
302
|
```
|
|
303
303
|
|
|
304
304
|
#### ✅ Correct
|
|
305
305
|
|
|
306
|
-
```ts
|
|
306
|
+
```ts option='{ "allowIIFEs": true }'
|
|
307
307
|
var foo = (() => 'foo')();
|
|
308
308
|
|
|
309
309
|
var bar = (function () {
|
|
@@ -65,7 +65,7 @@ Note the above is an example of a possible configuration you could use - it is n
|
|
|
65
65
|
|
|
66
66
|
The following patterns are considered incorrect code if no options are provided:
|
|
67
67
|
|
|
68
|
-
```ts
|
|
68
|
+
```ts showPlaygroundButton
|
|
69
69
|
class Animal {
|
|
70
70
|
constructor(name) {
|
|
71
71
|
// No accessibility modifier
|
|
@@ -88,7 +88,7 @@ class Animal {
|
|
|
88
88
|
|
|
89
89
|
The following patterns are considered correct with the default options `{ accessibility: 'explicit' }`:
|
|
90
90
|
|
|
91
|
-
```ts
|
|
91
|
+
```ts option='{ "accessibility": "explicit" }' showPlaygroundButton
|
|
92
92
|
class Animal {
|
|
93
93
|
public constructor(
|
|
94
94
|
public breed,
|
|
@@ -114,7 +114,7 @@ class Animal {
|
|
|
114
114
|
|
|
115
115
|
The following patterns are considered incorrect with the accessibility set to **no-public** `[{ accessibility: 'no-public' }]`:
|
|
116
116
|
|
|
117
|
-
```ts
|
|
117
|
+
```ts option='{ "accessibility": "no-public" }' showPlaygroundButton
|
|
118
118
|
class Animal {
|
|
119
119
|
public constructor(
|
|
120
120
|
public breed,
|
|
@@ -140,7 +140,7 @@ class Animal {
|
|
|
140
140
|
|
|
141
141
|
The following patterns are considered correct with the accessibility set to **no-public** `[{ accessibility: 'no-public' }]`:
|
|
142
142
|
|
|
143
|
-
```ts
|
|
143
|
+
```ts option='{ "accessibility": "no-public" }' showPlaygroundButton
|
|
144
144
|
class Animal {
|
|
145
145
|
constructor(
|
|
146
146
|
protected breed,
|
|
@@ -178,7 +178,7 @@ e.g. `[ { overrides: { constructors: 'no-public' } } ]`
|
|
|
178
178
|
|
|
179
179
|
The following patterns are considered incorrect with the example override
|
|
180
180
|
|
|
181
|
-
```ts
|
|
181
|
+
```ts option='{ "overrides": { "constructors": "no-public" } }' showPlaygroundButton
|
|
182
182
|
class Animal {
|
|
183
183
|
public constructor(protected animalName) {}
|
|
184
184
|
public get name() {
|
|
@@ -189,7 +189,7 @@ class Animal {
|
|
|
189
189
|
|
|
190
190
|
The following patterns are considered correct with the example override
|
|
191
191
|
|
|
192
|
-
```ts
|
|
192
|
+
```ts option='{ "overrides": { "constructors": "no-public" } }' showPlaygroundButton
|
|
193
193
|
class Animal {
|
|
194
194
|
constructor(protected animalName) {}
|
|
195
195
|
public get name() {
|
|
@@ -204,7 +204,7 @@ e.g. `[ { accessibility: 'no-public', overrides: { properties: 'explicit' } } ]`
|
|
|
204
204
|
|
|
205
205
|
The following patterns are considered incorrect with the example override
|
|
206
206
|
|
|
207
|
-
```ts
|
|
207
|
+
```ts option='{ "accessibility": "no-public", "overrides": { "properties": "explicit" } }' showPlaygroundButton
|
|
208
208
|
class Animal {
|
|
209
209
|
constructor(protected animalName) {}
|
|
210
210
|
get name() {
|
|
@@ -220,7 +220,7 @@ class Animal {
|
|
|
220
220
|
|
|
221
221
|
The following patterns are considered correct with the example override
|
|
222
222
|
|
|
223
|
-
```ts
|
|
223
|
+
```ts option='{ "accessibility": "no-public", "overrides": { "properties": "explicit" } }' showPlaygroundButton
|
|
224
224
|
class Animal {
|
|
225
225
|
constructor(protected animalName) {}
|
|
226
226
|
get name() {
|
|
@@ -238,7 +238,7 @@ e.g. `[ { accessibility: 'off', overrides: { parameterProperties: 'explicit' } }
|
|
|
238
238
|
|
|
239
239
|
The following code is considered incorrect with the example override
|
|
240
240
|
|
|
241
|
-
```ts
|
|
241
|
+
```ts option='{ "accessibility": "off", "overrides": { "parameterProperties": "explicit" } }' showPlaygroundButton
|
|
242
242
|
class Animal {
|
|
243
243
|
constructor(readonly animalName: string) {}
|
|
244
244
|
}
|
|
@@ -246,7 +246,7 @@ class Animal {
|
|
|
246
246
|
|
|
247
247
|
The following code patterns are considered correct with the example override
|
|
248
248
|
|
|
249
|
-
```ts
|
|
249
|
+
```ts option='{ "accessibility": "off", "overrides": { "parameterProperties": "explicit" } }' showPlaygroundButton
|
|
250
250
|
class Animal {
|
|
251
251
|
constructor(public readonly animalName: string) {}
|
|
252
252
|
}
|
|
@@ -264,7 +264,7 @@ e.g. `[ { accessibility: 'off', overrides: { parameterProperties: 'no-public' }
|
|
|
264
264
|
|
|
265
265
|
The following code is considered incorrect with the example override
|
|
266
266
|
|
|
267
|
-
```ts
|
|
267
|
+
```ts option='{ "accessibility": "off", "overrides": { "parameterProperties": "no-public" } }' showPlaygroundButton
|
|
268
268
|
class Animal {
|
|
269
269
|
constructor(public readonly animalName: string) {}
|
|
270
270
|
}
|
|
@@ -272,7 +272,7 @@ class Animal {
|
|
|
272
272
|
|
|
273
273
|
The following code is considered correct with the example override
|
|
274
274
|
|
|
275
|
-
```ts
|
|
275
|
+
```ts option='{ "accessibility": "off", "overrides": { "parameterProperties": "no-public" } }' showPlaygroundButton
|
|
276
276
|
class Animal {
|
|
277
277
|
constructor(public animalName: string) {}
|
|
278
278
|
}
|
|
@@ -286,7 +286,7 @@ As no checks on the overridden member type are performed all permutations of vis
|
|
|
286
286
|
|
|
287
287
|
The follow pattern is considered incorrect for the given configuration
|
|
288
288
|
|
|
289
|
-
```ts
|
|
289
|
+
```ts option='{ "overrides": { "accessors" : "off" } }' showPlaygroundButton
|
|
290
290
|
class Animal {
|
|
291
291
|
constructor(protected animalName) {}
|
|
292
292
|
public get name() {
|
|
@@ -300,7 +300,7 @@ class Animal {
|
|
|
300
300
|
|
|
301
301
|
The following patterns are considered correct with the example override
|
|
302
302
|
|
|
303
|
-
```ts
|
|
303
|
+
```ts option='{ "overrides": { "accessors" : "off" } }' showPlaygroundButton
|
|
304
304
|
class Animal {
|
|
305
305
|
public constructor(protected animalName) {}
|
|
306
306
|
public get name() {
|
|
@@ -317,7 +317,7 @@ class Animal {
|
|
|
317
317
|
If you want to ignore some specific methods, you can do it by specifying method names. Note that this option does not care for the context, and will ignore every method with these names, which could lead to it missing some cases. You should use this sparingly.
|
|
318
318
|
e.g. `[ { ignoredMethodNames: ['specificMethod', 'whateverMethod'] } ]`
|
|
319
319
|
|
|
320
|
-
```ts
|
|
320
|
+
```ts option='{ "ignoredMethodNames": ["specificMethod", "whateverMethod"] }' showPlaygroundButton
|
|
321
321
|
class Animal {
|
|
322
322
|
get specificMethod() {
|
|
323
323
|
console.log('No error because you specified this method on option');
|