aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmaury Levé2018-06-22 14:41:52 +0200
committerGitHub2018-06-22 14:41:52 +0200
commit08d6560282dcd46710d7ad2db4ab8a4bb969e116 (patch)
tree23826903e1181a36481993b6c4b6100884a6c630
parent3922c3cd97c13f08bd2ec833e84ac167432d7de8 (diff)
downloadsonar-css-08d6560282dcd46710d7ad2db4ab8a4bb969e116.tar.bz2
Rule S4655: '!important' should not be used on 'keyframes' (#61)
-rw-r--r--its/plugin/projects/issues-project/src/file1.css17
-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.java12
-rw-r--r--sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/KeyframeDeclarationNoImportant.java31
-rw-r--r--sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4655.html23
-rw-r--r--sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4655.json16
-rw-r--r--sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/Sonar_way_profile.json1
-rw-r--r--sonarpedia.json4
9 files changed, 119 insertions, 19 deletions
diff --git a/its/plugin/projects/issues-project/src/file1.css b/its/plugin/projects/issues-project/src/file1.css
index 3d5ac89..4f9b880 100644
--- a/its/plugin/projects/issues-project/src/file1.css
+++ b/its/plugin/projects/issues-project/src/file1.css
@@ -1,7 +1,16 @@
.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 */
+}
+
+@keyframes important1 {
+ from {
+ margin-top: 50px;
+ }
+ 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 3d5ac89..4f9b880 100644
--- a/its/plugin/projects/issues-project/src/file2.less
+++ b/its/plugin/projects/issues-project/src/file2.less
@@ -1,7 +1,16 @@
.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 */
+}
+
+@keyframes important1 {
+ from {
+ margin-top: 50px;
+ }
+ 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 3d5ac89..4f9b880 100644
--- a/its/plugin/projects/issues-project/src/file3.scss
+++ b/its/plugin/projects/issues-project/src/file3.scss
@@ -1,7 +1,16 @@
.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 */
+}
+
+@keyframes important1 {
+ from {
+ margin-top: 50px;
+ }
+ 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 9e3a3b2..fe625d5 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.KeyframeDeclarationNoImportant;
import org.sonar.css.plugin.rules.NoEmptySource;
import org.sonar.css.plugin.rules.ColorNoInvalidHex;
import org.sonar.css.plugin.rules.StringNoNewline;
@@ -54,11 +55,12 @@ public class CssRules {
public static List<Class> getRuleClasses() {
return Collections.unmodifiableList(Arrays.asList(
- ColorNoInvalidHex.class,
- CommentNoEmpty.class,
- NoEmptySource.class,
- StringNoNewline.class,
- UnitNoUnknown.class
+ ColorNoInvalidHex.class,
+ CommentNoEmpty.class,
+ KeyframeDeclarationNoImportant.class,
+ NoEmptySource.class,
+ StringNoNewline.class,
+ UnitNoUnknown.class
));
}
diff --git a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/KeyframeDeclarationNoImportant.java b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/KeyframeDeclarationNoImportant.java
new file mode 100644
index 0000000..503f1ad
--- /dev/null
+++ b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/KeyframeDeclarationNoImportant.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 = "S4655")
+public class KeyframeDeclarationNoImportant implements CssRule {
+
+ @Override
+ public String stylelintKey() {
+ return "keyframe-declaration-no-important";
+ }
+}
diff --git a/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4655.html b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4655.html
new file mode 100644
index 0000000..e0653cf
--- /dev/null
+++ b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4655.html
@@ -0,0 +1,23 @@
+<p><code>!important</code> within keyframes declarations is completely ignored in some browsers and therefore it should not be used to be consistent
+among all browsers.</p>
+<h2>Noncompliant Code Example</h2>
+<pre>
+@keyframes kf {
+ from { margin-top: 50px; }
+ 50% { margin-top: 150px !important; } /* Noncompliant; ignored */
+ to { margin-top: 100px; }
+}
+</pre>
+<h2>Compliant Solution</h2>
+<pre>
+@keyframes kf {
+ from { margin-top: 50px; }
+ 50% { margin-top: 150px; }
+ to { margin-top: 100px; }
+}
+</pre>
+<h2>See</h2>
+<ul>
+ <li> https://developer.mozilla.org/en-US/docs/Web/CSS/@keyframes#!important_in_a_keyframe </li>
+</ul>
+
diff --git a/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4655.json b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4655.json
new file mode 100644
index 0000000..75a203f
--- /dev/null
+++ b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4655.json
@@ -0,0 +1,16 @@
+{
+ "title": "\"!important\" should not be used on \"keyframes\"",
+ "type": "BUG",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "1min"
+ },
+ "tags": [
+
+ ],
+ "defaultSeverity": "Major",
+ "ruleSpecification": "RSPEC-4655",
+ "sqKey": "S4655",
+ "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 613e33f..8f0de75 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
@@ -4,6 +4,7 @@
"S4647",
"S4652",
"S4653",
+ "S4655",
"S4663",
"S4667"
]
diff --git a/sonarpedia.json b/sonarpedia.json
index a4ca82e..26f40e5 100644
--- a/sonarpedia.json
+++ b/sonarpedia.json
@@ -3,8 +3,8 @@
"languages": [
"CSS"
],
+ "latest-update": "2018-06-22T12:40:51.596Z",
"options": {
"no-language-in-filenames": true
-
}
-}
+} \ No newline at end of file