Skip to content

Commit 87dde3c

Browse files
committed
Fix #75 FP on rule multiple-variable-declarations-same-scope within mixin calls when parameters are the same variables
1 parent 158fcc4 commit 87dde3c

File tree

8 files changed

+29
-31
lines changed

8 files changed

+29
-31
lines changed

css-checks/src/test/resources/checks/less/multipleVariableDeclarationsSameScope.less

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@
1717
border-radius: @radius;
1818
}
1919

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

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

css-frontend/src/main/java/org/sonar/css/tree/symbol/SymbolVisitor.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,10 @@ public void visitLessMixinParameters(LessMixinParametersTree tree) {
7373
leaveScope();
7474
}
7575

76-
private void leaveScope() {
77-
if (currentScope != null) {
78-
currentScope = currentScope.outer();
79-
}
80-
}
81-
82-
private void enterScope(Tree tree) {
83-
currentScope = treeScopeMap.get(tree);
84-
if (currentScope == null) {
85-
throw new IllegalStateException("No scope found for the tree");
86-
}
87-
}
88-
8976
@Override
9077
public void visitLessVariable(LessVariableTree tree) {
9178
Usage.Kind usage;
92-
93-
if (tree.parent().is(Tree.Kind.LESS_VARIABLE_DECLARATION, Tree.Kind.LESS_MIXIN_PARAMETER)) {
79+
if (tree.parent().is(Tree.Kind.LESS_VARIABLE_DECLARATION)) {
9480
usage = Usage.Kind.DECLARATION;
9581
} else {
9682
usage = Usage.Kind.READ;
@@ -108,4 +94,18 @@ private void initScopes() {
10894
currentScope = null;
10995
}
11096

97+
98+
private void leaveScope() {
99+
if (currentScope != null) {
100+
currentScope = currentScope.outer();
101+
}
102+
}
103+
104+
private void enterScope(Tree tree) {
105+
currentScope = treeScopeMap.get(tree);
106+
if (currentScope == null) {
107+
throw new IllegalStateException("No scope found for the tree");
108+
}
109+
}
110+
111111
}

its/ruling/projects/custom/less/multipleVariableDeclarationsSameScope.less

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@
1717
border-radius: @radius;
1818
}
1919

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

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

its/ruling/tests/src/test/expected/less-experimental-property-usage.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,8 +1886,6 @@
18861886
16,
18871887
21,
18881888
22,
1889-
27,
1890-
28,
18911889
],
18921890
'project:custom/less/obsoleteFunctions.less':[
18931891
6,

its/ruling/tests/src/test/expected/less-line-length.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,8 +1045,6 @@
10451045
'project:custom/less/multipleVariableDeclarationsSameScope.less':[
10461046
1,
10471047
5,
1048-
20,
1049-
26,
10501048
],
10511049
'project:custom/less/nestedRulesets/nestedRulesets.less':[
10521050
18,

its/ruling/tests/src/test/expected/less-multiple-variable-declarations-same-scope.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,5 @@
88
'project:custom/less/multipleVariableDeclarationsSameScope.less':[
99
1,
1010
5,
11-
20,
12-
26,
1311
],
1412
}

its/ruling/tests/src/test/expected/less-prefer-single-line-comments.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2116,8 +2116,6 @@
21162116
'project:custom/less/multipleVariableDeclarationsSameScope.less':[
21172117
1,
21182118
5,
2119-
20,
2120-
26,
21212119
],
21222120
'project:custom/less/nestedRulesets/nestedRulesets.less':[
21232121
1,

its/ruling/tests/src/test/expected/less-variable-declaration-first.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
8,
1616
9,
1717
12,
18+
24,
19+
27,
1820
],
1921
'project:custom/less/variableDeclarationFirst.less':[
2022
19,

0 commit comments

Comments
 (0)