diff options
| author | Amaury Levé | 2018-06-26 14:03:10 +0200 |
|---|---|---|
| committer | Amaury Levé | 2018-06-26 14:22:27 +0200 |
| commit | 83a0a343d718c58d432bb218e412527de049070f (patch) | |
| tree | 5d3e1273e3b60a5690a893b276b9e69b1f8b7c93 | |
| parent | 4a1ff687e026063223350de7e1e4550847cf0d1a (diff) | |
| download | sonar-css-83a0a343d718c58d432bb218e412527de049070f.tar.bz2 | |
Rule S4662: at-rules should be valid
8 files changed, 76 insertions, 3 deletions
diff --git a/its/plugin/projects/issues-project/src/file1.css b/its/plugin/projects/issues-project/src/file1.css index ad26232..03b5ce8 100644 --- a/its/plugin/projects/issues-project/src/file1.css +++ b/its/plugin/projects/issues-project/src/file1.css @@ -21,7 +21,7 @@ a:unknown { /* S4659 | selecto } .class1 { /* S4666 | no-duplicate-selectors */ - width: 100px; + padding: 100px; } a { @@ -36,6 +36,10 @@ unknown { /* S4670 | selecto color: black; } +@unknown { /* S4662 | at-rule-no-unknown */ + width: 1px; +} + @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 fde33bf..3d6e90b 100644 --- a/its/plugin/projects/issues-project/src/file2.less +++ b/its/plugin/projects/issues-project/src/file2.less @@ -21,7 +21,7 @@ a:unknown { /* S4659 | selecto } .class1 { /* S4666 | no-duplicate-selectors */ - width: 100px; + padding: 100px; } a { @@ -36,6 +36,10 @@ unknown { /* S4670 | selecto color: black; } +@unknown { /* S4662 | at-rule-no-unknown */ + width: 1px; +} + @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 ad26232..03b5ce8 100644 --- a/its/plugin/projects/issues-project/src/file3.scss +++ b/its/plugin/projects/issues-project/src/file3.scss @@ -21,7 +21,7 @@ a:unknown { /* S4659 | selecto } .class1 { /* S4666 | no-duplicate-selectors */ - width: 100px; + padding: 100px; } a { @@ -36,6 +36,10 @@ unknown { /* S4670 | selecto color: black; } +@unknown { /* S4662 | at-rule-no-unknown */ + width: 1px; +} + @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 c463622..5248ff0 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 @@ -29,6 +29,7 @@ import javax.annotation.Nullable; import org.sonar.api.batch.rule.CheckFactory; import org.sonar.api.batch.rule.Checks; import org.sonar.api.rule.RuleKey; +import org.sonar.css.plugin.rules.AtRuleNoUnknown; import org.sonar.css.plugin.rules.BlockNoEmpty; import org.sonar.css.plugin.rules.ColorNoInvalidHex; import org.sonar.css.plugin.rules.CommentNoEmpty; @@ -67,6 +68,7 @@ public class CssRules { public static List<Class> getRuleClasses() { return Collections.unmodifiableList(Arrays.asList( + AtRuleNoUnknown.class, BlockNoEmpty.class, ColorNoInvalidHex.class, CommentNoEmpty.class, diff --git a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/AtRuleNoUnknown.java b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/AtRuleNoUnknown.java new file mode 100644 index 0000000..3a2a821 --- /dev/null +++ b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/AtRuleNoUnknown.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 = "S4662") +public class AtRuleNoUnknown implements CssRule { + + @Override + public String stylelintKey() { + return "at-rule-no-unknown"; + } +} diff --git a/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4662.html b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4662.html new file mode 100644 index 0000000..96e4255 --- /dev/null +++ b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4662.html @@ -0,0 +1,11 @@ +<p>The W3C specifications define the valid <code>at-rules</code>. Only the official and browser-specific <code>at-rules</code> should be used to get +the expected impact in the final rendering.</p> +<h2>Noncompliant Code Example</h2> +<pre> +@unknown {} +</pre> +<h2>Compliant Solution</h2> +<pre> +@media (max-width: 960px) {} +</pre> + diff --git a/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4662.json b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4662.json new file mode 100644 index 0000000..d2cfb03 --- /dev/null +++ b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4662.json @@ -0,0 +1,16 @@ +{ + "title": "\"at-rules\" should be valid", + "type": "BUG", + "status": "ready", + "remediation": { + "func": "Constant\/Issue", + "constantCost": "1min" + }, + "tags": [ + + ], + "defaultSeverity": "Major", + "ruleSpecification": "RSPEC-4662", + "sqKey": "S4662", + "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 7e9fe85..73fa72d 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 @@ -15,6 +15,7 @@ "S4658", "S4659", "S4660", + "S4662", "S4663", "S4666", "S4667", |
