Skip to content

Commit

Permalink
fix(attr-no-unnecessary-whitespace): fix when equals symbol in value (#…
Browse files Browse the repository at this point in the history
…405)

Co-authored-by: Shinigami <chrissi92@hotmail.de>
  • Loading branch information
nicolashenry and Shinigami committed May 19, 2020
1 parent 48ca676 commit fe4f3c6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
26 changes: 13 additions & 13 deletions src/rules/attr-no-unnecessary-whitespace.js
Expand Up @@ -10,19 +10,19 @@ export default {
var col = event.col + event.tagName.length + 1

for (var i = 0; i < attrs.length; i++) {
if (
exceptions.indexOf(attrs[i].name) === -1 &&
/[^=](\s+=\s+|=\s+|\s+=)/g.test(attrs[i].raw.trim())
) {
reporter.error(
"The attribute '" +
attrs[i].name +
"' must not have spaces between the name and value.",
event.line,
col + attrs[i].index,
self,
attrs[i].raw
)
if (exceptions.indexOf(attrs[i].name) === -1) {
var match = /(\s*)=(\s*)/.exec(attrs[i].raw.trim())
if (match && (match[1].length !== 0 || match[2].length !== 0)) {
reporter.error(
"The attribute '" +
attrs[i].name +
"' must not have spaces between the name and value.",
event.line,
col + attrs[i].index,
self,
attrs[i].raw
)
}
}
}
})
Expand Down
Expand Up @@ -24,8 +24,10 @@ describe('Rules: ' + ruldId, function () {
})

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

0 comments on commit fe4f3c6

Please sign in to comment.