diff --git a/README.md b/README.md
index 19693fb..fcb6090 100644
--- a/README.md
+++ b/README.md
@@ -83,6 +83,7 @@ The plugin has so far *only been tested on Windows* and it'll be no surprise if
sonar.ts.tslintconfigpath | Mandatory | Path to the tslint.json file that configures the rules to be used in linting |
sonar.ts.excludetypedefinitionfiles | Optional | Excludes .d.ts files from analysis, defaults to true |
sonar.ts.forceZeroCoverage | Optional | Forces code coverage percentage to zero when no report is supplied, defaults to false |
+sonar.ts.ignoreNotFound | Optional | Don't set code coverage percentage to zero when file is not found in report, defaults to false |
sonar.ts.tslinttimeout | Optional | Max time to wait for TsLint to finish processing a single file (in milliseconds), defaults to 60 seconds |
sonar.ts.tslintrulesdir | Optional | Path to a folder containing custom TsLint rules referenced in tslint.json |
sonar.ts.lcov.reportpath | Optional | Path to an LCOV code-coverage report to be included in analysis |
diff --git a/src/main/java/com/pablissimo/sonar/TsCoverageSensor.java b/src/main/java/com/pablissimo/sonar/TsCoverageSensor.java
index 8034429..dbb5eb3 100644
--- a/src/main/java/com/pablissimo/sonar/TsCoverageSensor.java
+++ b/src/main/java/com/pablissimo/sonar/TsCoverageSensor.java
@@ -84,6 +84,8 @@ protected void saveMeasureFromLCOVFile(Project project, SensorContext context) {
LCOVParser parser = getParser(moduleFileSystem.baseDir());
Map coveredFiles = parser.parseFile(lcovFile);
+
+ final boolean ignoreNotFound = isIgnoreNotFoundActivated();
for (File file : moduleFileSystem.files(this.filePredicates.hasLanguage(TypeScriptLanguage.LANGUAGE_KEY))) {
try {
@@ -94,7 +96,7 @@ protected void saveMeasureFromLCOVFile(Project project, SensorContext context) {
for (Measure measure : fileCoverage.createMeasures()) {
context.saveMeasure(resource, measure);
}
- } else {
+ } else if (!ignoreNotFound) {
// colour all lines as not executed
saveZeroValueForResource(resource, context);
}
@@ -135,6 +137,10 @@ private boolean isForceZeroCoverageActivated() {
return settings.getBoolean(TypeScriptPlugin.SETTING_FORCE_ZERO_COVERAGE);
}
+ private boolean isIgnoreNotFoundActivated() {
+ return settings.getBoolean(TypeScriptPlugin.SETTING_IGNORE_NOT_FOUND);
+ }
+
private boolean isLCOVReportProvided() {
return StringUtils.isNotBlank(settings.getString(TypeScriptPlugin.SETTING_LCOV_REPORT_PATH));
}
diff --git a/src/main/java/com/pablissimo/sonar/TypeScriptPlugin.java b/src/main/java/com/pablissimo/sonar/TypeScriptPlugin.java
index 258dd84..f614bed 100644
--- a/src/main/java/com/pablissimo/sonar/TypeScriptPlugin.java
+++ b/src/main/java/com/pablissimo/sonar/TypeScriptPlugin.java
@@ -91,6 +91,7 @@
public class TypeScriptPlugin extends SonarPlugin {
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_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";
diff --git a/src/test/java/com/pablissimo/sonar/TsCoverageSensorTest.java b/src/test/java/com/pablissimo/sonar/TsCoverageSensorTest.java
index 623f739..93fd908 100644
--- a/src/test/java/com/pablissimo/sonar/TsCoverageSensorTest.java
+++ b/src/test/java/com/pablissimo/sonar/TsCoverageSensorTest.java
@@ -132,6 +132,24 @@ public void savesZeroCoverage_IfParserOutputsNothingForFile() {
verify(context).saveMeasure(eq(this.sonarFile), eq(CoreMetrics.UNCOVERED_LINES), eq(5.0));
}
+ @Test
+ public void savesNoCoverage_IfNotFoundFilesAreIgnored() {
+ when(this.settings.getBoolean(TypeScriptPlugin.SETTING_IGNORE_NOT_FOUND)).thenReturn(true);
+
+ Measure linesMeasure = mock(Measure.class);
+ when(this.context.getMeasure(eq(this.sonarFile), eq(CoreMetrics.LINES))).thenReturn(linesMeasure);
+
+ Measure nclocLines = mock(Measure.class);
+ when(nclocLines.getIntValue()).thenReturn(5);
+ when(nclocLines.getValue()).thenReturn(5.0);
+ when(this.context.getMeasure(eq(this.sonarFile), eq(CoreMetrics.NCLOC))).thenReturn(nclocLines);
+
+ this.sensor.analyse(mock(Project.class), this.context);
+ verify(context, never()).saveMeasure(eq(this.sonarFile), any(Measure.class));
+ verify(context, never()).saveMeasure(eq(this.sonarFile), eq(CoreMetrics.LINES_TO_COVER), any(Double.class));
+ verify(context, never()).saveMeasure(eq(this.sonarFile), eq(CoreMetrics.UNCOVERED_LINES), any(Double.class));
+ }
+
@Test
public void savesCoverage_IfParserOutputHasDetailsForFile() {
when(this.file.getAbsolutePath()).thenReturn("path");