Skip to content

Commit acb926d

Browse files
committed
refactor: use capture method to check if path matched
1 parent cc5decf commit acb926d

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

lib/rules/folder-naming-convention.js

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const {
1717
globPatternValidator,
1818
} = require('../utils/validation');
1919
const { getDocUrl } = require('../utils/doc');
20-
const { isNotEmpty } = require('../utils/utility');
20+
const { isNotEmpty, isNil } = require('../utils/utility');
2121
const NAMING_CONVENTION = require('../constants/naming-convention');
2222
const {
2323
FOLDER_NAMING_CONVENTION_ERROR_MESSAGE,
@@ -73,31 +73,29 @@ module.exports = {
7373
continue;
7474
}
7575
for (const path of getSubPaths(folderPath)) {
76-
if (!micromatch.isMatch(path, folderPattern)) {
77-
continue;
78-
} else {
79-
const matchedPaths =
80-
micromatch.capture(folderPattern, path) || [];
81-
const folders = matchedPaths
82-
.filter(isNotEmpty)
83-
.reduce((s, p) => s.concat(getAllFolders(p)), []);
76+
const matchedPaths = micromatch.capture(folderPattern, path);
8477

85-
for (const folder of folders) {
86-
if (
87-
!micromatch.isMatch(
78+
if (isNil(matchedPaths)) continue;
79+
80+
const folders = matchedPaths
81+
.filter(isNotEmpty)
82+
.reduce((s, p) => s.concat(getAllFolders(p)), []);
83+
84+
for (const folder of folders) {
85+
if (
86+
!micromatch.isMatch(
87+
folder,
88+
NAMING_CONVENTION[namingPattern] || namingPattern
89+
)
90+
) {
91+
context.report({
92+
node,
93+
message: FOLDER_NAMING_CONVENTION_ERROR_MESSAGE(
8894
folder,
89-
NAMING_CONVENTION[namingPattern] || namingPattern
90-
)
91-
) {
92-
context.report({
93-
node,
94-
message: FOLDER_NAMING_CONVENTION_ERROR_MESSAGE(
95-
folder,
96-
namingPattern
97-
),
98-
});
99-
return;
100-
}
95+
namingPattern
96+
),
97+
});
98+
return;
10199
}
102100
}
103101
}

0 commit comments

Comments
 (0)