55
66'use strict' ;
77
8+ const minimatch = require ( 'minimatch' ) ;
89const docsUrl = require ( '../util/docsUrl' ) ;
910const report = require ( '../util/report' ) ;
1011
@@ -70,6 +71,35 @@ module.exports = {
7071 required : [ 'disallowedFor' ] ,
7172 additionalProperties : false ,
7273 } ,
74+
75+ {
76+ type : 'object' ,
77+ properties : {
78+ propNamePattern : { type : 'string' } ,
79+ allowedFor : {
80+ type : 'array' ,
81+ uniqueItems : true ,
82+ items : { type : 'string' } ,
83+ } ,
84+ message : { type : 'string' } ,
85+ } ,
86+ additionalProperties : false ,
87+ } ,
88+ {
89+ type : 'object' ,
90+ properties : {
91+ propNamePattern : { type : 'string' } ,
92+ disallowedFor : {
93+ type : 'array' ,
94+ uniqueItems : true ,
95+ minItems : 1 ,
96+ items : { type : 'string' } ,
97+ } ,
98+ message : { type : 'string' } ,
99+ } ,
100+ required : [ 'disallowedFor' ] ,
101+ additionalProperties : false ,
102+ } ,
73103 ] ,
74104 } ,
75105 } ,
@@ -81,16 +111,31 @@ module.exports = {
81111 const configuration = context . options [ 0 ] || { } ;
82112 const forbid = new Map ( ( configuration . forbid || DEFAULTS ) . map ( ( value ) => {
83113 const propName = typeof value === 'string' ? value : value . propName ;
114+ const propPattern = value . propNamePattern ;
115+ const prop = propName || propPattern ;
84116 const options = {
85117 allowList : typeof value === 'string' ? [ ] : ( value . allowedFor || [ ] ) ,
86118 disallowList : typeof value === 'string' ? [ ] : ( value . disallowedFor || [ ] ) ,
87119 message : typeof value === 'string' ? null : value . message ,
120+ isPattern : ! ! value . propNamePattern ,
88121 } ;
89- return [ propName , options ] ;
122+ return [ prop , options ] ;
90123 } ) ) ;
91124
125+ function getPropOptions ( prop ) {
126+ // Get config options having pattern
127+ const propNamePatternArray = Array . from ( forbid . entries ( ) ) . filter ( ( propEntry ) => propEntry [ 1 ] . isPattern ) ;
128+ // Match current prop with pattern options, return if matched
129+ const propNamePattern = propNamePatternArray . find ( ( propPatternVal ) => minimatch ( prop , propPatternVal [ 0 ] ) ) ;
130+ // Get options for matched propNamePattern
131+ const propNamePatternOptions = propNamePattern && propNamePattern [ 1 ] ;
132+
133+ const options = forbid . get ( prop ) || propNamePatternOptions ;
134+ return options ;
135+ }
136+
92137 function isForbidden ( prop , tagName ) {
93- const options = forbid . get ( prop ) ;
138+ const options = getPropOptions ( prop ) ;
94139 if ( ! options ) {
95140 return false ;
96141 }
@@ -121,7 +166,7 @@ module.exports = {
121166 return ;
122167 }
123168
124- const customMessage = forbid . get ( prop ) . message ;
169+ const customMessage = getPropOptions ( prop ) . message ;
125170
126171 report ( context , customMessage || messages . propIsForbidden , ! customMessage && 'propIsForbidden' , {
127172 node,
0 commit comments