diff --git a/src/rules/attr-no-unnecessary-whitespace.js b/src/rules/attr-no-unnecessary-whitespace.js index 3ea911f49..c3a4dc9dc 100644 --- a/src/rules/attr-no-unnecessary-whitespace.js +++ b/src/rules/attr-no-unnecessary-whitespace.js @@ -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 + ) + } } } }) diff --git a/test/rules/attr-no-unnecessary-whitespace.js b/test/rules/attr-no-unnecessary-whitespace.spec.js similarity index 78% rename from test/rules/attr-no-unnecessary-whitespace.js rename to test/rules/attr-no-unnecessary-whitespace.spec.js index 5952c4806..299d7dd11 100644 --- a/test/rules/attr-no-unnecessary-whitespace.js +++ b/test/rules/attr-no-unnecessary-whitespace.spec.js @@ -24,8 +24,10 @@ describe('Rules: ' + ruldId, function () { }) it('Attribute without spaces should not result in an error', function () { - var code = '
' - var messages = HTMLHint.verify(code, ruleOptions) - expect(messages.length).to.be(0) + var codes = ['', ''] + for (var i = 0; i < codes.length; i++) { + var messages = HTMLHint.verify(codes[i], ruleOptions) + expect(messages.length).to.be(0) + } }) })