@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,68 +0,0 @@
1
- ---
2
- description: 'Require each enum member value to be explicitly initialized.'
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-enum-initializers** for documentation.
11
-
12
- TypeScript `enum`s are a practical way to organize semantically related constant values.
13
- Members of `enum`s that don't have explicit values are by default given sequentially increasing numbers.
14
-
15
- In projects where the value of `enum` members are important, allowing implicit values for enums can cause bugs if `enum`s are modified over time.
16
-
17
- This rule recommends having each `enum` member value explicitly initialized.
18
-
19
- ## Examples
20
-
21
- <Tabs>
22
- <TabItem value="❌ Incorrect">
23
-
24
- ```ts
25
- enum Status {
26
- Open = 1,
27
- Close,
28
- }
29
-
30
- enum Direction {
31
- Up,
32
- Down,
33
- }
34
-
35
- enum Color {
36
- Red,
37
- Green = 'Green',
38
- Blue = 'Blue',
39
- }
40
- ```
41
-
42
- </TabItem>
43
- <TabItem value="✅ Correct">
44
-
45
- ```ts
46
- enum Status {
47
- Open = 'Open',
48
- Close = 'Close',
49
- }
50
-
51
- enum Direction {
52
- Up = 1,
53
- Down = 2,
54
- }
55
-
56
- enum Color {
57
- Red = 'Red',
58
- Green = 'Green',
59
- Blue = 'Blue',
60
- }
61
- ```
62
-
63
- </TabItem>
64
- </Tabs>
65
-
66
- ## When Not To Use It
67
-
68
- If you don't care about `enum`s having implicit values you can safely disable this rule.
@@ -1,45 +0,0 @@
1
- ---
2
- description: 'Enforce the use of Array.prototype.find() over Array.prototype.filter() followed by [0] when looking for a single result.'
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-find** for documentation.
11
-
12
- When searching for the first item in an array matching a condition, it may be tempting to use code like `arr.filter(x => x > 0)[0]`.
13
- However, it is simpler to use [Array.prototype.find()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find) instead, `arr.find(x => x > 0)`, which also returns the first entry matching a condition.
14
- Because the `.find()` only needs to execute the callback until it finds a match, it's also more efficient.
15
-
16
- :::info
17
-
18
- Beware the difference in short-circuiting behavior between the approaches.
19
- `.find()` will only execute the callback on array elements until it finds a match, whereas `.filter()` executes the callback for all array elements.
20
- Therefore, when fixing errors from this rule, be sure that your `.filter()` callbacks do not have side effects.
21
-
22
- :::
23
-
24
- <Tabs>
25
- <TabItem value="❌ Incorrect">
26
-
27
- ```ts
28
- [1, 2, 3].filter(x => x > 1)[0];
29
-
30
- [1, 2, 3].filter(x => x > 1).at(0);
31
- ```
32
-
33
- </TabItem>
34
- <TabItem value="✅ Correct">
35
-
36
- ```ts
37
- [1, 2, 3].find(x => x > 1);
38
- ```
39
-
40
- </TabItem>
41
- </Tabs>
42
-
43
- ## When Not To Use It
44
-
45
- If you intentionally use patterns like `.filter(callback)[0]` to execute side effects in `callback` on all array elements, you will want to avoid this rule.
@@ -1,50 +0,0 @@
1
- ---
2
- description: 'Enforce the use of `for-of` loop over the standard `for` loop where possible.'
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-for-of** for documentation.
11
-
12
- Many developers default to writing `for (let i = 0; i < ...` loops to iterate over arrays.
13
- However, in many of those arrays, the loop iterator variable (e.g. `i`) is only used to access the respective element of the array.
14
- In those cases, a `for-of` loop is easier to read and write.
15
-
16
- This rule recommends a for-of loop when the loop index is only used to read from an array that is being iterated.
17
-
18
- ## Examples
19
-
20
- <Tabs>
21
- <TabItem value="❌ Incorrect">
22
-
23
- ```ts
24
- declare const array: string[];
25
-
26
- for (let i = 0; i < array.length; i++) {
27
- console.log(array[i]);
28
- }
29
- ```
30
-
31
- </TabItem>
32
- <TabItem value="✅ Correct">
33
-
34
- ```ts
35
- declare const array: string[];
36
-
37
- for (const x of array) {
38
- console.log(x);
39
- }
40
-
41
- for (let i = 0; i < array.length; i++) {
42
- // i is used, so for-of could not be used.
43
- console.log(i, array[i]);
44
- }
45
- ```
46
-
47
- </TabItem>
48
- </Tabs>
49
-
50
- {/* Intentionally Omitted: When Not To Use It */}
@@ -1,98 +0,0 @@
1
- ---
2
- description: 'Enforce using function types instead of interfaces with call signatures.'
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-function-type** for documentation.
11
-
12
- TypeScript allows for two common ways to declare a type for a function:
13
-
14
- - Function type: `() => string`
15
- - Object type with a signature: `{ (): string }`
16
-
17
- The function type form is generally preferred when possible for being more succinct.
18
-
19
- This rule suggests using a function type instead of an interface or object type literal with a single call signature.
20
-
21
- ## Examples
22
-
23
- <Tabs>
24
- <TabItem value="❌ Incorrect">
25
-
26
- ```ts
27
- interface Example {
28
- (): string;
29
- }
30
- ```
31
-
32
- ```ts
33
- function foo(example: { (): number }): number {
34
- return example();
35
- }
36
- ```
37
-
38
- ```ts
39
- interface ReturnsSelf {
40
- // returns the function itself, not the `this` argument.
41
- (arg: string): this;
42
- }
43
- ```
44
-
45
- </TabItem>
46
- <TabItem value="✅ Correct">
47
-
48
- ```ts
49
- type Example = () => string;
50
- ```
51
-
52
- ```ts
53
- function foo(example: () => number): number {
54
- return bar();
55
- }
56
- ```
57
-
58
- ```ts
59
- // returns the function itself, not the `this` argument.
60
- type ReturnsSelf = (arg: string) => ReturnsSelf;
61
- ```
62
-
63
- ```ts
64
- function foo(bar: { (): string; baz: number }): string {
65
- return bar();
66
- }
67
- ```
68
-
69
- ```ts
70
- interface Foo {
71
- bar: string;
72
- }
73
- interface Bar extends Foo {
74
- (): void;
75
- }
76
- ```
77
-
78
- ```ts
79
- // multiple call signatures (overloads) is allowed:
80
- interface Overloaded {
81
- (data: string): number;
82
- (id: number): string;
83
- }
84
- // this is equivelent to Overloaded interface.
85
- type Intersection = ((data: string) => number) & ((id: number) => string);
86
- ```
87
-
88
- </TabItem>
89
- </Tabs>
90
-
91
- ## When Not To Use It
92
-
93
- If you specifically want to use an interface or type literal with a single call signature for stylistic reasons, you can avoid this rule.
94
-
95
- This rule has a known edge case of sometimes triggering on global augmentations such as `interface Function`.
96
- These edge cases are rare and often symptomatic of odd code.
97
- We recommend you use an [inline ESLint disable comment](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1).
98
- See [#454](https://github.com/typescript-eslint/typescript-eslint/issues/454) for details.
@@ -1,81 +0,0 @@
1
- ---
2
- description: 'Enforce `includes` method over `indexOf` method.'
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-includes** for documentation.
11
-
12
- Prior to ES2015, `Array#indexOf` and `String#indexOf` comparisons against `-1` were the standard ways to check whether a value exists in an array or string, respectively.
13
- Alternatives that are easier to read and write now exist: ES2015 added `String#includes` and ES2016 added `Array#includes`.
14
-
15
- This rule reports when an `.indexOf` call can be replaced with an `.includes`.
16
- Additionally, this rule reports the tests of simple regular expressions in favor of `String#includes`.
17
-
18
- > This rule will report on any receiver object of an `indexOf` method call that has an `includes` method where the two methods have the same parameters.
19
- > Matching types include: `String`, `Array`, `ReadonlyArray`, and typed arrays.
20
-
21
- ## Examples
22
-
23
- <Tabs>
24
- <TabItem value="❌ Incorrect">
25
-
26
- ```ts
27
- const str: string;
28
- const array: any[];
29
- const readonlyArray: ReadonlyArray<any>;
30
- const typedArray: UInt8Array;
31
- const maybe: string;
32
- const userDefined: {
33
- indexOf(x: any): number;
34
- includes(x: any): boolean;
35
- };
36
-
37
- str.indexOf(value) !== -1;
38
- array.indexOf(value) !== -1;
39
- readonlyArray.indexOf(value) === -1;
40
- typedArray.indexOf(value) > -1;
41
- maybe?.indexOf('') !== -1;
42
- userDefined.indexOf(value) >= 0;
43
-
44
- /example/.test(str);
45
- ```
46
-
47
- </TabItem>
48
- <TabItem value="✅ Correct">
49
-
50
- ```ts
51
- const str: string;
52
- const array: any[];
53
- const readonlyArray: ReadonlyArray<any>;
54
- const typedArray: UInt8Array;
55
- const maybe: string;
56
- const userDefined: {
57
- indexOf(x: any): number;
58
- includes(x: any): boolean;
59
- };
60
-
61
- str.includes(value);
62
- array.includes(value);
63
- !readonlyArray.includes(value);
64
- typedArray.includes(value);
65
- maybe?.includes('');
66
- userDefined.includes(value);
67
-
68
- str.includes('example');
69
-
70
- // The two methods have different parameters.
71
- declare const mismatchExample: {
72
- indexOf(x: unknown, fromIndex?: number): number;
73
- includes(x: unknown): boolean;
74
- };
75
- mismatchExample.indexOf(value) >= 0;
76
- ```
77
-
78
- </TabItem>
79
- </Tabs>
80
-
81
- {/* Intentionally Omitted: When Not To Use It */}
@@ -1,111 +0,0 @@
1
- ---
2
- description: 'Require all enum members to be literal values.'
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-literal-enum-member** for documentation.
11
-
12
- TypeScript allows the value of an enum member to be many different kinds of valid JavaScript expressions.
13
- However, because enums create their own scope whereby each enum member becomes a variable in that scope, developers are often surprised at the resultant values.
14
- For example:
15
-
16
- ```ts
17
- const imOutside = 2;
18
- const b = 2;
19
- enum Foo {
20
- outer = imOutside,
21
- a = 1,
22
- b = a,
23
- c = b,
24
- // does c == Foo.b == Foo.c == 1?
25
- // or does c == b == 2?
26
- }
27
- ```
28
-
29
- > The answer is that `Foo.c` will be `1` at runtime [[TypeScript playground](https://www.typescriptlang.org/play/#src=const%20imOutside%20%3D%202%3B%0D%0Aconst%20b%20%3D%202%3B%0D%0Aenum%20Foo%20%7B%0D%0A%20%20%20%20outer%20%3D%20imOutside%2C%0D%0A%20%20%20%20a%20%3D%201%2C%0D%0A%20%20%20%20b%20%3D%20a%2C%0D%0A%20%20%20%20c%20%3D%20b%2C%0D%0A%20%20%20%20%2F%2F%20does%20c%20%3D%3D%20Foo.b%20%3D%3D%20Foo.c%20%3D%3D%201%3F%0D%0A%20%20%20%20%2F%2F%20or%20does%20c%20%3D%3D%20b%20%3D%3D%202%3F%0D%0A%7D)].
30
-
31
- Therefore, it's often better to prevent unexpected results in code by requiring the use of literal values as enum members.
32
- This rule reports when an enum member is given a value that is not a literal.
33
-
34
- ## Examples
35
-
36
- <Tabs>
37
- <TabItem value="❌ Incorrect">
38
-
39
- ```ts
40
- const str = 'Test';
41
- const string1 = 'string1';
42
- const string2 = 'string2';
43
-
44
- enum Invalid {
45
- A = str, // Variable assignment
46
- B = `Interpolates ${string1} and ${string2}`, // Template literal with interpolation
47
- C = 2 + 2, // Expression assignment
48
- D = C, // Assignment to another enum member
49
- }
50
- ```
51
-
52
- </TabItem>
53
- <TabItem value="✅ Correct">
54
-
55
- ```ts
56
- enum Valid {
57
- A, // No initializer; initialized with ascending integers starting from 0
58
- B = 'TestStr', // A regular string
59
- C = `A template literal string`, // A template literal without interpolation
60
- D = 4, // A number
61
- }
62
- ```
63
-
64
- </TabItem>
65
- </Tabs>
66
-
67
- ## Options
68
-
69
- ### `allowBitwiseExpressions`
70
-
71
- {/* insert option description */}
72
-
73
- Examples of code for the `{ "allowBitwiseExpressions": true }` option:
74
-
75
- <Tabs>
76
- <TabItem value="❌ Incorrect">
77
-
78
- ```ts option='{ "allowBitwiseExpressions": true }'
79
- const x = 1;
80
- enum Foo {
81
- A = x << 0,
82
- B = x >> 0,
83
- C = x >>> 0,
84
- D = x | 0,
85
- E = x & 0,
86
- F = x ^ 0,
87
- G = ~x,
88
- }
89
- ```
90
-
91
- </TabItem>
92
- <TabItem value="✅ Correct">
93
-
94
- ```ts option='{ "allowBitwiseExpressions": true }'
95
- enum Foo {
96
- A = 1 << 0,
97
- B = 1 >> 0,
98
- C = 1 >>> 0,
99
- D = 1 | 0,
100
- E = 1 & 0,
101
- F = 1 ^ 0,
102
- G = ~1,
103
- }
104
- ```
105
-
106
- </TabItem>
107
- </Tabs>
108
-
109
- ## When Not To Use It
110
-
111
- If you want use anything other than simple literals as an enum value, this rule might not be for you.
@@ -1,51 +0,0 @@
1
- ---
2
- description: 'Require using `namespace` keyword over `module` keyword to declare custom TypeScript modules.'
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-namespace-keyword** for documentation.
11
-
12
- TypeScript historically allowed a form of code organization called "custom modules" (`module Example {}`), later renamed to "namespaces" (`namespace Example`).
13
-
14
- Namespaces are an outdated way to organize TypeScript code.
15
- ES2015 module syntax is now preferred (`import`/`export`).
16
-
17
- For projects still using custom modules / namespaces, it's preferred to refer to them as namespaces.
18
- This rule reports when the `module` keyword is used instead of `namespace`.
19
-
20
- > This rule does not report on the use of TypeScript module declarations to describe external APIs (`declare module 'foo' {}`).
21
-
22
- ## Examples
23
-
24
- <Tabs>
25
- <TabItem value="❌ Incorrect">
26
-
27
- ```ts
28
- module Example {}
29
- ```
30
-
31
- </TabItem>
32
- <TabItem value="✅ Correct">
33
-
34
- ```ts
35
- namespace Example {}
36
-
37
- declare module 'foo' {}
38
- ```
39
-
40
- </TabItem>
41
- </Tabs>
42
-
43
- ## When Not To Use It
44
-
45
- If you are not using TypeScript's older `module`/`namespace` keywords, then you will not need this rule.
46
-
47
- ## Further Reading
48
-
49
- - [Modules](https://www.typescriptlang.org/docs/handbook/modules.html)
50
- - [Namespaces](https://www.typescriptlang.org/docs/handbook/namespaces.html)
51
- - [Namespaces and Modules](https://www.typescriptlang.org/docs/handbook/namespaces-and-modules.html)