Skip to content

feat: Add ignoreWords parameter to folder-naming-convention rule #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions docs/rules/folder-naming-convention.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,36 @@ Customizes the error message displayed when a folder does not match the naming p
- `{{ target }}`: Represents the target folder.
- `{{ pattern }}`: Represents the naming pattern for the target folder.

##### `ignoreWords`

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.

```js
export default [
{
plugins: {
'check-file': checkFile,
},
rules: {
'check-file/folder-naming-convention': [
'error',
{
'src/**/': 'CAMEL_CASE',
'mocks/*/': 'KEBAB_CASE',
},
{
errorMessage:
'The folder "{{ target }}" does not match the "{{ pattern }}" pattern, see contribute.md for details',
ignoreWords: ['skip_word_a', 'skip_word_b'],
},
],
},
},
];
```

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.

```js
export default [
{
Expand Down
10 changes: 10 additions & 0 deletions lib/rules/folder-naming-convention.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export default {
type: 'object',
properties: {
errorMessage: { type: 'string' },
ignoreWords: {
type: 'array',
items: { type: 'string' },
},
},
},
],
Expand Down Expand Up @@ -81,6 +85,7 @@ export default {
const filenameWithPath = getFilePath(context);
const folderPath = getFolderPath(filenameWithPath);
const errorMessage = context.options[1]?.errorMessage ?? '';
const ignoreWords = context.options[1]?.ignoreWords ?? [];

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

for (const folder of folders) {
// Skip validation if the folder name is in the ignore list
if (ignoreWords.includes(folder)) {
continue;
}

if (
!micromatch.isMatch(
folder,
Expand Down
52 changes: 52 additions & 0 deletions tests/lib/rules/folder-naming-convention.posix.js
Original file line number Diff line number Diff line change
Expand Up @@ -659,3 +659,55 @@ ruleTester.run(
],
}
);

ruleTester.run(
"folder-naming-convention with option: [{ 'mocks/**/': 'KEBAB_CASE' }, { ignoreWords: ['skip_word_a', 'skip_word_b'] }]",
rule,
{
valid: [
{
code: "var foo = 'bar';",
filename: 'mocks/skip_word_a/app-mock.ts',
options: [
{ 'mocks/**/': 'KEBAB_CASE' },
{ ignoreWords: ['skip_word_a', 'skip_word_b'] },
],
},
{
code: "var foo = 'bar';",
filename: 'mocks/skip_word_b/another-mock.ts',
options: [
{ 'mocks/**/': 'KEBAB_CASE' },
{ ignoreWords: ['skip_word_a', 'skip_word_b'] },
],
},
{
code: "var foo = 'bar';",
filename: 'mocks/valid-kebab-case/mock.ts',
options: [
{ 'mocks/**/': 'KEBAB_CASE' },
{ ignoreWords: ['skip_word_a', 'skip_word_b'] },
],
},
],

invalid: [
{
code: "var foo = 'bar';",
filename: 'mocks/InvalidCamelCase/mock.ts',
options: [
{ 'mocks/**/': 'KEBAB_CASE' },
{ ignoreWords: ['skip_word_a', 'skip_word_b'] },
],
errors: [
{
message:
'The folder "InvalidCamelCase" does not match the "KEBAB_CASE" pattern',
column: 1,
line: 1,
},
],
},
],
}
);
52 changes: 52 additions & 0 deletions tests/lib/rules/folder-naming-convention.windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -662,3 +662,55 @@ ruleTester.run(
],
}
);

ruleTester.run(
"folder-naming-convention with option: [{ 'mocks/**/': 'KEBAB_CASE' }, { ignoreWords: ['skip_word_a', 'skip_word_b'] }]",
rule,
{
valid: [
{
code: "var foo = 'bar';",
filename: 'mocks\\skip_word_a\\app-mock.ts',
options: [
{ 'mocks/**/': 'KEBAB_CASE' },
{ ignoreWords: ['skip_word_a', 'skip_word_b'] },
],
},
{
code: "var foo = 'bar';",
filename: 'mocks\\skip_word_b\\another-mock.ts',
options: [
{ 'mocks/**/': 'KEBAB_CASE' },
{ ignoreWords: ['skip_word_a', 'skip_word_b'] },
],
},
{
code: "var foo = 'bar';",
filename: 'mocks\\valid-kebab-case\\mock.ts',
options: [
{ 'mocks/**/': 'KEBAB_CASE' },
{ ignoreWords: ['skip_word_a', 'skip_word_b'] },
],
},
],

invalid: [
{
code: "var foo = 'bar';",
filename: 'mocks\\InvalidCamelCase\\mock.ts',
options: [
{ 'mocks/**/': 'KEBAB_CASE' },
{ ignoreWords: ['skip_word_a', 'skip_word_b'] },
],
errors: [
{
message:
'The folder "InvalidCamelCase" does not match the "KEBAB_CASE" pattern',
column: 1,
line: 1,
},
],
},
],
}
);