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
Copy file name to clipboardExpand all lines: docs/rules/folder-naming-convention.md
+37-3Lines changed: 37 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -8,9 +8,7 @@ This rule aims to format the name of the specified folder. This rule uses the gl
8
8
9
9
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`.
10
10
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).
14
12
15
13
| Formatting | Name |
16
14
| ----------- | ---------------------- |
@@ -43,6 +41,8 @@ Examples of **correct** folder name for this rule:
43
41
src/components/displayLabel/displayLabel.js
44
42
```
45
43
44
+
## Custom patterns
45
+
46
46
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 `__`:
47
47
48
48
```js
@@ -53,6 +53,40 @@ In addition to the built-in naming conventions, you can also set custom naming p
53
53
54
54
**Tip:** To exclude `__tests__` folder in `src`, use the glob expression `src/!(__tests__)/**/` to get the target folders.
55
55
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.
0 commit comments