diff options
8 files changed, 85 insertions, 3 deletions
| diff --git a/its/plugin/projects/issues-project/src/file1.css b/its/plugin/projects/issues-project/src/file1.css index ad5a908..3d5ac89 100644 --- a/its/plugin/projects/issues-project/src/file1.css +++ b/its/plugin/projects/issues-project/src/file1.css @@ -2,4 +2,6 @@    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 */  }
\ 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 ad5a908..3d5ac89 100644 --- a/its/plugin/projects/issues-project/src/file2.less +++ b/its/plugin/projects/issues-project/src/file2.less @@ -2,4 +2,6 @@    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 */  }
\ 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 ad5a908..3d5ac89 100644 --- a/its/plugin/projects/issues-project/src/file3.scss +++ b/its/plugin/projects/issues-project/src/file3.scss @@ -2,4 +2,6 @@    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 */  }
\ 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 5a4be0c..d9037cb 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 @@ -25,6 +25,7 @@ import org.sonar.api.rule.RuleKey;  import org.sonar.css.plugin.rules.ColorNoInvalidHex;  import org.sonar.css.plugin.rules.CommentNoEmpty;  import org.sonar.css.plugin.rules.CssRule; +import org.sonar.css.plugin.rules.StringNoNewline;  import org.sonar.css.plugin.rules.UnitNoUnknown;  import java.util.Arrays; @@ -53,8 +54,9 @@ public class CssRules {    public static List<Class> getRuleClasses() {      return Collections.unmodifiableList(Arrays.asList(          ColorNoInvalidHex.class, -        UnitNoUnknown.class, -        CommentNoEmpty.class +        CommentNoEmpty.class,        +            StringNoNewline.class, +            UnitNoUnknown.class      ));    } diff --git a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/StringNoNewline.java b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/StringNoNewline.java new file mode 100644 index 0000000..a00077f --- /dev/null +++ b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/StringNoNewline.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 = "S4652") +public class StringNoNewline implements CssRule { + +  @Override +  public String stylelintKey() { +    return "string-no-newline"; +  } +} diff --git a/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4652.html b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4652.html new file mode 100644 index 0000000..ae6f801 --- /dev/null +++ b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4652.html @@ -0,0 +1,26 @@ +<p>According to the W3C specifications:</p> +<blockquote> +  <p>A string cannot directly contain a newline. To include a newline in a string, use an escape representing the line feed character in ISO-10646 +  (U+000A), such as "\A" or "\00000a".</p> +  <p>[...]</p> +  <p>It is possible to break strings over several lines, for aesthetic or other reasons, but in such a case the newline itself has to be escaped with +  a backslash (\).</p> +</blockquote> +<h2>Noncompliant Code Example</h2> +<pre> +a { +  content: "first +    second"; +} +</pre> +<h2>Compliant Solution</h2> +<pre> +a { +  content: "first\Asecond"; +} +</pre> +<h2>See</h2> +<ul> +  <li> https://www.w3.org/TR/CSS2/syndata.html#strings </li> +</ul> +
 diff --git a/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4652.json b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4652.json new file mode 100644 index 0000000..06dcd4d --- /dev/null +++ b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4652.json @@ -0,0 +1,16 @@ +{ +  "title": "Strings should not contain new lines", +  "type": "CODE_SMELL", +  "status": "ready", +  "remediation": { +    "func": "Constant\/Issue", +    "constantCost": "1min" +  }, +  "tags": [ +     +  ], +  "defaultSeverity": "Major", +  "ruleSpecification": "RSPEC-4652", +  "sqKey": "S4652", +  "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 f7ce787..68da351 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 @@ -2,7 +2,8 @@    "name": "Sonar way",    "ruleKeys": [      "S4647", +    "S4652",      "S4653",      "S4663"    ] -} +}
 | 
