-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbool-attribute-value.js
43 lines (35 loc) · 1.25 KB
/
bool-attribute-value.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* @file rule: bool-attribute-value
* @author nighca<[email protected]>
*/
var booleanAttributes = [
'allowfullscreen', 'async', 'autofocus', 'autoplay',
'checked', 'controls', 'default', 'defer',
'disabled', 'formnovalidate', 'hidden', 'ismap',
'itemscope', 'loop', 'multiple', 'muted', 'novalidate',
'open', 'readonly', 'required', 'reversed',
'scoped', 'seamless', 'selected', 'sortable', 'typemustmatch'
];
module.exports = {
name: 'bool-attribute-value',
desc: 'Value of boolean attributes should not be set.',
lint: function (getCfg, document, reporter) {
document.querySelectorAll('*').forEach(function (element) {
if (!getCfg(element)) {
return;
}
booleanAttributes.forEach(function (attribute) {
if (element.getAttribute(attribute)) {
reporter.warn(
element.startIndex,
'003',
'Value of boolean attribute "' + attribute + '" should not be set.'
);
}
});
});
},
format: function (getCfg, document, options) {
options['bool-attribute-value'] = getCfg() ? 'remove' : 'preserve';
}
};