@typescript-eslint/eslint-plugin 8.33.1-alpha.5 → 8.33.1

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.
Files changed (161) hide show
  1. package/package.json +9 -10
  2. package/docs/rules/README.md +0 -57
  3. package/docs/rules/TEMPLATE.md +0 -36
  4. package/docs/rules/adjacent-overload-signatures.mdx +0 -105
  5. package/docs/rules/array-type.mdx +0 -126
  6. package/docs/rules/await-thenable.mdx +0 -184
  7. package/docs/rules/ban-ts-comment.mdx +0 -165
  8. package/docs/rules/ban-tslint-comment.mdx +0 -45
  9. package/docs/rules/ban-types.md +0 -26
  10. package/docs/rules/block-spacing.md +0 -15
  11. package/docs/rules/brace-style.md +0 -15
  12. package/docs/rules/camelcase.md +0 -15
  13. package/docs/rules/class-literal-property-style.mdx +0 -112
  14. package/docs/rules/class-methods-use-this.mdx +0 -135
  15. package/docs/rules/comma-dangle.md +0 -15
  16. package/docs/rules/comma-spacing.md +0 -15
  17. package/docs/rules/consistent-generic-constructors.mdx +0 -87
  18. package/docs/rules/consistent-indexed-object-style.mdx +0 -105
  19. package/docs/rules/consistent-return.mdx +0 -51
  20. package/docs/rules/consistent-type-assertions.mdx +0 -196
  21. package/docs/rules/consistent-type-definitions.mdx +0 -133
  22. package/docs/rules/consistent-type-exports.mdx +0 -97
  23. package/docs/rules/consistent-type-imports.mdx +0 -139
  24. package/docs/rules/default-param-last.mdx +0 -59
  25. package/docs/rules/dot-notation.mdx +0 -94
  26. package/docs/rules/explicit-function-return-type.mdx +0 -359
  27. package/docs/rules/explicit-member-accessibility.mdx +0 -353
  28. package/docs/rules/explicit-module-boundary-types.mdx +0 -287
  29. package/docs/rules/func-call-spacing.md +0 -15
  30. package/docs/rules/indent.md +0 -15
  31. package/docs/rules/init-declarations.mdx +0 -12
  32. package/docs/rules/key-spacing.md +0 -15
  33. package/docs/rules/keyword-spacing.md +0 -15
  34. package/docs/rules/lines-around-comment.md +0 -15
  35. package/docs/rules/lines-between-class-members.md +0 -15
  36. package/docs/rules/max-params.mdx +0 -54
  37. package/docs/rules/member-delimiter-style.md +0 -15
  38. package/docs/rules/member-ordering.mdx +0 -1483
  39. package/docs/rules/method-signature-style.mdx +0 -124
  40. package/docs/rules/naming-convention.mdx +0 -755
  41. package/docs/rules/no-array-constructor.mdx +0 -34
  42. package/docs/rules/no-array-delete.mdx +0 -44
  43. package/docs/rules/no-base-to-string.mdx +0 -115
  44. package/docs/rules/no-confusing-non-null-assertion.mdx +0 -75
  45. package/docs/rules/no-confusing-void-expression.mdx +0 -148
  46. package/docs/rules/no-deprecated.mdx +0 -119
  47. package/docs/rules/no-dupe-class-members.mdx +0 -16
  48. package/docs/rules/no-duplicate-enum-values.mdx +0 -66
  49. package/docs/rules/no-duplicate-imports.mdx +0 -17
  50. package/docs/rules/no-duplicate-type-constituents.mdx +0 -89
  51. package/docs/rules/no-dynamic-delete.mdx +0 -64
  52. package/docs/rules/no-empty-function.mdx +0 -94
  53. package/docs/rules/no-empty-interface.mdx +0 -75
  54. package/docs/rules/no-empty-object-type.mdx +0 -150
  55. package/docs/rules/no-explicit-any.mdx +0 -177
  56. package/docs/rules/no-extra-non-null-assertion.mdx +0 -60
  57. package/docs/rules/no-extra-parens.md +0 -15
  58. package/docs/rules/no-extra-semi.md +0 -15
  59. package/docs/rules/no-extraneous-class.mdx +0 -329
  60. package/docs/rules/no-floating-promises.mdx +0 -282
  61. package/docs/rules/no-for-in-array.mdx +0 -67
  62. package/docs/rules/no-implied-eval.mdx +0 -106
  63. package/docs/rules/no-import-type-side-effects.mdx +0 -80
  64. package/docs/rules/no-inferrable-types.mdx +0 -113
  65. package/docs/rules/no-invalid-this.mdx +0 -16
  66. package/docs/rules/no-invalid-void-type.mdx +0 -119
  67. package/docs/rules/no-loop-func.mdx +0 -12
  68. package/docs/rules/no-loss-of-precision.mdx +0 -17
  69. package/docs/rules/no-magic-numbers.mdx +0 -131
  70. package/docs/rules/no-meaningless-void-operator.mdx +0 -61
  71. package/docs/rules/no-misused-new.mdx +0 -53
  72. package/docs/rules/no-misused-promises.mdx +0 -314
  73. package/docs/rules/no-misused-spread.mdx +0 -132
  74. package/docs/rules/no-mixed-enums.mdx +0 -96
  75. package/docs/rules/no-namespace.mdx +0 -157
  76. package/docs/rules/no-non-null-asserted-nullish-coalescing.mdx +0 -60
  77. package/docs/rules/no-non-null-asserted-optional-chain.mdx +0 -46
  78. package/docs/rules/no-non-null-assertion.mdx +0 -48
  79. package/docs/rules/no-parameter-properties.mdx +0 -16
  80. package/docs/rules/no-redeclare.mdx +0 -79
  81. package/docs/rules/no-redundant-type-constituents.mdx +0 -102
  82. package/docs/rules/no-require-imports.mdx +0 -114
  83. package/docs/rules/no-restricted-imports.mdx +0 -84
  84. package/docs/rules/no-restricted-types.mdx +0 -70
  85. package/docs/rules/no-shadow.mdx +0 -143
  86. package/docs/rules/no-this-alias.mdx +0 -124
  87. package/docs/rules/no-type-alias.mdx +0 -626
  88. package/docs/rules/no-unnecessary-boolean-literal-compare.mdx +0 -165
  89. package/docs/rules/no-unnecessary-condition.mdx +0 -293
  90. package/docs/rules/no-unnecessary-parameter-property-assignment.mdx +0 -42
  91. package/docs/rules/no-unnecessary-qualifier.mdx +0 -57
  92. package/docs/rules/no-unnecessary-template-expression.mdx +0 -108
  93. package/docs/rules/no-unnecessary-type-arguments.mdx +0 -85
  94. package/docs/rules/no-unnecessary-type-assertion.mdx +0 -97
  95. package/docs/rules/no-unnecessary-type-constraint.mdx +0 -61
  96. package/docs/rules/no-unnecessary-type-conversion.mdx +0 -79
  97. package/docs/rules/no-unnecessary-type-parameters.mdx +0 -255
  98. package/docs/rules/no-unsafe-argument.mdx +0 -98
  99. package/docs/rules/no-unsafe-assignment.mdx +0 -101
  100. package/docs/rules/no-unsafe-call.mdx +0 -120
  101. package/docs/rules/no-unsafe-declaration-merging.mdx +0 -65
  102. package/docs/rules/no-unsafe-enum-comparison.mdx +0 -98
  103. package/docs/rules/no-unsafe-function-type.mdx +0 -65
  104. package/docs/rules/no-unsafe-member-access.mdx +0 -81
  105. package/docs/rules/no-unsafe-return.mdx +0 -126
  106. package/docs/rules/no-unsafe-type-assertion.mdx +0 -63
  107. package/docs/rules/no-unsafe-unary-minus.mdx +0 -60
  108. package/docs/rules/no-unused-expressions.mdx +0 -52
  109. package/docs/rules/no-unused-vars.mdx +0 -136
  110. package/docs/rules/no-use-before-define.mdx +0 -98
  111. package/docs/rules/no-useless-constructor.mdx +0 -21
  112. package/docs/rules/no-useless-empty-export.mdx +0 -53
  113. package/docs/rules/no-useless-template-literals.mdx +0 -9
  114. package/docs/rules/no-var-requires.mdx +0 -77
  115. package/docs/rules/no-wrapper-object-types.mdx +0 -75
  116. package/docs/rules/non-nullable-type-assertion-style.mdx +0 -47
  117. package/docs/rules/object-curly-spacing.md +0 -15
  118. package/docs/rules/only-throw-error.mdx +0 -150
  119. package/docs/rules/padding-line-between-statements.md +0 -15
  120. package/docs/rules/parameter-properties.mdx +0 -522
  121. package/docs/rules/prefer-as-const.mdx +0 -51
  122. package/docs/rules/prefer-destructuring.mdx +0 -101
  123. package/docs/rules/prefer-enum-initializers.mdx +0 -68
  124. package/docs/rules/prefer-find.mdx +0 -45
  125. package/docs/rules/prefer-for-of.mdx +0 -50
  126. package/docs/rules/prefer-function-type.mdx +0 -98
  127. package/docs/rules/prefer-includes.mdx +0 -81
  128. package/docs/rules/prefer-literal-enum-member.mdx +0 -111
  129. package/docs/rules/prefer-namespace-keyword.mdx +0 -51
  130. package/docs/rules/prefer-nullish-coalescing.mdx +0 -349
  131. package/docs/rules/prefer-optional-chain.mdx +0 -304
  132. package/docs/rules/prefer-promise-reject-errors.mdx +0 -78
  133. package/docs/rules/prefer-readonly-parameter-types.mdx +0 -408
  134. package/docs/rules/prefer-readonly.mdx +0 -111
  135. package/docs/rules/prefer-reduce-type-parameter.mdx +0 -66
  136. package/docs/rules/prefer-regexp-exec.mdx +0 -52
  137. package/docs/rules/prefer-return-this-type.mdx +0 -93
  138. package/docs/rules/prefer-string-starts-ends-with.mdx +0 -84
  139. package/docs/rules/prefer-ts-expect-error.mdx +0 -86
  140. package/docs/rules/promise-function-async.mdx +0 -143
  141. package/docs/rules/quotes.md +0 -15
  142. package/docs/rules/related-getter-setter-pairs.mdx +0 -61
  143. package/docs/rules/require-array-sort-compare.mdx +0 -89
  144. package/docs/rules/require-await.mdx +0 -53
  145. package/docs/rules/restrict-plus-operands.mdx +0 -245
  146. package/docs/rules/restrict-template-expressions.mdx +0 -167
  147. package/docs/rules/return-await.mdx +0 -339
  148. package/docs/rules/semi.md +0 -15
  149. package/docs/rules/sort-type-constituents.mdx +0 -209
  150. package/docs/rules/sort-type-union-intersection-members.mdx +0 -16
  151. package/docs/rules/space-before-blocks.md +0 -15
  152. package/docs/rules/space-before-function-paren.md +0 -15
  153. package/docs/rules/space-infix-ops.md +0 -15
  154. package/docs/rules/strict-boolean-expressions.mdx +0 -184
  155. package/docs/rules/switch-exhaustiveness-check.mdx +0 -280
  156. package/docs/rules/triple-slash-reference.mdx +0 -129
  157. package/docs/rules/type-annotation-spacing.md +0 -15
  158. package/docs/rules/typedef.mdx +0 -350
  159. package/docs/rules/unbound-method.mdx +0 -114
  160. package/docs/rules/unified-signatures.mdx +0 -132
  161. package/docs/rules/use-unknown-in-catch-callback-variable.mdx +0 -97
@@ -1,165 +0,0 @@
1
- ---
2
- description: 'Disallow `@ts-<directive>` comments or require descriptions after directives.'
3
- ---
4
-
5
- import Tabs from '@theme/Tabs';
6
- import TabItem from '@theme/TabItem';
7
-
8
- > 🛑 This file is source code, not the primary documentation location! 🛑
9
- >
10
- > See **https://typescript-eslint.io/rules/ban-ts-comment** for documentation.
11
-
12
- TypeScript provides several directive comments that can be used to alter how it processes files.
13
- Using these to suppress TypeScript compiler errors reduces the effectiveness of TypeScript overall.
14
- Instead, it's generally better to correct the types of code, to make directives unnecessary.
15
-
16
- The directive comments supported by TypeScript are:
17
-
18
- ```ts
19
- // @ts-expect-error
20
- // @ts-ignore
21
- // @ts-nocheck
22
- // @ts-check
23
- ```
24
-
25
- This rule lets you set which directive comments you want to allow in your codebase.
26
-
27
- ## Options
28
-
29
- By default, only `@ts-check` is allowed, as it enables rather than suppresses errors.
30
-
31
- ### `ts-expect-error`, `ts-ignore`, `ts-nocheck`, `ts-check` directives
32
-
33
- A value of `true` for a particular directive means that this rule will report if it finds any usage of said directive.
34
-
35
- <Tabs>
36
- <TabItem value="❌ Incorrect">
37
-
38
- ```ts option='{ "ts-ignore": true }'
39
- if (false) {
40
- // @ts-ignore: Unreachable code error
41
- console.log('hello');
42
- }
43
- if (false) {
44
- /* @ts-ignore: Unreachable code error */
45
- console.log('hello');
46
- }
47
- ```
48
-
49
- </TabItem>
50
- <TabItem value="✅ Correct">
51
-
52
- ```ts option='{ "ts-ignore": true }'
53
- if (false) {
54
- // Compiler warns about unreachable code error
55
- console.log('hello');
56
- }
57
- ```
58
-
59
- </TabItem>
60
- </Tabs>
61
-
62
- ### `allow-with-description`
63
-
64
- A value of `'allow-with-description'` for a particular directive means that this rule will report if it finds a directive that does not have a description following the directive (on the same line).
65
-
66
- For example, with `{ 'ts-expect-error': 'allow-with-description' }`:
67
-
68
- <Tabs>
69
- <TabItem value="❌ Incorrect">
70
-
71
- ```ts option='{ "ts-expect-error": "allow-with-description" }'
72
- if (false) {
73
- // @ts-expect-error
74
- console.log('hello');
75
- }
76
- if (false) {
77
- /* @ts-expect-error */
78
- console.log('hello');
79
- }
80
- ```
81
-
82
- </TabItem>
83
- <TabItem value="✅ Correct">
84
-
85
- ```ts option='{ "ts-expect-error": "allow-with-description" }'
86
- if (false) {
87
- // @ts-expect-error: Unreachable code error
88
- console.log('hello');
89
- }
90
- if (false) {
91
- /* @ts-expect-error: Unreachable code error */
92
- console.log('hello');
93
- }
94
- ```
95
-
96
- </TabItem>
97
- </Tabs>
98
- ### `descriptionFormat`
99
-
100
- {/* insert option description */}
101
-
102
- For each directive type, you can specify a custom format in the form of a regular expression. Only description that matches the pattern will be allowed.
103
-
104
- For example, with `{ 'ts-expect-error': { descriptionFormat: '^: TS\\d+ because .+$' } }`:
105
-
106
- <Tabs>
107
- <TabItem value="❌ Incorrect">
108
-
109
- {/* prettier-ignore */}
110
- ```ts option='{ "ts-expect-error": { "descriptionFormat": "^: TS\\\\d+ because .+$" } }'
111
- // @ts-expect-error: the library definition is wrong
112
- const a = doSomething('hello');
113
- ```
114
-
115
- </TabItem>
116
- <TabItem value="✅ Correct">
117
-
118
- {/* prettier-ignore */}
119
- ```ts option='{ "ts-expect-error": { "descriptionFormat": "^: TS\\\\d+ because .+$" } }'
120
- // @ts-expect-error: TS1234 because the library definition is wrong
121
- const a = doSomething('hello');
122
- ```
123
-
124
- </TabItem>
125
- </Tabs>
126
-
127
- ### `minimumDescriptionLength`
128
-
129
- {/* insert option description */}
130
-
131
- Use `minimumDescriptionLength` to set a minimum length for descriptions when using the `allow-with-description` option for a directive.
132
-
133
- For example, with `{ 'ts-expect-error': 'allow-with-description', minimumDescriptionLength: 10 }` the following pattern is:
134
-
135
- <Tabs>
136
- <TabItem value="❌ Incorrect">
137
-
138
- ```ts option='{ "ts-expect-error": "allow-with-description", "minimumDescriptionLength": 10 }'
139
- if (false) {
140
- // @ts-expect-error: TODO
141
- console.log('hello');
142
- }
143
- ```
144
-
145
- </TabItem>
146
- <TabItem value="✅ Correct">
147
-
148
- ```ts option='{ "ts-expect-error": "allow-with-description", "minimumDescriptionLength": 10 }'
149
- if (false) {
150
- // @ts-expect-error The rationale for this override is described in issue #1337 on GitLab
151
- console.log('hello');
152
- }
153
- ```
154
-
155
- </TabItem>
156
- </Tabs>
157
-
158
- ## When Not To Use It
159
-
160
- If your project or its dependencies were not architected with strong type safety in mind, it can be difficult to always adhere to proper TypeScript semantics.
161
- You might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.
162
-
163
- ## Further Reading
164
-
165
- - TypeScript [Type Checking JavaScript Files](https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html)
@@ -1,45 +0,0 @@
1
- ---
2
- description: 'Disallow `// tslint:<rule-flag>` comments.'
3
- ---
4
-
5
- import Tabs from '@theme/Tabs';
6
- import TabItem from '@theme/TabItem';
7
-
8
- > 🛑 This file is source code, not the primary documentation location! 🛑
9
- >
10
- > See **https://typescript-eslint.io/rules/ban-tslint-comment** for documentation.
11
-
12
- Useful when migrating from TSLint to ESLint. Once TSLint has been removed, this rule helps locate TSLint annotations (e.g. `// tslint:disable`).
13
-
14
- > See the [TSLint rule flags docs](https://palantir.github.io/tslint/usage/rule-flags) for reference.
15
-
16
- ## Examples
17
-
18
- <Tabs>
19
- <TabItem value="❌ Incorrect">
20
-
21
- ```ts
22
- /* tslint:disable */
23
- /* tslint:enable */
24
- /* tslint:disable:rule1 rule2 rule3... */
25
- /* tslint:enable:rule1 rule2 rule3... */
26
- // tslint:disable-next-line
27
- someCode(); // tslint:disable-line
28
- // tslint:disable-next-line:rule1 rule2 rule3...
29
- ```
30
-
31
- </TabItem>
32
- <TabItem value="✅ Correct">
33
-
34
- ```ts
35
- // This is a comment that just happens to mention tslint
36
- /* This is a multiline comment that just happens to mention tslint */
37
- someCode(); // This is a comment that just happens to mention tslint
38
- ```
39
-
40
- </TabItem>
41
- </Tabs>
42
-
43
- ## When Not To Use It
44
-
45
- If you are still using TSLint alongside ESLint.
@@ -1,26 +0,0 @@
1
- ---
2
- displayed_sidebar: rulesSidebar
3
- ---
4
-
5
- :::danger Deprecated
6
-
7
- The old `ban-types` rule encompassed multiple areas of functionality, and so has been split into several rules.
8
-
9
- **[`no-restricted-types`](./no-restricted-types.mdx)** is the new rule for banning a configurable list of type names.
10
- It has no options enabled by default and is akin to rules like [`no-restricted-globals`](https://eslint.org/docs/latest/rules/no-restricted-globals), [`no-restricted-properties`](https://eslint.org/docs/latest/rules/no-restricted-properties), and [`no-restricted-syntax`](https://eslint.org/docs/latest/rules/no-restricted-syntax).
11
-
12
- The default options from `ban-types` are now covered by:
13
-
14
- - **[`no-empty-object-type`](./no-empty-object-type.mdx)**: banning the built-in `{}` type in confusing locations
15
- - **[`no-unsafe-function-type`](./no-unsafe-function-type.mdx)**: banning the built-in `Function`
16
- - **[`no-wrapper-object-types`](./no-wrapper-object-types.mdx)**: banning `Object` and built-in class wrappers such as `Number`
17
-
18
- `ban-types` itself is removed in typescript-eslint v8.
19
- See [Announcing typescript-eslint v8 Beta](/blog/announcing-typescript-eslint-v8-beta) for more details.
20
- :::
21
-
22
- <!-- This doc file has been left on purpose because `ban-types` is a well-known
23
- rule. This exists to help direct people to the replacement rules.
24
-
25
- Note that there is no actual way to get to this page in the normal navigation,
26
- so end-users will only be able to get to this page from the search bar. -->
@@ -1,15 +0,0 @@
1
- ---
2
- displayed_sidebar: rulesSidebar
3
- ---
4
-
5
- :::danger Deprecated
6
-
7
- This rule has been moved to the [ESLint stylistic plugin](https://eslint.style).
8
- See [#8072](https://github.com/typescript-eslint/typescript-eslint/issues/8072) and [#8074](https://github.com/typescript-eslint/typescript-eslint/issues/8074) for more information.
9
-
10
- :::
11
-
12
- <!-- This doc file has been left on purpose to help direct people to the stylistic plugin.
13
-
14
- Note that there is no actual way to get to this page in the normal navigation,
15
- so end-users will only be able to get to this page from the search bar. -->
@@ -1,15 +0,0 @@
1
- ---
2
- displayed_sidebar: rulesSidebar
3
- ---
4
-
5
- :::danger Deprecated
6
-
7
- This rule has been moved to the [ESLint stylistic plugin](https://eslint.style).
8
- See [#8072](https://github.com/typescript-eslint/typescript-eslint/issues/8072) and [#8074](https://github.com/typescript-eslint/typescript-eslint/issues/8074) for more information.
9
-
10
- :::
11
-
12
- <!-- This doc file has been left on purpose to help direct people to the stylistic plugin.
13
-
14
- Note that there is no actual way to get to this page in the normal navigation,
15
- so end-users will only be able to get to this page from the search bar. -->
@@ -1,15 +0,0 @@
1
- ---
2
- displayed_sidebar: rulesSidebar
3
- ---
4
-
5
- :::danger Deprecated
6
-
7
- This rule has been deprecated in favour of the [`naming-convention`](./naming-convention.mdx) rule.
8
-
9
- :::
10
-
11
- <!-- This doc file has been left on purpose because `camelcase` is a core ESLint
12
- rule. This exists to help direct people to the replacement rule.
13
-
14
- Note that there is no actual way to get to this page in the normal navigation,
15
- so end-users will only be able to get to this page from the search bar. -->
@@ -1,112 +0,0 @@
1
- ---
2
- description: 'Enforce that literals on classes are exposed in a consistent style.'
3
- ---
4
-
5
- import Tabs from '@theme/Tabs';
6
- import TabItem from '@theme/TabItem';
7
-
8
- > 🛑 This file is source code, not the primary documentation location! 🛑
9
- >
10
- > See **https://typescript-eslint.io/rules/class-literal-property-style** for documentation.
11
-
12
- Some TypeScript applications store literal values on classes using fields with the `readonly` modifier to prevent them from being reassigned.
13
- When writing TypeScript libraries that could be used by JavaScript users, however, it's typically safer to expose these literals using `getter`s, since the `readonly` modifier is enforced at compile type.
14
-
15
- This rule aims to ensure that literals exposed by classes are done so consistently, in one of the two style described above.
16
- By default this rule prefers the `fields` style as it means JS doesn't have to setup & teardown a function closure.
17
-
18
- ## Options
19
-
20
- :::note
21
- This rule only checks for constant _literal_ values (string, template string, number, bigint, boolean, regexp, null). It does not check objects or arrays, because a readonly field behaves differently to a getter in those cases. It also does not check functions, as it is a common pattern to use readonly fields with arrow function values as auto-bound methods.
22
- This is because these types can be mutated and carry with them more complex implications about their usage.
23
- :::
24
-
25
- ### `"fields"`
26
-
27
- This style checks for any getter methods that return literal values, and requires them to be defined using fields with the `readonly` modifier instead.
28
-
29
- Examples of code with the `fields` style:
30
-
31
- <Tabs>
32
- <TabItem value="❌ Incorrect">
33
-
34
- ```ts option='"fields"'
35
- class Mx {
36
- public static get myField1() {
37
- return 1;
38
- }
39
-
40
- private get ['myField2']() {
41
- return 'hello world';
42
- }
43
- }
44
- ```
45
-
46
- </TabItem>
47
- <TabItem value="✅ Correct">
48
-
49
- ```ts option='"fields"'
50
- class Mx {
51
- public readonly myField1 = 1;
52
-
53
- // not a literal
54
- public readonly myField2 = [1, 2, 3];
55
-
56
- private readonly ['myField3'] = 'hello world';
57
-
58
- public get myField4() {
59
- return `hello from ${window.location.href}`;
60
- }
61
- }
62
- ```
63
-
64
- </TabItem>
65
- </Tabs>
66
-
67
- ### `"getters"`
68
-
69
- This style checks for any `readonly` fields that are assigned literal values, and requires them to be defined as getters instead.
70
- This style pairs well with the [`@typescript-eslint/prefer-readonly`](prefer-readonly.mdx) rule,
71
- as it will identify fields that can be `readonly`, and thus should be made into getters.
72
-
73
- Examples of code with the `getters` style:
74
-
75
- <Tabs>
76
- <TabItem value="❌ Incorrect">
77
-
78
- ```ts option='"getters"'
79
- class Mx {
80
- readonly myField1 = 1;
81
- readonly myField2 = `hello world`;
82
- private readonly myField3 = 'hello world';
83
- }
84
- ```
85
-
86
- </TabItem>
87
- <TabItem value="✅ Correct">
88
-
89
- ```ts option='"getters"'
90
- class Mx {
91
- // no readonly modifier
92
- public myField1 = 'hello';
93
-
94
- // not a literal
95
- public readonly myField2 = [1, 2, 3];
96
-
97
- public static get myField3() {
98
- return 1;
99
- }
100
-
101
- private get ['myField4']() {
102
- return 'hello world';
103
- }
104
- }
105
- ```
106
-
107
- </TabItem>
108
- </Tabs>
109
-
110
- ## When Not To Use It
111
-
112
- When you have no strong preference, or do not wish to enforce a particular style for how literal values are exposed by your classes.
@@ -1,135 +0,0 @@
1
- ---
2
- description: 'Enforce that class methods utilize `this`.'
3
- ---
4
-
5
- import Tabs from '@theme/Tabs';
6
- import TabItem from '@theme/TabItem';
7
-
8
- > 🛑 This file is source code, not the primary documentation location! 🛑
9
- >
10
- > See **https://typescript-eslint.io/rules/class-methods-use-this** for documentation.
11
-
12
- It adds support for ignoring `override` methods and/or methods on classes that implement an interface. It also supports auto-accessor properties.
13
-
14
- ## Options
15
-
16
- This rule adds the following options:
17
-
18
- ```ts
19
- interface Options extends BaseClassMethodsUseThisOptions {
20
- ignoreOverrideMethods?: boolean;
21
- ignoreClassesThatImplementAnInterface?: boolean | 'public-fields';
22
- }
23
-
24
- const defaultOptions: Options = {
25
- ...baseClassMethodsUseThisOptions,
26
- ignoreOverrideMethods: false,
27
- ignoreClassesThatImplementAnInterface: false,
28
- };
29
- ```
30
-
31
- ### `ignoreOverrideMethods`
32
-
33
- {/* insert option description */}
34
-
35
- Example of correct code when `ignoreOverrideMethods` is set to `true`:
36
-
37
- ```ts option='{ "ignoreOverrideMethods": true }' showPlaygroundButton
38
- abstract class Base {
39
- abstract method(): void;
40
- abstract property: () => void;
41
- }
42
-
43
- class Derived extends Base {
44
- override method() {}
45
- override property = () => {};
46
- }
47
- ```
48
-
49
- ### `ignoreClassesThatImplementAnInterface`
50
-
51
- {/* insert option description */}
52
-
53
- If specified, it can be either:
54
-
55
- - `true`: Ignore all classes that implement an interface
56
- - `'public-fields'`: Ignore only the public fields of classes that implement an interface
57
-
58
- Note that this option applies to all class members, not just those defined in the interface.
59
-
60
- #### `true`
61
-
62
- Examples of code when `ignoreClassesThatImplementAnInterface` is set to `true`:
63
-
64
- <Tabs>
65
- <TabItem value="❌ Incorrect">
66
-
67
- ```ts option='{ "ignoreClassesThatImplementAnInterface": true }' showPlaygroundButton
68
- class Standalone {
69
- method() {}
70
- property = () => {};
71
- }
72
- ```
73
-
74
- </TabItem>
75
- <TabItem value="✅ Correct">
76
-
77
- ```ts option='{ "ignoreClassesThatImplementAnInterface": true }' showPlaygroundButton
78
- interface Base {
79
- method(): void;
80
- }
81
-
82
- class Derived implements Base {
83
- method() {}
84
- property = () => {};
85
- }
86
- ```
87
-
88
- </TabItem>
89
- </Tabs>
90
-
91
- #### `'public-fields'`
92
-
93
- Example of incorrect code when `ignoreClassesThatImplementAnInterface` is set to `'public-fields'`:
94
-
95
- <Tabs>
96
- <TabItem value="❌ Incorrect">
97
-
98
- ```ts option='{ "ignoreClassesThatImplementAnInterface": "public-fields" }' showPlaygroundButton
99
- interface Base {
100
- method(): void;
101
- }
102
-
103
- class Derived implements Base {
104
- method() {}
105
- property = () => {};
106
-
107
- private privateMethod() {}
108
- private privateProperty = () => {};
109
-
110
- protected protectedMethod() {}
111
- protected protectedProperty = () => {};
112
- }
113
- ```
114
-
115
- </TabItem>
116
- <TabItem value="✅ Correct">
117
-
118
- ```ts option='{ "ignoreClassesThatImplementAnInterface": "public-fields" }'
119
- interface Base {
120
- method(): void;
121
- }
122
-
123
- class Derived implements Base {
124
- method() {}
125
- property = () => {};
126
- }
127
- ```
128
-
129
- </TabItem>
130
- </Tabs>
131
-
132
- ## When Not To Use It
133
-
134
- If your project dynamically changes `this` scopes around in a way TypeScript has difficulties modeling, this rule may not be viable to use.
135
- You might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.
@@ -1,15 +0,0 @@
1
- ---
2
- displayed_sidebar: rulesSidebar
3
- ---
4
-
5
- :::danger Deprecated
6
-
7
- This rule has been moved to the [ESLint stylistic plugin](https://eslint.style).
8
- See [#8072](https://github.com/typescript-eslint/typescript-eslint/issues/8072) and [#8074](https://github.com/typescript-eslint/typescript-eslint/issues/8074) for more information.
9
-
10
- :::
11
-
12
- <!-- This doc file has been left on purpose to help direct people to the stylistic plugin.
13
-
14
- Note that there is no actual way to get to this page in the normal navigation,
15
- so end-users will only be able to get to this page from the search bar. -->
@@ -1,15 +0,0 @@
1
- ---
2
- displayed_sidebar: rulesSidebar
3
- ---
4
-
5
- :::danger Deprecated
6
-
7
- This rule has been moved to the [ESLint stylistic plugin](https://eslint.style).
8
- See [#8072](https://github.com/typescript-eslint/typescript-eslint/issues/8072) and [#8074](https://github.com/typescript-eslint/typescript-eslint/issues/8074) for more information.
9
-
10
- :::
11
-
12
- <!-- This doc file has been left on purpose to help direct people to the stylistic plugin.
13
-
14
- Note that there is no actual way to get to this page in the normal navigation,
15
- so end-users will only be able to get to this page from the search bar. -->
@@ -1,87 +0,0 @@
1
- ---
2
- description: 'Enforce specifying generic type arguments on type annotation or constructor name of a constructor call.'
3
- ---
4
-
5
- import Tabs from '@theme/Tabs';
6
- import TabItem from '@theme/TabItem';
7
-
8
- > 🛑 This file is source code, not the primary documentation location! 🛑
9
- >
10
- > See **https://typescript-eslint.io/rules/consistent-generic-constructors** for documentation.
11
-
12
- When constructing a generic class, you can specify the type arguments on either the left-hand side (as a type annotation) or the right-hand side (as part of the constructor call):
13
-
14
- ```ts
15
- // Left-hand side
16
- const map: Map<string, number> = new Map();
17
-
18
- // Right-hand side
19
- const map = new Map<string, number>();
20
- ```
21
-
22
- This rule ensures that type arguments appear consistently on one side of the declaration.
23
- Keeping to one side consistently improve code readability.
24
-
25
- > The rule never reports when there are type parameters on both sides, or neither sides of the declaration.
26
- > It also doesn't report if the names of the type annotation and the constructor don't match.
27
-
28
- ## Options
29
-
30
- - `'constructor'` _(default)_: type arguments that **only** appear on the type annotation are disallowed.
31
- - `'type-annotation'`: type arguments that **only** appear on the constructor are disallowed.
32
-
33
- ### `'constructor'`
34
-
35
- {/* insert option description */}
36
-
37
- <Tabs>
38
- <TabItem value="❌ Incorrect">
39
-
40
- ```ts option='"constructor"'
41
- const map: Map<string, number> = new Map();
42
- const set: Set<string> = new Set();
43
- ```
44
-
45
- </TabItem>
46
- <TabItem value="✅ Correct">
47
-
48
- ```ts option='"constructor"'
49
- const map = new Map<string, number>();
50
- const map: Map<string, number> = new MyMap();
51
- const set = new Set<string>();
52
- const set = new Set();
53
- const set: Set<string> = new Set<string>();
54
- ```
55
-
56
- </TabItem>
57
- </Tabs>
58
-
59
- ### `'type-annotation'`
60
-
61
- <Tabs>
62
- <TabItem value="❌ Incorrect">
63
-
64
- ```ts option='"type-annotation"'
65
- const map = new Map<string, number>();
66
- const set = new Set<string>();
67
- ```
68
-
69
- </TabItem>
70
- <TabItem value="✅ Correct">
71
-
72
- ```ts option='"type-annotation"'
73
- const map: Map<string, number> = new Map();
74
- const set: Set<string> = new Set();
75
- const set = new Set();
76
- const set: Set<string> = new Set<string>();
77
- ```
78
-
79
- </TabItem>
80
- </Tabs>
81
-
82
- ## When Not To Use It
83
-
84
- You can turn this rule off if you don't want to enforce one kind of generic constructor style over the other.
85
-
86
- However, keep in mind that inconsistent style can harm readability in a project.
87
- We recommend picking a single option for this rule that works best for your project.