diff options
| author | Amaury Levé | 2018-06-25 14:34:12 +0200 | 
|---|---|---|
| committer | Elena Vilchik | 2018-06-26 11:49:59 +0200 | 
| commit | 260881d116176050141705295ce871bf23a790c2 (patch) | |
| tree | d3aca93598630be01974d1a7aee238510561add1 | |
| parent | ad92bb6746b5b29ce41f91f7aa6dc2bb8195fa07 (diff) | |
| download | sonar-css-260881d116176050141705295ce871bf23a790c2.tar.bz2 | |
Rule S4670: Selectors should be known
8 files changed, 78 insertions, 4 deletions
| diff --git a/its/plugin/projects/issues-project/src/file1.css b/its/plugin/projects/issues-project/src/file1.css index 35a9655..65a0392 100644 --- a/its/plugin/projects/issues-project/src/file1.css +++ b/its/plugin/projects/issues-project/src/file1.css @@ -24,6 +24,9 @@ a {    color: pink;;                                               /* S1116 | no-extra-semicolons */  } +unknown {                                                     /* S4670 | selector-type-no-unknown */ +  color: black; +}  @keyframes important1 {    from { @@ -34,4 +37,4 @@ a {    }  } -foo { }                                                       /* S4658 | block-no-empty */
\ No newline at end of file +.class2 { }                                                   /* 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 78138c9..4b76034 100644 --- a/its/plugin/projects/issues-project/src/file2.less +++ b/its/plugin/projects/issues-project/src/file2.less @@ -24,6 +24,9 @@ a {    color: pink;;                                               /* S1116 | no-extra-semicolons */  } +unknown {                                                     /* S4670 | selector-type-no-unknown */ +  color: black; +}  @keyframes important1 {    from { @@ -34,4 +37,4 @@ a {    }  } -foo { }                                                       /* S4658 | block-no-empty */
\ No newline at end of file +.class2 { }                                                   /* 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 35a9655..65a0392 100644 --- a/its/plugin/projects/issues-project/src/file3.scss +++ b/its/plugin/projects/issues-project/src/file3.scss @@ -24,6 +24,9 @@ a {    color: pink;;                                               /* S1116 | no-extra-semicolons */  } +unknown {                                                     /* S4670 | selector-type-no-unknown */ +  color: black; +}  @keyframes important1 {    from { @@ -34,4 +37,4 @@ a {    }  } -foo { }                                                       /* S4658 | block-no-empty */
\ No newline at end of file +.class2 { }                                                   /* S4658 | block-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 3951f64..8eea45f 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 @@ -43,6 +43,7 @@ import org.sonar.css.plugin.rules.NoDuplicateSelectors;  import org.sonar.css.plugin.rules.NoEmptySource;  import org.sonar.css.plugin.rules.NoExtraSemicolons;  import org.sonar.css.plugin.rules.PropertyNoUnknown; +import org.sonar.css.plugin.rules.SelectorTypeNoUnknown;  import org.sonar.css.plugin.rules.StringNoNewline;  import org.sonar.css.plugin.rules.UnitNoUnknown; @@ -77,6 +78,7 @@ public class CssRules {        NoEmptySource.class,        NoExtraSemicolons.class,        PropertyNoUnknown.class, +      SelectorTypeNoUnknown.class,        StringNoNewline.class,        UnitNoUnknown.class      )); diff --git a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/SelectorTypeNoUnknown.java b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/SelectorTypeNoUnknown.java new file mode 100644 index 0000000..e3a0bf7 --- /dev/null +++ b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/SelectorTypeNoUnknown.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 = "S4670") +public class SelectorTypeNoUnknown implements CssRule { + +  @Override +  public String stylelintKey() { +    return "selector-type-no-unknown"; +  } +} diff --git a/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4670.html b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4670.html new file mode 100644 index 0000000..98fc58c --- /dev/null +++ b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4670.html @@ -0,0 +1,15 @@ +<p>HTML, SVG, and MathML define the selectors which can be used in a CSS. A selector that is not part of them is likely to be a typo or a +misunderstanding of the CSS syntax.</p> +<h2>Noncompliant Code Example</h2> +<pre> +field {} + +ul list {} +</pre> +<h2>Compliant Solution</h2> +<pre> +input {} + +ul li {} +</pre> + diff --git a/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4670.json b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4670.json new file mode 100644 index 0000000..3d3f3ea --- /dev/null +++ b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4670.json @@ -0,0 +1,16 @@ +{ +  "title": "Selectors should be known", +  "type": "BUG", +  "status": "ready", +  "remediation": { +    "func": "Constant\/Issue", +    "constantCost": "5min" +  }, +  "tags": [ +     +  ], +  "defaultSeverity": "Critical", +  "ruleSpecification": "RSPEC-4670", +  "sqKey": "S4670", +  "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 079c18c..23dc9cf 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",      "S4663",      "S4666", -    "S4667" +    "S4667", +    "S4670"    ]  }
 | 
