Skip to content

Commit

Permalink
[FEATURE] Add TypeScript code quality analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
Aurélien Baudet committed May 18, 2016
1 parent a2c1718 commit 70ae02d
Show file tree
Hide file tree
Showing 89 changed files with 3,829 additions and 0 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<module>sonar-web-frontend-angular-eslint</module>
<module>sonar-duplication-cpd</module>
<module>sonar-duplication-simian</module>
<module>sonar-web-frontend-typescript</module>
<module>sonar-web-frontend-plugin</module>
</modules>

Expand Down
5 changes: 5 additions & 0 deletions sonar-web-frontend-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
<artifactId>sonar-web-frontend-angular-eslint</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>fr.sii.sonar</groupId>
<artifactId>sonar-web-frontend-typescript</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
2 changes: 2 additions & 0 deletions sonar-web-frontend-typescript/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target
/target/*
59 changes: 59 additions & 0 deletions sonar-web-frontend-typescript/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>fr.sii.sonar</groupId>
<artifactId>sonar-sii-plugin-parent</artifactId>
<version>2.0.1-SNAPSHOT</version>
</parent>

<artifactId>sonar-web-frontend-typescript</artifactId>
<packaging>sonar-plugin</packaging>

<name>SII web frontend plugin :: TypeScript</name>
<description>Consume reports generated by tslint for code quality. Also consume reports for code duplication (either simian or cpd). Consumes the unit/integration tests reports (generated by Jasmin) coverage report (lcov generated by Istanbul). The information generated by reports are added in Sonar</description>

<dependencies>
<dependency>
<groupId>fr.sii.sonar</groupId>
<artifactId>sonar-report-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>fr.sii.sonar</groupId>
<artifactId>sonar-coverage-lcov</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>fr.sii.sonar</groupId>
<artifactId>sonar-test-junit</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>fr.sii.sonar</groupId>
<artifactId>sonar-duplication-cpd</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>fr.sii.sonar</groupId>
<artifactId>sonar-duplication-simian</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-packaging-maven-plugin</artifactId>
<version>${sonar.plugin.version}</version>
<extensions>true</extensions>
<configuration>
<pluginClass>fr.sii.sonar.web.frontend.typescript.TypeScriptPlugin</pluginClass>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package fr.sii.sonar.web.frontend.typescript;

import org.sonar.api.config.Settings;

import fr.sii.sonar.report.core.common.language.ConfigurableLanguage;

public class TypeScript extends ConfigurableLanguage {

public TypeScript(Settings settings) {
super(settings, TypeScriptLanguageConstants.LANGUAGE_KEY, TypeScriptLanguageConstants.FILE_SUFFIXES_KEY, TypeScriptLanguageConstants.FILE_SUFFIXES_DEFVALUE, "TS");
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package fr.sii.sonar.web.frontend.typescript;

import fr.sii.sonar.report.core.common.ReportConstants;
import fr.sii.sonar.report.core.common.language.LanguageConstants;

public abstract class TypeScriptLanguageConstants implements ReportConstants, LanguageConstants {
public static final String FILE_SUFFIXES_KEY = "sonar.sii.ts.suffixes";
public static final String FILE_SUFFIXES_DEFVALUE = ".ts";
public static final String LANGUAGE_KEY = "ts";
public static final String CATEGORY = "TypeScript";
public static final String SUB_CATEGORY = "General";

public String getLanguageKey() {
return LANGUAGE_KEY;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
package fr.sii.sonar.web.frontend.typescript;

import java.util.Arrays;
import java.util.List;

import org.sonar.api.SonarPlugin;
import org.sonar.api.config.PropertyDefinition;
import org.sonar.api.resources.Qualifiers;

import fr.sii.sonar.report.core.common.PluginDependencies;
import fr.sii.sonar.web.frontend.typescript.coverage.LcovIntegrationCoverageConstants;
import fr.sii.sonar.web.frontend.typescript.coverage.LcovIntegrationCoverageSensor;
import fr.sii.sonar.web.frontend.typescript.coverage.LcovOverallCoverageConstants;
import fr.sii.sonar.web.frontend.typescript.coverage.LcovOverallCoverageSensor;
import fr.sii.sonar.web.frontend.typescript.coverage.LcovUnitCoverageConstants;
import fr.sii.sonar.web.frontend.typescript.coverage.LcovUnitCoverageSensor;
import fr.sii.sonar.web.frontend.typescript.duplication.TypeScriptDuplicationConstants;
import fr.sii.sonar.web.frontend.typescript.duplication.TypeScriptDuplicationSensor;
import fr.sii.sonar.web.frontend.typescript.quality.TslintQualityConstants;
import fr.sii.sonar.web.frontend.typescript.quality.TslintQualitySensor;
import fr.sii.sonar.web.frontend.typescript.quality.TslintProfileDefinition;
import fr.sii.sonar.web.frontend.typescript.quality.TslintRulesDefinition;
import fr.sii.sonar.web.frontend.typescript.test.JUnitConstants;
import fr.sii.sonar.web.frontend.typescript.test.JUnitIntegrationConstants;
import fr.sii.sonar.web.frontend.typescript.test.JUnitIntegrationReportSensor;
import fr.sii.sonar.web.frontend.typescript.test.JUnitReportSensor;

/**
* This class is the entry point for all extensions
*/
public final class TypeScriptPlugin extends SonarPlugin {


// This is where you're going to declare all your Sonar extensions
@SuppressWarnings({ "rawtypes" })
public List getExtensions() {
return Arrays.asList(
// needed here for standalone version
PluginDependencies.class,

// general configuration
PropertyDefinition.builder(TypeScriptLanguageConstants.FILE_SUFFIXES_KEY)
.defaultValue(TypeScriptLanguageConstants.FILE_SUFFIXES_DEFVALUE)
.category(TypeScriptLanguageConstants.CATEGORY)
.subCategory(TypeScriptLanguageConstants.SUB_CATEGORY)
.name("File suffixes for TypeScript files")
.description("Comma-separated list of suffixes for files to analyze.")
.onQualifiers(Qualifiers.PROJECT)
.build(),

TypeScript.class,

// Quality configuration
PropertyDefinition.builder(TslintQualityConstants.REPORT_PATH_KEY)
.defaultValue(TslintQualityConstants.REPORT_PATH_DEFVALUE)
.category(TslintQualityConstants.CATEGORY)
.subCategory(TslintQualityConstants.SUB_CATEGORY)
.name("TypeScript quality report path")
.description("The path to the TypeScript report file to load")
.onQualifiers(Qualifiers.PROJECT)
.build(),
PropertyDefinition.builder(TslintQualityConstants.FAIL_MISSING_FILE_KEY)
.defaultValue(TslintQualityConstants.FAIL_MISSING_FILE_DEFVALUE)
.category(TslintQualityConstants.CATEGORY)
.subCategory(TslintQualityConstants.SUB_CATEGORY)
.name("Fail on missing source file")
.description("True to stop analysis if a source file is not found")
.onQualifiers(Qualifiers.PROJECT)
.build(),
PropertyDefinition.builder(TslintQualityConstants.SKIP_FILE_METRICS_KEY)
.defaultValue(TslintQualityConstants.SKIP_FILE_METRICS_DEFVALUE)
.category(TslintQualityConstants.CATEGORY)
.subCategory(TslintQualityConstants.SUB_CATEGORY)
.name("Skip save of file metrics")
.description("If you have several plugins that are able to handle TypeScript, you may have an error (Can not add the same measure twice). Set it to true to let the other plugin save the metrics")
.onQualifiers(Qualifiers.PROJECT)
.build(),

TslintQualityConstants.class,
TslintRulesDefinition.class,
TslintProfileDefinition.class,
TslintQualitySensor.class,

// Unit coverage configuration
PropertyDefinition.builder(LcovUnitCoverageConstants.REPORT_PATH_KEY)
.defaultValue(LcovUnitCoverageConstants.REPORT_PATH_DEFVALUE)
.category(LcovUnitCoverageConstants.CATEGORY)
.subCategory(LcovUnitCoverageConstants.SUB_CATEGORY)
.name("TypeScript unit tests coverage report path")
.description("The path to the TypeScript report file to load for unit tests coverage")
.onQualifiers(Qualifiers.PROJECT)
.build(),
PropertyDefinition.builder(LcovUnitCoverageConstants.FAIL_MISSING_FILE_KEY)
.defaultValue(LcovUnitCoverageConstants.FAIL_MISSING_FILE_DEFVALUE)
.category(LcovUnitCoverageConstants.CATEGORY)
.subCategory(LcovUnitCoverageConstants.SUB_CATEGORY)
.name("Fail on missing source file")
.description("True to stop analysis if a source file is not found")
.onQualifiers(Qualifiers.PROJECT)
.build()

// LcovUnitCoverageConstants.class,
// LcovUnitCoverageSensor.class,
//
// // Integration coverage configuration
// PropertyDefinition.builder(LcovIntegrationCoverageConstants.REPORT_PATH_KEY)
// .defaultValue(LcovIntegrationCoverageConstants.REPORT_PATH_DEFVALUE)
// .category(LcovIntegrationCoverageConstants.CATEGORY)
// .subCategory(LcovIntegrationCoverageConstants.SUB_CATEGORY)
// .name("TypeScript integration tests coverage report path")
// .description("The path to the TypeScript report file to load for integration tests coverage")
// .onQualifiers(Qualifiers.PROJECT)
// .build(),
// PropertyDefinition.builder(LcovIntegrationCoverageConstants.FAIL_MISSING_FILE_KEY)
// .defaultValue(LcovIntegrationCoverageConstants.FAIL_MISSING_FILE_DEFVALUE)
// .category(LcovIntegrationCoverageConstants.CATEGORY)
// .subCategory(LcovIntegrationCoverageConstants.SUB_CATEGORY)
// .name("Fail on missing source file")
// .description("True to stop analysis if a source file is not found")
// .onQualifiers(Qualifiers.PROJECT)
// .build(),
//
// LcovIntegrationCoverageConstants.class,
// LcovIntegrationCoverageSensor.class,
//
// // Overall coverage configuration
// PropertyDefinition.builder(LcovOverallCoverageConstants.REPORT_PATH_KEY)
// .defaultValue(LcovOverallCoverageConstants.REPORT_PATH_DEFVALUE)
// .category(LcovOverallCoverageConstants.CATEGORY)
// .subCategory(LcovOverallCoverageConstants.SUB_CATEGORY)
// .name("TypeScript overall tests coverage report path")
// .description("The path to the TypeScript report file to load for overall tests coverage")
// .onQualifiers(Qualifiers.PROJECT)
// .build(),
// PropertyDefinition.builder(LcovOverallCoverageConstants.FAIL_MISSING_FILE_KEY)
// .defaultValue(LcovOverallCoverageConstants.FAIL_MISSING_FILE_DEFVALUE)
// .category(LcovOverallCoverageConstants.CATEGORY)
// .subCategory(LcovOverallCoverageConstants.SUB_CATEGORY)
// .name("Fail on missing source file")
// .description("True to stop analysis if a source file is not found")
// .onQualifiers(Qualifiers.PROJECT)
// .build(),
//
// LcovOverallCoverageConstants.class,
// LcovOverallCoverageSensor.class,
//
// // Unit testing configuration
// PropertyDefinition.builder(JUnitConstants.REPORT_PATH_KEY)
// .defaultValue(JUnitConstants.REPORT_PATH_DEFVALUE)
// .category(JUnitConstants.CATEGORY)
// .subCategory(JUnitConstants.SUB_CATEGORY)
// .name("TypeScript junit unit test report path")
// .description("The path to the TypeScript report file to load")
// .onQualifiers(Qualifiers.PROJECT)
// .build(),
// PropertyDefinition.builder(JUnitConstants.FAIL_MISSING_FILE_KEY)
// .defaultValue(JUnitConstants.FAIL_MISSING_FILE_DEFVALUE)
// .category(JUnitConstants.CATEGORY)
// .subCategory(JUnitConstants.SUB_CATEGORY)
// .name("Fail on missing test file")
// .description("True to stop analysis if a test file is not found")
// .onQualifiers(Qualifiers.PROJECT)
// .build(),
//
// JUnitConstants.class,
// JUnitReportSensor.class,
//
// // Integration testing configuration
// PropertyDefinition.builder(JUnitIntegrationConstants.REPORT_PATH_KEY)
// .defaultValue(JUnitIntegrationConstants.REPORT_PATH_DEFVALUE)
// .category(JUnitIntegrationConstants.CATEGORY)
// .subCategory(JUnitIntegrationConstants.SUB_CATEGORY)
// .name("TypeScript junit integration test report path")
// .description("The path to the TypeScript report file to load")
// .onQualifiers(Qualifiers.PROJECT)
// .build(),
// PropertyDefinition.builder(JUnitIntegrationConstants.FAIL_MISSING_FILE_KEY)
// .defaultValue(JUnitIntegrationConstants.FAIL_MISSING_FILE_DEFVALUE)
// .category(JUnitIntegrationConstants.CATEGORY)
// .subCategory(JUnitIntegrationConstants.SUB_CATEGORY)
// .name("Fail on missing test file")
// .description("True to stop analysis if a test file is not found")
// .onQualifiers(Qualifiers.PROJECT)
// .build(),
//
// JUnitIntegrationConstants.class,
// JUnitIntegrationReportSensor.class,
//
// // Duplication configuration
// PropertyDefinition.builder(TypeScriptDuplicationConstants.REPORT_PATH_KEY)
// .defaultValue(TypeScriptDuplicationConstants.REPORT_PATH_DEFVALUE)
// .category(TypeScriptDuplicationConstants.CATEGORY)
// .subCategory(TypeScriptDuplicationConstants.SUB_CATEGORY)
// .name("TypeScript duplication report path")
// .description("The path to the TypeScript report file to load")
// .onQualifiers(Qualifiers.PROJECT)
// .build(),
// PropertyDefinition.builder(TypeScriptDuplicationConstants.FAIL_MISSING_FILE_KEY)
// .defaultValue(TypeScriptDuplicationConstants.FAIL_MISSING_FILE_DEFVALUE)
// .category(TypeScriptDuplicationConstants.CATEGORY)
// .subCategory(TypeScriptDuplicationConstants.SUB_CATEGORY)
// .name("Fail on missing source file")
// .description("True to stop analysis if a source file is not found")
// .onQualifiers(Qualifiers.PROJECT)
// .build(),
// PropertyDefinition.builder(TypeScriptDuplicationConstants.SKIP_DUPLICATION_KEY)
// .defaultValue(TypeScriptDuplicationConstants.SKIP_DUPLICATION_DEFVAL)
// .category(TypeScriptDuplicationConstants.CATEGORY)
// .subCategory(TypeScriptDuplicationConstants.SUB_CATEGORY)
// .name("Skip duplication analysis")
// .description("True to skip code duplication analysis done by this plugin")
// .onQualifiers(Qualifiers.PROJECT)
// .build(),
//
// TypeScriptDuplicationConstants.class,
// TypeScriptDuplicationSensor.class
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package fr.sii.sonar.web.frontend.typescript.coverage;

import fr.sii.sonar.report.core.common.ReportConstants;
import fr.sii.sonar.report.core.coverage.CoverageConstants;
import fr.sii.sonar.web.frontend.typescript.TypeScriptLanguageConstants;

public class LcovIntegrationCoverageConstants extends TypeScriptLanguageConstants implements ReportConstants, CoverageConstants {
public static final String REPORT_PATH_KEY = "sonar.sii.coverage.it.ts.report.path";
public static final String FAIL_MISSING_FILE_KEY = "sonar.sii.coverage.it.ts.file.missing.fail";
public static final String REPORT_PATH_DEFVALUE = "/reports/sonar/ts-it.lcov";
public static final String FAIL_MISSING_FILE_DEFVALUE = "true";
public static final String SUB_CATEGORY = "Coverage";

public String getReportPathKey() {
return REPORT_PATH_KEY;
}

public String getMissingFileFailKey() {
return FAIL_MISSING_FILE_KEY;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package fr.sii.sonar.web.frontend.typescript.coverage;

import fr.sii.sonar.coverage.lcov.factory.LcovProviderFactory;
import fr.sii.sonar.report.core.common.PluginDependencies;
import fr.sii.sonar.report.core.common.ReportSensor;
import fr.sii.sonar.report.core.coverage.domain.CoverageReport;
import fr.sii.sonar.report.core.coverage.factory.IntegrationCoverageSaverFactory;

/**
* Sensor specific to TypeScript code coverage for integration tests that loads LCOV report
*
* @author Aurélien Baudet
*
*/
public class LcovIntegrationCoverageSensor extends ReportSensor<CoverageReport> {

public LcovIntegrationCoverageSensor(LcovIntegrationCoverageConstants constants, PluginDependencies pluginDependencies) {
super(constants, pluginDependencies, new LcovProviderFactory(), new IntegrationCoverageSaverFactory());
}

}
Loading

0 comments on commit 70ae02d

Please sign in to comment.