Skip to content

Commit a8e478c

Browse files
Adds ignore regular expression for htmlacademy/attr-req-value
1 parent e2c183f commit a8e478c

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

rules/attr-req-value/index.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
'use strict';
22
// 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+
416

517
module.exports = {
618
name: 'htmlacademy/attr-req-value',
@@ -12,18 +24,19 @@ module.exports = {
1224
const name = attribute.name.chars.toLowerCase();
1325

1426
// 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+
) {
1629
report({
1730
code: 'E006',
1831
position: attribute.loc,
1932
meta: {
2033
data: {
21-
attribute: name
22-
}
23-
}
34+
attribute: name,
35+
},
36+
},
2437
});
2538
}
2639
});
2740
}
28-
}
41+
},
2942
};

0 commit comments

Comments
 (0)