diff --git a/README.md b/README.md index 0477528e..e3f4a2d7 100644 --- a/README.md +++ b/README.md @@ -152,7 +152,6 @@ It computes the complexity/rule, meaning the average number of selectors per rul * Regular expression on property * Regular expression on unit * Rule properties should be alphabetically ordered -* Selectors should follow a naming convention * Shorthand properties should be used whenever possible * Shorthand properties should not be used * Single quotes should be used instead of double quotes for strings diff --git a/css-checks/src/main/java/org/sonar/css/checks/CheckList.java b/css-checks/src/main/java/org/sonar/css/checks/CheckList.java index 9e887973..74a05ccc 100644 --- a/css-checks/src/main/java/org/sonar/css/checks/CheckList.java +++ b/css-checks/src/main/java/org/sonar/css/checks/CheckList.java @@ -167,7 +167,6 @@ private static List getCommonChecks() { QuotedGenericFontFamilyNamesCheck.class, QuotedUrlCheck.class, SelectorLikeRegExCheck.class, - SelectorNamingConventionCheck.class, SelectorNumberCheck.class, SemicolonDeclarationCheck.class, SingleQuotesCheck.class, @@ -249,7 +248,6 @@ public static List getEmbeddedCssChecks() { QuotedGenericFontFamilyNamesCheck.class, QuotedUrlCheck.class, SelectorLikeRegExCheck.class, - SelectorNamingConventionCheck.class, SelectorNumberCheck.class, SemicolonDeclarationCheck.class, SingleQuotesCheck.class, diff --git a/css-checks/src/main/java/org/sonar/css/checks/common/SelectorNamingConventionCheck.java b/css-checks/src/main/java/org/sonar/css/checks/common/SelectorNamingConventionCheck.java deleted file mode 100644 index c6b9c470..00000000 --- a/css-checks/src/main/java/org/sonar/css/checks/common/SelectorNamingConventionCheck.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * SonarQube CSS / SCSS / Less Analyzer - * Copyright (C) 2013-2017 David RACODON - * mailto: david.racodon@gmail.com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.css.checks.common; - -import com.google.common.annotations.VisibleForTesting; -import org.sonar.check.Priority; -import org.sonar.check.Rule; -import org.sonar.check.RuleProperty; -import org.sonar.css.checks.CheckList; -import org.sonar.css.checks.CheckUtils; -import org.sonar.css.checks.Tags; -import org.sonar.plugins.css.api.tree.Tree; -import org.sonar.plugins.css.api.tree.css.ClassSelectorTree; -import org.sonar.plugins.css.api.tree.css.IdSelectorTree; -import org.sonar.plugins.css.api.tree.scss.ScssPlaceholderSelectorTree; -import org.sonar.plugins.css.api.visitors.DoubleDispatchVisitorCheck; -import org.sonar.squidbridge.annotations.SqaleConstantRemediation; - -import java.text.MessageFormat; -import java.util.regex.Pattern; -import java.util.regex.PatternSyntaxException; - -@Rule( - key = "selector-naming-convention", - name = "Selectors should follow a naming convention", - priority = Priority.MINOR, - tags = {Tags.CONVENTION}, - status = "DEPRECATED") -@SqaleConstantRemediation("10min") -public class SelectorNamingConventionCheck extends DoubleDispatchVisitorCheck { - - private static final String DEFAULT_FORMAT = "^[a-z][-a-z0-9]*$"; - @RuleProperty( - key = "Format", - description = "Regular expression used to check the selector names against. See " + CheckUtils.LINK_TO_JAVA_REGEX_PATTERN_DOC + " for detailed regular expression syntax.", - defaultValue = DEFAULT_FORMAT) - private String format = DEFAULT_FORMAT; - - @Override - public void visitClassSelector(ClassSelectorTree tree) { - if (!tree.className().isInterpolated() && !tree.className().text().matches(format)) { - addIssue(tree.className(), tree.className().text()); - } - super.visitClassSelector(tree); - } - - @Override - public void visitIdSelector(IdSelectorTree tree) { - if (!tree.identifier().isInterpolated() && !tree.text().matches(format)) { - addIssue(tree.identifier(), tree.text()); - } - super.visitIdSelector(tree); - } - - @Override - public void visitScssPlaceholderSelector(ScssPlaceholderSelectorTree tree) { - if (!tree.name().isInterpolated() && !tree.text().matches(format)) { - addIssue(tree.name(), tree.text()); - } - super.visitScssPlaceholderSelector(tree); - } - - @VisibleForTesting - void setFormat(String format) { - this.format = format; - } - - @Override - public void validateParameters() { - try { - Pattern.compile(format); - } catch (PatternSyntaxException exception) { - throw new IllegalStateException(paramsErrorMessage(), exception); - } - } - - private String paramsErrorMessage() { - return CheckUtils.paramsErrorMessage( - this.getClass(), - CheckList.CSS_REPOSITORY_KEY, - "format parameter \"" + format + "\" is not a valid regular expression."); - } - - private void addIssue(Tree tree, String value) { - addPreciseIssue( - tree, - MessageFormat.format( - "Rename selector \"{0}\" to match the regular expression: {1}", - value, format)); - } - -} diff --git a/css-checks/src/main/resources/org/sonar/css/checks/l10n/common/template/selector-naming-convention.html b/css-checks/src/main/resources/org/sonar/css/checks/l10n/common/template/selector-naming-convention.html deleted file mode 100644 index 4b6ca08f..00000000 --- a/css-checks/src/main/resources/org/sonar/css/checks/l10n/common/template/selector-naming-convention.html +++ /dev/null @@ -1,61 +0,0 @@ -

This rule is deprecated. It is now split into three dedicated rules:

- -

- Shared coding conventions allow teams to collaborate efficiently. This rule checks that all selector names match a - provided regular expression. -

-

- The default regular expression only allows lowercase letters, digits and hyphens. Uppercase letters are not allowed - because CSS selectors are used in HTML. As HTML is case-insensitive, it is usually written in lowercase and it may - be confusing and even error-prone to add CSS selectors with uppercase letters to the HTML code. -

- -

Noncompliant Code Example

-With format ^[a-z][-a-z0-9]*$: -
-.myBox {  /* Noncompliant: Should be 'mybox' or 'my-box' instead for example */
-}
-
-.my_box {  /* Noncompliant: Should be 'mybox' or 'my-box' instead for example */
-}
-
- -

Compliant Solution

-With format ^[a-z][-a-z0-9]*$: -
-.mybox {
-}
-
-.my-box {
-}
-
- -[begin-less] -

Exceptions

-

- Less interpolated selectors are not checked for naming convention. For instance, the following piece of code does - not raise an issue: -

-
-.abc-@{DEF} {
-  color: green;
-}
-
-[end-less] - -[begin-scss] -

Exceptions

-

- SCSS interpolated selectors are not checked for naming convention. For instance, the following piece of code does - not raise an issue: -

-
-.abc-#{$DEF} {
-  color: green;
-}
-
-[end-scss] diff --git a/css-checks/src/test/java/org/sonar/css/checks/common/SelectorNamingConventionCheckTest.java b/css-checks/src/test/java/org/sonar/css/checks/common/SelectorNamingConventionCheckTest.java deleted file mode 100644 index d50e00dd..00000000 --- a/css-checks/src/test/java/org/sonar/css/checks/common/SelectorNamingConventionCheckTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * SonarQube CSS / SCSS / Less Analyzer - * Copyright (C) 2013-2017 David RACODON - * mailto: david.racodon@gmail.com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.css.checks.common; - -import org.junit.Test; -import org.sonar.css.checks.CheckTestUtils; -import org.sonar.css.checks.verifier.CssCheckVerifier; - -import java.io.File; - -import static org.fest.assertions.Assertions.assertThat; - -public class SelectorNamingConventionCheckTest { - - private final SelectorNamingConventionCheck check = new SelectorNamingConventionCheck(); - - @Test - public void test_with_default_format() { - check.setFormat("^[a-z][-a-z0-9]*$"); - CssCheckVerifier.verifyCssFile(check, getTestFile("selectorNamingConvention.css")); - } - - @Test - public void test_with_custom_format() { - check.setFormat("^[-a-z]+$"); - CssCheckVerifier.verifyCssFile(check, getTestFile("selectorNamingConventionCustomFormat.css")); - } - - @Test - public void test_scss_placeholder() { - check.setFormat("^[-a-z]+$"); - CssCheckVerifier.verifyScssFile(check, getTestFile("selectorNamingConventionScssPlaceholder.scss")); - } - - @Test - public void test_interpolated_selectors_not_checked_on_less_file() { - check.setFormat("^[a-z][-a-z0-9]*$"); - CssCheckVerifier.verifyLessFile(check, getTestFile("selectorNamingConvention.less")); - } - - @Test - public void should_throw_an_illegal_state_exception_as_the_format_parameter_is_not_valid() { - try { - check.setFormat("("); - - CssCheckVerifier.issuesOnCssFile(check, CheckTestUtils.getCommonTestFile("selectorNamingConvention/selectorNamingConvention.css")).noMore(); - - } catch (IllegalStateException e) { - assertThat(e.getMessage()).isEqualTo("Check css:selector-naming-convention (Selectors should follow a naming convention): " - + "format parameter \"(\" is not a valid regular expression."); - } - } - - private File getTestFile(String fileName) { - return CheckTestUtils.getCommonTestFile("selectorNamingConvention/" + fileName); - } - -} 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 a08760cb..eb8b9b57 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,9 +39,6 @@ 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/tests/src/test/expected/css-alphabetize-declarations.json b/its/ruling/tests/src/test/expected/css-alphabetize-declarations.json index aedf5b1f..9596c13a 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,g +87, 101, 106, 111, diff --git a/its/ruling/tests/src/test/expected/css-selector-naming-convention.json b/its/ruling/tests/src/test/expected/css-selector-naming-convention.json deleted file mode 100644 index 5ed1d8c5..00000000 --- a/its/ruling/tests/src/test/expected/css-selector-naming-convention.json +++ /dev/null @@ -1,28 +0,0 @@ -{ -'project:custom/common/class-selector-naming-convention/selectorNamingConvention.css':[ -4, -7, -13, -13, -], -'project:custom/common/class-selector-naming-convention/selectorNamingConventionCustomFormat.css':[ -4, -7, -13, -13, -], -'project:custom/common/id-selector-naming-convention/selectorNamingConvention.css':[ -7, -10, -10, -], -'project:custom/common/selectorNamingConvention/selectorNamingConvention.css':[ -10, -13, -19, -], -'project:custom/common/selectorNamingConvention/selectorNamingConventionCustomFormat.css':[ -10, -13, -], -} 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 deleted file mode 100644 index dec3c588..00000000 --- a/its/ruling/tests/src/test/expected/less-selector-naming-convention.json +++ /dev/null @@ -1,21 +0,0 @@ -{ -'project:custom/common/class-selector-naming-convention/selectorNamingConvention.less':[ -4, -7, -13, -13, -20, -21, -22, -], -'project:custom/common/id-selector-naming-convention/selectorNamingConvention.less':[ -7, -10, -10, -], -'project:custom/common/selectorNamingConvention/selectorNamingConvention.less':[ -10, -13, -19, -], -} diff --git a/its/ruling/tests/src/test/expected/scss-selector-naming-convention.json b/its/ruling/tests/src/test/expected/scss-selector-naming-convention.json deleted file mode 100644 index a11c4b01..00000000 --- a/its/ruling/tests/src/test/expected/scss-selector-naming-convention.json +++ /dev/null @@ -1,22 +0,0 @@ -{ -'project:custom/common/class-selector-naming-convention/selectorNamingConvention.scss':[ -4, -7, -13, -13, -], -'project:custom/common/id-selector-naming-convention/selectorNamingConvention.scss':[ -7, -10, -10, -], -'project:custom/common/selectorNamingConvention/selectorNamingConventionScssPlaceholder.scss':[ -6, -], -'project:custom/scss/extend.scss':[ -1, -], -'project:custom/scss/placeholder-selector-naming-convention/selectorNamingConvention.scss':[ -4, -], -} diff --git a/sonar-css-plugin/src/test/java/org/sonar/plugins/css/css/CssRulesDefinitionTest.java b/sonar-css-plugin/src/test/java/org/sonar/plugins/css/css/CssRulesDefinitionTest.java index 1557fd4a..e2369453 100644 --- a/sonar-css-plugin/src/test/java/org/sonar/plugins/css/css/CssRulesDefinitionTest.java +++ b/sonar-css-plugin/src/test/java/org/sonar/plugins/css/css/CssRulesDefinitionTest.java @@ -38,7 +38,7 @@ public void test() { assertThat(repository.name()).isEqualTo("SonarQube"); assertThat(repository.language()).isEqualTo("css"); - assertThat(repository.rules()).hasSize(88); + assertThat(repository.rules()).hasSize(87); assertThat(CheckList.getEmbeddedCssChecks()).hasSize(repository.rules().size() - 6); diff --git a/sonar-css-plugin/src/test/java/org/sonar/plugins/css/less/LessRulesDefinitionTest.java b/sonar-css-plugin/src/test/java/org/sonar/plugins/css/less/LessRulesDefinitionTest.java index 714840c8..c7354d88 100644 --- a/sonar-css-plugin/src/test/java/org/sonar/plugins/css/less/LessRulesDefinitionTest.java +++ b/sonar-css-plugin/src/test/java/org/sonar/plugins/css/less/LessRulesDefinitionTest.java @@ -38,7 +38,7 @@ public void test() { assertThat(repository.name()).isEqualTo("SonarQube"); assertThat(repository.language()).isEqualTo("less"); - assertThat(repository.rules()).hasSize(89); + assertThat(repository.rules()).hasSize(88); RulesDefinition.Rule rule = repository.rule(DeprecatedEscapingFunctionCheck.class.getAnnotation(Rule.class).key()); assertThat(rule).isNotNull(); diff --git a/sonar-css-plugin/src/test/java/org/sonar/plugins/css/scss/ScssRulesDefinitionTest.java b/sonar-css-plugin/src/test/java/org/sonar/plugins/css/scss/ScssRulesDefinitionTest.java index 6c7c7b50..04d17403 100644 --- a/sonar-css-plugin/src/test/java/org/sonar/plugins/css/scss/ScssRulesDefinitionTest.java +++ b/sonar-css-plugin/src/test/java/org/sonar/plugins/css/scss/ScssRulesDefinitionTest.java @@ -38,7 +38,7 @@ public void test() { assertThat(repository.name()).isEqualTo("SonarQube"); assertThat(repository.language()).isEqualTo("scss"); - assertThat(repository.rules()).hasSize(100); + assertThat(repository.rules()).hasSize(99); RulesDefinition.Rule rule = repository.rule(ScssVariableNamingConventionCheck.class.getAnnotation(Rule.class).key()); assertThat(rule).isNotNull();