diff options
| author | Alban Auzeill | 2019-12-12 10:47:22 +0100 | 
|---|---|---|
| committer | Elena Vilchik | 2019-12-12 10:47:22 +0100 | 
| commit | 13fe08e87c8a70ffe6e248b774ef826bbe1f779d (patch) | |
| tree | 582a26fb92a2382a76153a35e61316bd360614ab | |
| parent | ccc590679d3a9ed060b875fbbaf2825bd37bf334 (diff) | |
| download | sonar-css-13fe08e87c8a70ffe6e248b774ef826bbe1f779d.tar.bz2 | |
Analyze CSS in non-CSS files even if no CSS files in the project (#218)
5 files changed, 79 insertions, 2 deletions
| diff --git a/its/plugin/projects/php-project/src/index.php b/its/plugin/projects/php-project/src/index.php new file mode 100644 index 0000000..54d36ee --- /dev/null +++ b/its/plugin/projects/php-project/src/index.php @@ -0,0 +1,13 @@ +<!doctype html> +<html lang="en"> +<head> +  <title>Index</title> +  <style> +  /* S4658 empty block */ +  p { } +  </style> +</head> +<body> +  <?= "Hello World!" ?> +</body> +</html> diff --git a/its/plugin/src/test/java/org/sonar/css/its/NoCssFileProjectTest.java b/its/plugin/src/test/java/org/sonar/css/its/NoCssFileProjectTest.java new file mode 100644 index 0000000..04f2384 --- /dev/null +++ b/its/plugin/src/test/java/org/sonar/css/its/NoCssFileProjectTest.java @@ -0,0 +1,64 @@ +/* + * SonarCSS + * Copyright (C) 2018-2019 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.its; + +import com.sonar.orchestrator.Orchestrator; +import com.sonar.orchestrator.build.SonarScanner; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.sonarqube.ws.Issues; +import org.sonarqube.ws.client.issues.SearchRequest; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.tuple; +import static org.sonar.css.its.Tests.newWsClient; + +public class NoCssFileProjectTest { + +  private static String PROJECT_KEY = "php-project"; + +  @ClassRule +  public static Orchestrator orchestrator = Tests.ORCHESTRATOR; + +  @BeforeClass +  public static void prepare() { +    orchestrator.getServer().provisionProject(PROJECT_KEY, PROJECT_KEY); +    SonarScanner scanner = Tests.createScanner(PROJECT_KEY); +    scanner.setProperty("sonar.php.file.suffixes", ".php"); +    orchestrator.executeBuild(scanner); +  } + +  @Test +  public void test() { +    SearchRequest request = new SearchRequest(); +    request.setComponentKeys(Collections.singletonList(PROJECT_KEY)); +    List<Issues.Issue> issuesList = newWsClient().issues().search(request).getIssuesList().stream() +      .filter(i -> i.getRule().startsWith("css:")) +      .collect(Collectors.toList()); + +    assertThat(issuesList).extracting(Issues.Issue::getRule, Issues.Issue::getLine, Issues.Issue::getComponent).containsExactlyInAnyOrder( +      tuple("css:S4658", 7, "php-project:src/index.php")); +  } + +} diff --git a/its/plugin/src/test/java/org/sonar/css/its/Tests.java b/its/plugin/src/test/java/org/sonar/css/its/Tests.java index f252263..bc9a418 100644 --- a/its/plugin/src/test/java/org/sonar/css/its/Tests.java +++ b/its/plugin/src/test/java/org/sonar/css/its/Tests.java @@ -40,6 +40,7 @@ import org.sonarqube.ws.client.measures.ComponentRequest;  @Suite.SuiteClasses({    MetricsTest.class,    IssuesTest.class, +  NoCssFileProjectTest.class,    StylelintReportTest.class,    MinifiedTest.class  }) diff --git a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/CssRuleSensor.java b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/CssRuleSensor.java index a21f2a0..87328d7 100644 --- a/sonar-css-plugin/src/main/java/org/sonar/css/plugin/CssRuleSensor.java +++ b/sonar-css-plugin/src/main/java/org/sonar/css/plugin/CssRuleSensor.java @@ -82,7 +82,6 @@ public class CssRuleSensor implements Sensor {    @Override    public void describe(SensorDescriptor descriptor) {      descriptor -      .onlyOnLanguage(CssLanguage.KEY)        .name("SonarCSS Rules");    } diff --git a/sonar-css-plugin/src/test/java/org/sonar/css/plugin/CssRuleSensorTest.java b/sonar-css-plugin/src/test/java/org/sonar/css/plugin/CssRuleSensorTest.java index cf33d50..a0a41f8 100644 --- a/sonar-css-plugin/src/test/java/org/sonar/css/plugin/CssRuleSensorTest.java +++ b/sonar-css-plugin/src/test/java/org/sonar/css/plugin/CssRuleSensorTest.java @@ -88,7 +88,7 @@ public class CssRuleSensorTest {      DefaultSensorDescriptor sensorDescriptor = new DefaultSensorDescriptor();      sensor.describe(sensorDescriptor);      assertThat(sensorDescriptor.name()).isEqualTo("SonarCSS Rules"); -    assertThat(sensorDescriptor.languages()).containsOnly("css"); +    assertThat(sensorDescriptor.languages()).isEmpty();    }    @Test | 
