diff options
9 files changed, 71 insertions, 4 deletions
| diff --git a/its/plugin/projects/issues-project/src/file1.css b/its/plugin/projects/issues-project/src/file1.css index 6e1dcdd..8d5bacb 100644 --- a/its/plugin/projects/issues-project/src/file1.css +++ b/its/plugin/projects/issues-project/src/file1.css @@ -24,4 +24,6 @@ a {    to {      margin-top: 100px !important;                             /* S4655 | keyframe-declaration-no-important */    } -}
\ No newline at end of file +} + +foo { }                                                       /* S4658 | block-no-empty */
\ 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 3f2809c..072a687 100644 --- a/its/plugin/projects/issues-project/src/file2.less +++ b/its/plugin/projects/issues-project/src/file2.less @@ -24,4 +24,6 @@ a {    to {      margin-top: 100px !important;                             /* S4655 | keyframe-declaration-no-important */    } -}
\ No newline at end of file +} + +foo { }                                                       /* S4658 | block-no-empty */
\ 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 6e1dcdd..8d5bacb 100644 --- a/its/plugin/projects/issues-project/src/file3.scss +++ b/its/plugin/projects/issues-project/src/file3.scss @@ -24,4 +24,6 @@ a {    to {      margin-top: 100px !important;                             /* S4655 | keyframe-declaration-no-important */    } -}
\ No newline at end of file +} + +foo { }                                                       /* S4658 | block-no-empty */
\ No newline at end of file diff --git a/its/plugin/src/test/java/org/sonar/css/its/StylelintReportTest.java b/its/plugin/src/test/java/org/sonar/css/its/StylelintReportTest.java index b10f7a4..13575c2 100644 --- a/its/plugin/src/test/java/org/sonar/css/its/StylelintReportTest.java +++ b/its/plugin/src/test/java/org/sonar/css/its/StylelintReportTest.java @@ -56,7 +56,7 @@ public class StylelintReportTest {          "external_stylelint:no-missing-end-of-source-newline",          "external_stylelint:rule-empty-line-before",          "external_stylelint:selector-pseudo-element-colon-notation", -        "external_stylelint:block-no-empty"); +        "css:S4658");      }    }  } 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 9545b1f..689d361 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.BlockNoEmpty;  import org.sonar.css.plugin.rules.ColorNoInvalidHex;  import org.sonar.css.plugin.rules.CommentNoEmpty;  import org.sonar.css.plugin.rules.CssRule; @@ -60,6 +61,7 @@ public class CssRules {    public static List<Class> getRuleClasses() {      return Collections.unmodifiableList(Arrays.asList( +      BlockNoEmpty.class,        ColorNoInvalidHex.class,        CommentNoEmpty.class,        DeclarationBlockNoDuplicateProperties.class, diff --git a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/BlockNoEmpty.java b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/BlockNoEmpty.java new file mode 100644 index 0000000..c27ed0e --- /dev/null +++ b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/BlockNoEmpty.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 = "S4658") +public class BlockNoEmpty implements CssRule { + +  @Override +  public String stylelintKey() { +    return "block-no-empty"; +  } +} diff --git a/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4658.html b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4658.html new file mode 100644 index 0000000..44648db --- /dev/null +++ b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4658.html @@ -0,0 +1,11 @@ +<p>Leftover empty blocks are usually introduced by mistake. They are useless and prevent readability of the code. They should be removed or completed +with real code.</p> +<h2>Noncompliant Code Example</h2> +<pre> +a { } +</pre> +<h2>Compliant Solution</h2> +<pre> +a { color: pink; } +</pre> + diff --git a/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4658.json b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4658.json new file mode 100644 index 0000000..5ba10d9 --- /dev/null +++ b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4658.json @@ -0,0 +1,16 @@ +{ +  "title": "Empty blocks should be removed", +  "type": "CODE_SMELL", +  "status": "ready", +  "remediation": { +    "func": "Constant\/Issue", +    "constantCost": "1min" +  }, +  "tags": [ +     +  ], +  "defaultSeverity": "Major", +  "ruleSpecification": "RSPEC-4658", +  "sqKey": "S4658", +  "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 0a7d005..d7ae454 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 @@ -10,6 +10,7 @@      "S4653",      "S4655",      "S4656", +    "S4658",      "S4663",      "S4667"    ] | 
