File tree Expand file tree Collapse file tree 3 files changed +413
-14
lines changed Expand file tree Collapse file tree 3 files changed +413
-14
lines changed Original file line number Diff line number Diff line change 4
4
*/
5
5
'use strict' ;
6
6
7
- const micromatch = require ( 'micromatch' ) ;
8
7
const { getFilename, getBasename } = require ( '../utils/filename' ) ;
9
8
const {
10
9
checkSettings,
11
10
namingPatternValidator,
12
11
globPatternValidator,
13
12
} = require ( '../utils/settings' ) ;
14
13
const { getDocUrl } = require ( '../utils/doc' ) ;
15
- const NAMING_CONVENTION = require ( '../constants/naming-convention ' ) ;
14
+ const { matchRule } = require ( '../utils/match ' ) ;
16
15
17
16
/**
18
17
* @type {import('eslint').Rule.RuleModule }
@@ -62,23 +61,32 @@ module.exports = {
62
61
const filename = getFilename ( filenameWithPath ) ;
63
62
64
63
for ( const [ fexPattern , namingPattern ] of Object . entries ( rules ) ) {
65
- if ( ! micromatch . isMatch ( filename , fexPattern ) ) {
66
- continue ;
67
- } else if (
68
- micromatch . isMatch (
64
+ const matchResult =
65
+ matchRule (
66
+ filenameWithPath ,
67
+ fexPattern ,
69
68
getBasename ( filename ) ,
70
- NAMING_CONVENTION [ namingPattern ] || namingPattern
71
- )
72
- ) {
73
- return ;
74
- } else {
69
+ namingPattern
70
+ ) ||
71
+ // legacy support for version below v1.2.0
72
+ // file only can be specified by fex pattern, not by file path pattern
73
+ // it's a legacy feature, will be removed in the future
74
+ matchRule (
75
+ filename ,
76
+ fexPattern ,
77
+ getBasename ( filename ) ,
78
+ namingPattern
79
+ ) ;
80
+
81
+ if ( matchResult ) {
82
+ const { path, pattern } = matchResult ;
75
83
context . report ( {
76
84
node,
77
85
message :
78
- 'The filename "{{filename }}" does not match the "{{namingPattern }}" style' ,
86
+ 'The filename "{{path }}" does not match the "{{pattern }}" style' ,
79
87
data : {
80
- filename ,
81
- namingPattern ,
88
+ path ,
89
+ pattern ,
82
90
} ,
83
91
} ) ;
84
92
return ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @fileoverview Utils about matching rule
3
+ * @author Duke Luo
4
+ */
5
+ 'use strict' ;
6
+
7
+ const micromatch = require ( 'micromatch' ) ;
8
+ const NAMING_CONVENTION = require ( '../constants/naming-convention' ) ;
9
+
10
+ /**
11
+ * @type {object | undefined } undefined or object with non-matching file path and naming pattern
12
+ * @param filePath
13
+ * @param targetFilePathPattern
14
+ * @param targetNaming
15
+ * @param targetNamingPattern
16
+ */
17
+ const matchRule = (
18
+ filePath ,
19
+ targetFilePathPattern ,
20
+ targetNaming ,
21
+ targetNamingPattern
22
+ ) => {
23
+ if ( ! micromatch . isMatch ( filePath , targetFilePathPattern ) ) {
24
+ return ;
25
+ } else if (
26
+ micromatch . isMatch (
27
+ targetNaming ,
28
+ NAMING_CONVENTION [ targetNamingPattern ] || targetNamingPattern
29
+ )
30
+ ) {
31
+ return ;
32
+ } else {
33
+ return {
34
+ path : filePath ,
35
+ pattern : targetNamingPattern ,
36
+ } ;
37
+ }
38
+ } ;
39
+
40
+ module . exports = {
41
+ matchRule,
42
+ } ;
You can’t perform that action at this time.
0 commit comments