Skip to content

Commit fe4f3c6

Browse files
nicolashenryShinigami
and
Shinigami
authoredMay 19, 2020
fix(attr-no-unnecessary-whitespace): fix when equals symbol in value (#405)
Co-authored-by: Shinigami <chrissi92@hotmail.de>
1 parent 48ca676 commit fe4f3c6

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed
 

‎src/rules/attr-no-unnecessary-whitespace.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ export default {
1010
var col = event.col + event.tagName.length + 1
1111

1212
for (var i = 0; i < attrs.length; i++) {
13-
if (
14-
exceptions.indexOf(attrs[i].name) === -1 &&
15-
/[^=](\s+=\s+|=\s+|\s+=)/g.test(attrs[i].raw.trim())
16-
) {
17-
reporter.error(
18-
"The attribute '" +
19-
attrs[i].name +
20-
"' must not have spaces between the name and value.",
21-
event.line,
22-
col + attrs[i].index,
23-
self,
24-
attrs[i].raw
25-
)
13+
if (exceptions.indexOf(attrs[i].name) === -1) {
14+
var match = /(\s*)=(\s*)/.exec(attrs[i].raw.trim())
15+
if (match && (match[1].length !== 0 || match[2].length !== 0)) {
16+
reporter.error(
17+
"The attribute '" +
18+
attrs[i].name +
19+
"' must not have spaces between the name and value.",
20+
event.line,
21+
col + attrs[i].index,
22+
self,
23+
attrs[i].raw
24+
)
25+
}
2626
}
2727
}
2828
})

‎test/rules/attr-no-unnecessary-whitespace.js ‎test/rules/attr-no-unnecessary-whitespace.spec.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ describe('Rules: ' + ruldId, function () {
2424
})
2525

2626
it('Attribute without spaces should not result in an error', function () {
27-
var code = '<div title="a" />'
28-
var messages = HTMLHint.verify(code, ruleOptions)
29-
expect(messages.length).to.be(0)
27+
var codes = ['<div title="a" />', '<div title="a = a" />']
28+
for (var i = 0; i < codes.length; i++) {
29+
var messages = HTMLHint.verify(codes[i], ruleOptions)
30+
expect(messages.length).to.be(0)
31+
}
3032
})
3133
})

0 commit comments

Comments
 (0)
Please sign in to comment.