Skip to content

Commit 2eb0d6b

Browse files
committed
Fix #57 FP on rule class-selector-naming-convention within mixin calls
1 parent 05350ed commit 2eb0d6b

File tree

6 files changed

+23
-2
lines changed

6 files changed

+23
-2
lines changed

css-checks/src/main/java/org/sonar/css/checks/common/ClassSelectorNamingConventionCheck.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.sonar.css.checks.Tags;
2929
import org.sonar.plugins.css.api.tree.css.ClassSelectorTree;
3030
import org.sonar.plugins.css.api.tree.css.IdentifierTree;
31+
import org.sonar.plugins.css.api.tree.less.LessMixinCallTree;
3132
import org.sonar.plugins.css.api.visitors.DoubleDispatchVisitorCheck;
3233
import org.sonar.squidbridge.annotations.ActivatedByDefault;
3334
import org.sonar.squidbridge.annotations.SqaleConstantRemediation;
@@ -56,7 +57,9 @@ public class ClassSelectorNamingConventionCheck extends DoubleDispatchVisitorChe
5657

5758
@Override
5859
public void visitClassSelector(ClassSelectorTree tree) {
59-
if (!tree.className().isInterpolated() && !tree.className().text().matches(format)) {
60+
if (!tree.className().isInterpolated()
61+
&& !tree.className().text().matches(format)
62+
&& !tree.parent().hasAncestor(LessMixinCallTree.class)) {
6063
addIssue(tree.className());
6164
}
6265
super.visitClassSelector(tree);

css-checks/src/test/resources/checks/common/class-selector-naming-convention/selectorNamingConvention.less

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,9 @@
1515

1616
.abc@{DEF}ghi { /* Compliant */
1717
}
18+
19+
.abc {
20+
.Mymixin;
21+
.Mymixin();
22+
.Mymxin
23+
}

css-frontend/src/test/java/org/sonar/css/parser/less/StyleSheetTreeTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public StyleSheetTreeTest() {
3939
public void stylesheet() throws Exception {
4040
StyleSheetTree tree;
4141

42+
tree = checkParsed(".abc { .space; }");
43+
assertThat(tree.atRules()).isEmpty();
44+
4245
checkParsed("");
4346
checkParsed(" ");
4447
checkParsed(" ");

its/ruling/projects/custom/common/class-selector-naming-convention/selectorNamingConvention.less

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,9 @@
1515

1616
.abc@{DEF}ghi { /* Compliant */
1717
}
18+
19+
.abc {
20+
.Mymixin;
21+
.Mymixin();
22+
.Mymxin
23+
}

its/ruling/tests/src/test/expected/css-alphabetize-declarations.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
59,
55
65,
66
71,
7-
87,
7+
87,g
88
101,
99
106,
1010
111,

its/ruling/tests/src/test/expected/less-selector-naming-convention.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
7,
55
13,
66
13,
7+
20,
8+
21,
9+
22,
710
],
811
'project:custom/common/id-selector-naming-convention/selectorNamingConvention.less':[
912
7,

0 commit comments

Comments
 (0)