Skip to content

Commit b16d357

Browse files
committed
fix(#21): folder-naming-convention should work well with multiple matchers in a folder pattern
1 parent 4536fc3 commit b16d357

File tree

3 files changed

+170
-2
lines changed

3 files changed

+170
-2
lines changed

lib/rules/folder-naming-convention.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ module.exports = {
7373
if (!micromatch.isMatch(path, folderPattern)) {
7474
continue;
7575
} else {
76-
const matchedPath = micromatch.capture(folderPattern, path)[0]; // only the first matched value is valid
77-
const folders = getAllFolders(matchedPath);
76+
const matchedPaths = micromatch.capture(folderPattern, path);
77+
const folders = matchedPaths
78+
.filter((p) => !!p)
79+
.reduce((s, p) => s.concat(getAllFolders(p)), []);
7880

7981
for (const folder of folders) {
8082
if (

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

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,89 @@ ruleTester.run(
9999
}
100100
);
101101

102+
ruleTester.run(
103+
"folder-naming-convention with option: [{ 'src/!(pages)/**': 'CAMEL_CASE' }]",
104+
rule,
105+
{
106+
valid: [
107+
{
108+
code: "var foo = 'bar';",
109+
filename: 'src/components/displayLabel/displayLabel.js',
110+
options: [{ 'src/!(pages)/**': 'CAMEL_CASE' }],
111+
},
112+
{
113+
code: "var foo = 'bar';",
114+
filename: 'src/components/visual/interactiveButton/index.js',
115+
options: [{ 'src/!(pages)/**': 'CAMEL_CASE' }],
116+
},
117+
{
118+
code: "var foo = 'bar';",
119+
filename: 'src/pages/home/index.js',
120+
options: [{ 'src/!(pages)/**': 'CAMEL_CASE' }],
121+
},
122+
{
123+
code: "var foo = 'bar';",
124+
filename: 'src/pages/Home/index.js',
125+
options: [{ 'src/!(pages)/**': 'CAMEL_CASE' }],
126+
},
127+
],
128+
129+
invalid: [
130+
{
131+
code: "var foo = 'bar';",
132+
filename: 'src/Components/DisplayLabel/displayLabel.js',
133+
options: [{ 'src/!(pages)/**': 'CAMEL_CASE' }],
134+
errors: [
135+
{
136+
message:
137+
'The folder "Components" does not match the "CAMEL_CASE" style',
138+
column: 1,
139+
line: 1,
140+
},
141+
],
142+
},
143+
{
144+
code: "var foo = 'bar';",
145+
filename: 'src/components/DisplayLabel/displayLabel.js',
146+
options: [{ 'src/!(pages)/**': 'CAMEL_CASE' }],
147+
errors: [
148+
{
149+
message:
150+
'The folder "DisplayLabel" does not match the "CAMEL_CASE" style',
151+
column: 1,
152+
line: 1,
153+
},
154+
],
155+
},
156+
{
157+
code: "var foo = 'bar';",
158+
filename: 'src/components/visual/interactive-button/index.js',
159+
options: [{ 'src/!(pages)/**': 'CAMEL_CASE' }],
160+
errors: [
161+
{
162+
message:
163+
'The folder "interactive-button" does not match the "CAMEL_CASE" style',
164+
column: 1,
165+
line: 1,
166+
},
167+
],
168+
},
169+
{
170+
code: "var foo = 'bar';",
171+
filename: 'src/Pages/home/index.js',
172+
options: [{ 'src/!(pages)/**': 'CAMEL_CASE' }],
173+
errors: [
174+
{
175+
message: 'The folder "Pages" does not match the "CAMEL_CASE" style',
176+
column: 1,
177+
line: 1,
178+
},
179+
],
180+
},
181+
],
182+
}
183+
);
184+
102185
ruleTester.run(
103186
"folder-naming-convention with option: [{ 'components/*/': '__+([a-z])' }]",
104187
rule,

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

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,89 @@ ruleTester.run(
102102
}
103103
);
104104

105+
ruleTester.run(
106+
"folder-naming-convention with option on Windows: [{ 'src/!(pages)/**': 'CAMEL_CASE' }]",
107+
rule,
108+
{
109+
valid: [
110+
{
111+
code: "var foo = 'bar';",
112+
filename: 'src\\components\\displayLabel\\displayLabel.js',
113+
options: [{ 'src/!(pages)/**': 'CAMEL_CASE' }],
114+
},
115+
{
116+
code: "var foo = 'bar';",
117+
filename: 'src\\components\\visual\\interactiveButton\\index.js',
118+
options: [{ 'src/!(pages)/**': 'CAMEL_CASE' }],
119+
},
120+
{
121+
code: "var foo = 'bar';",
122+
filename: 'src\\pages\\home\\index.js',
123+
options: [{ 'src/!(pages)/**': 'CAMEL_CASE' }],
124+
},
125+
{
126+
code: "var foo = 'bar';",
127+
filename: 'src\\pages\\Home\\index.js',
128+
options: [{ 'src/!(pages)/**': 'CAMEL_CASE' }],
129+
},
130+
],
131+
132+
invalid: [
133+
{
134+
code: "var foo = 'bar';",
135+
filename: 'src\\Components\\DisplayLabel\\displayLabel.js',
136+
options: [{ 'src/!(pages)/**': 'CAMEL_CASE' }],
137+
errors: [
138+
{
139+
message:
140+
'The folder "Components" does not match the "CAMEL_CASE" style',
141+
column: 1,
142+
line: 1,
143+
},
144+
],
145+
},
146+
{
147+
code: "var foo = 'bar';",
148+
filename: 'src\\components\\DisplayLabel\\displayLabel.js',
149+
options: [{ 'src/!(pages)/**': 'CAMEL_CASE' }],
150+
errors: [
151+
{
152+
message:
153+
'The folder "DisplayLabel" does not match the "CAMEL_CASE" style',
154+
column: 1,
155+
line: 1,
156+
},
157+
],
158+
},
159+
{
160+
code: "var foo = 'bar';",
161+
filename: 'src\\components\\visual\\interactive-button\\index.js',
162+
options: [{ 'src/!(pages)/**': 'CAMEL_CASE' }],
163+
errors: [
164+
{
165+
message:
166+
'The folder "interactive-button" does not match the "CAMEL_CASE" style',
167+
column: 1,
168+
line: 1,
169+
},
170+
],
171+
},
172+
{
173+
code: "var foo = 'bar';",
174+
filename: 'src\\Pages\\home\\index.js',
175+
options: [{ 'src/!(pages)/**': 'CAMEL_CASE' }],
176+
errors: [
177+
{
178+
message: 'The folder "Pages" does not match the "CAMEL_CASE" style',
179+
column: 1,
180+
line: 1,
181+
},
182+
],
183+
},
184+
],
185+
}
186+
);
187+
105188
ruleTester.run(
106189
"folder-naming-convention with option on Windows: [{ 'components/*/': '__+([a-z])' }]",
107190
rule,

0 commit comments

Comments
 (0)