diff options
| author | Amaury Levé | 2018-06-22 16:22:04 +0200 |
|---|---|---|
| committer | GitHub | 2018-06-22 16:22:04 +0200 |
| commit | 7385260825c79419a920bdf835e925cef916b404 (patch) | |
| tree | 0d50a28fc9e2eb0de3169c602651617c6d2a8c13 | |
| parent | 08d6560282dcd46710d7ad2db4ab8a4bb969e116 (diff) | |
| download | sonar-css-7385260825c79419a920bdf835e925cef916b404.tar.bz2 | |
Rule S4656: Properties should not be duplicated (#63)
8 files changed, 90 insertions, 15 deletions
diff --git a/its/plugin/projects/issues-project/src/file1.css b/its/plugin/projects/issues-project/src/file1.css index 4f9b880..afd6213 100644 --- a/its/plugin/projects/issues-project/src/file1.css +++ b/its/plugin/projects/issues-project/src/file1.css @@ -1,9 +1,11 @@ .class1 { - background-color: #ffw; /* S4647 | color-no-invalid-hex */ - width: 100pixels; /* S4653 | unit-no-unknown */ - /* */ /* S4663 | comment-no-empty */ + background-color: #ffw; /* S4647 | color-no-invalid-hex */ + width: 100pixels; /* S4653 | unit-no-unknown */ + /* */ /* S4663 | comment-no-empty */ content: "first - second"; /* S4652 | string-no-newline */ + second"; /* S4652 | string-no-newline */ + color: pink; + color: orange; /* S4656 | declaration-block-no-duplicate-properties */ } @keyframes important1 { @@ -13,4 +15,4 @@ to { margin-top: 100px !important; /* S4655 | keyframe-declaration-no-important */ } -}
\ No newline at end of file +} diff --git a/its/plugin/projects/issues-project/src/file2.less b/its/plugin/projects/issues-project/src/file2.less index 4f9b880..afd6213 100644 --- a/its/plugin/projects/issues-project/src/file2.less +++ b/its/plugin/projects/issues-project/src/file2.less @@ -1,9 +1,11 @@ .class1 { - background-color: #ffw; /* S4647 | color-no-invalid-hex */ - width: 100pixels; /* S4653 | unit-no-unknown */ - /* */ /* S4663 | comment-no-empty */ + background-color: #ffw; /* S4647 | color-no-invalid-hex */ + width: 100pixels; /* S4653 | unit-no-unknown */ + /* */ /* S4663 | comment-no-empty */ content: "first - second"; /* S4652 | string-no-newline */ + second"; /* S4652 | string-no-newline */ + color: pink; + color: orange; /* S4656 | declaration-block-no-duplicate-properties */ } @keyframes important1 { @@ -13,4 +15,4 @@ to { margin-top: 100px !important; /* S4655 | keyframe-declaration-no-important */ } -}
\ No newline at end of file +} diff --git a/its/plugin/projects/issues-project/src/file3.scss b/its/plugin/projects/issues-project/src/file3.scss index 4f9b880..afd6213 100644 --- a/its/plugin/projects/issues-project/src/file3.scss +++ b/its/plugin/projects/issues-project/src/file3.scss @@ -1,9 +1,11 @@ .class1 { - background-color: #ffw; /* S4647 | color-no-invalid-hex */ - width: 100pixels; /* S4653 | unit-no-unknown */ - /* */ /* S4663 | comment-no-empty */ + background-color: #ffw; /* S4647 | color-no-invalid-hex */ + width: 100pixels; /* S4653 | unit-no-unknown */ + /* */ /* S4663 | comment-no-empty */ content: "first - second"; /* S4652 | string-no-newline */ + second"; /* S4652 | string-no-newline */ + color: pink; + color: orange; /* S4656 | declaration-block-no-duplicate-properties */ } @keyframes important1 { @@ -13,4 +15,4 @@ to { margin-top: 100px !important; /* S4655 | keyframe-declaration-no-important */ } -}
\ No newline at end of file +} 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 fe625d5..92d59aa 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 @@ -24,6 +24,7 @@ import org.sonar.api.batch.rule.Checks; import org.sonar.api.rule.RuleKey; import org.sonar.css.plugin.rules.CommentNoEmpty; import org.sonar.css.plugin.rules.CssRule; +import org.sonar.css.plugin.rules.DeclarationBlockNoDuplicateProperties; import org.sonar.css.plugin.rules.KeyframeDeclarationNoImportant; import org.sonar.css.plugin.rules.NoEmptySource; import org.sonar.css.plugin.rules.ColorNoInvalidHex; @@ -57,6 +58,7 @@ public class CssRules { return Collections.unmodifiableList(Arrays.asList( ColorNoInvalidHex.class, CommentNoEmpty.class, + DeclarationBlockNoDuplicateProperties.class, KeyframeDeclarationNoImportant.class, NoEmptySource.class, StringNoNewline.class, diff --git a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/DeclarationBlockNoDuplicateProperties.java b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/DeclarationBlockNoDuplicateProperties.java new file mode 100644 index 0000000..75382de --- /dev/null +++ b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/DeclarationBlockNoDuplicateProperties.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 = "S4656") +public class DeclarationBlockNoDuplicateProperties implements CssRule { + + @Override + public String stylelintKey() { + return "declaration-block-no-duplicate-properties"; + } +} diff --git a/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4656.html b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4656.html new file mode 100644 index 0000000..d852e29 --- /dev/null +++ b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4656.html @@ -0,0 +1,19 @@ +<p>CSS allows duplicate property names but only the last instance of a duplicated name determines the actual value that will be used for it. +Therefore, changing values of other occurrences of a duplicated name will have no effect and may cause misunderstandings and bugs.</p> +<p>This rule ignores <code>$sass</code>, <code>@less</code>, and <code>var(--custom-property)</code> variable syntaxes.</p> +<h2>Noncompliant Code Example</h2> +<pre> +a { + color: pink; + background: orange; + color: orange +} +</pre> +<h2>Compliant Solution</h2> +<pre> +a { + color: pink; + background: orange +} +</pre> + diff --git a/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4656.json b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4656.json new file mode 100644 index 0000000..895ddb2 --- /dev/null +++ b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4656.json @@ -0,0 +1,16 @@ +{ + "title": "Properties should not be duplicated", + "type": "BUG", + "status": "ready", + "remediation": { + "func": "Constant\/Issue", + "constantCost": "1min" + }, + "tags": [ + + ], + "defaultSeverity": "Major", + "ruleSpecification": "RSPEC-4656", + "sqKey": "S4656", + "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 8f0de75..14b9668 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 @@ -5,6 +5,7 @@ "S4652", "S4653", "S4655", + "S4656", "S4663", "S4667" ] |
