@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,755 +0,0 @@
1
- ---
2
- description: 'Enforce naming conventions for everything across a codebase.'
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/naming-convention** for documentation.
11
-
12
- Enforcing naming conventions helps keep the codebase consistent, and reduces overhead when thinking about how to name a variable.
13
- Additionally, a well-designed style guide can help communicate intent, such as by enforcing all private properties begin with an `_`, and all global-level constants are written in `UPPER_CASE`.
14
-
15
- :::note
16
- This rule is _feature frozen_: it will no longer receive new features such as new options.
17
- It still will accept bug and documentation fixes for its existing area of features and to support new TypeScript versions.
18
-
19
- Stylistic rules that enforce naming and/or sorting conventions tend to grow incomprehensibly complex as increasingly obscure features are requested.
20
- This rule has reached the limit of what is reasonable for the typescript-eslint project to maintain.
21
- See [eslint-plugin: Feature freeze naming and sorting stylistic rules](https://github.com/typescript-eslint/typescript-eslint/issues/8792) for more information.
22
- :::
23
-
24
- ## Examples
25
-
26
- This rule allows you to enforce conventions for any identifier, using granular selectors to create a fine-grained style guide.
27
-
28
- :::note
29
-
30
- This rule only needs type information in specific cases, detailed below.
31
-
32
- :::
33
-
34
- ## Options
35
-
36
- This rule accepts an array of objects, with each object describing a different naming convention.
37
- Each property will be described in detail below. Also see the examples section below for illustrated examples.
38
-
39
- ```ts
40
- type Options = {
41
- // format options
42
- format:
43
- | (
44
- | 'camelCase'
45
- | 'strictCamelCase'
46
- | 'PascalCase'
47
- | 'StrictPascalCase'
48
- | 'snake_case'
49
- | 'UPPER_CASE'
50
- )[]
51
- | null;
52
- custom?: {
53
- regex: string;
54
- match: boolean;
55
- };
56
- leadingUnderscore?:
57
- | 'forbid'
58
- | 'require'
59
- | 'requireDouble'
60
- | 'allow'
61
- | 'allowDouble'
62
- | 'allowSingleOrDouble';
63
- trailingUnderscore?:
64
- | 'forbid'
65
- | 'require'
66
- | 'requireDouble'
67
- | 'allow'
68
- | 'allowDouble'
69
- | 'allowSingleOrDouble';
70
- prefix?: string[];
71
- suffix?: string[];
72
-
73
- // selector options
74
- selector: Selector | Selector[];
75
- filter?:
76
- | string
77
- | {
78
- regex: string;
79
- match: boolean;
80
- };
81
- // the allowed values for these are dependent on the selector - see below
82
- modifiers?: Modifiers<Selector>[];
83
- types?: Types<Selector>[];
84
- }[];
85
-
86
- // the default config is similar to ESLint's camelcase rule but more strict
87
- const defaultOptions: Options = [
88
- {
89
- selector: 'default',
90
- format: ['camelCase'],
91
- leadingUnderscore: 'allow',
92
- trailingUnderscore: 'allow',
93
- },
94
-
95
- {
96
- selector: 'import',
97
- format: ['camelCase', 'PascalCase'],
98
- },
99
-
100
- {
101
- selector: 'variable',
102
- format: ['camelCase', 'UPPER_CASE'],
103
- leadingUnderscore: 'allow',
104
- trailingUnderscore: 'allow',
105
- },
106
-
107
- {
108
- selector: 'typeLike',
109
- format: ['PascalCase'],
110
- },
111
- ];
112
- ```
113
-
114
- ### Format Options
115
-
116
- Every single selector can have the same set of format options.
117
- For information about how each selector is applied, see ["How does the rule evaluate a name's format?"](#how-does-the-rule-evaluate-a-names-format).
118
-
119
- #### `format`
120
-
121
- The `format` option defines the allowed formats for the identifier. This option accepts an array of the following values, and the identifier can match any of them:
122
-
123
- - `camelCase` - standard camelCase format - no underscores are allowed between characters, and consecutive capitals are allowed (i.e. both `myID` and `myId` are valid).
124
- - `PascalCase` - same as `camelCase`, except the first character must be upper-case.
125
- - `snake_case` - standard snake_case format - all characters must be lower-case, and underscores are allowed.
126
- - `strictCamelCase` - same as `camelCase`, but consecutive capitals are not allowed (i.e. `myId` is valid, but `myID` is not).
127
- - `StrictPascalCase` - same as `strictCamelCase`, except the first character must be upper-case.
128
- - `UPPER_CASE` - same as `snake_case`, except all characters must be upper-case.
129
-
130
- Instead of an array, you may also pass `null`. This signifies "this selector shall not have its format checked".
131
- This can be useful if you want to enforce no particular format for a specific selector, after applying a group selector.
132
-
133
- #### `custom`
134
-
135
- The `custom` option defines a custom regex that the identifier must (or must not) match. This option allows you to have a bit more finer-grained control over identifiers, letting you ban (or force) certain patterns and substrings.
136
- Accepts an object with the following properties:
137
-
138
- - `match` - true if the identifier _must_ match the `regex`, false if the identifier _must not_ match the `regex`.
139
- - `regex` - a string that is then passed into RegExp to create a new regular expression: `new RegExp(regex)`
140
-
141
- #### `filter`
142
-
143
- The `filter` option operates similar to `custom`, accepting the same shaped object, except that it controls if the rest of the configuration should or should not be applied to an identifier.
144
-
145
- You can use this to include or exclude specific identifiers from specific configurations.
146
-
147
- Accepts an object with the following properties:
148
-
149
- - `match` - true if the identifier _must_ match the `regex`, false if the identifier _must not_ match the `regex`.
150
- - `regex` - a string that is then passed into RegExp to create a new regular expression: `new RegExp(regex)`
151
-
152
- Alternatively, `filter` accepts a regular expression (anything accepted into `new RegExp(filter)`). In this case, it's treated as if you had passed an object with the regex and `match: true`.
153
-
154
- #### `leadingUnderscore` / `trailingUnderscore`
155
-
156
- The `leadingUnderscore` / `trailingUnderscore` options control whether leading/trailing underscores are considered valid. Accepts one of the following values:
157
-
158
- - `allow` - existence of a single leading/trailing underscore is not explicitly enforced.
159
- - `allowDouble` - existence of a double leading/trailing underscore is not explicitly enforced.
160
- - `allowSingleOrDouble` - existence of a single or a double leading/trailing underscore is not explicitly enforced.
161
- - `forbid` - a leading/trailing underscore is not allowed at all.
162
- - `require` - a single leading/trailing underscore must be included.
163
- - `requireDouble` - two leading/trailing underscores must be included.
164
-
165
- #### `prefix` / `suffix`
166
-
167
- The `prefix` / `suffix` options control which prefix/suffix strings must exist for the identifier. Accepts an array of strings.
168
-
169
- If these are provided, the identifier must start with one of the provided values. For example, if you provide `{ prefix: ['Class', 'IFace', 'Type'] }`, then the following names are valid: `ClassBar`, `IFaceFoo`, `TypeBaz`, but the name `Bang` is not valid, as it contains none of the prefixes.
170
-
171
- **Note:** As [documented above](#format-options), the prefix is trimmed before format is validated, therefore PascalCase must be used to allow variables such as `isEnabled` using the prefix `is`.
172
-
173
- ### Selector Options
174
-
175
- - `selector` allows you to specify what types of identifiers to target.
176
- - Accepts one or array of selectors to define an option block that applies to one or multiple selectors.
177
- - For example, if you provide `{ selector: ['function', 'variable'] }`, then it will apply the same option to variable and function nodes.
178
- - See [Allowed Selectors, Modifiers and Types](#allowed-selectors-modifiers-and-types) below for the complete list of allowed selectors.
179
- - `modifiers` allows you to specify which modifiers to granularly apply to, such as the accessibility (`#private`/`private`/`protected`/`public`), or if the thing is `static`, etc.
180
- - The name must match _all_ of the modifiers.
181
- - For example, if you provide `{ modifiers: ['private','readonly','static'] }`, then it will only match something that is `private static readonly`, and something that is just `private` will not match.
182
- - The following `modifiers` are allowed:
183
- - `abstract`,`override`,`private`,`protected`,`readonly`,`static` - matches any member explicitly declared with the given modifier.
184
- - `async` - matches any method, function, or function variable which is async via the `async` keyword (e.g. does not match functions that return promises without using `async` keyword)
185
- - `const` - matches a variable declared as being `const` (`const x = 1`).
186
- - `destructured` - matches a variable declared via an object destructuring pattern (`const {x, z = 2}`).
187
- - Note that this does not match renamed destructured properties (`const {x: y, a: b = 2}`).
188
- - `exported` - matches anything that is exported from the module.
189
- - `global` - matches a variable/function declared in the top-level scope.
190
- - `#private` - matches any member with a private identifier (an identifier that starts with `#`)
191
- - `public` - matches any member that is either explicitly declared as `public`, or has no visibility modifier (i.e. implicitly public).
192
- - `requiresQuotes` - matches any name that requires quotes as it is not a valid identifier (i.e. has a space, a dash, etc in it).
193
- - `unused` - matches anything that is not used.
194
- - `types` allows you to specify which types to match. This option supports simple, primitive types only (`array`,`boolean`,`function`,`number`,`string`).
195
- - The name must match _one_ of the types.
196
- - **_NOTE - Using this option will require that you lint with type information._**
197
- - For example, this lets you do things like enforce that `boolean` variables are prefixed with a verb.
198
- - The following `types` are allowed:
199
- - `array` matches any type assignable to `Array<unknown> | null | undefined`
200
- - `boolean` matches any type assignable to `boolean | null | undefined`
201
- - `function` matches any type assignable to `Function | null | undefined`
202
- - `number` matches any type assignable to `number | null | undefined`
203
- - `string` matches any type assignable to `string | null | undefined`
204
-
205
- The ordering of selectors does not matter. The implementation will automatically sort the selectors to ensure they match from most-specific to least specific. It will keep checking selectors in that order until it finds one that matches the name. See ["How does the rule automatically order selectors?"](#how-does-the-rule-automatically-order-selectors)
206
-
207
- #### Allowed Selectors, Modifiers and Types
208
-
209
- There are two types of selectors, individual selectors, and grouped selectors.
210
-
211
- ##### Individual Selectors
212
-
213
- Individual Selectors match specific, well-defined sets. There is no overlap between each of the individual selectors.
214
-
215
- - `classicAccessor` - matches any accessor. It refers to the methods attached to `get` and `set` syntax.
216
- - Allowed `modifiers`: `abstract`, `override`, `private`, `protected`, `public`, `requiresQuotes`, `static`.
217
- - Allowed `types`: `array`, `boolean`, `function`, `number`, `string`.
218
- - `autoAccessor` - matches any auto-accessor. An auto-accessor is just a class field starting with an `accessor` keyword.
219
- - Allowed `modifiers`: `abstract`, `override`, `private`, `protected`, `public`, `requiresQuotes`, `static`.
220
- - Allowed `types`: `array`, `boolean`, `function`, `number`, `string`.
221
- - `class` - matches any class declaration.
222
- - Allowed `modifiers`: `abstract`, `exported`, `unused`.
223
- - Allowed `types`: none.
224
- - `classMethod` - matches any class method. Also matches properties that have direct function expression or arrow function expression values. Does not match accessors.
225
- - Allowed `modifiers`: `abstract`, `async`, `override`, `#private`, `private`, `protected`, `public`, `requiresQuotes`, `static`.
226
- - Allowed `types`: none.
227
- - `classProperty` - matches any class property. Does not match properties that have direct function expression or arrow function expression values.
228
- - Allowed `modifiers`: `abstract`, `override`, `#private`, `private`, `protected`, `public`, `readonly`, `requiresQuotes`, `static`.
229
- - Allowed `types`: `array`, `boolean`, `function`, `number`, `string`.
230
- - `enum` - matches any enum declaration.
231
- - Allowed `modifiers`: `exported`, `unused`.
232
- - Allowed `types`: none.
233
- - `enumMember` - matches any enum member.
234
- - Allowed `modifiers`: `requiresQuotes`.
235
- - Allowed `types`: none.
236
- - `function` - matches any named function declaration or named function expression.
237
- - Allowed `modifiers`: `async`, `exported`, `global`, `unused`.
238
- - Allowed `types`: none.
239
- - `import` - matches namespace imports and default imports (i.e. does not match named imports).
240
- - Allowed `modifiers`: `default`, `namespace`.
241
- - Allowed `types`: none.
242
- - `interface` - matches any interface declaration.
243
- - Allowed `modifiers`: `exported`, `unused`.
244
- - Allowed `types`: none.
245
- - `objectLiteralMethod` - matches any object literal method. Also matches properties that have direct function expression or arrow function expression values. Does not match accessors.
246
- - Allowed `modifiers`: `async`, `public`, `requiresQuotes`.
247
- - Allowed `types`: none.
248
- - `objectLiteralProperty` - matches any object literal property. Does not match properties that have direct function expression or arrow function expression values.
249
- - Allowed `modifiers`: `public`, `requiresQuotes`.
250
- - Allowed `types`: `array`, `boolean`, `function`, `number`, `string`.
251
- - `parameter` - matches any function parameter. Does not match parameter properties.
252
- - Allowed `modifiers`: `destructured`, `unused`.
253
- - Allowed `types`: `array`, `boolean`, `function`, `number`, `string`.
254
- - `parameterProperty` - matches any parameter property.
255
- - Allowed `modifiers`: `private`, `protected`, `public`, `readonly`.
256
- - Allowed `types`: `array`, `boolean`, `function`, `number`, `string`.
257
- - `typeAlias` - matches any type alias declaration.
258
- - Allowed `modifiers`: `exported`, `unused`.
259
- - Allowed `types`: none.
260
- - `typeMethod` - matches any object type method. Also matches properties that have direct function expression or arrow function expression values. Does not match accessors.
261
- - Allowed `modifiers`: `public`, `requiresQuotes`.
262
- - Allowed `types`: none.
263
- - `typeParameter` - matches any generic type parameter declaration.
264
- - Allowed `modifiers`: `unused`.
265
- - Allowed `types`: none.
266
- - `typeProperty` - matches any object type property. Does not match properties that have direct function expression or arrow function expression values.
267
- - Allowed `modifiers`: `public`, `readonly`, `requiresQuotes`.
268
- - Allowed `types`: `array`, `boolean`, `function`, `number`, `string`.
269
- - `variable` - matches any `const` / `let` / `var` variable name.
270
- - Allowed `modifiers`: `async`, `const`, `destructured`, `exported`, `global`, `unused`.
271
- - Allowed `types`: `array`, `boolean`, `function`, `number`, `string`.
272
-
273
- ##### Group Selectors
274
-
275
- Group Selectors are provided for convenience, and essentially bundle up sets of individual selectors.
276
-
277
- - `default` - matches everything.
278
- - Allowed `modifiers`: all modifiers.
279
- - Allowed `types`: none.
280
- - `accessor` - matches the same as `classicAccessor` and `autoAccessor`.
281
- - Allowed `modifiers`: `abstract`, `override`, `private`, `protected`, `public`, `requiresQuotes`, `static`.
282
- - Allowed `types`: `array`, `boolean`, `function`, `number`, `string`.
283
- - `memberLike` - matches the same as `classicAccessor`, `autoAccessor`, `enumMember`, `method`, `parameterProperty`, `property`.
284
- - Allowed `modifiers`: `abstract`, `async`, `override`, `#private`, `private`, `protected`, `public`, `readonly`, `requiresQuotes`, `static`.
285
- - Allowed `types`: none.
286
- - `method` - matches the same as `classMethod`, `objectLiteralMethod`, `typeMethod`.
287
- - Allowed `modifiers`: `abstract`, `async`, `override`, `#private`, `private`, `protected`, `public`, `readonly`, `requiresQuotes`, `static`.
288
- - Allowed `types`: none.
289
- - `property` - matches the same as `classProperty`, `objectLiteralProperty`, `typeProperty`.
290
- - Allowed `modifiers`: `abstract`, `async`, `override`, `#private`, `private`, `protected`, `public`, `readonly`, `requiresQuotes`, `static`.
291
- - Allowed `types`: `array`, `boolean`, `function`, `number`, `string`.
292
- - `typeLike` - matches the same as `class`, `enum`, `interface`, `typeAlias`, `typeParameter`.
293
- - Allowed `modifiers`: `abstract`, `unused`.
294
- - Allowed `types`: none.
295
- - `variableLike` - matches the same as `function`, `parameter` and `variable`.
296
- - Allowed `modifiers`: `async`, `unused`.
297
- - Allowed `types`: none.
298
-
299
- ## FAQ
300
-
301
- This is a big rule, and there's a lot of docs. Here are a few clarifications that people often ask about or figure out via trial-and-error.
302
-
303
- ### How does the rule evaluate a selector?
304
-
305
- Each selector is checked in the following way:
306
-
307
- 1. check the `filter`
308
- 1. if `filter` is omitted → skip this step.
309
- 2. if the name matches the `filter` → continue evaluating this selector.
310
- 3. if the name does not match the `filter` → skip this selector and continue to the next selector.
311
- 2. check the `selector`
312
- 1. if `selector` is one individual selector → the name's type must be of that type.
313
- 2. if `selector` is a group selector → the name's type must be one of the grouped types.
314
- 3. if `selector` is an array of selectors → apply the above for each selector in the array.
315
- 3. check the `types`
316
- 1. if `types` is omitted → skip this step.
317
- 2. if the name has a type in `types` → continue evaluating this selector.
318
- 3. if the name does not have a type in `types` → skip this selector and continue to the next selector.
319
-
320
- A name is considered to pass the config if it:
321
-
322
- 1. Matches one selector and passes all of that selector's format checks.
323
- 2. Matches no selectors.
324
-
325
- A name is considered to fail the config if it matches one selector and fails one that selector's format checks.
326
-
327
- ### How does the rule automatically order selectors?
328
-
329
- Each identifier should match exactly one selector. It may match multiple group selectors - but only ever one selector.
330
- With that in mind - the base sort order works out to be:
331
-
332
- 1. Individual Selectors
333
- 2. Grouped Selectors
334
- 3. Default Selector
335
-
336
- Within each of these categories, some further sorting occurs based on what selector options are supplied:
337
-
338
- 1. `filter` is given the highest priority above all else.
339
- 2. `types`
340
- 3. `modifiers`
341
- 4. everything else
342
-
343
- For example, if you provide the following config:
344
-
345
- ```ts
346
- [
347
- /* 1 */ { selector: 'default', format: ['camelCase'] },
348
- /* 2 */ { selector: 'variable', format: ['snake_case'] },
349
- /* 3 */ { selector: 'variable', types: ['boolean'], format: ['UPPER_CASE'] },
350
- /* 4 */ { selector: 'variableLike', format: ['PascalCase'] },
351
- ];
352
- ```
353
-
354
- Then for the code `const x = 1`, the rule will validate the selectors in the following order: `3`, `2`, `4`, `1`.
355
- To clearly spell it out:
356
-
357
- - (3) is tested first because it has `types` and is an individual selector.
358
- - (2) is tested next because it is an individual selector.
359
- - (4) is tested next as it is a grouped selector.
360
- - (1) is tested last as it is the base default selector.
361
-
362
- Its worth noting that whilst this order is applied, all selectors may not run on a name.
363
- This is explained in ["How does the rule evaluate a name's format?"](#how-does-the-rule-evaluate-a-names-format)
364
-
365
- ### How does the rule evaluate a name's format?
366
-
367
- When the format of an identifier is checked, it is checked in the following order:
368
-
369
- 1. validate leading underscore
370
- 1. validate trailing underscore
371
- 1. validate prefix
372
- 1. validate suffix
373
- 1. validate custom
374
- 1. validate format
375
-
376
- For steps 1-4, if the identifier matches the option, the matching part will be removed.
377
- This is done so that you can apply formats like PascalCase without worrying about prefixes or underscores causing it to not match.
378
-
379
- One final note is that if the name were to become empty via this trimming process, it is considered to match all `format`s. An example of where this might be useful is for generic type parameters, where you want all names to be prefixed with `T`, but also want to allow for the single character `T` name.
380
-
381
- Here are some examples to help illustrate
382
-
383
- Name: `_IMyInterface`
384
- Selector:
385
-
386
- ```json
387
- {
388
- "leadingUnderscore": "require",
389
- "prefix": ["I"],
390
- "format": ["UPPER_CASE", "StrictPascalCase"]
391
- }
392
- ```
393
-
394
- 1. `name = _IMyInterface`
395
- 1. validate leading underscore
396
- 1. config is provided
397
- 1. check name → pass
398
- 1. Trim underscore → `name = IMyInterface`
399
- 1. validate trailing underscore
400
- 1. config is not provided → skip
401
- 1. validate prefix
402
- 1. config is provided
403
- 1. check name → pass
404
- 1. Trim prefix → `name = MyInterface`
405
- 1. validate suffix
406
- 1. config is not provided → skip
407
- 1. validate custom
408
- 1. config is not provided → skip
409
- 1. validate format
410
- 1. for each format...
411
- 1. `format = 'UPPER_CASE'`
412
- 1. check format → fail.
413
- - Important to note that if you supply multiple formats - the name only needs to match _one_ of them!
414
- 1. `format = 'StrictPascalCase'`
415
- 1. check format → success.
416
- 1. **_success_**
417
-
418
- Name: `IMyInterface`
419
- Selector:
420
-
421
- ```json
422
- {
423
- "format": ["StrictPascalCase"],
424
- "trailingUnderscore": "allow",
425
- "custom": {
426
- "regex": "^I[A-Z]",
427
- "match": false
428
- }
429
- }
430
- ```
431
-
432
- 1. `name = IMyInterface`
433
- 1. validate leading underscore
434
- 1. config is not provided → skip
435
- 1. validate trailing underscore
436
- 1. config is provided
437
- 1. check name → pass
438
- 1. Trim underscore → `name = IMyInterface`
439
- 1. validate prefix
440
- 1. config is not provided → skip
441
- 1. validate suffix
442
- 1. config is not provided → skip
443
- 1. validate custom
444
- 1. config is provided
445
- 1. `regex = new RegExp("^I[A-Z]")`
446
- 1. `regex.test(name) === custom.match`
447
- 1. **_fail_** → report and exit
448
-
449
- ### What happens if I provide a `modifiers` to a Group Selector?
450
-
451
- Some group selectors accept `modifiers`. For the most part these will work exactly the same as with individual selectors.
452
- There is one exception to this in that a modifier might not apply to all individual selectors covered by a group selector.
453
-
454
- For example - `memberLike` includes the `enumMember` selector, and it allows the `protected` modifier.
455
- An `enumMember` can never ever be `protected`, which means that the following config will never match any `enumMember`:
456
-
457
- ```json
458
- {
459
- "selector": "memberLike",
460
- "modifiers": ["protected"]
461
- }
462
- ```
463
-
464
- To help with matching, members that cannot specify an accessibility will always have the `public` modifier. This means that the following config will always match any `enumMember`:
465
-
466
- ```json
467
- {
468
- "selector": "memberLike",
469
- "modifiers": ["public"]
470
- }
471
- ```
472
-
473
- ## Examples
474
-
475
- ### Enforce that all variables, functions and properties follow are camelCase
476
-
477
- ```json
478
- {
479
- "@typescript-eslint/naming-convention": [
480
- "error",
481
- { "selector": "variableLike", "format": ["camelCase"] }
482
- ]
483
- }
484
- ```
485
-
486
- ### Enforce that private members are prefixed with an underscore
487
-
488
- ```json
489
- {
490
- "@typescript-eslint/naming-convention": [
491
- "error",
492
- {
493
- "selector": "memberLike",
494
- "modifiers": ["private"],
495
- "format": ["camelCase"],
496
- "leadingUnderscore": "require"
497
- }
498
- ]
499
- }
500
- ```
501
-
502
- ### Enforce that boolean variables are prefixed with an allowed verb
503
-
504
- **Note:** As [documented above](#format-options), the prefix is trimmed before format is validated, thus PascalCase must be used to allow variables such as `isEnabled`.
505
-
506
- ```json
507
- {
508
- "@typescript-eslint/naming-convention": [
509
- "error",
510
- {
511
- "selector": "variable",
512
- "types": ["boolean"],
513
- "format": ["PascalCase"],
514
- "prefix": ["is", "should", "has", "can", "did", "will"]
515
- }
516
- ]
517
- }
518
- ```
519
-
520
- ### Enforce that all variables are either in camelCase or UPPER_CASE
521
-
522
- ```json
523
- {
524
- "@typescript-eslint/naming-convention": [
525
- "error",
526
- {
527
- "selector": "variable",
528
- "format": ["camelCase", "UPPER_CASE"]
529
- }
530
- ]
531
- }
532
- ```
533
-
534
- ### Enforce that all const variables are in UPPER_CASE
535
-
536
- ```json
537
- {
538
- "@typescript-eslint/naming-convention": [
539
- "error",
540
- {
541
- "selector": "variable",
542
- "modifiers": ["const"],
543
- "format": ["UPPER_CASE"]
544
- }
545
- ]
546
- }
547
- ```
548
-
549
- ### Enforce that type parameters (generics) are prefixed with `T`
550
-
551
- This allows you to emulate the old `generic-type-naming` rule.
552
-
553
- ```json
554
- {
555
- "@typescript-eslint/naming-convention": [
556
- "error",
557
- {
558
- "selector": "typeParameter",
559
- "format": ["PascalCase"],
560
- "prefix": ["T"]
561
- }
562
- ]
563
- }
564
- ```
565
-
566
- ### Enforce that interface names do not begin with an `I`
567
-
568
- This allows you to emulate the old `interface-name-prefix` rule.
569
-
570
- ```json
571
- {
572
- "@typescript-eslint/naming-convention": [
573
- "error",
574
- {
575
- "selector": "interface",
576
- "format": ["PascalCase"],
577
- "custom": {
578
- "regex": "^I[A-Z]",
579
- "match": false
580
- }
581
- }
582
- ]
583
- }
584
- ```
585
-
586
- ### Enforce that function names are either in camelCase or PascalCase
587
-
588
- Function names are typically camelCase, but UI library components (especially JSX, such as React and Solid) use PascalCase to distinguish them from intrinsic elements. If you are writing function components, consider allowing both camelCase and PascalCase for functions.
589
-
590
- ```json
591
- {
592
- "@typescript-eslint/naming-convention": [
593
- "error",
594
- {
595
- "selector": "function",
596
- "format": ["camelCase", "PascalCase"]
597
- }
598
- ]
599
- }
600
- ```
601
-
602
- ### Enforce that variable and function names are in camelCase
603
-
604
- This allows you to lint multiple type with same pattern.
605
-
606
- ```json
607
- {
608
- "@typescript-eslint/naming-convention": [
609
- "error",
610
- {
611
- "selector": ["variable", "function"],
612
- "format": ["camelCase"],
613
- "leadingUnderscore": "allow"
614
- }
615
- ]
616
- }
617
- ```
618
-
619
- ### Ignore properties that **_require_** quotes
620
-
621
- Sometimes you have to use a quoted name that breaks the convention (for example, HTTP headers).
622
- If this is a common thing in your codebase, then you have a few options.
623
-
624
- If you simply want to allow all property names that require quotes, you can use the `requiresQuotes` modifier to match any property name that _requires_ quoting, and use `format: null` to ignore the name.
625
-
626
- ```jsonc
627
- {
628
- "@typescript-eslint/naming-convention": [
629
- "error",
630
- {
631
- "selector": [
632
- "classProperty",
633
- "objectLiteralProperty",
634
- "typeProperty",
635
- "classMethod",
636
- "objectLiteralMethod",
637
- "typeMethod",
638
- "accessor",
639
- "enumMember",
640
- ],
641
- "format": null,
642
- "modifiers": ["requiresQuotes"],
643
- },
644
- ],
645
- }
646
- ```
647
-
648
- If you have a small and known list of exceptions, you can use the `filter` option to ignore these specific names only:
649
-
650
- ```jsonc
651
- {
652
- "@typescript-eslint/naming-convention": [
653
- "error",
654
- {
655
- "selector": "property",
656
- "format": ["strictCamelCase"],
657
- "filter": {
658
- // you can expand this regex to add more allowed names
659
- "regex": "^(Property-Name-One|Property-Name-Two)$",
660
- "match": false,
661
- },
662
- },
663
- ],
664
- }
665
- ```
666
-
667
- You can use the `filter` option to ignore names with specific characters:
668
-
669
- ```jsonc
670
- {
671
- "@typescript-eslint/naming-convention": [
672
- "error",
673
- {
674
- "selector": "property",
675
- "format": ["strictCamelCase"],
676
- "filter": {
677
- // you can expand this regex as you find more cases that require quoting that you want to allow
678
- "regex": "[- ]",
679
- "match": false,
680
- },
681
- },
682
- ],
683
- }
684
- ```
685
-
686
- Note that there is no way to ignore any name that is quoted - only names that are required to be quoted.
687
- This is intentional - adding quotes around a name is not an escape hatch for proper naming.
688
- If you want an escape hatch for a specific name - you should can use an [`eslint-disable` comment](https://eslint.org/docs/user-guide/configuring#disabling-rules-with-inline-comments).
689
-
690
- ### Ignore destructured names
691
-
692
- Sometimes you might want to allow destructured properties to retain their original name, even if it breaks your naming convention.
693
-
694
- You can use the `destructured` modifier to match these names, and explicitly set `format: null` to apply no formatting:
695
-
696
- ```jsonc
697
- {
698
- "@typescript-eslint/naming-convention": [
699
- "error",
700
- {
701
- "selector": "variable",
702
- "modifiers": ["destructured"],
703
- "format": null,
704
- },
705
- ],
706
- }
707
- ```
708
-
709
- ### Enforce the codebase follows ESLint's `camelcase` conventions
710
-
711
- ```json
712
- {
713
- "camelcase": "off",
714
- "@typescript-eslint/naming-convention": [
715
- "error",
716
- {
717
- "selector": "default",
718
- "format": ["camelCase"]
719
- },
720
-
721
- {
722
- "selector": "variable",
723
- "format": ["camelCase", "UPPER_CASE"]
724
- },
725
- {
726
- "selector": "parameter",
727
- "format": ["camelCase"],
728
- "leadingUnderscore": "allow"
729
- },
730
-
731
- {
732
- "selector": "memberLike",
733
- "modifiers": ["private"],
734
- "format": ["camelCase"],
735
- "leadingUnderscore": "require"
736
- },
737
-
738
- {
739
- "selector": "typeLike",
740
- "format": ["PascalCase"]
741
- }
742
- ]
743
- }
744
- ```
745
-
746
- ## When Not To Use It
747
-
748
- This rule can be very strict.
749
- If you don't have strong needs for enforcing naming conventions, we recommend using it only to flag very egregious violations of your naming standards.
750
- Consider documenting your naming conventions and enforcing them in code review if you have processes like that.
751
-
752
- If you do not want to enforce naming conventions for anything, you can disable this rule.
753
-
754
- However, keep in mind that inconsistent style can harm readability in a project.
755
- We recommend that if you care about naming conventions, pick a single option for this rule that works best for your project.