@@ -52,6 +52,11 @@ module.exports = {
52
52
uniqueItems : true ,
53
53
items : { type : 'string' } ,
54
54
} ,
55
+ allowedForPatterns : {
56
+ type : 'array' ,
57
+ uniqueItems : true ,
58
+ items : { type : 'string' } ,
59
+ } ,
55
60
message : { type : 'string' } ,
56
61
} ,
57
62
additionalProperties : false ,
@@ -66,12 +71,20 @@ module.exports = {
66
71
minItems : 1 ,
67
72
items : { type : 'string' } ,
68
73
} ,
74
+ disallowedForPatterns : {
75
+ type : 'array' ,
76
+ uniqueItems : true ,
77
+ minItems : 1 ,
78
+ items : { type : 'string' } ,
79
+ } ,
69
80
message : { type : 'string' } ,
70
81
} ,
71
- required : [ 'disallowedFor' ] ,
82
+ anyOf : [
83
+ { required : [ 'disallowedFor' ] } ,
84
+ { required : [ 'disallowedForPatterns' ] } ,
85
+ ] ,
72
86
additionalProperties : false ,
73
87
} ,
74
-
75
88
{
76
89
type : 'object' ,
77
90
properties : {
@@ -81,6 +94,11 @@ module.exports = {
81
94
uniqueItems : true ,
82
95
items : { type : 'string' } ,
83
96
} ,
97
+ allowedForPatterns : {
98
+ type : 'array' ,
99
+ uniqueItems : true ,
100
+ items : { type : 'string' } ,
101
+ } ,
84
102
message : { type : 'string' } ,
85
103
} ,
86
104
additionalProperties : false ,
@@ -95,9 +113,18 @@ module.exports = {
95
113
minItems : 1 ,
96
114
items : { type : 'string' } ,
97
115
} ,
116
+ disallowedForPatterns : {
117
+ type : 'array' ,
118
+ uniqueItems : true ,
119
+ minItems : 1 ,
120
+ items : { type : 'string' } ,
121
+ } ,
98
122
message : { type : 'string' } ,
99
123
} ,
100
- required : [ 'disallowedFor' ] ,
124
+ anyOf : [
125
+ { required : [ 'disallowedFor' ] } ,
126
+ { required : [ 'disallowedForPatterns' ] } ,
127
+ ] ,
101
128
additionalProperties : false ,
102
129
} ,
103
130
] ,
@@ -114,8 +141,10 @@ module.exports = {
114
141
const propPattern = value . propNamePattern ;
115
142
const prop = propName || propPattern ;
116
143
const options = {
117
- allowList : typeof value === 'string' ? [ ] : ( value . allowedFor || [ ] ) ,
118
- disallowList : typeof value === 'string' ? [ ] : ( value . disallowedFor || [ ] ) ,
144
+ allowList : [ ] . concat ( value . allowedFor || [ ] ) ,
145
+ allowPatternList : [ ] . concat ( value . allowedForPatterns || [ ] ) ,
146
+ disallowList : [ ] . concat ( value . disallowedFor || [ ] ) ,
147
+ disallowPatternList : [ ] . concat ( value . disallowedForPatterns || [ ] ) ,
119
148
message : typeof value === 'string' ? null : value . message ,
120
149
isPattern : ! ! value . propNamePattern ,
121
150
} ;
@@ -140,10 +169,40 @@ module.exports = {
140
169
return false ;
141
170
}
142
171
172
+ function checkIsTagForbiddenByAllowOptions ( ) {
173
+ if ( options . allowList . indexOf ( tagName ) !== - 1 ) {
174
+ return false ;
175
+ }
176
+
177
+ if ( options . allowPatternList . length === 0 ) {
178
+ return true ;
179
+ }
180
+
181
+ return options . allowPatternList . every (
182
+ ( pattern ) => ! minimatch ( tagName , pattern )
183
+ ) ;
184
+ }
185
+
186
+ function checkIsTagForbiddenByDisallowOptions ( ) {
187
+ if ( options . disallowList . indexOf ( tagName ) !== - 1 ) {
188
+ return true ;
189
+ }
190
+
191
+ if ( options . disallowPatternList . length === 0 ) {
192
+ return false ;
193
+ }
194
+
195
+ return options . disallowPatternList . some (
196
+ ( pattern ) => minimatch ( tagName , pattern )
197
+ ) ;
198
+ }
199
+
200
+ const hasDisallowOptions = options . disallowList . length > 0 || options . disallowPatternList . length > 0 ;
201
+
143
202
// disallowList should have a least one item (schema configuration)
144
- const isTagForbidden = options . disallowList . length > 0
145
- ? options . disallowList . indexOf ( tagName ) !== - 1
146
- : options . allowList . indexOf ( tagName ) === - 1 ;
203
+ const isTagForbidden = hasDisallowOptions
204
+ ? checkIsTagForbiddenByDisallowOptions ( )
205
+ : checkIsTagForbiddenByAllowOptions ( ) ;
147
206
148
207
// if the tagName is undefined (`<this.something>`), we assume it's a forbidden element
149
208
return typeof tagName === 'undefined' || isTagForbidden ;
0 commit comments