Skip to content

Commit

Permalink
Fix #75 FP on rule multiple-variable-declarations-same-scope within m…
Browse files Browse the repository at this point in the history
…ixin calls when parameters are the same variables
  • Loading branch information
racodond committed Dec 6, 2017
1 parent 158fcc4 commit 87dde3c
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
border-radius: @radius;
}

.border-radius2(@radius, @radius) { /* Noncompliant ![sc=18;ec=24;secondary=+0]! !{Merge those multiple variable declarations within the same scope.}! */
.border-radius2(@radius) {
-webkit-border-radius: @radius;
-moz-border-radius: @radius;
border-radius: @radius;
@radius: 10;
}

.border-radius3(@radius: 3px, @radius: 4px) { /* Noncompliant ![sc=18;ec=24;secondary=+0]! !{Merge those multiple variable declarations within the same scope.}! */
-webkit-border-radius: @radius;
-moz-border-radius: @radius;
@radius: 10;

.myclass {
@radius: 10;
border-radius: @radius;
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,10 @@ public void visitLessMixinParameters(LessMixinParametersTree tree) {
leaveScope();
}

private void leaveScope() {
if (currentScope != null) {
currentScope = currentScope.outer();
}
}

private void enterScope(Tree tree) {
currentScope = treeScopeMap.get(tree);
if (currentScope == null) {
throw new IllegalStateException("No scope found for the tree");
}
}

@Override
public void visitLessVariable(LessVariableTree tree) {
Usage.Kind usage;

if (tree.parent().is(Tree.Kind.LESS_VARIABLE_DECLARATION, Tree.Kind.LESS_MIXIN_PARAMETER)) {
if (tree.parent().is(Tree.Kind.LESS_VARIABLE_DECLARATION)) {
usage = Usage.Kind.DECLARATION;
} else {
usage = Usage.Kind.READ;
Expand All @@ -108,4 +94,18 @@ private void initScopes() {
currentScope = null;
}


private void leaveScope() {
if (currentScope != null) {
currentScope = currentScope.outer();
}
}

private void enterScope(Tree tree) {
currentScope = treeScopeMap.get(tree);
if (currentScope == null) {
throw new IllegalStateException("No scope found for the tree");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
border-radius: @radius;
}

.border-radius2(@radius, @radius) { /* Noncompliant ![sc=18;ec=24;secondary=+0]! !{Merge those multiple variable declarations within the same scope.}! */
.border-radius2(@radius) {
-webkit-border-radius: @radius;
-moz-border-radius: @radius;
border-radius: @radius;
@radius: 10;
}

.border-radius3(@radius: 3px, @radius: 4px) { /* Noncompliant ![sc=18;ec=24;secondary=+0]! !{Merge those multiple variable declarations within the same scope.}! */
-webkit-border-radius: @radius;
-moz-border-radius: @radius;
@radius: 10;

.myclass {
@radius: 10;
border-radius: @radius;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1886,8 +1886,6 @@
16,
21,
22,
27,
28,
],
'project:custom/less/obsoleteFunctions.less':[
6,
Expand Down
2 changes: 0 additions & 2 deletions its/ruling/tests/src/test/expected/less-line-length.json
Original file line number Diff line number Diff line change
Expand Up @@ -1045,8 +1045,6 @@
'project:custom/less/multipleVariableDeclarationsSameScope.less':[
1,
5,
20,
26,
],
'project:custom/less/nestedRulesets/nestedRulesets.less':[
18,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@
'project:custom/less/multipleVariableDeclarationsSameScope.less':[
1,
5,
20,
26,
],
}
Original file line number Diff line number Diff line change
Expand Up @@ -2116,8 +2116,6 @@
'project:custom/less/multipleVariableDeclarationsSameScope.less':[
1,
5,
20,
26,
],
'project:custom/less/nestedRulesets/nestedRulesets.less':[
1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
8,
9,
12,
24,
27,
],
'project:custom/less/variableDeclarationFirst.less':[
19,
Expand Down

0 comments on commit 87dde3c

Please sign in to comment.