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

Commit

Permalink
Merge from master
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablissimo committed Feb 19, 2017
2 parents 9724219 + e7eff25 commit 141bb05
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 13 deletions.
12 changes: 10 additions & 2 deletions .travis.yml
Expand Up @@ -4,11 +4,19 @@ jdk:

script: ./travis.sh

cache:
directories:
- $HOME/.m2/repository

before_cache:
# remove all the artifacts (JAR, ZIP) that are installed in local repo because of mvn deploy
- rm -rf $HOME/.m2/repository/com/pablissimo
- find $HOME/.m2 -name resolver-status.properties -exec rm {} \;

addons:
artifacts:
s3_region: "us-west-2"
paths:
- $(ls ./target/*.jar | tr "\n" ":")
target_paths: builds/$TRAVIS_BRANCH/$TRAVIS_BUILD_NUMBER
after_success:
- mvn clean test jacoco:report coveralls:report

17 changes: 11 additions & 6 deletions src/main/java/com/pablissimo/sonar/TsRulesDefinition.java
Expand Up @@ -60,6 +60,11 @@ private void loadCustomRules() {
if (this.settings == null)
return;

if (settings.getBoolean(TypeScriptPlugin.SETTING_TS_LINT_DISALLOW_CUSTOM_RULES)) {
LOG.info("Usage of custom rules is inhibited");
return;
}

List<String> configKeys = settings.getKeysStartingWith(TypeScriptPlugin.SETTING_TS_RULE_CONFIGS);

for (String cfgKey : configKeys) {
Expand Down Expand Up @@ -132,15 +137,15 @@ public static void loadRules(InputStream stream, List<TsLintRule> rulesCollectio
ruleDescription
);
}

rulesCollection.add(tsRule);
}

Collections.sort(rulesCollection, (TsLintRule r1, TsLintRule r2) -> r1.key.compareTo(r2.key));
}

private void createRule(NewRepository repository, TsLintRule tsRule) {
NewRule sonarRule =
NewRule sonarRule =
repository
.createRule(tsRule.key)
.setName(tsRule.name)
Expand Down Expand Up @@ -169,19 +174,19 @@ private void createRule(NewRepository repository, TsLintRule tsRule) {

sonarRule.setDebtRemediationFunction(debtRemediationFn);
}

RuleType type = null;

if (tsRule.debtType != null && RuleType.names().contains(tsRule.debtType)) {
// Try and parse it as a new-style rule type (since 5.5 SQALE's been replaced
// with something simpler, and there's really only three buckets)
type = RuleType.valueOf(tsRule.debtType);
}

if (type == null) {
type = RuleType.CODE_SMELL;
}

sonarRule.setType(type);
}

Expand All @@ -203,7 +208,7 @@ public void define(Context context) {
for (TsLintRule customRule : tslintRules) {
createRule(repository, customRule);
}

repository.done();
}

Expand Down
16 changes: 13 additions & 3 deletions src/main/java/com/pablissimo/sonar/TypeScriptPlugin.java
Expand Up @@ -130,6 +130,15 @@
description = "If set, the contents of this file will parsed for linting issues rather than the plugin running tslint itself",
project = true,
global = false
),
@Property(
key = TypeScriptPlugin.SETTING_TS_LINT_DISALLOW_CUSTOM_RULES,
defaultValue = "false",
type = PropertyType.BOOLEAN,
name = "Disallow the usage of custom rules",
description = "If set to true, custom rules will no longer be used for analysis",
project = false,
global = true
)
})
public class TypeScriptPlugin implements Plugin {
Expand All @@ -150,11 +159,11 @@ public class TypeScriptPlugin implements Plugin {

// Current settings
public static final String SETTING_EXCLUDE_TYPE_DEFINITION_FILES = "sonar.ts.excludeTypeDefinitionFiles";

public static final String SETTING_FORCE_ZERO_COVERAGE = "sonar.ts.coverage.forceZeroIfUnspecified";
public static final String SETTING_IGNORE_NOT_FOUND = "sonar.ts.coverage.ignoreNotFound";
public static final String SETTING_LCOV_REPORT_PATH = "sonar.ts.coverage.lcovReportPath";

public static final String SETTING_TS_LINT_ENABLED = "sonar.ts.tslint.enabled";
public static final String SETTING_TS_LINT_PATH = "sonar.ts.tslint.path";
public static final String SETTING_TS_LINT_CONFIG_PATH = "sonar.ts.tslint.configPath";
Expand All @@ -164,8 +173,9 @@ public class TypeScriptPlugin implements Plugin {
public static final String SETTING_TS_LINT_TYPECHECK = "sonar.ts.tslint.typeCheck";
public static final String SETTING_TS_LINT_PROJECT_PATH = "sonar.ts.tslint.projectPath";
public static final String SETTING_TS_LINT_OUTPUT_PATH = "sonar.ts.tslint.outputPath";
public static final String SETTING_TS_LINT_DISALLOW_CUSTOM_RULES = "sonar.ts.disallowcustomrules";



@Override
public void define(Context ctx) {
// Core components - the actual sensors doing the work or configuring
Expand Down
14 changes: 13 additions & 1 deletion src/test/java/com/pablissimo/sonar/TsRulesDefinitionTest.java
Expand Up @@ -156,7 +156,7 @@ public void ConfiguresAdditionalRules() {
assertEquals(Severity.MAJOR, rule5.severity());
assertEquals("#5 description", rule5.htmlDescription());
assertEquals(RuleType.VULNERABILITY, rule5.type());

assertEquals("30min", rule5.debtRemediationFunction().gapMultiplier());
assertEquals("15min", rule5.debtRemediationFunction().baseEffort());
}
Expand Down Expand Up @@ -193,6 +193,18 @@ public void CheckCustomRulesConfigNotProvided() {
assertEquals(0, rules.size());
}

@Test
public void CheckCustomRulesInhibited() {

Settings settings = mock(Settings.class);
when(settings.getBoolean(TypeScriptPlugin.SETTING_TS_LINT_DISALLOW_CUSTOM_RULES)).thenReturn(true);

TsRulesDefinition rulesDef = new TsRulesDefinition(settings);
List<TsLintRule> rules = rulesDef.getRules();
assertNotNull(rules);
assertEquals(0, rules.size());
}

private Rule getRule(String name) {
return this.context.repository(TsRulesDefinition.REPOSITORY_NAME).rule(name);
}
Expand Down
4 changes: 3 additions & 1 deletion src/test/java/com/pablissimo/sonar/TypeScriptPluginTest.java
Expand Up @@ -57,7 +57,7 @@ public void definesExpectedProperties() {
Annotation annotation = plugin.getClass().getAnnotations()[0];
Properties propertiesAnnotation = (Properties) annotation;

assertEquals(12, propertiesAnnotation.value().length);
assertEquals(13, propertiesAnnotation.value().length);

Property[] properties = propertiesAnnotation.value();
assertNotNull(findPropertyByName(properties,
Expand All @@ -84,6 +84,8 @@ public void definesExpectedProperties() {
TypeScriptPlugin.SETTING_TS_LINT_PROJECT_PATH));
assertNotNull(findPropertyByName(properties,
TypeScriptPlugin.SETTING_TS_LINT_OUTPUT_PATH));
assertNotNull(findPropertyByName(properties,
TypeScriptPlugin.SETTING_TS_LINT_DISALLOW_CUSTOM_RULES));
}

@Test
Expand Down
2 changes: 2 additions & 0 deletions travis.sh
@@ -1,5 +1,7 @@
#!/bin/bash

mvn clean test jacoco:report coveralls:report

if [ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
mvn sonar:sonar \
-Dsonar.host.url=$SONAR_URL \
Expand Down

0 comments on commit 141bb05

Please sign in to comment.