Skip to content

Commit 0804431

Browse files
committed
feat(#23): only rule folder-naming-convention support NEXT_JS_APP_ROUTER_CASE
1 parent 7e8a0af commit 0804431

File tree

4 files changed

+75
-50
lines changed

4 files changed

+75
-50
lines changed

lib/constants/naming-convention.js

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -34,42 +34,11 @@ const SCREAMING_SNAKE_CASE = '+([A-Z])*([A-Z0-9])*(_+([A-Z0-9]))';
3434
*/
3535
const FLAT_CASE = '+([a-z0-9])';
3636

37-
/**
38-
* @example [helpPageId]
39-
*/
40-
const NEXTJS_DYNAMIC_SEGMENTS = `\\[${CAMEL_CASE}\\]`;
41-
42-
/**
43-
* @example [...auth]
44-
*/
45-
const NEXTJS_CATCH_ALL_SEGMENTS = `\\[...${CAMEL_CASE}\\]`;
46-
47-
/**
48-
* @example [[...auth]]
49-
*/
50-
const NEXTJS_OPTIONAL_CATCH_ALL_SEGMENTS = `\\[\\[...${CAMEL_CASE}\\]\\]`;
51-
52-
/**
53-
* @example (auth)
54-
*/
55-
const NEXTJS_ROUTE_GROUPS = `\\(${KEBAB_CASE}\\)`;
56-
57-
/**
58-
* @example \@feed
59-
*/
60-
const NEXTJS_NAMED_SLOTS = `\\@${KEBAB_CASE}`;
61-
62-
/**
63-
* @example app, [helpPageId], [...auth], [[...auth]], (auth), \@feed
64-
*/
65-
const NEXT_JS_APP_ROUTER_CASE = `@(${KEBAB_CASE}|${NEXTJS_DYNAMIC_SEGMENTS}|${NEXTJS_CATCH_ALL_SEGMENTS}|${NEXTJS_OPTIONAL_CATCH_ALL_SEGMENTS}|${NEXTJS_ROUTE_GROUPS}|${NEXTJS_NAMED_SLOTS})`;
66-
6737
module.exports = {
6838
CAMEL_CASE,
6939
PASCAL_CASE,
7040
SNAKE_CASE,
7141
KEBAB_CASE,
7242
SCREAMING_SNAKE_CASE,
7343
FLAT_CASE,
74-
NEXT_JS_APP_ROUTER_CASE,
7544
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* @file Built in next js app router naming convention
3+
* @author Huan Luo
4+
*/
5+
'use strict';
6+
7+
const { CAMEL_CASE, KEBAB_CASE } = require('./naming-convention');
8+
9+
/**
10+
* @example [helpPageId]
11+
*/
12+
const NEXT_JS_DYNAMIC_SEGMENTS = `\\[${CAMEL_CASE}\\]`;
13+
14+
/**
15+
* @example [...auth]
16+
*/
17+
const NEXT_JS_CATCH_ALL_SEGMENTS = `\\[...${CAMEL_CASE}\\]`;
18+
19+
/**
20+
* @example [[...auth]]
21+
*/
22+
const NEXT_JS_OPTIONAL_CATCH_ALL_SEGMENTS = `\\[\\[...${CAMEL_CASE}\\]\\]`;
23+
24+
/**
25+
* @example (auth)
26+
*/
27+
const NEXT_JS_ROUTE_GROUPS = `\\(${KEBAB_CASE}\\)`;
28+
29+
/**
30+
* @example \@feed
31+
*/
32+
const NEXT_JS_NAMED_SLOTS = `\\@${KEBAB_CASE}`;
33+
34+
/**
35+
* @example app, [helpPageId], [...auth], [[...auth]], (auth), \@feed
36+
*/
37+
const NEXT_JS_APP_ROUTER_CASE = `@(${KEBAB_CASE}|${NEXT_JS_DYNAMIC_SEGMENTS}|${NEXT_JS_CATCH_ALL_SEGMENTS}|${NEXT_JS_OPTIONAL_CATCH_ALL_SEGMENTS}|${NEXT_JS_ROUTE_GROUPS}|${NEXT_JS_NAMED_SLOTS})`;
38+
39+
module.exports = {
40+
NEXT_JS_APP_ROUTER_CASE,
41+
};

lib/rules/folder-naming-convention.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ const {
1313
} = require('../utils/filename');
1414
const {
1515
validateNamingPatternObject,
16-
namingPatternValidator,
1716
globPatternValidator,
17+
folderNamingPatternValidator,
1818
} = require('../utils/validation');
1919
const { getDocUrl } = require('../utils/doc');
2020
const { isNotEmpty, isNil } = require('../utils/utility');
21-
const NAMING_CONVENTION = require('../constants/naming-convention');
21+
const BASIC_NAMING_CONVENTION = require('../constants/naming-convention');
22+
const NEXT_JS_NAMING_CONVENTION = require('../constants/next-js-naming-convention');
2223
const {
2324
FOLDER_NAMING_CONVENTION_ERROR_MESSAGE,
2425
} = require('../constants/message');
@@ -52,7 +53,7 @@ module.exports = {
5253
const message = validateNamingPatternObject(
5354
rules,
5455
globPatternValidator,
55-
namingPatternValidator
56+
folderNamingPatternValidator
5657
);
5758

5859
if (message) {
@@ -87,7 +88,9 @@ module.exports = {
8788
if (
8889
!micromatch.isMatch(
8990
folder,
90-
NAMING_CONVENTION[namingPattern] || namingPattern
91+
BASIC_NAMING_CONVENTION[namingPattern] ||
92+
NEXT_JS_NAMING_CONVENTION[namingPattern] ||
93+
namingPattern
9194
)
9295
) {
9396
context.report({

lib/utils/validation.js

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
'use strict';
66

77
const isGlob = require('is-glob');
8-
const NAMING_CONVENTION = require('../constants/naming-convention');
8+
const BASIC_NAMING_CONVENTION = require('../constants/naming-convention');
9+
const NEXT_JS_NAMING_CONVENTION = require('../constants/next-js-naming-convention');
910
const { PREFINED_MATCH_SYNTAX_REGEXP } = require('../constants/regex');
1011
const { isObject } = require('./utility');
1112
const {
@@ -42,32 +43,43 @@ const validateNamingPatternObject = (config, keyValidator, valueValidator) => {
4243
* @returns {boolean} true if pattern is a valid naming pattern
4344
* @param {string} namingPattern pattern string
4445
*/
45-
const namingPatternValidator = (namingPattern) => {
46-
const buildInPatterns = Object.keys(NAMING_CONVENTION);
47-
48-
return isGlob(namingPattern) || buildInPatterns.includes(namingPattern);
49-
};
46+
const basicNamingPatternValidator = (namingPattern) =>
47+
Object.keys(BASIC_NAMING_CONVENTION).includes(namingPattern);
5048

5149
/**
52-
* @returns {boolean} true if pattern is a valid filename naming pattern
50+
* @returns {boolean} true if pattern is a valid naming pattern
5351
* @param {string} namingPattern pattern string
5452
*/
55-
const filenameNamingPatternValidator = (namingPattern) => {
56-
return (
57-
namingPatternValidator(namingPattern) ||
58-
PREFINED_MATCH_SYNTAX_REGEXP.test(namingPattern)
59-
);
60-
};
53+
const nextJsNamingPatternValidator = (namingPattern) =>
54+
Object.keys(NEXT_JS_NAMING_CONVENTION).includes(namingPattern);
6155

6256
/**
6357
* @returns {boolean} true if pattern is a valid glob pattern
6458
* @param {string} pattern pattern string
6559
*/
6660
const globPatternValidator = isGlob;
6761

62+
/**
63+
* @returns {boolean} true if pattern is a valid filename naming pattern
64+
* @param {string} namingPattern pattern string
65+
*/
66+
const filenameNamingPatternValidator = (namingPattern) =>
67+
globPatternValidator(namingPattern) ||
68+
basicNamingPatternValidator(namingPattern) ||
69+
PREFINED_MATCH_SYNTAX_REGEXP.test(namingPattern);
70+
71+
/**
72+
* @returns {boolean} true if pattern is a valid filename naming pattern
73+
* @param {string} namingPattern pattern string
74+
*/
75+
const folderNamingPatternValidator = (namingPattern) =>
76+
globPatternValidator(namingPattern) ||
77+
basicNamingPatternValidator(namingPattern) ||
78+
nextJsNamingPatternValidator(namingPattern);
79+
6880
module.exports = {
6981
validateNamingPatternObject,
70-
namingPatternValidator,
71-
filenameNamingPatternValidator,
7282
globPatternValidator,
83+
filenameNamingPatternValidator,
84+
folderNamingPatternValidator,
7385
};

0 commit comments

Comments
 (0)