From 12d9eddb516233de212434b329a35e114c387c5c Mon Sep 17 00:00:00 2001 From: Amaury Levé Date: Mon, 25 Jun 2018 13:41:54 +0200 Subject: Rule S4654: CSS properties should be valid --- its/plugin/projects/issues-project/src/file1.css | 4 ++- its/plugin/projects/issues-project/src/file2.less | 4 ++- its/plugin/projects/issues-project/src/file3.scss | 4 ++- .../main/java/org/sonar/css/plugin/CssRules.java | 2 ++ .../sonar/css/plugin/rules/PropertyNoUnknown.java | 31 ++++++++++++++++++++++ .../org/sonar/l10n/css/rules/css/S4654.html | 22 +++++++++++++++ .../org/sonar/l10n/css/rules/css/S4654.json | 16 +++++++++++ .../l10n/css/rules/css/Sonar_way_profile.json | 1 + 8 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/PropertyNoUnknown.java create mode 100644 sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4654.html create mode 100644 sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4654.json diff --git a/its/plugin/projects/issues-project/src/file1.css b/its/plugin/projects/issues-project/src/file1.css index 8d5bacb..68e9107 100644 --- a/its/plugin/projects/issues-project/src/file1.css +++ b/its/plugin/projects/issues-project/src/file1.css @@ -2,7 +2,7 @@ @import "a.css"; /* S1128 | no-duplicate-at-import-rules */ .class1 { -background-color: #ffw; /* S4647 | color-no-invalid-hex */ + background-color: #ffw; /* S4647 | color-no-invalid-hex */ width: 100pixels; /* S4653 | unit-no-unknown */ /* */ /* S4663 | comment-no-empty */ content: "first @@ -11,12 +11,14 @@ background-color: #ffw; /* S4647 | color-n 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 */ + heigth: 100%; /* S4654 | property-no-unknown */ } a { color: pink;; /* S1116 | no-extra-semicolons */ } + @keyframes important1 { from { margin-top: 50px; diff --git a/its/plugin/projects/issues-project/src/file2.less b/its/plugin/projects/issues-project/src/file2.less index 072a687..f6718d5 100644 --- a/its/plugin/projects/issues-project/src/file2.less +++ b/its/plugin/projects/issues-project/src/file2.less @@ -2,7 +2,7 @@ @import "a.css"; /* S1128 | no-duplicate-at-import-rules | Doesn't raise for LESS */ .class1 { -background-color: #ffw; /* S4647 | color-no-invalid-hex */ + background-color: #ffw; /* S4647 | color-no-invalid-hex */ width: 100pixels; /* S4653 | unit-no-unknown */ /* */ /* S4663 | comment-no-empty */ content: "first @@ -11,12 +11,14 @@ background-color: #ffw; /* S4647 | color-n 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 */ + heigth: 100%; /* S4654 | property-no-unknown */ } a { color: pink;; /* S1116 | no-extra-semicolons */ } + @keyframes important1 { from { margin-top: 50px; diff --git a/its/plugin/projects/issues-project/src/file3.scss b/its/plugin/projects/issues-project/src/file3.scss index 8d5bacb..68e9107 100644 --- a/its/plugin/projects/issues-project/src/file3.scss +++ b/its/plugin/projects/issues-project/src/file3.scss @@ -2,7 +2,7 @@ @import "a.css"; /* S1128 | no-duplicate-at-import-rules */ .class1 { -background-color: #ffw; /* S4647 | color-no-invalid-hex */ + background-color: #ffw; /* S4647 | color-no-invalid-hex */ width: 100pixels; /* S4653 | unit-no-unknown */ /* */ /* S4663 | comment-no-empty */ content: "first @@ -11,12 +11,14 @@ background-color: #ffw; /* S4647 | color-n 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 */ + heigth: 100%; /* S4654 | property-no-unknown */ } a { color: pink;; /* S1116 | no-extra-semicolons */ } + @keyframes important1 { from { margin-top: 50px; 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 689d361..87ff17b 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 @@ -40,6 +40,7 @@ import org.sonar.css.plugin.rules.KeyframeDeclarationNoImportant; import org.sonar.css.plugin.rules.NoDuplicateAtImportRules; import org.sonar.css.plugin.rules.NoEmptySource; import org.sonar.css.plugin.rules.NoExtraSemicolons; +import org.sonar.css.plugin.rules.PropertyNoUnknown; import org.sonar.css.plugin.rules.StringNoNewline; import org.sonar.css.plugin.rules.UnitNoUnknown; @@ -71,6 +72,7 @@ public class CssRules { NoDuplicateAtImportRules.class, NoEmptySource.class, NoExtraSemicolons.class, + PropertyNoUnknown.class, StringNoNewline.class, UnitNoUnknown.class )); diff --git a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/PropertyNoUnknown.java b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/PropertyNoUnknown.java new file mode 100644 index 0000000..cb4e51d --- /dev/null +++ b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/PropertyNoUnknown.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 = "S4654") +public class PropertyNoUnknown implements CssRule { + + @Override + public String stylelintKey() { + return "property-no-unknown"; + } +} diff --git a/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4654.html b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4654.html new file mode 100644 index 0000000..18f759a --- /dev/null +++ b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4654.html @@ -0,0 +1,22 @@ +

The W3C specifications define the valid CSS properties. Only the official and browser-specific properties should be used to get the expected impact +in the final rendering.

+

This rule ignores:

+

- $sass, @less, and var(--custom-property) variable syntaxes.

+

- vendor-prefixed properties (e.g., -moz-align-self, -webkit-align-self).

+

Noncompliant Code Example

+
+a {
+  colour: blue; // Noncompliant: colour is not part of the specifications
+}
+
+

Compliant Solution

+
+a {
+  color: blue;
+}
+
+

See

+ + diff --git a/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4654.json b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4654.json new file mode 100644 index 0000000..f466127 --- /dev/null +++ b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4654.json @@ -0,0 +1,16 @@ +{ + "title": "CSS properties should be valid", + "type": "BUG", + "status": "ready", + "remediation": { + "func": "Constant\/Issue", + "constantCost": "5min" + }, + "tags": [ + + ], + "defaultSeverity": "Blocker", + "ruleSpecification": "RSPEC-4654", + "sqKey": "S4654", + "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 d7ae454..5c03bb6 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 @@ -8,6 +8,7 @@ "S4649", "S4652", "S4653", + "S4654", "S4655", "S4656", "S4658", -- cgit v1.2.3