From 7a2daa058f3da99a224a2c874e554f88d2ad8104 Mon Sep 17 00:00:00 2001 From: Amaury Levé Date: Thu, 21 Jun 2018 15:53:16 +0200 Subject: Rule S4663: Comments should not be empty (#51) --- its/plugin/projects/issues-project/src/file1.css | 5 ++-- its/plugin/projects/issues-project/src/file2.less | 5 ++-- its/plugin/projects/issues-project/src/file3.scss | 5 ++-- .../main/java/org/sonar/css/plugin/CssRules.java | 4 ++- .../org/sonar/css/plugin/rules/CommentNoEmpty.java | 31 ++++++++++++++++++++++ .../org/sonar/l10n/css/rules/css/S4663.html | 10 +++++++ .../org/sonar/l10n/css/rules/css/S4663.json | 16 +++++++++++ .../l10n/css/rules/css/Sonar_way_profile.json | 3 ++- 8 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/CommentNoEmpty.java create mode 100644 sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4663.html create mode 100644 sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4663.json diff --git a/its/plugin/projects/issues-project/src/file1.css b/its/plugin/projects/issues-project/src/file1.css index b0dcf70..ad5a908 100644 --- a/its/plugin/projects/issues-project/src/file1.css +++ b/its/plugin/projects/issues-project/src/file1.css @@ -1,4 +1,5 @@ .class1 { - background-color: #ffw; /* S4647 | color-no-invalid-hex */ - width: 100pixels; /* S4653 | unit-no-unknown */ + background-color: #ffw; /* S4647 | color-no-invalid-hex */ + width: 100pixels; /* S4653 | unit-no-unknown */ + /* */ /* S4663 | comment-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 b0dcf70..ad5a908 100644 --- a/its/plugin/projects/issues-project/src/file2.less +++ b/its/plugin/projects/issues-project/src/file2.less @@ -1,4 +1,5 @@ .class1 { - background-color: #ffw; /* S4647 | color-no-invalid-hex */ - width: 100pixels; /* S4653 | unit-no-unknown */ + background-color: #ffw; /* S4647 | color-no-invalid-hex */ + width: 100pixels; /* S4653 | unit-no-unknown */ + /* */ /* S4663 | comment-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 b0dcf70..ad5a908 100644 --- a/its/plugin/projects/issues-project/src/file3.scss +++ b/its/plugin/projects/issues-project/src/file3.scss @@ -1,4 +1,5 @@ .class1 { - background-color: #ffw; /* S4647 | color-no-invalid-hex */ - width: 100pixels; /* S4653 | unit-no-unknown */ + background-color: #ffw; /* S4647 | color-no-invalid-hex */ + width: 100pixels; /* S4653 | unit-no-unknown */ + /* */ /* S4663 | comment-no-empty */ } \ 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 1dac08c..5a4be0c 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 @@ -23,6 +23,7 @@ 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.ColorNoInvalidHex; +import org.sonar.css.plugin.rules.CommentNoEmpty; import org.sonar.css.plugin.rules.CssRule; import org.sonar.css.plugin.rules.UnitNoUnknown; @@ -52,7 +53,8 @@ public class CssRules { public static List getRuleClasses() { return Collections.unmodifiableList(Arrays.asList( ColorNoInvalidHex.class, - UnitNoUnknown.class + UnitNoUnknown.class, + CommentNoEmpty.class )); } diff --git a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/CommentNoEmpty.java b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/CommentNoEmpty.java new file mode 100644 index 0000000..547b5db --- /dev/null +++ b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/CommentNoEmpty.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 = "S4663") +public class CommentNoEmpty implements CssRule { + + @Override + public String stylelintKey() { + return "comment-no-empty"; + } +} diff --git a/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4663.html b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4663.html new file mode 100644 index 0000000..2b11dea --- /dev/null +++ b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4663.html @@ -0,0 +1,10 @@ +

An empty comment is likely to be a mistake and doesn't help to improve the readability of the code. For these reasons, it should be removed.

+

Noncompliant Code Example

+
+/* */
+
+/*
+
+ */
+
+ diff --git a/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4663.json b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4663.json new file mode 100644 index 0000000..70b312a --- /dev/null +++ b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4663.json @@ -0,0 +1,16 @@ +{ + "title": "Comments should not be empty", + "type": "CODE_SMELL", + "status": "ready", + "remediation": { + "func": "Constant\/Issue", + "constantCost": "1min" + }, + "tags": [ + + ], + "defaultSeverity": "Minor", + "ruleSpecification": "RSPEC-4663", + "sqKey": "S4663", + "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 a0e81bb..f7ce787 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 @@ -2,6 +2,7 @@ "name": "Sonar way", "ruleKeys": [ "S4647", - "S4653" + "S4653", + "S4663" ] } -- cgit v1.2.3