Skip to content

Commit

Permalink
Fixes #19
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Edwards committed Aug 8, 2015
1 parent b9e040d commit af03cd7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
20 changes: 13 additions & 7 deletions lib/rules/validate-attribute-separator.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,20 @@ module.exports.prototype =

return attribute.name + '\\s*=\\s*' + value.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&')
}).join('|')
, regex = new RegExp('.*\\(' + pattern + '\\)', 'g')
, parsedLine = line.replace(regex, '#attribute#')
, attributes = parsedLine.split(separator)
, filteredAttributes = attributes.filter(filterSeparators)

if (attributes.length !== attributeCount || filteredAttributes.length !== attributeCount) {
errors.add('Invalid attribute separator found', lineNumber)
, regexFind = new RegExp(/\(([^(]*)\)/g)
, match

while ((match = regexFind.exec(line)) !== null) {
var regexReplace = new RegExp(pattern, 'g')
, parsedLine = match[1].replace(regexReplace, '#attribute#')
, attributes = parsedLine.split(separator)
, filteredAttributes = attributes.filter(filterSeparators)

if (attributes.length !== attributeCount || filteredAttributes.length !== attributeCount) {
errors.add('Invalid attribute separator found', lineNumber)
}
}

})

function filterSeparators(attribute) {
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/rules/validate-attribute-separator.jade
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
input(type='text')
input(type='text' name='name' checked='true')
input(type='text',name='name',value='value')
input(type='text', name='name', value='value')
Expand All @@ -11,3 +12,5 @@ input(type='text' name='name' ,value='value')
a(style={color: 'red', background: 'green'})
a(class = ['red', 'green', 'blue'])
a(class= {active: currentUrl === '/', inactive: true})
a(href="https://mozilla.org") Mozilla
a(target="_blank" href=plate.url).boilerplate= plate.name
8 changes: 4 additions & 4 deletions test/rules/validate-attribute-separator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function createTest(linter, fixturesPath) {
it('should report multiple errors found in file', function () {
var result = linter.checkFile(fixturePath)

assert.equal(result.length, 9)
assert.equal(result.length, 10)
assert.equal(result[0].code, 'JADE:LINT_VALIDATEATTRIBUTESEPARATOR')
})

Expand All @@ -71,7 +71,7 @@ function createTest(linter, fixturesPath) {
it('should report multiple errors found in file', function () {
var result = linter.checkFile(fixturePath)

assert.equal(result.length, 9)
assert.equal(result.length, 10)
assert.equal(result[0].code, 'JADE:LINT_VALIDATEATTRIBUTESEPARATOR')
})

Expand All @@ -94,7 +94,7 @@ function createTest(linter, fixturesPath) {
it('should report multiple errors found in file', function () {
var result = linter.checkFile(fixturePath)

assert.equal(result.length, 9)
assert.equal(result.length, 10)
assert.equal(result[0].code, 'JADE:LINT_VALIDATEATTRIBUTESEPARATOR')
})

Expand All @@ -117,7 +117,7 @@ function createTest(linter, fixturesPath) {
it('should report multiple errors found in file', function () {
var result = linter.checkFile(fixturePath)

assert.equal(result.length, 9)
assert.equal(result.length, 10)
assert.equal(result[0].code, 'JADE:LINT_VALIDATEATTRIBUTESEPARATOR')
})

Expand Down

0 comments on commit af03cd7

Please sign in to comment.