Skip to content

Commit

Permalink
Merge pull request sasstools#156 from bgriffith/feature/exclude-dupli…
Browse files Browse the repository at this point in the history
…cate

Enhance no-duplicate-properties rule to allow exceptions
  • Loading branch information
DanPurdy committed Sep 12, 2015
2 parents 0919356 + 3b13fc2 commit 9172f92
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 11 deletions.
5 changes: 5 additions & 0 deletions docs/rules/no-duplicate-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

Rule `no-duplicate-properties` will enforce that duplicate properties are not allowed within the same block.

## Options

* `exclude`: `[array of property names to be excluded from this rule]` (defaults to empty array `[]`)


## Examples

When enabled, the following are disallowed:
Expand Down
20 changes: 12 additions & 8 deletions lib/rules/no-duplicate-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ var helpers = require('../helpers');

module.exports = {
'name': 'no-duplicate-properties',
'defaults': {},
'defaults': {
'exclude': []
},
'detect': function (ast, parser) {
var result = [];

Expand All @@ -26,13 +28,15 @@ module.exports = {
properties.push(property);
}
else {
result = helpers.addUnique(result, {
'ruleId': parser.rule.name,
'line': item.start.line,
'column': item.start.column,
'message': 'Duplicate properties are not allowed within a block',
'severity': parser.severity
});
if (parser.options.exclude.indexOf(property) === -1) {
result = helpers.addUnique(result, {
'ruleId': parser.rule.name,
'line': item.start.line,
'column': item.start.column,
'message': 'Duplicate properties are not allowed within a block',
'severity': parser.severity
});
}
}
});
});
Expand Down
19 changes: 16 additions & 3 deletions tests/rules/no-duplicate-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,25 @@ var lint = require('./_lint');
var file = lint.file('no-duplicate-properties.scss');

describe('no duplicate properties', function () {
//////////////////////////////
// Duplicate Property
//////////////////////////////
it('enforce', function (done) {
lint.test(file, {
'no-duplicate-properties': 1
}, function (data) {
lint.assert.equal(4, data.warningCount);
done();
});
});

it('enforce - [exclude: background]', function (done) {
lint.test(file, {
'no-duplicate-properties': [
1,
{
'exclude': [
'background'
]
}
]
}, function (data) {
lint.assert.equal(3, data.warningCount);
done();
Expand Down
5 changes: 5 additions & 0 deletions tests/sass/no-duplicate-properties.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@
display: none;
}
}

.qux {
background: rgb(200, 54, 54);
background: rgba(200, 54, 54, 0.5);
}

0 comments on commit 9172f92

Please sign in to comment.