Skip to content

Commit 10ce27b

Browse files
committed
feat: add skipWords parameter
1 parent 59d9844 commit 10ce27b

File tree

5 files changed

+222
-44
lines changed

5 files changed

+222
-44
lines changed

docs/rules/folder-naming-convention.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,36 @@ Customizes the error message displayed when a folder does not match the naming p
113113
- `{{ target }}`: Represents the target folder.
114114
- `{{ pattern }}`: Represents the naming pattern for the target folder.
115115

116+
##### `ignoreWords`
117+
118+
An array of folder names to ignore during naming convention validation. Folders whose names exactly match any string in this array will be skipped and not validated against the naming pattern.
119+
120+
```js
121+
export default [
122+
{
123+
plugins: {
124+
'check-file': checkFile,
125+
},
126+
rules: {
127+
'check-file/folder-naming-convention': [
128+
'error',
129+
{
130+
'src/**/': 'CAMEL_CASE',
131+
'mocks/*/': 'KEBAB_CASE',
132+
},
133+
{
134+
errorMessage:
135+
'The folder "{{ target }}" does not match the "{{ pattern }}" pattern, see contribute.md for details',
136+
ignoreWords: ['skip_word_a', 'skip_word_b'],
137+
},
138+
],
139+
},
140+
},
141+
];
142+
```
143+
144+
With this configuration, folders named `skip_word_a` or `skip_word_b` will not be validated against the naming pattern, allowing paths like `mocks/skip_word_a/app-mock.ts` to pass validation even though `skip_word_a` doesn't follow the `KEBAB_CASE` pattern.
145+
116146
```js
117147
export default [
118148
{

lib/rules/folder-naming-convention.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ export default {
4848
type: 'object',
4949
properties: {
5050
errorMessage: { type: 'string' },
51+
ignoreWords: {
52+
type: 'array',
53+
items: { type: 'string' },
54+
},
5155
},
5256
},
5357
],
@@ -81,6 +85,7 @@ export default {
8185
const filenameWithPath = getFilePath(context);
8286
const folderPath = getFolderPath(filenameWithPath);
8387
const errorMessage = context.options[1]?.errorMessage ?? '';
88+
const ignoreWords = context.options[1]?.ignoreWords ?? [];
8489

8590
for (const [folderPattern, namingPattern] of Object.entries(rules)) {
8691
if (
@@ -100,6 +105,11 @@ export default {
100105
.reduce((s, p) => s.concat(getAllFolders(p)), []);
101106

102107
for (const folder of folders) {
108+
// Skip validation if the folder name is in the ignore list
109+
if (ignoreWords.includes(folder)) {
110+
continue;
111+
}
112+
103113
if (
104114
!micromatch.isMatch(
105115
folder,

package-lock.json

Lines changed: 78 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/lib/rules/folder-naming-convention.posix.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,3 +659,55 @@ ruleTester.run(
659659
],
660660
}
661661
);
662+
663+
ruleTester.run(
664+
"folder-naming-convention with option: [{ 'mocks/**/': 'KEBAB_CASE' }, { ignoreWords: ['skip_word_a', 'skip_word_b'] }]",
665+
rule,
666+
{
667+
valid: [
668+
{
669+
code: "var foo = 'bar';",
670+
filename: 'mocks/skip_word_a/app-mock.ts',
671+
options: [
672+
{ 'mocks/**/': 'KEBAB_CASE' },
673+
{ ignoreWords: ['skip_word_a', 'skip_word_b'] },
674+
],
675+
},
676+
{
677+
code: "var foo = 'bar';",
678+
filename: 'mocks/skip_word_b/another-mock.ts',
679+
options: [
680+
{ 'mocks/**/': 'KEBAB_CASE' },
681+
{ ignoreWords: ['skip_word_a', 'skip_word_b'] },
682+
],
683+
},
684+
{
685+
code: "var foo = 'bar';",
686+
filename: 'mocks/valid-kebab-case/mock.ts',
687+
options: [
688+
{ 'mocks/**/': 'KEBAB_CASE' },
689+
{ ignoreWords: ['skip_word_a', 'skip_word_b'] },
690+
],
691+
},
692+
],
693+
694+
invalid: [
695+
{
696+
code: "var foo = 'bar';",
697+
filename: 'mocks/InvalidCamelCase/mock.ts',
698+
options: [
699+
{ 'mocks/**/': 'KEBAB_CASE' },
700+
{ ignoreWords: ['skip_word_a', 'skip_word_b'] },
701+
],
702+
errors: [
703+
{
704+
message:
705+
'The folder "InvalidCamelCase" does not match the "KEBAB_CASE" pattern',
706+
column: 1,
707+
line: 1,
708+
},
709+
],
710+
},
711+
],
712+
}
713+
);

0 commit comments

Comments
 (0)