Skip to content

Commit

Permalink
Merge pull request #936 from bgriffith/feature/fix-variable-declarations
Browse files Browse the repository at this point in the history
Fix false positives on variable declarations
  • Loading branch information
DanPurdy authored Nov 7, 2016
2 parents 0fbf9bd + 77449fa commit 60624c2
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/rules/declarations-before-nesting.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ module.exports = {
}

if (item.is('declaration')) {
var property = item.content[0];

if (property && property.is('property')) {
if (property.content[0] && property.content[0].is('variable')) {
return;
}
}

declarationIndex = j;
declaration = item;
}
Expand Down
9 changes: 8 additions & 1 deletion lib/rules/no-duplicate-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,18 @@ module.exports = {

declaration.eachFor('property', function (item) {
var property = '';
item.content.forEach(function (subItem) {

// Check if declaration is actually a variable declaration
if (item.content[0] && item.content[0].is('variable')) {
return;
}

item.forEach(function (subItem) {
// Although not a selector the method here helps us construct the proper property name
// taking into account any interpolation etc
property += selectorHelpers.constructSelector(subItem);
});

if (properties.indexOf(property) !== -1 && properties.length >= 1) {
if (parser.options.exclude.indexOf(property) !== -1 && properties[properties.length - 1] !== property) {
warnMessage = 'Excluded duplicate properties must directly follow each other.';
Expand Down
7 changes: 7 additions & 0 deletions tests/sass/declarations-before-nesting.sass
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,10 @@
content: 'baz'

content: 'baz'

// issue #935 - ignore variables
+foo
#{$bar}
content: 'foobar'

$baz: 'qux'
9 changes: 9 additions & 0 deletions tests/sass/declarations-before-nesting.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,12 @@

content: 'baz';
}

// issue #935 - ignore variables
@mixin foo {
#{$bar} {
content: 'foobar';
}

$baz: 'qux';
}
5 changes: 5 additions & 0 deletions tests/sass/no-duplicate-properties.sass
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ $paint-border-2: left
border-#{$paint-border-1}: $size solid $color
border-#{$paint-border-2}: $size solid $color
border-#{$paint-border-2}: $size solid $color

// issue #935 - ignore variables
+foo
$i: 0
$i: 1
6 changes: 6 additions & 0 deletions tests/sass/no-duplicate-properties.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,9 @@ $paint-border-2: left;
border-#{$paint-border-2}: $size solid $color;
border-#{$paint-border-2}: $size solid $color;
}

// issue #935 - ignore variables
@mixin foo {
$i: 0;
$i: 1;
}

0 comments on commit 60624c2

Please sign in to comment.