Search in sources :

Example 6 with RuleDetails

use of org.sonarsource.sonarlint.core.client.api.common.RuleDetails in project sonarlint-intellij by SonarSource.

the class ConnectedSonarLintFacadeTest method should_get_rule_name.

@Test
public void should_get_rule_name() {
    RuleDetails ruleDetails = mock(RuleDetails.class);
    when(ruleDetails.getName()).thenReturn("name");
    when(engine.getRuleDetails("rule1")).thenReturn(ruleDetails);
    assertThat(facade.getRuleName("rule1")).isEqualTo("name");
    assertThat(facade.getRuleName("invalid")).isNull();
}
Also used : RuleDetails(org.sonarsource.sonarlint.core.client.api.common.RuleDetails) Test(org.junit.Test)

Example 7 with RuleDetails

use of org.sonarsource.sonarlint.core.client.api.common.RuleDetails in project sonarlint-core by SonarSource.

the class ConnectedIssueMediumTest method simpleJavaScriptUnbinded.

@Test
public void simpleJavaScriptUnbinded() throws Exception {
    String ruleKey = "javascript:UnusedVariable";
    RuleDetails ruleDetails = sonarlint.getRuleDetails(ruleKey);
    assertThat(ruleDetails.getKey()).isEqualTo(ruleKey);
    assertThat(ruleDetails.getName()).isEqualTo("Unused local variables should be removed");
    assertThat(ruleDetails.getLanguage()).isEqualTo("js");
    assertThat(ruleDetails.getSeverity()).isEqualTo("MAJOR");
    assertThat(ruleDetails.getHtmlDescription()).contains("<p>", "If a local variable is declared but not used");
    assertThat(ruleDetails.getExtendedDescription()).isEmpty();
    ClientInputFile inputFile = prepareInputFile("foo.js", "function foo() {\n" + "  var x;\n" + "  var y; //NOSONAR\n" + "}", false);
    final List<Issue> issues = new ArrayList<>();
    sonarlint.analyze(new ConnectedAnalysisConfiguration(null, baseDir.toPath(), temp.newFolder().toPath(), Arrays.asList(inputFile), ImmutableMap.<String, String>of()), new StoreIssueListener(issues), null, null);
    assertThat(issues).extracting("ruleKey", "startLine", "inputFile.path").containsOnly(tuple(ruleKey, 2, inputFile.getPath()));
}
Also used : Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) ArrayList(java.util.ArrayList) ConnectedAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedAnalysisConfiguration) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) RuleDetails(org.sonarsource.sonarlint.core.client.api.common.RuleDetails) Test(org.junit.Test)

Example 8 with RuleDetails

use of org.sonarsource.sonarlint.core.client.api.common.RuleDetails in project sonarlint-intellij by SonarSource.

the class ConnectedSonarLintFacadeTest method should_get_description.

@Test
public void should_get_description() {
    RuleDetails ruleDetails = mock(RuleDetails.class);
    when(ruleDetails.getExtendedDescription()).thenReturn("desc");
    when(ruleDetails.getHtmlDescription()).thenReturn("html");
    when(engine.getRuleDetails("rule1")).thenReturn(ruleDetails);
    assertThat(facade.getDescription("rule1")).isEqualTo("html<br/><br/>desc");
    assertThat(facade.getDescription("invalid")).isNull();
}
Also used : RuleDetails(org.sonarsource.sonarlint.core.client.api.common.RuleDetails) Test(org.junit.Test)

Example 9 with RuleDetails

use of org.sonarsource.sonarlint.core.client.api.common.RuleDetails in project sonarlint-intellij by SonarSource.

the class StandaloneSonarLintFacadeTest method should_get_rule_name.

@Test
public void should_get_rule_name() {
    RuleDetails ruleDetails = mock(RuleDetails.class);
    when(ruleDetails.getName()).thenReturn("name");
    when(engine.getRuleDetails("rule1")).thenReturn(ruleDetails);
    assertThat(facade.getRuleName("rule1")).isEqualTo("name");
    assertThat(facade.getRuleName("invalid")).isNull();
}
Also used : RuleDetails(org.sonarsource.sonarlint.core.client.api.common.RuleDetails) Test(org.junit.Test)

Aggregations

RuleDetails (org.sonarsource.sonarlint.core.client.api.common.RuleDetails)9 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)4 ClientInputFile (org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile)3 Issue (org.sonarsource.sonarlint.core.client.api.common.analysis.Issue)3 TestClientInputFile (org.sonarsource.sonarlint.core.TestClientInputFile)2 StandaloneAnalysisConfiguration (org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 File (java.io.File)1 Path (java.nio.file.Path)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 RuleKey (org.sonar.api.rule.RuleKey)1 StandaloneSonarLintEngineImpl (org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl)1 LogOutput (org.sonarsource.sonarlint.core.client.api.common.LogOutput)1 ConnectedAnalysisConfiguration (org.sonarsource.sonarlint.core.client.api.connected.ConnectedAnalysisConfiguration)1 StandaloneGlobalConfiguration (org.sonarsource.sonarlint.core.client.api.standalone.StandaloneGlobalConfiguration)1 StandaloneGlobalContainer (org.sonarsource.sonarlint.core.container.standalone.StandaloneGlobalContainer)1