diff options
| author | Amaury Levé | 2018-06-25 11:55:11 +0200 | 
|---|---|---|
| committer | Amaury Levé | 2018-06-25 15:05:03 +0200 | 
| commit | 0105e87be8d99a8e9c99faa0a278fc3a2d676a20 (patch) | |
| tree | 09f6c39469ecc29714e0b466a6a27e1e26332285 | |
| parent | 99ba1731fae85f49ae6bd9462a7d52070f104b52 (diff) | |
| download | sonar-css-0105e87be8d99a8e9c99faa0a278fc3a2d676a20.tar.bz2 | |
Rule S1116: Empty statements should be removed
8 files changed, 110 insertions, 27 deletions
| 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 @@ +<p>Empty statements, i.e. <code>;</code>, are usually introduced by mistake, for example because:</p> +<ul> +  <li> It was meant to be replaced by an actual statement, but this was forgotten. </li> +  <li> There was a typo which lead the semicolon to be doubled, i.e. <code>;;</code>. </li> +</ul> +<h2>See</h2> +<ul> +  <li> MISRA C:2004, 14.3 - Before preprocessing, a null statement shall only occur on a line by itself; it may be followed by a comment provided that +  the first character following the null statement is a white-space character. </li> +  <li> MISRA C++:2008, 6-2-3 - Before preprocessing, a null statement shall only occur on a line by itself; it may be followed by a comment, provided +  that the first character following the null statement is a white-space character. </li> +  <li> <a href="https://www.securecoding.cert.org/confluence/x/NYA5">CERT, MSC12-C.</a> - Detect and remove code that has no effect or is never +  executed </li> +  <li> <a href="https://www.securecoding.cert.org/confluence/x/7gCTAw">CERT, MSC51-J.</a> - Do not place a semicolon immediately following an if, for, +  or while condition </li> +  <li> <a href="https://www.securecoding.cert.org/confluence/x/i4FtAg">CERT, EXP15-C.</a> - Do not place a semicolon on the same line as an if, for, +  or while statement </li> +</ul> + 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", | 
