You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(eslint-plugin): [naming-convention] split property and method selectors into more granular classXXX, objectLiteralXXX, typeXXX
Fixes#1477Closes#2802
This allows users to target different types of properties differently.
Adds the following selectors (self explanatory - just breaking the selectors up):
- `classProperty`
- `objectLiteralProperty`
- `typeProperty`
- `classMethod`
- `objectLiteralMethod`
- `typeMethod`
Converts
- `property` to a meta selector for `classProperty`, `objectLiteralProperty`, `typeProperty`
- `method` to a meta selector for `classMethod`, `objectLiteralMethod`, `typeMethod`
Copy file name to clipboardExpand all lines: packages/eslint-plugin/docs/rules/naming-convention.md
+32-8
Original file line number
Diff line number
Diff line change
@@ -154,21 +154,27 @@ If these are provided, the identifier must start with one of the provided values
154
154
155
155
### Selector Options
156
156
157
-
-`selector`(see "Allowed Selectors, Modifiers and Types" below).
157
+
-`selector`allows you to specify what types of identifiers to target.
158
158
- Accepts one or array of selectors to define an option block that applies to one or multiple selectors.
159
159
- For example, if you provide `{ selector: ['variable', 'function'] }`, then it will apply the same option to variable and function nodes.
160
+
- See [Allowed Selectors, Modifiers and Types](#allowed-selectors-modifiers-and-types) below for the complete list of allowed selectors.
160
161
-`modifiers` allows you to specify which modifiers to granularly apply to, such as the accessibility (`private`/`public`/`protected`), or if the thing is `static`, etc.
161
162
- The name must match _all_ of the modifiers.
162
163
- For example, if you provide `{ modifiers: ['private', 'static', 'readonly'] }`, then it will only match something that is `private static readonly`, and something that is just `private` will not match.
164
+
- The following `modifiers` are allowed:
165
+
-`const` - matches a variable declared as being `const` (`const x = 1`).
166
+
-`public` - matches any member that is either explicitly declared as `public`, or has no visibility modifier (i.e. implicitly public).
167
+
-`readonly`, `static`, `abstract`, `protected`, `private` - matches any member explicitly declared with the given modifier.
163
168
-`types` allows you to specify which types to match. This option supports simple, primitive types only (`boolean`, `string`, `number`, `array`, `function`).
164
169
- The name must match _one_ of the types.
165
170
-**_NOTE - Using this option will require that you lint with type information._**
166
171
- For example, this lets you do things like enforce that `boolean` variables are prefixed with a verb.
167
-
-`boolean` matches any type assignable to `boolean | null | undefined`
168
-
-`string` matches any type assignable to `string | null | undefined`
169
-
-`number` matches any type assignable to `number | null | undefined`
170
-
-`array` matches any type assignable to `Array<unknown> | null | undefined`
171
-
-`function` matches any type assignable to `Function | null | undefined`
172
+
- The following `types` are allowed:
173
+
-`boolean` matches any type assignable to `boolean | null | undefined`
174
+
-`string` matches any type assignable to `string | null | undefined`
175
+
-`number` matches any type assignable to `number | null | undefined`
176
+
-`array` matches any type assignable to `Array<unknown> | null | undefined`
177
+
-`function` matches any type assignable to `Function | null | undefined`
172
178
173
179
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.
174
180
@@ -202,13 +208,25 @@ Individual Selectors match specific, well-defined sets. There is no overlap betw
202
208
-`parameter` - matches any function parameter. Does not match parameter properties.
-`property` - matches any object, class, or object type property. Does not match properties that have direct function expression or arrow function expression values.
211
+
-`classProperty` - matches any class property. Does not match properties that have direct function expression or arrow function expression values.
-`objectLiteralProperty` - matches any object literal property. Does not match properties that have direct function expression or arrow function expression values.
-`typeProperty` - matches any object type property. Does not match properties that have direct function expression or arrow function expression values.
-`method` - matches any object, class, or object type method. Also matches properties that have direct function expression or arrow function expression values. Does not match accessors.
223
+
-`classMethod` - matches any class method. Also matches properties that have direct function expression or arrow function expression values. Does not match accessors.
-`objectLiteralMethod` - matches any object literal method. Also matches properties that have direct function expression or arrow function expression values. Does not match accessors.
-`typeMethod` - matches any object type method. Also matches properties that have direct function expression or arrow function expression values. Does not match accessors.
0 commit comments