@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,52 +0,0 @@
1
- ---
2
- description: 'Enforce `RegExp#exec` over `String#match` if no global flag is provided.'
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/prefer-regexp-exec** for documentation.
11
-
12
- `String#match` is defined to work the same as `RegExp#exec` when the regular expression does not include the `g` flag.
13
- Keeping to consistently using one of the two can help improve code readability.
14
-
15
- This rule reports when a `String#match` call can be replaced with an equivalent `RegExp#exec`.
16
-
17
- > `RegExp#exec` may also be slightly faster than `String#match`; this is the reason to choose it as the preferred usage.
18
-
19
- ## Examples
20
-
21
- <Tabs>
22
- <TabItem value="❌ Incorrect">
23
-
24
- ```ts
25
- 'something'.match(/thing/);
26
-
27
- 'some things are just things'.match(/thing/);
28
-
29
- const text = 'something';
30
- const search = /thing/;
31
- text.match(search);
32
- ```
33
-
34
- </TabItem>
35
- <TabItem value="✅ Correct">
36
-
37
- ```ts
38
- /thing/.exec('something');
39
-
40
- 'some things are just things'.match(/thing/g);
41
-
42
- const text = 'something';
43
- const search = /thing/;
44
- search.exec(text);
45
- ```
46
-
47
- </TabItem>
48
- </Tabs>
49
-
50
- ## When Not To Use It
51
-
52
- If you prefer consistent use of `String#match` for both with `g` flag and without it, you can turn this rule off.
@@ -1,93 +0,0 @@
1
- ---
2
- description: 'Enforce that `this` is used when only `this` type is returned.'
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/prefer-return-this-type** for documentation.
11
-
12
- [Method chaining](https://en.wikipedia.org/wiki/Method_chaining) is a common pattern in OOP languages and TypeScript provides a special [polymorphic `this` type](https://www.typescriptlang.org/docs/handbook/2/classes.html#this-types) to facilitate it.
13
- Class methods that explicitly declare a return type of the class name instead of `this` make it harder for extending classes to call that method: the returned object will be typed as the base class, not the derived class.
14
-
15
- This rule reports when a class method declares a return type of that class name instead of `this`.
16
-
17
- ```ts
18
- class Animal {
19
- eat(): Animal {
20
- // ~~~~~~
21
- // Either removing this type annotation or replacing
22
- // it with `this` would remove the type error below.
23
- console.log("I'm moving!");
24
- return this;
25
- }
26
- }
27
-
28
- class Cat extends Animal {
29
- meow(): Cat {
30
- console.log('Meow~');
31
- return this;
32
- }
33
- }
34
-
35
- const cat = new Cat();
36
- cat.eat().meow();
37
- // ~~~~
38
- // Error: Property 'meow' does not exist on type 'Animal'.
39
- // because `eat` returns `Animal` and not all animals meow.
40
- ```
41
-
42
- ## Examples
43
-
44
- <Tabs>
45
- <TabItem value="❌ Incorrect">
46
-
47
- ```ts
48
- class Foo {
49
- f1(): Foo {
50
- return this;
51
- }
52
- f2 = (): Foo => {
53
- return this;
54
- };
55
- f3(): Foo | undefined {
56
- return Math.random() > 0.5 ? this : undefined;
57
- }
58
- }
59
- ```
60
-
61
- </TabItem>
62
- <TabItem value="✅ Correct">
63
-
64
- ```ts
65
- class Foo {
66
- f1(): this {
67
- return this;
68
- }
69
- f2() {
70
- return this;
71
- }
72
- f3 = (): this => {
73
- return this;
74
- };
75
- f4 = () => {
76
- return this;
77
- };
78
- }
79
-
80
- class Base {}
81
- class Derived extends Base {
82
- f(): Base {
83
- return this;
84
- }
85
- }
86
- ```
87
-
88
- </TabItem>
89
- </Tabs>
90
-
91
- ## When Not To Use It
92
-
93
- If you don't use method chaining or explicit return values, you can safely turn this rule off.
@@ -1,84 +0,0 @@
1
- ---
2
- description: 'Enforce using `String#startsWith` and `String#endsWith` over other equivalent methods of checking substrings.'
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/prefer-string-starts-ends-with** for documentation.
11
-
12
- There are multiple ways to verify if a string starts or ends with a specific string, such as `foo.indexOf('bar') === 0`.
13
- As of ES2015, the most common way in JavaScript is to use `String#startsWith` and `String#endsWith`.
14
- Keeping to those methods consistently helps with code readability.
15
-
16
- This rule reports when a string method can be replaced safely with `String#startsWith` or `String#endsWith`.
17
-
18
- ## Examples
19
-
20
- <Tabs>
21
- <TabItem value="❌ Incorrect">
22
-
23
- ```ts
24
- declare const foo: string;
25
-
26
- // starts with
27
- foo[0] === 'b';
28
- foo.charAt(0) === 'b';
29
- foo.indexOf('bar') === 0;
30
- foo.slice(0, 3) === 'bar';
31
- foo.substring(0, 3) === 'bar';
32
- foo.match(/^bar/) != null;
33
- /^bar/.test(foo);
34
-
35
- // ends with
36
- foo[foo.length - 1] === 'b';
37
- foo.charAt(foo.length - 1) === 'b';
38
- foo.lastIndexOf('bar') === foo.length - 3;
39
- foo.slice(-3) === 'bar';
40
- foo.substring(foo.length - 3) === 'bar';
41
- foo.match(/bar$/) != null;
42
- /bar$/.test(foo);
43
- ```
44
-
45
- </TabItem>
46
- <TabItem value="✅ Correct">
47
-
48
- ```ts
49
- declare const foo: string;
50
-
51
- // starts with
52
- foo.startsWith('bar');
53
-
54
- // ends with
55
- foo.endsWith('bar');
56
- ```
57
-
58
- </TabItem>
59
- </Tabs>
60
-
61
- ## Options
62
-
63
- ### `allowSingleElementEquality`
64
-
65
- {/* insert option description */}
66
-
67
- If switched to `'always'`, the rule will allow equality checks against the first or last character in a string.
68
- This can be preferable in projects that don't deal with special character encodings and prefer a more succinct style.
69
-
70
- The following code is considered incorrect by default, but is allowed with `allowSingleElementEquality: 'always'`:
71
-
72
- ```ts option='{ "allowSingleElementEquality": "always" }' showPlaygroundButton
73
- declare const text: string;
74
-
75
- text[0] === 'a';
76
- text[0] === text[0].toUpperCase();
77
- text[0] === text[1];
78
- text[text.length - 1] === 'b';
79
- ```
80
-
81
- ## When Not To Use It
82
-
83
- If you don't mind which style of string checking is used, you can turn this rule off safely.
84
- However, keep in mind that inconsistent style can harm readability in a project.
@@ -1,86 +0,0 @@
1
- ---
2
- description: 'Enforce using `@ts-expect-error` over `@ts-ignore`.'
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/prefer-ts-expect-error** for documentation.
11
-
12
- :::danger Deprecated
13
-
14
- This rule has been deprecated in favor of [`@typescript-eslint/ban-ts-comment`](./ban-ts-comment.mdx).
15
- This rule (`@typescript-eslint/prefer-ts-expect-error`) will be removed in a future major version of typescript-eslint.
16
-
17
- When it was first created, `@typescript-eslint/ban-ts-comment` rule was only responsible for suggesting to remove `@ts-ignore` directive.
18
- It was later updated to suggest replacing `@ts-ignore` with `@ts-expect-error` directive, so that it replaces `@typescript-eslint/prefer-ts-expect-error` entirely.
19
-
20
- :::
21
-
22
- TypeScript allows you to suppress all errors on a line by placing a comment starting with `@ts-ignore` or `@ts-expect-error` immediately before the erroring line.
23
- The two directives work the same, except `@ts-expect-error` causes a type error if placed before a line that's not erroring in the first place.
24
-
25
- This means it's easy for `@ts-ignore`s to be forgotten about, and remain in code even after the error they were suppressing is fixed.
26
- This is dangerous, as if a new error arises on that line it'll be suppressed by the forgotten about `@ts-ignore`, and so be missed.
27
-
28
- ## Examples
29
-
30
- This rule reports any usage of `@ts-ignore`, including a fixer to replace with `@ts-expect-error`.
31
-
32
- <Tabs>
33
- <TabItem value="❌ Incorrect">
34
-
35
- ```ts
36
- // @ts-ignore
37
- const str: string = 1;
38
-
39
- /**
40
- * Explaining comment
41
- *
42
- * @ts-ignore */
43
- const multiLine: number = 'value';
44
-
45
- /** @ts-ignore */
46
- const block: string = 1;
47
-
48
- const isOptionEnabled = (key: string): boolean => {
49
- // @ts-ignore: if key isn't in globalOptions it'll be undefined which is false
50
- return !!globalOptions[key];
51
- };
52
- ```
53
-
54
- </TabItem>
55
- <TabItem value="✅ Correct">
56
-
57
- ```ts
58
- // @ts-expect-error
59
- const str: string = 1;
60
-
61
- /**
62
- * Explaining comment
63
- *
64
- * @ts-expect-error */
65
- const multiLine: number = 'value';
66
-
67
- /** @ts-expect-error */
68
- const block: string = 1;
69
-
70
- const isOptionEnabled = (key: string): boolean => {
71
- // @ts-expect-error: if key isn't in globalOptions it'll be undefined which is false
72
- return !!globalOptions[key];
73
- };
74
- ```
75
-
76
- </TabItem>
77
- </Tabs>
78
-
79
- ## When Not To Use It
80
-
81
- If you are compiling against multiple versions of TypeScript and using `@ts-ignore` to ignore version-specific type errors, this rule might get in your way.
82
- 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.
83
-
84
- ## Further Reading
85
-
86
- - [Original Implementing PR](https://github.com/microsoft/TypeScript/pull/36014)
@@ -1,143 +0,0 @@
1
- ---
2
- description: 'Require any function or method that returns a Promise to be marked async.'
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/promise-function-async** for documentation.
11
-
12
- Ensures that each function is only capable of:
13
-
14
- - returning a rejected promise, or
15
- - throwing an Error object.
16
-
17
- In contrast, non-`async`, `Promise`-returning functions are technically capable of either.
18
- Code that handles the results of those functions will often need to handle both cases, which can get complex.
19
- This rule's practice removes a requirement for creating code to handle both cases.
20
-
21
- > When functions return unions of `Promise` and non-`Promise` types implicitly, it is usually a mistake—this rule flags those cases. If it is intentional, make the return type explicitly to allow the rule to pass.
22
-
23
- ## Examples
24
-
25
- Examples of code for this rule
26
-
27
- <Tabs>
28
- <TabItem value="❌ Incorrect">
29
-
30
- ```ts
31
- const arrowFunctionReturnsPromise = () => Promise.resolve('value');
32
-
33
- function functionReturnsPromise() {
34
- return Promise.resolve('value');
35
- }
36
-
37
- function functionReturnsUnionWithPromiseImplicitly(p: boolean) {
38
- return p ? 'value' : Promise.resolve('value');
39
- }
40
- ```
41
-
42
- </TabItem>
43
- <TabItem value="✅ Correct">
44
-
45
- ```ts
46
- const arrowFunctionReturnsPromise = async () => Promise.resolve('value');
47
-
48
- async function functionReturnsPromise() {
49
- return Promise.resolve('value');
50
- }
51
-
52
- // An explicit return type that is not Promise means this function cannot be made async, so it is ignored by the rule
53
- function functionReturnsUnionWithPromiseExplicitly(
54
- p: boolean,
55
- ): string | Promise<string> {
56
- return p ? 'value' : Promise.resolve('value');
57
- }
58
-
59
- async function functionReturnsUnionWithPromiseImplicitly(p: boolean) {
60
- return p ? 'value' : Promise.resolve('value');
61
- }
62
- ```
63
-
64
- </TabItem>
65
- </Tabs>
66
-
67
- ## Options
68
-
69
- ### `allowAny`
70
-
71
- {/* insert option description */}
72
-
73
- If you want additional safety, consider turning this option off, as it makes the rule less able to catch incorrect Promise behaviors.
74
-
75
- Examples of code with `{ "allowAny": false }`:
76
-
77
- <Tabs>
78
- <TabItem value="❌ Incorrect">
79
-
80
- ```ts option='{ "allowAny": false }'
81
- const returnsAny = () => ({}) as any;
82
- ```
83
-
84
- </TabItem>
85
- <TabItem value="✅ Correct">
86
-
87
- ```ts option='{ "allowAny": false }'
88
- const returnsAny = async () => ({}) as any;
89
- ```
90
-
91
- </TabItem>
92
- </Tabs>
93
-
94
- ### `allowedPromiseNames`
95
-
96
- {/* insert option description */}
97
-
98
- For projects that use constructs other than the global built-in `Promise` for asynchronous code.
99
- This option allows specifying string names of classes or interfaces that cause a function to be checked as well.
100
-
101
- Examples of code with `{ "allowedPromiseNames": ["Bluebird"] }`:
102
-
103
- <Tabs>
104
- <TabItem value="❌ Incorrect">
105
-
106
- ```ts option='{ "allowedPromiseNames": ["Bluebird"] }'
107
- class Bluebird {}
108
-
109
- const returnsBluebird = () => new Bluebird(() => {});
110
- ```
111
-
112
- </TabItem>
113
- <TabItem value="✅ Correct">
114
-
115
- ```ts option='{ "allowedPromiseNames": ["Bluebird"] }'
116
- class Bluebird {}
117
-
118
- const returnsBluebird = async () => new Bluebird(() => {});
119
- ```
120
-
121
- </TabItem>
122
- </Tabs>
123
-
124
- ### `checkArrowFunctions`
125
-
126
- {/* insert option description */}
127
-
128
- ### `checkFunctionDeclarations`
129
-
130
- {/* insert option description */}
131
-
132
- ### `checkFunctionExpressions`
133
-
134
- {/* insert option description */}
135
-
136
- ### `checkMethodDeclarations`
137
-
138
- {/* insert option description */}
139
-
140
- ## When Not To Use It
141
-
142
- This rule can be difficult to enable on projects that use APIs which require functions to always be `async`.
143
- You might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) along with filing issues on your dependencies 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,61 +0,0 @@
1
- ---
2
- description: 'Enforce that `get()` types should be assignable to their equivalent `set()` type.'
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/related-getter-setter-pairs** for documentation.
11
-
12
- TypeScript allows defining different types for a `get` parameter and its corresponding `set` return.
13
- Prior to TypeScript 4.3, the types had to be identical.
14
- From TypeScript 4.3 to 5.0, the `get` type had to be a subtype of the `set` type.
15
- As of TypeScript 5.1, the types may be completely unrelated as long as there is an explicit type annotation.
16
-
17
- Defining drastically different types for a `get` and `set` pair can be confusing.
18
- It means that assigning a property to itself would not work:
19
-
20
- ```ts
21
- // Assumes box.value's get() return is assignable to its set() parameter
22
- box.value = box.value;
23
- ```
24
-
25
- This rule reports cases where a `get()` and `set()` have the same name, but the `get()`'s type is not assignable to the `set()`'s.
26
-
27
- ## Examples
28
-
29
- <Tabs>
30
- <TabItem value="❌ Incorrect">
31
-
32
- ```ts
33
- interface Box {
34
- get value(): string;
35
- set value(newValue: number);
36
- }
37
- ```
38
-
39
- </TabItem>
40
- <TabItem value="✅ Correct">
41
-
42
- ```ts
43
- interface Box {
44
- get value(): string;
45
- set value(newValue: string);
46
- }
47
- ```
48
-
49
- </TabItem>
50
- </Tabs>
51
-
52
- ## When Not To Use It
53
-
54
- If your project needs to model unusual relationships between data, such as older DOM types, this rule may not be useful for you.
55
- 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.
56
-
57
- ## Further Reading
58
-
59
- - [MDN documentation on `get`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get)
60
- - [MDN documentation on `set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/set)
61
- - [TypeScript 5.1 Release Notes > Unrelated Types for Getters and Setters](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-1.html#unrelated-types-for-getters-and-setters)
@@ -1,89 +0,0 @@
1
- ---
2
- description: 'Require `Array#sort` and `Array#toSorted` calls to always provide a `compareFunction`.'
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/require-array-sort-compare** for documentation.
11
-
12
- When called without a compare function, `Array#sort()` and `Array#toSorted()` converts all non-undefined array elements into strings and then compares said strings based off their UTF-16 code units [[ECMA specification](https://www.ecma-international.org/ecma-262/9.0/#sec-sortcompare)].
13
-
14
- The result is that elements are sorted alphabetically, regardless of their type.
15
- For example, when sorting numbers, this results in a "10 before 2" order:
16
-
17
- ```ts
18
- [1, 2, 3, 10, 20, 30].sort(); //→ [1, 10, 2, 20, 3, 30]
19
- ```
20
-
21
- This rule reports on any call to the sort methods that do not provide a `compare` argument.
22
-
23
- ## Examples
24
-
25
- This rule aims to ensure all calls of the native sort methods provide a `compareFunction`, while ignoring calls to user-defined methods.
26
-
27
- <Tabs>
28
- <TabItem value="❌ Incorrect">
29
-
30
- ```ts
31
- const array: any[];
32
- const stringArray: string[];
33
-
34
- array.sort();
35
-
36
- // String arrays should be sorted using `String#localeCompare`.
37
- stringArray.sort();
38
- ```
39
-
40
- </TabItem>
41
- <TabItem value="✅ Correct">
42
-
43
- ```ts
44
- const array: any[];
45
- const userDefinedType: { sort(): void };
46
-
47
- array.sort((a, b) => a - b);
48
- array.sort((a, b) => a.localeCompare(b));
49
-
50
- userDefinedType.sort();
51
- ```
52
-
53
- </TabItem>
54
- </Tabs>
55
-
56
- ## Options
57
-
58
- ### `ignoreStringArrays`
59
-
60
- {/* insert option description */}
61
-
62
- Examples of code for this rule with `{ ignoreStringArrays: true }`:
63
-
64
- <Tabs>
65
- <TabItem value="❌ Incorrect">
66
-
67
- ```ts option='{ "ignoreStringArrays": true }'
68
- const one = 1;
69
- const two = 2;
70
- const three = 3;
71
- [one, two, three].sort();
72
- ```
73
-
74
- </TabItem>
75
- <TabItem value="✅ Correct">
76
-
77
- ```ts option='{ "ignoreStringArrays": true }'
78
- const one = '1';
79
- const two = '2';
80
- const three = '3';
81
- [one, two, three].sort();
82
- ```
83
-
84
- </TabItem>
85
- </Tabs>
86
-
87
- ## When Not To Use It
88
-
89
- If you intentionally want your arrays to be always sorted in a string-like manner, you can turn this rule off safely.
@@ -1,53 +0,0 @@
1
- ---
2
- description: 'Disallow async functions which do not return promises and have no `await` expression.'
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/require-await** for documentation.
11
-
12
- It uses type information to allow promise-returning functions to be marked as `async` without containing an `await` expression.
13
-
14
- :::note
15
- `yield` expressions in [async generator functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function*) behave differently from sync generator functions (they unwrap promises), so the base rule never checks async generator functions. On the other hand, our rule uses type information and can detect async generator functions that both never use `await` and always yield non-promise values.
16
- :::
17
-
18
- ## Examples
19
-
20
- <Tabs>
21
- <TabItem value="❌ Incorrect">
22
-
23
- ```ts
24
- async function returnNumber() {
25
- return 1;
26
- }
27
-
28
- async function* asyncGenerator() {
29
- yield 1;
30
- }
31
-
32
- const num = returnNumber();
33
- const callAsyncGenerator = () => asyncGenerator();
34
- ```
35
-
36
- </TabItem>
37
- <TabItem value="✅ Correct">
38
-
39
- ```ts
40
- function returnNumber() {
41
- return 1;
42
- }
43
-
44
- function* syncGenerator() {
45
- yield 1;
46
- }
47
-
48
- const num = returnNumber();
49
- const callSyncGenerator = () => syncGenerator();
50
- ```
51
-
52
- </TabItem>
53
- </Tabs>