3
3
* @author Florian Ehmke, Huan Luo
4
4
*/
5
5
6
- import { FILENAME_BLOCKLIST_ERROR_MESSAGE } from '../constants/message.js' ;
6
+ import {
7
+ FILENAME_BLOCKLIST_ERROR_MESSAGE ,
8
+ FILENAME_BLOCKLIST_NONPATTERN_ERROR_MESSAGE ,
9
+ } from '../constants/message.js' ;
7
10
import { getDocUrl } from '../utils/doc.js' ;
8
11
import { getFilePath , getFilename } from '../utils/filename.js' ;
9
12
import { matchRule } from '../utils/rule.js' ;
10
13
import {
11
14
validateNamingPatternObject ,
12
15
globPatternValidator ,
16
+ stringResponseValidator ,
13
17
} from '../utils/validation.js' ;
14
18
15
19
/**
@@ -31,17 +35,23 @@ export default {
31
35
type : 'string' ,
32
36
} ,
33
37
} ,
38
+ {
39
+ stringResponse : {
40
+ type : 'boolean' ,
41
+ } ,
42
+ } ,
34
43
] ,
35
44
} ,
36
45
37
46
create ( context ) {
38
47
return {
39
48
Program : ( node ) => {
40
49
const rules = context . options [ 0 ] ;
50
+ const stringResponse = context . options [ 1 ] ;
41
51
const message = validateNamingPatternObject (
42
52
rules ,
43
53
globPatternValidator ,
44
- globPatternValidator
54
+ stringResponse ? stringResponseValidator : globPatternValidator
45
55
) ;
46
56
47
57
if ( message ) {
@@ -55,9 +65,10 @@ export default {
55
65
const filenameWithPath = getFilePath ( context ) ;
56
66
const filename = getFilename ( filenameWithPath ) ;
57
67
58
- for ( const [ blockListPattern , useInsteadPattern ] of Object . entries (
59
- rules
60
- ) ) {
68
+ for ( const [
69
+ blockListPattern ,
70
+ useInsteadPatternOrString ,
71
+ ] of Object . entries ( rules ) ) {
61
72
const matchResult =
62
73
matchRule ( filenameWithPath , blockListPattern ) ||
63
74
// TODO: remove this in next major version
@@ -66,13 +77,17 @@ export default {
66
77
// it's a legacy feature, will be removed in the future
67
78
matchRule ( filename , blockListPattern ) ;
68
79
80
+ const messageFN = stringResponse
81
+ ? FILENAME_BLOCKLIST_NONPATTERN_ERROR_MESSAGE
82
+ : FILENAME_BLOCKLIST_ERROR_MESSAGE ;
83
+
69
84
if ( matchResult ) {
70
85
context . report ( {
71
86
node,
72
- message : FILENAME_BLOCKLIST_ERROR_MESSAGE (
87
+ message : messageFN (
73
88
filename ,
74
89
blockListPattern ,
75
- useInsteadPattern
90
+ useInsteadPatternOrString
76
91
) ,
77
92
} ) ;
78
93
return ;
0 commit comments