From 2eb0d6b36592f285609ff40bbc21bf69f2eb354a Mon Sep 17 00:00:00 2001 From: David RACODON Date: Thu, 14 Sep 2017 18:30:04 +0200 Subject: [PATCH] Fix #57 FP on rule class-selector-naming-convention within mixin calls --- .../checks/common/ClassSelectorNamingConventionCheck.java | 5 ++++- .../selectorNamingConvention.less | 6 ++++++ .../java/org/sonar/css/parser/less/StyleSheetTreeTest.java | 3 +++ .../selectorNamingConvention.less | 6 ++++++ .../src/test/expected/css-alphabetize-declarations.json | 2 +- .../src/test/expected/less-selector-naming-convention.json | 3 +++ 6 files changed, 23 insertions(+), 2 deletions(-) diff --git a/css-checks/src/main/java/org/sonar/css/checks/common/ClassSelectorNamingConventionCheck.java b/css-checks/src/main/java/org/sonar/css/checks/common/ClassSelectorNamingConventionCheck.java index a1cc093d..00c2057d 100644 --- a/css-checks/src/main/java/org/sonar/css/checks/common/ClassSelectorNamingConventionCheck.java +++ b/css-checks/src/main/java/org/sonar/css/checks/common/ClassSelectorNamingConventionCheck.java @@ -28,6 +28,7 @@ import org.sonar.css.checks.Tags; import org.sonar.plugins.css.api.tree.css.ClassSelectorTree; import org.sonar.plugins.css.api.tree.css.IdentifierTree; +import org.sonar.plugins.css.api.tree.less.LessMixinCallTree; import org.sonar.plugins.css.api.visitors.DoubleDispatchVisitorCheck; import org.sonar.squidbridge.annotations.ActivatedByDefault; import org.sonar.squidbridge.annotations.SqaleConstantRemediation; @@ -56,7 +57,9 @@ public class ClassSelectorNamingConventionCheck extends DoubleDispatchVisitorChe @Override public void visitClassSelector(ClassSelectorTree tree) { - if (!tree.className().isInterpolated() && !tree.className().text().matches(format)) { + if (!tree.className().isInterpolated() + && !tree.className().text().matches(format) + && !tree.parent().hasAncestor(LessMixinCallTree.class)) { addIssue(tree.className()); } super.visitClassSelector(tree); diff --git a/css-checks/src/test/resources/checks/common/class-selector-naming-convention/selectorNamingConvention.less b/css-checks/src/test/resources/checks/common/class-selector-naming-convention/selectorNamingConvention.less index afb89fd4..8ac8cf93 100644 --- a/css-checks/src/test/resources/checks/common/class-selector-naming-convention/selectorNamingConvention.less +++ b/css-checks/src/test/resources/checks/common/class-selector-naming-convention/selectorNamingConvention.less @@ -15,3 +15,9 @@ .abc@{DEF}ghi { /* Compliant */ } + +.abc { + .Mymixin; + .Mymixin(); + .Mymxin +} diff --git a/css-frontend/src/test/java/org/sonar/css/parser/less/StyleSheetTreeTest.java b/css-frontend/src/test/java/org/sonar/css/parser/less/StyleSheetTreeTest.java index eb8b9b57..a08760cb 100644 --- a/css-frontend/src/test/java/org/sonar/css/parser/less/StyleSheetTreeTest.java +++ b/css-frontend/src/test/java/org/sonar/css/parser/less/StyleSheetTreeTest.java @@ -39,6 +39,9 @@ public StyleSheetTreeTest() { public void stylesheet() throws Exception { StyleSheetTree tree; + tree = checkParsed(".abc { .space; }"); + assertThat(tree.atRules()).isEmpty(); + checkParsed(""); checkParsed(" "); checkParsed(" "); diff --git a/its/ruling/projects/custom/common/class-selector-naming-convention/selectorNamingConvention.less b/its/ruling/projects/custom/common/class-selector-naming-convention/selectorNamingConvention.less index afb89fd4..8ac8cf93 100644 --- a/its/ruling/projects/custom/common/class-selector-naming-convention/selectorNamingConvention.less +++ b/its/ruling/projects/custom/common/class-selector-naming-convention/selectorNamingConvention.less @@ -15,3 +15,9 @@ .abc@{DEF}ghi { /* Compliant */ } + +.abc { + .Mymixin; + .Mymixin(); + .Mymxin +} diff --git a/its/ruling/tests/src/test/expected/css-alphabetize-declarations.json b/its/ruling/tests/src/test/expected/css-alphabetize-declarations.json index 9596c13a..aedf5b1f 100644 --- a/its/ruling/tests/src/test/expected/css-alphabetize-declarations.json +++ b/its/ruling/tests/src/test/expected/css-alphabetize-declarations.json @@ -4,7 +4,7 @@ 59, 65, 71, -87, +87,g 101, 106, 111, diff --git a/its/ruling/tests/src/test/expected/less-selector-naming-convention.json b/its/ruling/tests/src/test/expected/less-selector-naming-convention.json index 08f4c4ff..dec3c588 100644 --- a/its/ruling/tests/src/test/expected/less-selector-naming-convention.json +++ b/its/ruling/tests/src/test/expected/less-selector-naming-convention.json @@ -4,6 +4,9 @@ 7, 13, 13, +20, +21, +22, ], 'project:custom/common/id-selector-naming-convention/selectorNamingConvention.less':[ 7,