Skip to content

Commit 0e85d34

Browse files
committed
refactor: using matchRule to refactor rule folder-match-with-fex
1 parent a16938d commit 0e85d34

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

lib/rules/folder-match-with-fex.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
*/
55
'use strict';
66

7-
const micromatch = require('micromatch');
87
const { getFolderPath, getFilename } = require('../utils/filename');
98
const { checkSettings, globPatternValidator } = require('../utils/settings');
109
const { getDocUrl } = require('../utils/doc');
10+
const { matchRule } = require('../utils/match');
1111

1212
/**
1313
* @type {import('eslint').Rule.RuleModule}
@@ -60,18 +60,22 @@ module.exports = {
6060
const folderPath = getFolderPath(filenameWithPath);
6161

6262
for (const [fexPattern, folderPattern] of Object.entries(rules)) {
63-
if (!micromatch.isMatch(filename, fexPattern)) {
64-
continue;
65-
} else if (micromatch.isMatch(folderPath, folderPattern)) {
66-
return;
67-
} else {
63+
const matchResult = matchRule(
64+
filename,
65+
fexPattern,
66+
folderPath,
67+
folderPattern
68+
);
69+
70+
if (matchResult) {
71+
const { pattern } = matchResult;
6872
context.report({
6973
node,
7074
message:
71-
'The folder of the file "{{filenameWithPath}}" does not match "{{folderPattern}}"',
75+
'The folder of the file "{{filenameWithPath}}" does not match "{{pattern}}"',
7276
data: {
7377
filenameWithPath,
74-
folderPattern,
78+
pattern,
7579
},
7680
});
7781
return;

0 commit comments

Comments
 (0)