diff options
8 files changed, 76 insertions, 0 deletions
| diff --git a/its/plugin/projects/issues-project/src/file1.css b/its/plugin/projects/issues-project/src/file1.css index e4e194b..35a9655 100644 --- a/its/plugin/projects/issues-project/src/file1.css +++ b/its/plugin/projects/issues-project/src/file1.css @@ -16,6 +16,10 @@    padding: 20px;                                              /* S4657 | declaration-block-no-shorthand-property-overrides */  } +.class1 {                                                     /* S4666 | no-duplicate-selectors */ +  width: 100px; +} +  a {    color: pink;;                                               /* S1116 | no-extra-semicolons */  } diff --git a/its/plugin/projects/issues-project/src/file2.less b/its/plugin/projects/issues-project/src/file2.less index b0a09ac..78138c9 100644 --- a/its/plugin/projects/issues-project/src/file2.less +++ b/its/plugin/projects/issues-project/src/file2.less @@ -16,6 +16,10 @@    padding: 20px;                                              /* S4657 | declaration-block-no-shorthand-property-overrides */  } +.class1 {                                                     /* S4666 | no-duplicate-selectors */ +  width: 100px; +} +  a {    color: pink;;                                               /* S1116 | no-extra-semicolons */  } diff --git a/its/plugin/projects/issues-project/src/file3.scss b/its/plugin/projects/issues-project/src/file3.scss index e4e194b..35a9655 100644 --- a/its/plugin/projects/issues-project/src/file3.scss +++ b/its/plugin/projects/issues-project/src/file3.scss @@ -16,6 +16,10 @@    padding: 20px;                                              /* S4657 | declaration-block-no-shorthand-property-overrides */  } +.class1 {                                                     /* S4666 | no-duplicate-selectors */ +  width: 100px; +} +  a {    color: pink;;                                               /* S1116 | no-extra-semicolons */  } diff --git a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/CssRules.java b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/CssRules.java index 479adb5..3951f64 100644 --- a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/CssRules.java +++ b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/CssRules.java @@ -39,6 +39,7 @@ import org.sonar.css.plugin.rules.FontFamilyNoDuplicateNames;  import org.sonar.css.plugin.rules.FontFamilyNoMissingGenericFamilyKeyword;  import org.sonar.css.plugin.rules.KeyframeDeclarationNoImportant;  import org.sonar.css.plugin.rules.NoDuplicateAtImportRules; +import org.sonar.css.plugin.rules.NoDuplicateSelectors;  import org.sonar.css.plugin.rules.NoEmptySource;  import org.sonar.css.plugin.rules.NoExtraSemicolons;  import org.sonar.css.plugin.rules.PropertyNoUnknown; @@ -72,6 +73,7 @@ public class CssRules {        FontFamilyNoMissingGenericFamilyKeyword.class,        KeyframeDeclarationNoImportant.class,        NoDuplicateAtImportRules.class, +      NoDuplicateSelectors.class,        NoEmptySource.class,        NoExtraSemicolons.class,        PropertyNoUnknown.class, diff --git a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/NoDuplicateSelectors.java b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/NoDuplicateSelectors.java new file mode 100644 index 0000000..9c1d2df --- /dev/null +++ b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/NoDuplicateSelectors.java @@ -0,0 +1,31 @@ +/* + * SonarCSS + * Copyright (C) 2018-2018 SonarSource SA + * mailto:info AT sonarsource DOT 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.plugin.rules; + +import org.sonar.check.Rule; + +@Rule(key = "S4666") +public class NoDuplicateSelectors implements CssRule { + +  @Override +  public String stylelintKey() { +    return "no-duplicate-selectors"; +  } +} diff --git a/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4666.html b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4666.html new file mode 100644 index 0000000..9521f64 --- /dev/null +++ b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4666.html @@ -0,0 +1,14 @@ +<p>When a selector appears more than once in a statement, this is not a bug but probably a mistake that reduces the readability of the source code. +Therefore, selectors should not be duplicated.</p> +<h2>Noncompliant Code Example</h2> +<pre> +.foo, +.bar, +.foo {} +</pre> +<h2>Compliant Solution</h2> +<pre> +.bar, +.foo {} +</pre> + diff --git a/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4666.json b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4666.json new file mode 100644 index 0000000..f8be3d1 --- /dev/null +++ b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4666.json @@ -0,0 +1,16 @@ +{ +  "title": "Selectors should not be duplicated", +  "type": "CODE_SMELL", +  "status": "ready", +  "remediation": { +    "func": "Constant\/Issue", +    "constantCost": "1min" +  }, +  "tags": [ +     +  ], +  "defaultSeverity": "Minor", +  "ruleSpecification": "RSPEC-4666", +  "sqKey": "S4666", +  "scope": "Main" +} diff --git a/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/Sonar_way_profile.json b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/Sonar_way_profile.json index aa28914..079c18c 100644 --- a/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/Sonar_way_profile.json +++ b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/Sonar_way_profile.json @@ -14,6 +14,7 @@      "S4657",      "S4658",      "S4663", +    "S4666",      "S4667"    ]  }
 | 
