Skip to content
This repository has been archived by the owner on Jul 8, 2019. It is now read-only.

Commit

Permalink
Merge branch 'porscheinformatik-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablissimo committed Jan 8, 2017
2 parents 83fb48d + 21c5ac9 commit 224a249
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/main/java/com/pablissimo/sonar/TsLintSensor.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public TsLintSensor(Settings settings, PathResolver resolver,
this.executor = executor;
this.parser = parser;
}

@Override
public void describe(SensorDescriptor desc) {
desc
Expand All @@ -42,7 +42,12 @@ public void describe(SensorDescriptor desc) {
}

@Override
public void execute(SensorContext ctx) {
public void execute(SensorContext ctx) {
if (!this.settings.getBoolean(TypeScriptPlugin.SETTING_TS_LINT_ENABLED)) {
LOG.debug("Skipping tslint execution - " + TypeScriptPlugin.SETTING_TS_LINT_ENABLED + " set to false");
return;
}

String pathToTsLint = this.resolver.getPath(ctx, TypeScriptPlugin.SETTING_TS_LINT_PATH, TSLINT_FALLBACK_PATH);
String pathToTsLintConfig = this.resolver.getPath(ctx, TypeScriptPlugin.SETTING_TS_LINT_CONFIG_PATH, CONFIG_FILENAME);
String rulesDir = this.resolver.getPath(ctx, TypeScriptPlugin.SETTING_TS_LINT_RULES_DIR, null);
Expand Down Expand Up @@ -101,7 +106,7 @@ else if (pathToTsLintConfig == null) {
if (batchIssues == null || batchIssues.size() == 0) {
continue;
}

if (!fileMap.containsKey(filePath)) {
LOG.warn("TsLint reported issues against a file that wasn't sent to it - will be ignored: " + filePath);
continue;
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/pablissimo/sonar/TypeScriptPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
import org.sonar.api.*;

@Properties({
@Property(
key = TypeScriptPlugin.SETTING_TS_LINT_ENABLED,
type = PropertyType.BOOLEAN,
defaultValue = "true",
name = "Enable TSLint",
description = "Run TSLint on SonarQube analysis",
project = true
),
@Property(
key = TypeScriptPlugin.SETTING_TS_LINT_PATH,
defaultValue = "",
Expand Down Expand Up @@ -107,6 +115,7 @@ public class TypeScriptPlugin implements Plugin {
public static final String SETTING_EXCLUDE_TYPE_DEFINITION_FILES = "sonar.ts.excludetypedefinitionfiles";
public static final String SETTING_FORCE_ZERO_COVERAGE = "sonar.ts.forceZeroCoverage";
public static final String SETTING_IGNORE_NOT_FOUND = "sonar.ts.ignoreNotFound";
public static final String SETTING_TS_LINT_ENABLED = "sonar.ts.tslintenabled";
public static final String SETTING_TS_LINT_PATH = "sonar.ts.tslintpath";
public static final String SETTING_TS_LINT_CONFIG_PATH = "sonar.ts.tslintconfigpath";
public static final String SETTING_TS_LINT_TIMEOUT = "sonar.ts.tslinttimeout";
Expand Down
14 changes: 13 additions & 1 deletion src/test/java/com/pablissimo/sonar/TsLintSensorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ public void setUp() throws Exception {
this.fakePathResolutions.put(TypeScriptPlugin.SETTING_TS_LINT_RULES_DIR, "/path/to/rules");

this.settings = mock(Settings.class);

when(this.settings.getInt(TypeScriptPlugin.SETTING_TS_LINT_TIMEOUT)).thenReturn(45000);
when(this.settings.getBoolean(TypeScriptPlugin.SETTING_TS_LINT_ENABLED)).thenReturn(true);
this.executor = mock(TsLintExecutor.class);
this.parser = mock(TsLintParser.class);

this.resolver = mock(PathResolver.class);
this.sensor = spy(new TsLintSensor(settings, this.resolver, this.executor, this.parser));

Expand Down Expand Up @@ -240,6 +241,17 @@ public void execute_doesNothingWhenNotConfigured() throws IOException {

assertEquals(0, this.context.allIssues().size());
}

@Test
public void analyse_doesNothingWhenDisabled() throws IOException {
when(this.settings.getBoolean(TypeScriptPlugin.SETTING_TS_LINT_ENABLED)).thenReturn(Boolean.FALSE);

this.sensor.execute(this.context);

verify(this.executor, times(0)).execute(any(TsLintExecutorConfig.class), any(List.class));

assertEquals(0, this.context.allIssues().size());
}

@Test
public void execute_doesNothingWhenNoConfigPathset() throws IOException {
Expand Down
4 changes: 3 additions & 1 deletion src/test/java/com/pablissimo/sonar/TypeScriptPluginTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void definesExpectedProperties() {
Annotation annotation = plugin.getClass().getAnnotations()[0];
Properties propertiesAnnotation = (Properties) annotation;

assertEquals(8, propertiesAnnotation.value().length);
assertEquals(9, propertiesAnnotation.value().length);

Property[] properties = propertiesAnnotation.value();
assertNotNull(findPropertyByName(properties,
Expand All @@ -66,6 +66,8 @@ public void definesExpectedProperties() {
TypeScriptPlugin.SETTING_FORCE_ZERO_COVERAGE));
assertNotNull(findPropertyByName(properties,
TypeScriptPlugin.SETTING_LCOV_REPORT_PATH));
assertNotNull(findPropertyByName(properties,
TypeScriptPlugin.SETTING_TS_LINT_ENABLED));
assertNotNull(findPropertyByName(properties,
TypeScriptPlugin.SETTING_TS_LINT_PATH));
assertNotNull(findPropertyByName(properties,
Expand Down

0 comments on commit 224a249

Please sign in to comment.