Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance no-duplicate-properties rule to allow exceptions #156

Merged
merged 5 commits into from
Sep 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}