Skip to content

Commit 1e167cf

Browse files
authored
feat: add ignoreWords parameter to folder-naming-convention rule (#59)
* feat: add skipWords parameter * fix: rollback package-lock.json
1 parent 59d9844 commit 1e167cf

File tree

4 files changed

+144
-0
lines changed

4 files changed

+144
-0
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,

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+
);

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

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

0 commit comments

Comments
 (0)