diff options
8 files changed, 77 insertions, 0 deletions
diff --git a/its/plugin/projects/issues-project/src/file1.css b/its/plugin/projects/issues-project/src/file1.css index 68e9107..e4e194b 100644 --- a/its/plugin/projects/issues-project/src/file1.css +++ b/its/plugin/projects/issues-project/src/file1.css @@ -12,6 +12,8 @@ font: 1em/1.3 Times; /* S4649 | font-family-no-missing-generic-family-keyword */ font-family: serif, serif; /* S4648 | font-family-no-duplicate-names */ heigth: 100%; /* S4654 | property-no-unknown */ + padding-left: 10px; + padding: 20px; /* S4657 | declaration-block-no-shorthand-property-overrides */ } a { diff --git a/its/plugin/projects/issues-project/src/file2.less b/its/plugin/projects/issues-project/src/file2.less index f6718d5..b0a09ac 100644 --- a/its/plugin/projects/issues-project/src/file2.less +++ b/its/plugin/projects/issues-project/src/file2.less @@ -12,6 +12,8 @@ font: 1em/1.3 Times; /* S4649 | font-family-no-missing-generic-family-keyword */ font-family: serif, serif; /* S4648 | font-family-no-duplicate-names */ heigth: 100%; /* S4654 | property-no-unknown */ + padding-left: 10px; + padding: 20px; /* S4657 | declaration-block-no-shorthand-property-overrides */ } a { diff --git a/its/plugin/projects/issues-project/src/file3.scss b/its/plugin/projects/issues-project/src/file3.scss index 68e9107..e4e194b 100644 --- a/its/plugin/projects/issues-project/src/file3.scss +++ b/its/plugin/projects/issues-project/src/file3.scss @@ -12,6 +12,8 @@ font: 1em/1.3 Times; /* S4649 | font-family-no-missing-generic-family-keyword */ font-family: serif, serif; /* S4648 | font-family-no-duplicate-names */ heigth: 100%; /* S4654 | property-no-unknown */ + padding-left: 10px; + padding: 20px; /* S4657 | declaration-block-no-shorthand-property-overrides */ } a { 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 87ff17b..479adb5 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 @@ -34,6 +34,7 @@ import org.sonar.css.plugin.rules.ColorNoInvalidHex; 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.DeclarationBlockNoShorthandPropertyOverrides; import org.sonar.css.plugin.rules.FontFamilyNoDuplicateNames; import org.sonar.css.plugin.rules.FontFamilyNoMissingGenericFamilyKeyword; import org.sonar.css.plugin.rules.KeyframeDeclarationNoImportant; @@ -66,6 +67,7 @@ public class CssRules { ColorNoInvalidHex.class, CommentNoEmpty.class, DeclarationBlockNoDuplicateProperties.class, + DeclarationBlockNoShorthandPropertyOverrides.class, FontFamilyNoDuplicateNames.class, FontFamilyNoMissingGenericFamilyKeyword.class, KeyframeDeclarationNoImportant.class, diff --git a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/DeclarationBlockNoShorthandPropertyOverrides.java b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/DeclarationBlockNoShorthandPropertyOverrides.java new file mode 100644 index 0000000..4520129 --- /dev/null +++ b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/DeclarationBlockNoShorthandPropertyOverrides.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 = "S4657") +public class DeclarationBlockNoShorthandPropertyOverrides implements CssRule { + + @Override + public String stylelintKey() { + return "declaration-block-no-shorthand-property-overrides"; + } +} diff --git a/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4657.html b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4657.html new file mode 100644 index 0000000..ae083b9 --- /dev/null +++ b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4657.html @@ -0,0 +1,21 @@ +<p>A shorthand property defined after a longhand property will completely override the value defined in the longhand property making the longhand one +useless. The code should be refactored to consider the longhand property or to remove it completely.</p> +<h2>Noncompliant Code Example</h2> +<pre> +a { + padding-left: 10px; + padding: 20px; // Noncompliant; padding is overriding padding-left making it useless +} +</pre> +<h2>Compliant Solution</h2> +<pre> +a { + padding: 10px; // Compliant; padding is defining a general behaviour and padding-left, just after, is precising the left case + padding-left: 20px; +} +</pre> +<h2>See</h2> +<ul> + <li> https://developer.mozilla.org/en-US/docs/Web/CSS/Shorthand_properties </li> +</ul> + diff --git a/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4657.json b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4657.json new file mode 100644 index 0000000..6ac7d97 --- /dev/null +++ b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4657.json @@ -0,0 +1,16 @@ +{ + "title": "Shorthand properties that override related longhand properties should be avoided", + "type": "BUG", + "status": "ready", + "remediation": { + "func": "Constant\/Issue", + "constantCost": "5min" + }, + "tags": [ + + ], + "defaultSeverity": "Critical", + "ruleSpecification": "RSPEC-4657", + "sqKey": "S4657", + "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 5c03bb6..aa28914 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 @@ -11,6 +11,7 @@ "S4654", "S4655", "S4656", + "S4657", "S4658", "S4663", "S4667" |
