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

Commit

Permalink
Merge branch 'master' into issue35
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablissimo committed Jun 18, 2016
2 parents 170e9d1 + 5e9b15a commit 1eaae62
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 22 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ SonarQube plugin for TypeScript files
##Demos

A live deployed demo hitting a few large open-source TypeScript projects can be found here:
http://sonar.pablissimo.com
https://sonar.pablissimo.com

Suggestions for more projects (or ones with easy-to-gather code coverage info) appreciated!

* [Microsoft TypeScript Compiler](http://sonar.pablissimo.com/overview?id=18739)
* [Turbulenz Engine](http://sonar.pablissimo.com/overview?id=20352)
* [Microsoft Visual Studio Code](http://sonar.pablissimo.com/overview?id=19179)
* [Angular Framework](http://sonar.pablissimo.com/overview?id=18822)
* [Microsoft TypeScript Compiler](https://sonar.pablissimo.com/overview?id=18739)
* [Turbulenz Engine](https://sonar.pablissimo.com/overview?id=20352)
* [Microsoft Visual Studio Code](https://sonar.pablissimo.com/overview?id=19179)
* [Angular Framework](https://sonar.pablissimo.com/overview?id=18822)

##Overview

Expand Down Expand Up @@ -80,8 +80,8 @@ The plugin has so far *only been tested on Windows* and it'll be no surprise if
</thead>
<tbody>
<tr><td>sonar.ts.tslintconfigpath</td><td><b>Mandatory</b></td><td>Path to the tslint.json file that configures the rules to be used in linting</td></tr>
<tr><td>sonar.ts.excludetypedefinitionfiles</td><td><b>Optional</b></td><td>Excludes .d.ts files from analysis</td></tr>
<tr><td>sonar.ts.forceZeroCoverage</td><td><b>Optional</b></td><td>Forces code coverage percentage to zero when no report is supplied</td></tr>
<tr><td>sonar.ts.excludetypedefinitionfiles</td><td><b>Optional</b></td><td>Excludes .d.ts files from analysis, defaults to true</td></tr>
<tr><td>sonar.ts.forceZeroCoverage</td><td><b>Optional</b></td><td>Forces code coverage percentage to zero when no report is supplied, defaults to false</td></tr>
<tr><td>sonar.ts.tslinttimeout</td><td><b>Optional</b></td><td>Max time to wait for TsLint to finish processing a single file (in milliseconds), defaults to 60 seconds</td></tr>
<tr><td>sonar.ts.tslintrulesdir</td><td><b>Optional</b></td><td>Path to a folder containing custom TsLint rules referenced in tslint.json</td></tr>
<tr><td>sonar.ts.lcov.reportpath</td><td><b>Optional</b></td><td>Path to an LCOV code-coverage report to be included in analysis</td></tr>
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/com/pablissimo/sonar/LOCSensor.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.Sensor;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.batch.fs.FileSystem;
Expand All @@ -13,6 +16,8 @@
import org.sonar.api.resources.Project;

public class LOCSensor implements Sensor {
private static final Logger LOG = LoggerFactory.getLogger(LOCSensor.class);

private FileSystem fileSystem;

/**
Expand Down Expand Up @@ -42,7 +47,7 @@ public void analyse(Project project, SensorContext sensorContext) {
public String toString() {
return getClass().getSimpleName();
}

protected BufferedReader getReaderFromFile(InputFile inputFile) throws FileNotFoundException {
return new BufferedReader(new FileReader(inputFile.file()));
}
Expand All @@ -53,9 +58,9 @@ private int getNonCommentLineCount(InputFile inputFile) {
try {
br = this.getReaderFromFile(inputFile);

boolean isEOF = false;
boolean isEOF;
boolean isCommentOpen = false;
boolean isACommentLine = false;
boolean isACommentLine;
do {

String line = br.readLine();
Expand Down Expand Up @@ -102,11 +107,9 @@ private int getNonCommentLineCount(InputFile inputFile) {
br.close();

} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
LOG.error("File not found", e);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
LOG.error("Error while reading BufferedReader", e);
}
return value;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/pablissimo/sonar/TsCoverageSensor.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ protected LCOVParser getParser(File baseDirectory) {
}

private void saveZeroValueForResource(org.sonar.api.resources.File resource, SensorContext context) {
PropertiesBuilder<Integer, Integer> lineHitsData = new PropertiesBuilder<Integer, Integer>(CoreMetrics.COVERAGE_LINE_HITS_DATA);
PropertiesBuilder<Integer, Integer> lineHitsData = new PropertiesBuilder<>(CoreMetrics.COVERAGE_LINE_HITS_DATA);

for (int x = 1; x < context.getMeasure(resource, CoreMetrics.LINES).getIntValue(); x++) {
lineHitsData.add(x, 0);
Expand Down Expand Up @@ -151,4 +151,4 @@ public File getIOFile(File baseDir, String path) {

return file;
}
}
}
6 changes: 2 additions & 4 deletions src/main/java/com/pablissimo/sonar/TsLintSensor.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ public TsLintSensor(Settings settings, FileSystem fileSystem, ResourcePerspectiv
}

public boolean shouldExecuteOnProject(Project project) {
boolean toReturn = hasFilesToAnalyze();

return toReturn;
return hasFilesToAnalyze();
}

private boolean hasFilesToAnalyze() {
Expand Down Expand Up @@ -86,7 +84,7 @@ else if (pathToTsLintConfig == null) {

RuleQuery ruleQuery = RuleQuery.create().withRepositoryKey(TsRulesDefinition.REPOSITORY_NAME);
Collection<Rule> allRules = this.ruleFinder.findAll(ruleQuery);
HashSet<String> ruleNames = new HashSet<String>();
HashSet<String> ruleNames = new HashSet<>();
for (Rule rule : allRules) {
ruleNames.add(rule.getKey());
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/pablissimo/sonar/TypeScriptLanguage.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class TypeScriptLanguage extends AbstractLanguage {
public static final String LANGUAGE_NAME = "TypeScript";
public static final String LANGUAGE_KEY = "ts";
public static final String[] LANGUAGE_EXTENSIONS = { "ts", "tsx" };
public static final String LANGUAGE_DEFINITION_EXTENSION = "d.ts";
protected static final String LANGUAGE_DEFINITION_EXTENSION = "d.ts";

public TypeScriptLanguage(){
super(LANGUAGE_KEY, LANGUAGE_NAME);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/pablissimo/sonar/model/TsLintConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class TsLintConfig {
private Map<String, Object> rules;

public TsLintConfig() {
this.rules = new HashMap<String, Object>();
this.rules = new HashMap<>();
}

public Map<String, Object> getRules() {
Expand Down

0 comments on commit 1eaae62

Please sign in to comment.