aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmaury Levé2018-06-25 11:35:15 +0200
committerElena Vilchik2018-06-25 11:57:13 +0200
commit99ba1731fae85f49ae6bd9462a7d52070f104b52 (patch)
treef3aceb434dba098a5b43d7512f9274e2043f21e6
parent15137476e5c5a2a4a39016928750cc0bd9af5f57 (diff)
downloadsonar-css-99ba1731fae85f49ae6bd9462a7d52070f104b52.tar.bz2
Rule S4648: Duplicated font names should be removed
-rw-r--r--its/plugin/projects/issues-project/src/file1.css15
-rw-r--r--its/plugin/projects/issues-project/src/file2.less17
-rw-r--r--its/plugin/projects/issues-project/src/file3.scss17
-rw-r--r--sonar-css-plugin/src/main/java/org/sonar/css/plugin/CssRules.java2
-rw-r--r--sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/FontFamilyNoDuplicateNames.java31
-rw-r--r--sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4648.html16
-rw-r--r--sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4648.json16
-rw-r--r--sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/Sonar_way_profile.json1
8 files changed, 92 insertions, 23 deletions
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 @@
+<p>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 <code>font</code> or <code>font-family</code> properties contain a duplicated font name. 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 {
+ font-family: 'Georgia', Georgia, serif;
+}
+</pre>
+<h2>Compliant Solution</h2>
+<pre>
+a {
+ font-family: Georgia, serif;
+}
+</pre>
+
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",