Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f7a9cb2

Browse files
committed
docs: typos and restructure a bit
1 parent 8acf037 commit f7a9cb2

File tree

1 file changed

+36
-26
lines changed

1 file changed

+36
-26
lines changed

packages/eslint-plugin/docs/rules/naming-convention.md

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ There are many different rules that have existed over time, but they have had th
1010
This rule allows you to enforce conventions for any identifier, using granular selectors to create a fine-grained style guide.
1111
By default, it enforces nothing.
1212

13-
### Note - this rule only needs type information in specfic cases, detailed below
13+
### Note - this rule only needs type information in specific cases, detailed below
1414

1515
## Options
1616

@@ -35,9 +35,10 @@ type Options = {
3535

3636
// selector options
3737
selector: Selector;
38+
filter?: string;
39+
// the allowed values for these are dependent on the selector - see below
3840
modifiers?: Modifiers<Selector>[];
3941
types?: Types<Selector>[];
40-
filter?: string;
4142
}[];
4243

4344
const defaultOptions: Options = [];
@@ -54,7 +55,7 @@ When the format of an identifier is checked, it is checked in the following orde
5455
1. validate suffix
5556
1. validate format
5657

57-
At each step, if the identifier matches the options, it the matching part will be removed.
58+
At each step, if the identifier matches the option, the matching part will be removed.
5859
For example, if you provide the following formating option: `{ leadingUnderscore: 'allow', prefix: ['I'], format: ['StrictPascalCase'] }`, for the identifier `_IMyInterface`, then the following checks will occur:
5960

6061
1. `name = _IMyInterface`
@@ -66,6 +67,8 @@ For example, if you provide the following formating option: `{ leadingUnderscore
6667
1. validate suffix - no check
6768
1. validate format - pass
6869

70+
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.
71+
6972
#### `format`
7073

7174
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:
@@ -83,7 +86,7 @@ The `leadingUnderscore` / `trailingUnderscore` options control whether leading/t
8386

8487
- `forbid` - a leading/trailing underscore is not allowed at all.
8588
- `allow` - existence of a leading/trailing underscore is not explicitly enforced.
86-
- `require` - a leading/trailing underscores must be included.
89+
- `require` - a leading/trailing underscore must be included.
8790

8891
#### `prefix` / `suffix`
8992

@@ -93,20 +96,40 @@ If these are provided, the identifier must start with one of the provided values
9396

9497
### Selector Options
9598

96-
The selector options determine which names that the formatting options will apply to.
97-
Each value for `selector` has a set of `types` and `modifiers` that are allowed to be used with it, which are explained below.
99+
- `selector` (see "Allowed Selectors, Modifiers and Types" below).
100+
- `filter` accepts a regular expression (anything accepted into `new RegExp(filter)`). It allows you to limit the scope of this configuration to names that match this regex.
101+
- `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.
102+
- The name must match _all_ of the modifiers.
103+
- 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.
104+
- `types` allows you to specify which types to match. This option supports simple, primitive types only (`boolean`, `string`, `number`, `array`, `function`). This lets you do things like enforce that `boolean` variables are prefixed with a verb.
105+
- **_NOTE - Using this option will require that you lint with type information._**
106+
- `boolean` matches any type assignable to `boolean | null | undefined`
107+
- `string` matches any type assignable to `string | null | undefined`
108+
- `number` matches any type assignable to `number | null | undefined`
109+
- `array` matches any type assignable to `Array<unknown> | null | undefined`
110+
- `function` matches any type asignable to `Function | null | undefined`
98111

99-
`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. The name must match _all_ of the modifiers. 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.
112+
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.
100113

101-
`types` allows you to specify which types to match. This option supports simple, primitive types only (`boolean`, `string`, `number`, `function`, `array`). This lets you do things like enforce that `boolean` variables are prefixed with a verb.
102-
**_NOTE - Using this option will require that you lint with type information._**
114+
For example, if you provide the following config:
103115

104-
`filter` accepts a regular expression (anything accepted into `new RegExp(filter)`). It allows you to limit the scope of this configuration to names that match this regex.
116+
```ts
117+
[
118+
/* 1 */ { selector: 'default', format: ['camelCase'] },
119+
/* 2 */ { selector: 'variable', format: ['snake_case'] },
120+
/* 3 */ { selector: 'variable', type: ['boolean'], format: ['UPPER_CASE'] },
121+
/* 4 */ { selector: 'variableLike', format: ['PascalCase'] },
122+
];
123+
```
124+
125+
Then for the code `const x = 1`, the rule will validate the selectors in the following order: `3`, `2`, `4`, `1`.
105126

106-
#### Allowed Selectors
127+
#### Allowed Selectors, Modifiers and Types
107128

108129
There are two types of selectors, individual selectors, and grouped selectors.
109130

131+
##### Individual Selectors
132+
110133
Individual Selectors match specific, well-defined sets. There is no overlap between each of the individual selectors.
111134

112135
- `variable` - matches any `var` / `let` / `const` variable name.
@@ -149,6 +172,8 @@ Individual Selectors match specific, well-defined sets. There is no overlap betw
149172
- Allowed `modifiers`: none.
150173
- Allowed `types`: none.
151174

175+
##### Group Selectors
176+
152177
Group Selectors are provided for convenience, and essentially bundle up sets of individual selectors.
153178

154179
- `default` - matches everything.
@@ -164,21 +189,6 @@ Group Selectors are provided for convenience, and essentially bundle up sets of
164189
- Allowed `modifiers`: `abstract`.
165190
- Allowed `types`: none.
166191

167-
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.
168-
169-
For example, if you provide the following config:
170-
171-
```ts
172-
[
173-
/* 1 */ { selector: 'default', format: ['camelCase'] },
174-
/* 2 */ { selector: 'variable', format: ['snake_case'] },
175-
/* 3 */ { selector: 'variable', type: ['boolean'], format: ['UPPER_CASE'] },
176-
/* 4 */ { selector: 'variableLike', format: ['PascalCase'] },
177-
];
178-
```
179-
180-
Then the rule will validate the selectors in the following order: `3`, `2`, `4`, `1`.
181-
182192
## When Not To Use It
183193

184194
If you do not want to enforce naming conventions for anything.

0 commit comments

Comments
 (0)