Skip to content

Commit bc1d546

Browse files
docs: add next.js example for the rule folder-naming-convention
* add next.js example * update the README file with the new pattern * merge all info regarding the new pattern * remove redundant newline
1 parent bc4f6ec commit bc1d546

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

docs/rules/folder-naming-convention.md

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ This rule aims to format the name of the specified folder. This rule uses the gl
88

99
There are six basic naming conventions built into this rule, including `CAMEL_CASE`, `PASCAL_CASE`, `SNAKE_CASE`, `KEBAB_CASE`, `SCREAMING_SNAKE_CASE` and `FLAT_CASE`.
1010

11-
**Additionally, there is a naming convention called `NEXT_JS_APP_ROUTER_CASE` used to format folder names in Next.js projects that used App Router.** `NEXT_JS_APP_ROUTER_CASE` aims to support a wide range of named constructs in Next.js App Router projects, including Standard routes, Dynamic segments, Catch-all segments, Optional Catch-all Segments, Route groups, and Named slots.
12-
13-
While `NEXT_JS_APP_ROUTER_CASE` covers many naming cases, it's possible that some cases may be missing. If you come across any missing cases, I encourage you to open an issue and provide the necessary details. Your feedback will help me improve and enhance the naming convention.
11+
Additionally, there is a naming convention called `NEXT_JS_APP_ROUTER_CASE` used to format folder names in Next.js projects that use the App Router. You can read more about it under [Built-in custom patterns](#built-in-custom-patterns).
1412

1513
| Formatting | Name |
1614
| ----------- | ---------------------- |
@@ -43,6 +41,8 @@ Examples of **correct** folder name for this rule:
4341
src/components/displayLabel/displayLabel.js
4442
```
4543

44+
## Custom patterns
45+
4646
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 `__`:
4747

4848
```js
@@ -53,6 +53,40 @@ In addition to the built-in naming conventions, you can also set custom naming p
5353

5454
**Tip:** To exclude `__tests__` folder in `src`, use the glob expression `src/!(__tests__)/**/` to get the target folders.
5555

56+
## Built-in custom patterns
57+
58+
Some patterns are complex enough that they warrant their own definition within the lib.
59+
60+
### Next.js custom pattern
61+
62+
The `NEXT_JS_APP_ROUTER_CASE` aims to support a wide range of named constructs in Next.js App Router projects.
63+
64+
If you would like to enforce a kebab-case naming convention for your folders, but also support Next.js' Standard routes, Dynamic segments, Catch-all segments, Optional Catch-all Segments, Route groups, and Named slots, this pattern is for you.
65+
66+
When using the pattern, all your folders need to be kebab-cased, but you can also do dynamic segments with camel case, so that it flows more natural with the code, i.e.
67+
68+
```
69+
/src/app/help-pages/[pageId]
70+
```
71+
72+
This is powerful because it allows you to have consistent link names, i.e. the links will be kebab cased, which is the most natural way of naming URL path segments.
73+
74+
But when you get in code and the dynamic segment needs to be passed to your component, you'll have a camel cased variable, i.e.
75+
76+
```
77+
// /src/app/help-pages/[pageId]/page.tsx
78+
79+
// If we have named our parameter "page-id", then you'd get "page-id" inside of
80+
// the params object, and you'd have to escape it, which would look nasty
81+
export const Page({ params: { pageId } }) { ... }
82+
```
83+
84+
Besides this, the custom pattern should support all other Next.js naming conventions.
85+
86+
You can read more about them [here](https://github.com/DukeLuo/eslint-plugin-check-file/pull/27#issuecomment-1582551071).
87+
88+
While `NEXT_JS_APP_ROUTER_CASE` covers many naming cases, it's possible that some cases may be missing. If you come across any missing cases, I encourage you to open an issue and provide the necessary details. Your feedback will help me improve and enhance the naming convention.
89+
5690
### Options
5791

5892
#### naming pattern object

0 commit comments

Comments
 (0)