diff options
8 files changed, 72 insertions, 0 deletions
| diff --git a/its/plugin/projects/issues-project/src/file1.css b/its/plugin/projects/issues-project/src/file1.css index dc18063..7ed5eae 100644 --- a/its/plugin/projects/issues-project/src/file1.css +++ b/its/plugin/projects/issues-project/src/file1.css @@ -14,6 +14,7 @@ a:unknown {                                                   /* S4659 | selecto    heigth: 100%;                                               /* S4654 | property-no-unknown */    padding-left: 10px;    padding: 20px;                                              /* S4657 | declaration-block-no-shorthand-property-overrides */ +  top: calc(1px+2px);                                         /* S4650 | function-calc-no-unspaced-operator */  }  // color: pink;                                               /* S4668 | no-invalid-double-slash-comments */ diff --git a/its/plugin/projects/issues-project/src/file2.less b/its/plugin/projects/issues-project/src/file2.less index 6afa093..e86afd8 100644 --- a/its/plugin/projects/issues-project/src/file2.less +++ b/its/plugin/projects/issues-project/src/file2.less @@ -14,6 +14,7 @@ a:unknown {                                                   /* S4659 | selecto    heigth: 100%;                                               /* S4654 | property-no-unknown */    padding-left: 10px;    padding: 20px;                                              /* S4657 | declaration-block-no-shorthand-property-overrides */ +  top: calc(1px+2px);                                         /* S4650 | function-calc-no-unspaced-operator */  }  // color: pink;                                               /* S4668 | no-invalid-double-slash-comments | Doesn't raise for LESS */ diff --git a/its/plugin/projects/issues-project/src/file3.scss b/its/plugin/projects/issues-project/src/file3.scss index 4c71388..4b68ede 100644 --- a/its/plugin/projects/issues-project/src/file3.scss +++ b/its/plugin/projects/issues-project/src/file3.scss @@ -14,6 +14,7 @@ a:unknown {                                                   /* S4659 | selecto    heigth: 100%;                                               /* S4654 | property-no-unknown */    padding-left: 10px;    padding: 20px;                                              /* S4657 | declaration-block-no-shorthand-property-overrides */ +  top: calc(1px+2px);                                         /* S4650 | function-calc-no-unspaced-operator */  }  // color: pink;                                               /* S4668 | no-invalid-double-slash-comments | Doesn't raise for 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 ab2a720..fe3088b 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.FunctionCalcNoUnspacedOperator;  import org.sonar.css.plugin.rules.FunctionLinearGradientNoNonstandardDirection;  import org.sonar.css.plugin.rules.KeyframeDeclarationNoImportant;  import org.sonar.css.plugin.rules.MediaFeatureNameNoUnknown; @@ -79,6 +80,7 @@ public class CssRules {        DeclarationBlockNoShorthandPropertyOverrides.class,        FontFamilyNoDuplicateNames.class,        FontFamilyNoMissingGenericFamilyKeyword.class, +      FunctionCalcNoUnspacedOperator.class,        FunctionLinearGradientNoNonstandardDirection.class,        KeyframeDeclarationNoImportant.class,        MediaFeatureNameNoUnknown.class, diff --git a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/FunctionCalcNoUnspacedOperator.java b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/FunctionCalcNoUnspacedOperator.java new file mode 100644 index 0000000..7470fc5 --- /dev/null +++ b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/FunctionCalcNoUnspacedOperator.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 = "S4650") +public class FunctionCalcNoUnspacedOperator implements CssRule { + +  @Override +  public String stylelintKey() { +    return "function-calc-no-unspaced-operator"; +  } +} diff --git a/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4650.html b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4650.html new file mode 100644 index 0000000..adca17a --- /dev/null +++ b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4650.html @@ -0,0 +1,19 @@ +<p><code>calc</code> is a CSS3 function that provides the possibility to do simple math in CSS (add, subtract, divide, multiply). Without spaces +around operators, <code>calc</code> will have no effect.</p> +<p>More precisely, before an operator, there must be a single whitespace or a newline plus indentation. After an operator, there must be a single +whitespace or a newline.</p> +<h2>Noncompliant Code Example</h2> +<pre> +#div1 { +    position: absolute; +    width: calc(100%- 100px); // Noncompliant; no space after the % sign +} +</pre> +<h2>Compliant Solution</h2> +<pre> +#div1 { +    position: absolute; +    width: calc(100% - 100px); +} +</pre> + diff --git a/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4650.json b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4650.json new file mode 100644 index 0000000..5720374 --- /dev/null +++ b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4650.json @@ -0,0 +1,16 @@ +{ +  "title": "\"calc\" members should be correctly spaced or indented", +  "type": "BUG", +  "status": "ready", +  "remediation": { +    "func": "Constant\/Issue", +    "constantCost": "1min" +  }, +  "tags": [ +     +  ], +  "defaultSeverity": "Blocker", +  "ruleSpecification": "RSPEC-4650", +  "sqKey": "S4650", +  "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 4fe2a7a..adbe829 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", +    "S4650",      "S4651",      "S4652",      "S4653", | 
