File tree Expand file tree Collapse file tree 1 file changed +19
-6
lines changed Expand file tree Collapse file tree 1 file changed +19
-6
lines changed Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
// eslint-disable-next-line camelcase
3
- const { is_tag_node, has_non_empty_attribute, is_boolean_attribute} = require ( '@linthtml/dom-utils' ) ;
3
+ const { is_tag_node, has_non_empty_attribute, is_boolean_attribute } = require ( '@linthtml/dom-utils' ) ;
4
+ const matchesIgnoreList = ( attributeName , ignoreList ) => ignoreList . some ( ( ignoreItem ) => {
5
+ if ( typeof ignoreItem === 'string' ) {
6
+ const regexString = ignoreItem . startsWith ( '/' ) && ignoreItem . endsWith ( '/' ) ? ignoreItem . slice ( 1 , - 1 ) : ignoreItem ;
7
+ const regex = new RegExp ( regexString ) ;
8
+ return regex . test ( attributeName ) ;
9
+ } else if ( ignoreItem instanceof RegExp ) {
10
+ return ignoreItem . test ( attributeName ) ;
11
+ } else {
12
+ return attributeName === ignoreItem ;
13
+ }
14
+ } ) ;
15
+
4
16
5
17
module . exports = {
6
18
name : 'htmlacademy/attr-req-value' ,
@@ -12,18 +24,19 @@ module.exports = {
12
24
const name = attribute . name . chars . toLowerCase ( ) ;
13
25
14
26
// eslint-disable-next-line camelcase
15
- if ( ! has_non_empty_attribute ( node , name ) && ! is_boolean_attribute ( attribute ) && ! rule_config . ignore ?. includes ( name ) ) {
27
+ if ( ! has_non_empty_attribute ( node , name ) && ! is_boolean_attribute ( attribute ) && ! matchesIgnoreList ( name , rule_config . ignore )
28
+ ) {
16
29
report ( {
17
30
code : 'E006' ,
18
31
position : attribute . loc ,
19
32
meta : {
20
33
data : {
21
- attribute : name
22
- }
23
- }
34
+ attribute : name ,
35
+ } ,
36
+ } ,
24
37
} ) ;
25
38
}
26
39
} ) ;
27
40
}
28
- }
41
+ } ,
29
42
} ;
You can’t perform that action at this time.
0 commit comments