diff options
9 files changed, 90 insertions, 4 deletions
| diff --git a/its/plugin/projects/issues-project/src/file1.css b/its/plugin/projects/issues-project/src/file1.css index 18807a3..dc18063 100644 --- a/its/plugin/projects/issues-project/src/file1.css +++ b/its/plugin/projects/issues-project/src/file1.css @@ -16,9 +16,11 @@ a:unknown {                                                   /* S4659 | selecto    padding: 20px;                                              /* S4657 | declaration-block-no-shorthand-property-overrides */  } +// color: pink;                                               /* S4668 | no-invalid-double-slash-comments */ +  .class1 {    width: 100px; -  // color: pink;                                             /* S4668 | no-invalid-double-slash-comments */ +  background: linear-gradient(top, #fff, #000);               /* S4651 | function-linear-gradient-no-nonstandard-direction */  }  .class1 {                                                     /* S4666 | no-duplicate-selectors */ diff --git a/its/plugin/projects/issues-project/src/file2.less b/its/plugin/projects/issues-project/src/file2.less index c9a912b..6afa093 100644 --- a/its/plugin/projects/issues-project/src/file2.less +++ b/its/plugin/projects/issues-project/src/file2.less @@ -16,9 +16,11 @@ a:unknown {                                                   /* S4659 | selecto    padding: 20px;                                              /* S4657 | declaration-block-no-shorthand-property-overrides */  } +// color: pink;                                               /* S4668 | no-invalid-double-slash-comments | Doesn't raise for LESS */ +  .class1 {    width: 100px; -  // color: pink;                                             /* S4668 | no-invalid-double-slash-comments */ +  background: linear-gradient(top, #fff, #000);               /* S4651 | function-linear-gradient-no-nonstandard-direction */  }  .class1 {                                                     /* S4666 | no-duplicate-selectors */ diff --git a/its/plugin/projects/issues-project/src/file3.scss b/its/plugin/projects/issues-project/src/file3.scss index 18807a3..4c71388 100644 --- a/its/plugin/projects/issues-project/src/file3.scss +++ b/its/plugin/projects/issues-project/src/file3.scss @@ -16,9 +16,11 @@ a:unknown {                                                   /* S4659 | selecto    padding: 20px;                                              /* S4657 | declaration-block-no-shorthand-property-overrides */  } +// color: pink;                                               /* S4668 | no-invalid-double-slash-comments | Doesn't raise for SCSS */ +  .class1 {    width: 100px; -  // color: pink;                                             /* S4668 | no-invalid-double-slash-comments */ +  background: linear-gradient(top, #fff, #000);               /* S4651 | function-linear-gradient-no-nonstandard-direction */  }  .class1 {                                                     /* S4666 | no-duplicate-selectors */ diff --git a/its/plugin/src/test/java/org/sonar/css/its/IssuesTest.java b/its/plugin/src/test/java/org/sonar/css/its/IssuesTest.java index b6d979d..dd37a06 100644 --- a/its/plugin/src/test/java/org/sonar/css/its/IssuesTest.java +++ b/its/plugin/src/test/java/org/sonar/css/its/IssuesTest.java @@ -53,7 +53,7 @@ public class IssuesTest {      assertThat(issuesList).extracting("rule").hasSize(        CssRules.getRuleClasses().size() * 3 /* issues are raised against .css, .less and .scss */        - 1 /* issue S1128 not raised on .less */ -      - 1 /* issue S4668 not raised on .less */); +      - 2 /* issue S4668 not raised on .less nor .scss */);    }  } 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 a44da11..ab2a720 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.DeclarationBlockNoDuplicateProperties;  import org.sonar.css.plugin.rules.DeclarationBlockNoShorthandPropertyOverrides;  import org.sonar.css.plugin.rules.FontFamilyNoDuplicateNames;  import org.sonar.css.plugin.rules.FontFamilyNoMissingGenericFamilyKeyword; +import org.sonar.css.plugin.rules.FunctionLinearGradientNoNonstandardDirection;  import org.sonar.css.plugin.rules.KeyframeDeclarationNoImportant;  import org.sonar.css.plugin.rules.MediaFeatureNameNoUnknown;  import org.sonar.css.plugin.rules.NoDuplicateAtImportRules; @@ -78,6 +79,7 @@ public class CssRules {        DeclarationBlockNoShorthandPropertyOverrides.class,        FontFamilyNoDuplicateNames.class,        FontFamilyNoMissingGenericFamilyKeyword.class, +      FunctionLinearGradientNoNonstandardDirection.class,        KeyframeDeclarationNoImportant.class,        MediaFeatureNameNoUnknown.class,        NoDuplicateAtImportRules.class, diff --git a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/FunctionLinearGradientNoNonstandardDirection.java b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/FunctionLinearGradientNoNonstandardDirection.java new file mode 100644 index 0000000..1f52b0f --- /dev/null +++ b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/FunctionLinearGradientNoNonstandardDirection.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 = "S4651") +public class FunctionLinearGradientNoNonstandardDirection implements CssRule { + +  @Override +  public String stylelintKey() { +    return "function-linear-gradient-no-nonstandard-direction"; +  } +} diff --git a/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4651.html b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4651.html new file mode 100644 index 0000000..20d64bb --- /dev/null +++ b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4651.html @@ -0,0 +1,30 @@ +<p><code>linear-gradient</code> was standardized with CSS3. Before that, it was possible to use different non-standard values to define the gradient's +direction. Because these values are not standard, they are not supported in all browsers and therefore they should no longer be used in order to get +the expected gradient in the latest browser versions that support CSS3.</p> +<p>This rule raises an issue when the first parameter of a <code>linear-gradient</code> is not a valid <code><side-or-corner></code> or +<code>angle</code>.</p> +<h2>Noncompliant Code Example</h2> +<pre> +.foo { +  background: linear-gradient(top, #fff, #000); +} + +.bar { +  background: linear-gradient(45, #fff, #000); +} +</pre> +<h2>Compliant Solution</h2> +<pre> +.foo { +  background: linear-gradient(to top, #fff, #000); +} + +.bar { +  background: linear-gradient(45deg, #fff, #000); +} +</pre> +<h2>See</h2> +<ul> +  <li> <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/linear-gradient#Syntax">MDN Specification</a> - linear gradient </li> +</ul> + diff --git a/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4651.json b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4651.json new file mode 100644 index 0000000..a383afd --- /dev/null +++ b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4651.json @@ -0,0 +1,16 @@ +{ +  "title": "\"linear-gradient\" directions should be valid", +  "type": "BUG", +  "status": "ready", +  "remediation": { +    "func": "Constant\/Issue", +    "constantCost": "1min" +  }, +  "tags": [ +     +  ], +  "defaultSeverity": "Critical", +  "ruleSpecification": "RSPEC-4651", +  "sqKey": "S4651", +  "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 823c793..4fe2a7a 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 @@ -6,6 +6,7 @@      "S4647",      "S4648",      "S4649", +    "S4651",      "S4652",      "S4653",      "S4654", | 
