-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add plugin IT for eslint-based rules (#1103)
- Loading branch information
1 parent
77b166c
commit 84e0498
Showing
9 changed files
with
151 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
if (cond) { | ||
foo(); | ||
} else { | ||
foo(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
its/plugin/tests/src/test/java/com/sonar/javascript/it/plugin/EslintBasedRulesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
its/plugin/tests/src/test/resources/eslint-based-rules.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters