From 0105e87be8d99a8e9c99faa0a278fc3a2d676a20 Mon Sep 17 00:00:00 2001 From: Amaury Levé Date: Mon, 25 Jun 2018 11:55:11 +0200 Subject: Rule S1116: Empty statements should be removed --- its/plugin/projects/issues-project/src/file1.css | 22 ++++++++------- its/plugin/projects/issues-project/src/file2.less | 22 ++++++++------- its/plugin/projects/issues-project/src/file3.scss | 22 ++++++++------- .../main/java/org/sonar/css/plugin/CssRules.java | 2 ++ .../sonar/css/plugin/rules/NoExtraSemicolons.java | 31 ++++++++++++++++++++++ .../org/sonar/l10n/css/rules/css/S1116.html | 19 +++++++++++++ .../org/sonar/l10n/css/rules/css/S1116.json | 18 +++++++++++++ .../l10n/css/rules/css/Sonar_way_profile.json | 1 + 8 files changed, 110 insertions(+), 27 deletions(-) create mode 100644 sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/NoExtraSemicolons.java create mode 100644 sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S1116.html create mode 100644 sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S1116.json diff --git a/its/plugin/projects/issues-project/src/file1.css b/its/plugin/projects/issues-project/src/file1.css index 13c2cc0..6e1dcdd 100644 --- a/its/plugin/projects/issues-project/src/file1.css +++ b/its/plugin/projects/issues-project/src/file1.css @@ -1,16 +1,20 @@ @import "a.css"; -@import "a.css"; /* S1128 | no-duplicate-at-import-rules */ +@import "a.css"; /* S1128 | no-duplicate-at-import-rules */ .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 */ color: pink; - 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 */ + 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 */ +} + +a { + color: pink;; /* S1116 | no-extra-semicolons */ } @keyframes important1 { @@ -18,6 +22,6 @@ margin-top: 50px; } to { - margin-top: 100px !important; /* S4655 | keyframe-declaration-no-important */ + 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 f8ddf14..3f2809c 100644 --- a/its/plugin/projects/issues-project/src/file2.less +++ b/its/plugin/projects/issues-project/src/file2.less @@ -1,16 +1,20 @@ @import "a.css"; -@import "a.css"; /* S1128 | no-duplicate-at-import-rules | Doesn't raise for LESS */ +@import "a.css"; /* S1128 | no-duplicate-at-import-rules | Doesn't raise for LESS */ .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 */ color: pink; - 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 */ + 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 */ +} + +a { + color: pink;; /* S1116 | no-extra-semicolons */ } @keyframes important1 { @@ -18,6 +22,6 @@ margin-top: 50px; } to { - margin-top: 100px !important; /* S4655 | keyframe-declaration-no-important */ + 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 13c2cc0..6e1dcdd 100644 --- a/its/plugin/projects/issues-project/src/file3.scss +++ b/its/plugin/projects/issues-project/src/file3.scss @@ -1,16 +1,20 @@ @import "a.css"; -@import "a.css"; /* S1128 | no-duplicate-at-import-rules */ +@import "a.css"; /* S1128 | no-duplicate-at-import-rules */ .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 */ color: pink; - 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 */ + 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 */ +} + +a { + color: pink;; /* S1116 | no-extra-semicolons */ } @keyframes important1 { @@ -18,6 +22,6 @@ margin-top: 50px; } to { - margin-top: 100px !important; /* S4655 | keyframe-declaration-no-important */ + 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 255f58f..9545b1f 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 @@ -38,6 +38,7 @@ import org.sonar.css.plugin.rules.FontFamilyNoMissingGenericFamilyKeyword; 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.StringNoNewline; import org.sonar.css.plugin.rules.UnitNoUnknown; @@ -67,6 +68,7 @@ public class CssRules { KeyframeDeclarationNoImportant.class, NoDuplicateAtImportRules.class, NoEmptySource.class, + NoExtraSemicolons.class, StringNoNewline.class, UnitNoUnknown.class )); diff --git a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/NoExtraSemicolons.java b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/NoExtraSemicolons.java new file mode 100644 index 0000000..c039e3d --- /dev/null +++ b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/NoExtraSemicolons.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 = "S1116") +public class NoExtraSemicolons implements CssRule { + + @Override + public String stylelintKey() { + return "no-extra-semicolons"; + } +} diff --git a/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S1116.html b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S1116.html new file mode 100644 index 0000000..b2bc4a3 --- /dev/null +++ b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S1116.html @@ -0,0 +1,19 @@ +

Empty statements, i.e. ;, are usually introduced by mistake, for example because:

+ +

See

+ + diff --git a/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S1116.json b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S1116.json new file mode 100644 index 0000000..d2937b8 --- /dev/null +++ b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S1116.json @@ -0,0 +1,18 @@ +{ + "title": "Empty statements should be removed", + "type": "CODE_SMELL", + "status": "ready", + "remediation": { + "func": "Constant\/Issue", + "constantCost": "2min" + }, + "tags": [ + "misra", + "cert", + "unused" + ], + "defaultSeverity": "Minor", + "ruleSpecification": "RSPEC-1116", + "sqKey": "S1116", + "scope": "All" +} 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 64ab8d6..0a7d005 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 @@ -1,6 +1,7 @@ { "name": "Sonar way", "ruleKeys": [ + "S1116", "S1128", "S4647", "S4648", -- cgit v1.2.3