diff options
9 files changed, 76 insertions, 1 deletions
| diff --git a/its/plugin/projects/issues-project/src/file1.css b/its/plugin/projects/issues-project/src/file1.css index 34aa80c..241fd2e 100644 --- a/its/plugin/projects/issues-project/src/file1.css +++ b/its/plugin/projects/issues-project/src/file1.css @@ -9,6 +9,7 @@      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 */  }  @keyframes important1 { diff --git a/its/plugin/projects/issues-project/src/file2.less b/its/plugin/projects/issues-project/src/file2.less index 35a63f4..e2d0e54 100644 --- a/its/plugin/projects/issues-project/src/file2.less +++ b/its/plugin/projects/issues-project/src/file2.less @@ -9,6 +9,7 @@      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 */  }  @keyframes important1 { diff --git a/its/plugin/projects/issues-project/src/file3.scss b/its/plugin/projects/issues-project/src/file3.scss index 22438ed..7b74808 100644 --- a/its/plugin/projects/issues-project/src/file3.scss +++ b/its/plugin/projects/issues-project/src/file3.scss @@ -9,6 +9,7 @@      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 */  }  @keyframes important1 { 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 adfbe11..518c976 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 @@ -51,7 +51,7 @@ public class IssuesTest {      List<Issue> issuesList = newWsClient().issues().search(request).getIssuesList();      assertThat(issuesList).extracting("rule").hasSize( -      CssRules.getRuleClasses().size() * 3 +      CssRules.getRuleClasses().size() * 3 /* issues are raised against .css, .less and .scss */        - 1 /* issue S1128 not raised on .less */);    } 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 91f1898..4456b50 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 @@ -33,6 +33,7 @@ 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.DeclarationBlockNoDuplicateProperties; +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; @@ -60,6 +61,7 @@ public class CssRules {        ColorNoInvalidHex.class,        CommentNoEmpty.class,        DeclarationBlockNoDuplicateProperties.class, +      FontFamilyNoMissingGenericFamilyKeyword.class,        KeyframeDeclarationNoImportant.class,        NoDuplicateAtImportRules.class,        NoEmptySource.class, diff --git a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/FontFamilyNoMissingGenericFamilyKeyword.java b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/FontFamilyNoMissingGenericFamilyKeyword.java new file mode 100644 index 0000000..9cdc1b5 --- /dev/null +++ b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/rules/FontFamilyNoMissingGenericFamilyKeyword.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 = "S4649") +public class FontFamilyNoMissingGenericFamilyKeyword implements CssRule { + +  @Override +  public String stylelintKey() { +    return "font-family-no-missing-generic-family-keyword"; +  } +} diff --git a/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4649.html b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4649.html new file mode 100644 index 0000000..0816eb7 --- /dev/null +++ b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4649.html @@ -0,0 +1,22 @@ +<p>If none of the font names defined in a <code>font</code> or <code>font-family</code> declaration are available on the browser of the user, the +browser will display the text using its default font. It's recommended to always define a generic font family for each declaration of +<code>font</code> or <code>font-family</code> to get a less degraded situation than relying on the default browser font. All browsers should implement +a list of generic font matching these families: <code>Serif</code>, <code>Sans-serif</code>, <code>cursive</code>, <code>fantasy</code>, +<code>Monospace</code>.</p> +<h2>Noncompliant Code Example</h2> +<pre> +a { +  font-family: Helvetica, Arial, Verdana, Tahoma; +} +</pre> +<h2>Compliant Solution</h2> +<pre> +a { +  font-family: Helvetica, Arial, Verdana, Tahoma, sans-serif; +} +</pre> +<h2>See</h2> +<ul> +  <li> https://www.w3.org/TR/CSS2/fonts.html#generic-font-families </li> +</ul> + diff --git a/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4649.json b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4649.json new file mode 100644 index 0000000..eb427fa --- /dev/null +++ b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4649.json @@ -0,0 +1,16 @@ +{ +  "title": "Font declarations should contain at least one generic font family", +  "type": "BUG", +  "status": "ready", +  "remediation": { +    "func": "Constant\/Issue", +    "constantCost": "1min" +  }, +  "tags": [ +     +  ], +  "defaultSeverity": "Major", +  "ruleSpecification": "RSPEC-4649", +  "sqKey": "S4649", +  "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 4455af6..5fb55c0 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 @@ -3,6 +3,7 @@    "ruleKeys": [      "S1128",      "S4647", +    "S4649",      "S4652",      "S4653",      "S4655", | 
