From 99ba1731fae85f49ae6bd9462a7d52070f104b52 Mon Sep 17 00:00:00 2001 From: Amaury Levé Date: Mon, 25 Jun 2018 11:35:15 +0200 Subject: Rule S4648: Duplicated font names should be removed --- its/plugin/projects/issues-project/src/file1.css | 15 ++++++----- its/plugin/projects/issues-project/src/file2.less | 17 ++++++------ its/plugin/projects/issues-project/src/file3.scss | 17 ++++++------ .../main/java/org/sonar/css/plugin/CssRules.java | 2 ++ .../plugin/rules/FontFamilyNoDuplicateNames.java | 31 ++++++++++++++++++++++ .../org/sonar/l10n/css/rules/css/S4648.html | 16 +++++++++++ .../org/sonar/l10n/css/rules/css/S4648.json | 16 +++++++++++ .../l10n/css/rules/css/Sonar_way_profile.json | 1 + 8 files changed, 92 insertions(+), 23 deletions(-) create mode 100644 sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/FontFamilyNoDuplicateNames.java create mode 100644 sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4648.html create mode 100644 sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4648.json diff --git a/its/plugin/projects/issues-project/src/file1.css b/its/plugin/projects/issues-project/src/file1.css index 241fd2e..13c2cc0 100644 --- a/its/plugin/projects/issues-project/src/file1.css +++ b/its/plugin/projects/issues-project/src/file1.css @@ -1,15 +1,16 @@ @import "a.css"; -@import "a.css"; /* S1128 | no-duplicate-at-import-rules */ +@import "a.css"; /* S1128 | no-duplicate-at-import-rules */ .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 */ - font: 1em/1.3 Times; /* S4649 | font-family-no-missing-generic-family-keyword */ + color: orange; /* S4656 | declaration-block-no-duplicate-properties */ + font: 1em/1.3 Times; /* S4649 | font-family-no-missing-generic-family-keyword */ + font-family: serif, serif; /* S4648 | font-family-no-duplicate-names */ } @keyframes important1 { diff --git a/its/plugin/projects/issues-project/src/file2.less b/its/plugin/projects/issues-project/src/file2.less index e2d0e54..f8ddf14 100644 --- a/its/plugin/projects/issues-project/src/file2.less +++ b/its/plugin/projects/issues-project/src/file2.less @@ -1,15 +1,16 @@ -@import 'a.css'; -@import 'a.css'; /* S1128 | no-duplicate-at-import-rules | Doesn't raise for LESS */ +@import "a.css"; +@import "a.css"; /* S1128 | no-duplicate-at-import-rules | Doesn't raise for LESS */ .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 */ - font: 1em/1.3 Times; /* S4649 | font-family-no-missing-generic-family-keyword */ + color: orange; /* S4656 | declaration-block-no-duplicate-properties */ + font: 1em/1.3 Times; /* S4649 | font-family-no-missing-generic-family-keyword */ + font-family: serif, serif; /* S4648 | font-family-no-duplicate-names */ } @keyframes important1 { diff --git a/its/plugin/projects/issues-project/src/file3.scss b/its/plugin/projects/issues-project/src/file3.scss index 7b74808..13c2cc0 100644 --- a/its/plugin/projects/issues-project/src/file3.scss +++ b/its/plugin/projects/issues-project/src/file3.scss @@ -1,15 +1,16 @@ -@import 'a.css'; -@import 'a.css'; /* S1128 | no-duplicate-at-import-rules */ +@import "a.css"; +@import "a.css"; /* S1128 | no-duplicate-at-import-rules */ .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 */ - font: 1em/1.3 Times; /* S4649 | font-family-no-missing-generic-family-keyword */ + color: orange; /* S4656 | declaration-block-no-duplicate-properties */ + font: 1em/1.3 Times; /* S4649 | font-family-no-missing-generic-family-keyword */ + font-family: serif, serif; /* S4648 | font-family-no-duplicate-names */ } @keyframes important1 { 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 4456b50..255f58f 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 @@ -33,6 +33,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.FontFamilyNoDuplicateNames; import org.sonar.css.plugin.rules.FontFamilyNoMissingGenericFamilyKeyword; import org.sonar.css.plugin.rules.KeyframeDeclarationNoImportant; import org.sonar.css.plugin.rules.NoDuplicateAtImportRules; @@ -61,6 +62,7 @@ public class CssRules { ColorNoInvalidHex.class, CommentNoEmpty.class, DeclarationBlockNoDuplicateProperties.class, + FontFamilyNoDuplicateNames.class, FontFamilyNoMissingGenericFamilyKeyword.class, KeyframeDeclarationNoImportant.class, NoDuplicateAtImportRules.class, diff --git a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/FontFamilyNoDuplicateNames.java b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/FontFamilyNoDuplicateNames.java new file mode 100644 index 0000000..b1258e2 --- /dev/null +++ b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/FontFamilyNoDuplicateNames.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 = "S4648") +public class FontFamilyNoDuplicateNames implements CssRule { + + @Override + public String stylelintKey() { + return "font-family-no-duplicate-names"; + } +} diff --git a/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4648.html b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4648.html new file mode 100644 index 0000000..02b3570 --- /dev/null +++ b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4648.html @@ -0,0 +1,16 @@ +
Having duplicated font names doesn't help to read the font declaration and may be an indicator the author of the line was not sure how to configure
+it. This rule raises an issue when font or font-family properties contain a duplicated font name. This rule ignores
+$sass, @less, and var(--custom-property) variable syntaxes.
+a {
+  font-family: 'Georgia', Georgia, serif;
+}
+
+
+a {
+  font-family: Georgia, serif;
+}
+
+
diff --git a/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4648.json b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4648.json
new file mode 100644
index 0000000..487ab8a
--- /dev/null
+++ b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4648.json
@@ -0,0 +1,16 @@
+{
+  "title": "Duplicated font names should be removed",
+  "type": "CODE_SMELL",
+  "status": "ready",
+  "remediation": {
+    "func": "Constant\/Issue",
+    "constantCost": "1min"
+  },
+  "tags": [
+    
+  ],
+  "defaultSeverity": "Major",
+  "ruleSpecification": "RSPEC-4648",
+  "sqKey": "S4648",
+  "scope": "All"
+}
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 5fb55c0..64ab8d6 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
@@ -3,6 +3,7 @@
   "ruleKeys": [
     "S1128",
     "S4647",
+    "S4648",
     "S4649",
     "S4652",
     "S4653",
-- 
cgit v1.2.3