Skip to content

Commit 2145e0e

Browse files
committed
docs: add docs for folder-naming-convention rule
1 parent f5caa66 commit 2145e0e

File tree

2 files changed

+57
-15
lines changed

2 files changed

+57
-15
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,17 @@ Then configure the rules you want to use under the rules section.
4646
"error",
4747
{
4848
"*.{jsx,tsx}":"CAMEL_CASE",
49-
"*.{js,ts}":"KEBAB_CASE",
49+
"*.{js,ts}":"KEBAB_CASE"
5050
}
5151
],
52-
"check-file/no-index":"error"
52+
"check-file/no-index":"error",
53+
"check-file/folder-naming-convention":[
54+
"error",
55+
{
56+
"src/**/":"CAMEL_CASE",
57+
"mocks/*/":"KEBAB_CASE"
58+
}
59+
]
5360
}
5461
}
5562
```
@@ -59,3 +66,4 @@ Then configure the rules you want to use under the rules section.
5966
- [check-file/folder-match-with-fex](docs/rules/folder-match-with-fex.md): Enforce a consistent naming pattern for the folder of the specified file extension
6067
- [check-file/filename-naming-convention](docs/rules/filename-naming-convention.md): Enforce a consistent naming pattern for the filename of the specified file extension
6168
- [check-file/no-index](docs/rules/no-index.md): A file cannot be named "index"
69+
- [check-file/folder-naming-convention](docs/rules/folder-naming-convention.md): Enforce a consistent naming pattern for the name of the specified folder
Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,69 @@
11
# The folder should follow the folder naming convention (folder-naming-convention)
22

3-
Please describe the origin of the rule here.
3+
Allows you to enforce a consistent naming pattern for the name of the specified folder.
44

55
## Rule Details
66

7-
This rule aims to...
7+
This rule aims to format the name of the specified folder. This rule uses the glob match syntax to match a folder and declare the naming pattern for the name.
88

9-
Examples of **incorrect** code for this rule:
9+
There are six naming conventions built into this rule, including `CAMEL_CASE`, `PASCAL_CASE`, `SNAKE_CASE`, `KEBAB_CASE`, `SCREAMING_SNAKE_CASE` and `FLAT_CASE`.
1010

11+
| Formatting | Name |
12+
|---|---|
13+
| helloWorld | `CAMEL_CASE` |
14+
| HelloWorld | `PASCAL_CASE` |
15+
| hello_world | `SNAKE_CASE` |
16+
| hello-world | `KEBAB_CASE` |
17+
| HELLO_WORLD | `SCREAMING_SNAKE_CASE` |
18+
| helloworld | `FLAT_CASE` |
19+
20+
If the rule had been set as follows:
1121
```js
22+
...
23+
'check-file/folder-naming-convention': ['error', { 'src/**/': 'CAMEL_CASE' }],
24+
...
25+
```
1226

13-
// fill me in
27+
Examples of **incorrect** folder name for this rule:
1428

29+
```sh
30+
src/Components/DisplayLabel/displayLabel.js
31+
src/components/DisplayLabel/displayLabel.js
32+
src/components/displayLabel/DisplayLabel.js
1533
```
1634

17-
Examples of **correct** code for this rule:
35+
Examples of **correct** folder name for this rule:
1836

19-
```js
20-
21-
// fill me in
37+
```sh
38+
src/components/displayLabel/displayLabel.js
39+
```
2240

41+
In addition to the built-in naming conventions, you can also set custom naming patterns using glob match syntax. The following code shows an example of how to ensure that all the folders under the `components` folder are named begin with `__`:
42+
```js
43+
...
44+
'check-file/folder-naming-convention': ['error', [{ 'components/*/': '__+([a-z])' }]],
45+
...
2346
```
2447

2548
### Options
2649

27-
If there are any options, describe them here. Otherwise, delete this section.
28-
29-
## When Not To Use It
50+
You need to specify a different naming pattern for different folder. The plugin will only check folders you explicitly provided:
3051

31-
Give a short description of when it would be appropriate to turn off this rule.
52+
```js
53+
module.exports = {
54+
plugins: [
55+
'check-file',
56+
],
57+
rules: {
58+
'check-file/folder-naming-convention': ['error', {
59+
'src/**/': 'CAMEL_CASE',
60+
'mocks/*/': 'KEBAB_CASE',
61+
}],
62+
},
63+
};
64+
```
3265

3366
## Further Reading
3467

35-
If there are other links that describe the issue this rule addresses, please include them here in a bulleted list.
68+
- [micromatch](https://github.com/micromatch/micromatch)
69+
- [glob](https://en.wikipedia.org/wiki/Glob_(programming))

0 commit comments

Comments
 (0)