Skip to content

Commit

Permalink
Add plugin IT for eslint-based rules (#1103)
Browse files Browse the repository at this point in the history
  • Loading branch information
vilchik-elena authored Oct 4, 2018
1 parent 77b166c commit 84e0498
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 15 deletions.
12 changes: 4 additions & 8 deletions eslint-bridge/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@
<sonar.language>ts</sonar.language>
<sonar.typescript.lcov.reportPaths>coverage/lcov.info</sonar.typescript.lcov.reportPaths>
<sonar.testExecutionReportPaths>test-report.xml</sonar.testExecutionReportPaths>
<nodeVersion>v10.11.0</nodeVersion>
<yarnVersion>v1.10.1</yarnVersion>
<npmVersion>6.4.1</npmVersion>
</properties>

<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.6</version>
<configuration>
<installDirectory>target</installDirectory>
</configuration>
Expand All @@ -39,8 +35,8 @@
<goal>install-node-and-yarn</goal>
</goals>
<configuration>
<nodeVersion>${nodeVersion}</nodeVersion>
<yarnVersion>${yarnVersion}</yarnVersion>
<nodeVersion>${node.version}</nodeVersion>
<yarnVersion>${yarn.version}</yarnVersion>
</configuration>
</execution>
<execution>
Expand All @@ -50,8 +46,8 @@
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>${nodeVersion}</nodeVersion>
<npmVersion>${npmVersion}</npmVersion>
<nodeVersion>${node.version}</nodeVersion>
<npmVersion>${npm.version}</npmVersion>
</configuration>
</execution>
<execution>
Expand Down
5 changes: 5 additions & 0 deletions its/plugin/projects/eslint_based_rules/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if (cond) {
foo();
} else {
foo();
}
21 changes: 21 additions & 0 deletions its/plugin/tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,27 @@
</includes>
</configuration>
</plugin>

<!-- install Node.js used for EslintBasedRulesTest -->
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<configuration>
<installDirectory>target</installDirectory>
</configuration>
<executions>
<execution>
<id>install node</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>${node.version}</nodeVersion>
<npmVersion>${npm.version}</npmVersion>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* SonarQube JavaScript Plugin
* Copyright (C) 2012-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 com.sonar.javascript.it.plugin;

import com.google.common.collect.ImmutableList;
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.SonarScanner;
import java.io.File;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.List;
import org.apache.commons.lang.SystemUtils;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.sonarqube.ws.Issues.Issue;
import org.sonarqube.ws.client.issues.SearchRequest;

import static com.sonar.javascript.it.plugin.Tests.newWsClient;
import static org.assertj.core.api.Assertions.assertThat;

public class EslintBasedRulesTest {

@ClassRule
public static Orchestrator orchestrator = Tests.ORCHESTRATOR;

private static final File PROJECT_DIR = TestUtils.projectDir("eslint_based_rules");

@BeforeClass
public static void startServer() {
orchestrator.resetData();

SonarScanner build = SonarScanner.create()
.setProjectKey("eslint-based-rules-project")
.setSourceEncoding("UTF-8")
.setSourceDirs(".")
.setProjectDir(PROJECT_DIR)
.setProperty("sonar.nodejs.executable", getNodeJSExecutable())
.setProfile("eslint-based-rules-profile");

orchestrator.executeBuild(build);
}

private static String getNodeJSExecutable() {
String executable = SystemUtils.IS_OS_WINDOWS ? "node.exe" : "node";
return Paths.get(System.getProperty("user.dir"), "target", "node", executable)
.toAbsolutePath().toString();
}

@Test
public void test() {
SearchRequest request = new SearchRequest();
request.setComponentKeys(Collections.singletonList("eslint-based-rules-project")).setRules(ImmutableList.of("javascript:S3923"));
List<Issue> issuesList = newWsClient().issues().search(request).getIssuesList();
assertThat(issuesList).hasSize(1);
assertThat(issuesList.get(0).getLine()).isEqualTo(1);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ public void should_save_issues_from_external_report() {
"external_eslint_repo:semi",
"external_eslint_repo:semi");
} else {
assertThat(jsIssuesList).isEmpty();
assertThat(jsIssuesList).extracting("rule").containsExactlyInAnyOrder(
"javascript:S2688",
"javascript:S1116");

assertThat(tsIssuesList).isEmpty();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,19 @@
@Suite.SuiteClasses({
BigProjectTest.class,
CoverageTest.class,
EslintBasedRulesTest.class,
EslintReportTest.class,
MetricsTest.class,
MinifiedFilesTest.class,
NoSonarTest.class,
SonarLintTest.class,
NoSonarTest.class
})
public final class Tests {


public static final String PROJECT_KEY = "project";
static final String PROJECT_KEY = "project";

public static final FileLocation JAVASCRIPT_PLUGIN_LOCATION = FileLocation.byWildcardMavenFilename(
static final FileLocation JAVASCRIPT_PLUGIN_LOCATION = FileLocation.byWildcardMavenFilename(
new File("../../../sonar-javascript-plugin/target"), "sonar-javascript-plugin-*.jar");

@ClassRule
Expand All @@ -61,6 +63,7 @@ public final class Tests {
.restoreProfileAtStartup(FileLocation.ofClasspath("/empty-profile.xml"))
.restoreProfileAtStartup(FileLocation.ofClasspath("/profile-javascript-custom-rules.xml"))
.restoreProfileAtStartup(FileLocation.ofClasspath("/nosonar.xml"))
.restoreProfileAtStartup(FileLocation.ofClasspath("/eslint-based-rules.xml"))
.build();

private Tests() {
Expand Down
12 changes: 12 additions & 0 deletions its/plugin/tests/src/test/resources/eslint-based-rules.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<profile>
<name>eslint-based-rules-profile</name>
<language>js</language>
<rules>
<rule>
<repositoryKey>javascript</repositoryKey>
<key>S3923</key> <!-- all duplicate branches -->
<priority>INFO</priority>
</rule>
</rules>
</profile>
1 change: 0 additions & 1 deletion nodejs-utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
Expand Down
25 changes: 23 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand Down Expand Up @@ -84,6 +85,9 @@
<sslr-squid-bridge.version>2.7.0.377</sslr-squid-bridge.version>
<gson.version>2.6.2</gson.version>
<analyzer-commons.version>1.8.0.295</analyzer-commons.version>
<node.version>v10.11.0</node.version>
<yarn.version>v1.10.1</yarn.version>
<npm.version>6.4.1</npm.version>

<artifactsToPublish>${project.groupId}:sonar-javascript-plugin:jar</artifactsToPublish>
<maven.test.redirectTestOutputToFile>true</maven.test.redirectTestOutputToFile>
Expand Down Expand Up @@ -196,7 +200,6 @@
</dependency>



<!-- Test dependencies -->
<dependency>
<groupId>${project.groupId}</groupId>
Expand Down Expand Up @@ -276,6 +279,24 @@
</dependencies>
</dependencyManagement>

<build>

<pluginManagement>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.6</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>

<profiles>
<profile>
<id>its</id>
Expand Down

0 comments on commit 84e0498

Please sign in to comment.