Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.5.2 API #435

Merged
merged 3 commits into from
Apr 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ before_install:

install:
- cd /tmp
- wget http://dist.sonar.codehaus.org/sonarqube-4.5.1.zip
- unzip sonarqube-4.5.1.zip
- wget http://dist.sonar.codehaus.org/sonarqube-4.5.4.zip
- unzip sonarqube-4.5.4.zip
- wget http://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist/2.4/sonar-runner-dist-2.4.zip
- unzip sonar-runner-dist-2.4.zip
- cd -
Expand All @@ -24,5 +24,5 @@ before_script:
script:
- mvn install -DskipTests=true
- mvn test
- RAILS_ENV=production PATH=$PATH:/tmp/sonar-runner-2.4/bin SONARHOME=/tmp/sonarqube-4.5.1 behave
- RAILS_ENV=production PATH=$PATH:/tmp/sonar-runner-2.4/bin SONARHOME=/tmp/sonarqube-4.5.4 behave

Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,20 @@
import org.sonar.cxx.api.CxxKeyword;
import org.sonar.cxx.parser.CxxGrammarImpl;
import org.sonar.squidbridge.checks.SquidCheck;

import com.sonar.sslr.api.Grammar;
import com.sonar.sslr.api.AstNode;

import org.sonar.api.server.rule.RulesDefinition;
import org.sonar.squidbridge.annotations.ActivatedByDefault;
import org.sonar.squidbridge.annotations.SqaleConstantRemediation;
import org.sonar.squidbridge.annotations.SqaleSubCharacteristic;

@Rule(
key = "BooleanEqualityComparison",
description = "Remove literal boolean values from conditional expressions to improve readability.",
name = "Literal boolean values should not be used in condition expressions",
priority = Priority.MINOR)

@ActivatedByDefault
@SqaleSubCharacteristic(RulesDefinition.SubCharacteristics.UNDERSTANDABILITY)
@SqaleConstantRemediation("5min")
public class BooleanEqualityComparisonCheck extends SquidCheck<Grammar> {

@Override
Expand Down
80 changes: 40 additions & 40 deletions cxx-checks/src/main/java/org/sonar/cxx/checks/CheckList.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,46 +33,46 @@ private CheckList() {
}

public static List<Class> getChecks() {
return ImmutableList.<Class> of(
CollapsibleIfCandidateCheck.class,
CommentedCodeCheck.class,
CommentRegularExpressionCheck.class,
CycleBetweenPackagesCheck.class,
DuplicatedIncludeCheck.class,
FileComplexityCheck.class,
FileHeaderCheck.class,
FileEncodingCheck.class,
FileRegularExpressionCheck.class,
LineRegularExpressionCheck.class,
FixmeTagPresenceCheck.class,
FunctionComplexityCheck.class,
HardcodedAccountCheck.class,
HardcodedIpCheck.class,
IndentationCheck.class,
MagicNumberCheck.class,
MissingCurlyBracesCheck.class,
MissingIncludeFileCheck.class,
MissingNewLineAtEndOfFileCheck.class,
NoSonarCheck.class,
ParsingErrorCheck.class,
ParsingErrorRecoveryCheck.class,
ReservedNamesCheck.class,
StringLiteralDuplicatedCheck.class,
SwitchLastCaseIsDefaultCheck.class,
TabCharacterCheck.class,
TodoTagPresenceCheck.class,
TooLongLineCheck.class,
TooManyLinesOfCodeInFileCheck.class,
TooManyStatementsPerLineCheck.class,
UndocumentedApiCheck.class,
UnnamedNamespaceInHeaderCheck.class,
UselessParenthesesCheck.class,
UseCorrectTypeCheck.class,
UsingNamespaceInHeaderCheck.class,
SafetyTagCheck.class,
UseCorrectIncludeCheck.class,
XPathCheck.class,
BooleanEqualityComparisonCheck.class
return ImmutableList.<Class>of(
CollapsibleIfCandidateCheck.class,
CommentedCodeCheck.class,
CommentRegularExpressionCheck.class,
CycleBetweenPackagesCheck.class,
DuplicatedIncludeCheck.class,
FileComplexityCheck.class,
FileHeaderCheck.class,
FileEncodingCheck.class,
FileRegularExpressionCheck.class,
LineRegularExpressionCheck.class,
FixmeTagPresenceCheck.class,
FunctionComplexityCheck.class,
HardcodedAccountCheck.class,
HardcodedIpCheck.class,
IndentationCheck.class,
MagicNumberCheck.class,
MissingCurlyBracesCheck.class,
MissingIncludeFileCheck.class,
MissingNewLineAtEndOfFileCheck.class,
NoSonarCheck.class,
ParsingErrorCheck.class,
ParsingErrorRecoveryCheck.class,
ReservedNamesCheck.class,
StringLiteralDuplicatedCheck.class,
SwitchLastCaseIsDefaultCheck.class,
TabCharacterCheck.class,
TodoTagPresenceCheck.class,
TooLongLineCheck.class,
TooManyLinesOfCodeInFileCheck.class,
TooManyStatementsPerLineCheck.class,
UndocumentedApiCheck.class,
UnnamedNamespaceInHeaderCheck.class,
UselessParenthesesCheck.class,
UseCorrectTypeCheck.class,
UsingNamespaceInHeaderCheck.class,
SafetyTagCheck.class,
UseCorrectIncludeCheck.class,
XPathCheck.class,
BooleanEqualityComparisonCheck.class
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,18 @@

import com.sonar.sslr.api.AstNode;
import com.sonar.sslr.api.Grammar;
import org.sonar.api.server.rule.RulesDefinition;
import org.sonar.squidbridge.annotations.ActivatedByDefault;
import org.sonar.squidbridge.annotations.SqaleConstantRemediation;
import org.sonar.squidbridge.annotations.SqaleSubCharacteristic;

@Rule(
key = "CollapsibleIfCandidate",
description = "Merge this if statement with the enclosing one.",
name = "Collapsible 'if' statements should be merged",
priority = Priority.MAJOR)

@ActivatedByDefault
@SqaleSubCharacteristic(RulesDefinition.SubCharacteristics.DATA_RELIABILITY)
@SqaleConstantRemediation("5min")
public class CollapsibleIfCandidateCheck extends SquidCheck<Grammar> {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,33 @@

import com.sonar.sslr.api.Token;
import com.sonar.sslr.api.Trivia;
import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.check.RuleProperty;
import org.sonar.squidbridge.annotations.NoSqale;
import org.sonar.squidbridge.annotations.RuleTemplate;

@Rule(
key = "CommentContainsPatternChecker",
name = "Regular expression on comment",
priority = Priority.MAJOR)
@RuleTemplate
@NoSqale
public class CommentContainsPatternChecker {

@RuleProperty(
key = "check",
description = "The Squid check")
private final SquidCheck<?> check;

@RuleProperty(
key = "pattern",
description = "The regular expression")
private final String pattern;

@RuleProperty(
key = "message",
description = "The violation message")
private final String message;

public CommentContainsPatternChecker(SquidCheck<?> check, String pattern, String message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,34 @@
*/
package org.sonar.cxx.checks;

import org.sonar.check.Cardinality;
import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.check.RuleProperty;
import org.sonar.squidbridge.checks.AbstractCommentRegularExpressionCheck;

import com.sonar.sslr.api.Grammar;
import org.sonar.squidbridge.annotations.NoSqale;
import org.sonar.squidbridge.annotations.RuleTemplate;

@Rule(
key = "CommentRegularExpression",
cardinality = Cardinality.MULTIPLE,
name = "Regular expression on comment",
priority = Priority.MAJOR)

@RuleTemplate
@NoSqale
public class CommentRegularExpressionCheck extends AbstractCommentRegularExpressionCheck<Grammar> {

private static final String DEFAULT_REGULAR_EXPRESSION = "";
private static final String DEFAULT_MESSAGE = "The regular expression matches this comment";

@RuleProperty(
key = "regularExpression",
description = "The regular expression",
defaultValue = DEFAULT_REGULAR_EXPRESSION)
public String regularExpression = DEFAULT_REGULAR_EXPRESSION;

@RuleProperty(
key = "message",
description = "The violation message",
defaultValue = DEFAULT_MESSAGE)
public String message = DEFAULT_MESSAGE;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,25 @@
import org.sonar.squidbridge.recognizer.EndWithDetector;
import org.sonar.squidbridge.recognizer.KeywordsDetector;
import org.sonar.squidbridge.recognizer.LanguageFootprint;

import com.google.common.collect.Sets;
import com.sonar.sslr.api.AstAndTokenVisitor;
import com.sonar.sslr.api.Grammar;
import com.sonar.sslr.api.Token;
import com.sonar.sslr.api.Trivia;
import org.sonar.api.server.rule.RulesDefinition;
import org.sonar.squidbridge.annotations.ActivatedByDefault;
import org.sonar.squidbridge.annotations.SqaleConstantRemediation;
import org.sonar.squidbridge.annotations.SqaleSubCharacteristic;
import org.sonar.squidbridge.annotations.Tags;

@Rule(
key = "CommentedCode",
description = "Commented code shall be avoided and therefore removed.",
name = "Sections of code should not be 'commented out'",
tags = {Tags.UNUSED},
priority = Priority.BLOCKER)

@ActivatedByDefault
@SqaleSubCharacteristic(RulesDefinition.SubCharacteristics.UNDERSTANDABILITY)
@SqaleConstantRemediation("5min")
public class CommentedCodeCheck extends SquidCheck<Grammar> implements AstAndTokenVisitor {

private static final double THRESHOLD = 0.94;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,25 @@
import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.squidbridge.checks.SquidCheck;

import com.sonar.sslr.api.Grammar;
import org.sonar.api.server.rule.RulesDefinition;
import org.sonar.squidbridge.annotations.ActivatedByDefault;
import org.sonar.squidbridge.annotations.SqaleConstantRemediation;
import org.sonar.squidbridge.annotations.SqaleSubCharacteristic;
import org.sonar.squidbridge.annotations.Tags;

/**
* Companion of {@link org.sonar.plugins.cxx.squid.DependencyAnalyzer} which actually does the job of finding cycles and
* creating the violations.
*/
@Rule(key = CycleBetweenPackagesCheck.RULE_KEY,
priority = Priority.MAJOR)

@Rule(
key = "CycleBetweenPackages",
name = "Avoid cyclic dependency between packages",
tags = {Tags.CONVENTION},
priority = Priority.MAJOR)
@ActivatedByDefault
@SqaleSubCharacteristic(RulesDefinition.SubCharacteristics.ARCHITECTURE_RELIABILITY)
@SqaleConstantRemediation("5min")
public class CycleBetweenPackagesCheck extends SquidCheck<Grammar> {

public static final String RULE_KEY = "CycleBetweenPackages";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,25 @@
import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.squidbridge.checks.SquidCheck;

import com.sonar.sslr.api.Grammar;
import org.sonar.api.server.rule.RulesDefinition;
import org.sonar.squidbridge.annotations.ActivatedByDefault;
import org.sonar.squidbridge.annotations.SqaleConstantRemediation;
import org.sonar.squidbridge.annotations.SqaleSubCharacteristic;
import org.sonar.squidbridge.annotations.Tags;

/**
* Companion of {@link org.sonar.plugins.cxx.squid.DependencyAnalyzer} which actually does the job of finding duplicated
* includes
*/
@Rule(key = DuplicatedIncludeCheck.RULE_KEY,
priority = Priority.MAJOR)

@Rule(
key = "DuplicatedInclude",
name = "Avoid including the same file multiple times",
tags = {Tags.PREPROCESSOR},
priority = Priority.MAJOR)
@ActivatedByDefault
@SqaleSubCharacteristic(RulesDefinition.SubCharacteristics.ARCHITECTURE_RELIABILITY)
@SqaleConstantRemediation("5min")
public class DuplicatedIncludeCheck extends SquidCheck<Grammar> {

public static final String RULE_KEY = "DuplicatedInclude";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,31 @@
import org.sonar.cxx.api.CxxMetric;
import org.sonar.squidbridge.checks.AbstractFileComplexityCheck;
import org.sonar.squidbridge.measures.MetricDef;

import com.sonar.sslr.api.Grammar;
import org.sonar.api.server.rule.RulesDefinition;
import org.sonar.squidbridge.annotations.ActivatedByDefault;
import org.sonar.squidbridge.annotations.SqaleLinearWithOffsetRemediation;
import org.sonar.squidbridge.annotations.SqaleSubCharacteristic;
import org.sonar.squidbridge.annotations.Tags;

@Rule(
key = "FileCyclomaticComplexity",
priority = Priority.MAJOR)
key = "FileComplexity",
name = "Files should not be too complex",
tags = {Tags.BRAIN_OVERLOAD},
priority = Priority.MAJOR)
//@ActivatedByDefault
@SqaleSubCharacteristic(RulesDefinition.SubCharacteristics.UNIT_TESTABILITY)
@SqaleLinearWithOffsetRemediation(
coeff = "1min",
offset = "30min",
effortToFixDescription = "per complexity point above the threshold")
public class FileComplexityCheck extends AbstractFileComplexityCheck<Grammar> {
private static final int DEFAULT_MAX = 200;

@RuleProperty(defaultValue = "" + DEFAULT_MAX)
@RuleProperty(
key = "max",
description = "Maximum complexity allowed",
defaultValue = "" + DEFAULT_MAX)
private int max = DEFAULT_MAX;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,24 @@
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.List;

import org.sonar.api.utils.SonarException;
import org.sonar.api.utils.SonarException; //@todo: deprecated, see http://javadocs.sonarsource.org/4.5.2/apidocs/deprecated-list.html
import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.cxx.visitors.CxxCharsetAwareVisitor;
import org.sonar.squidbridge.checks.SquidCheck;

import com.google.common.io.Files;
import com.sonar.sslr.api.AstNode;
import com.sonar.sslr.api.Grammar;
import java.nio.charset.CharsetEncoder;
import org.sonar.squidbridge.annotations.ActivatedByDefault;
import org.sonar.squidbridge.annotations.NoSqale;

@Rule(
key = "InvalidFileEncoding",
description = "Verify that all characters of the file can be encoded with the predefined charset.",
key = "FileEncoding",
name = "Verify that all characters of the file can be encoded with the predefined charset.",
priority = Priority.MINOR)

@ActivatedByDefault
@NoSqale
public class FileEncodingCheck extends SquidCheck<Grammar> implements CxxCharsetAwareVisitor {

private Charset charset;
Expand All @@ -53,7 +54,7 @@ public void visitFile(AstNode astNode) {
try {
lines = Files.readLines(getContext().getFile(), charset);
} catch (IOException e) {
throw new SonarException(e);
throw new SonarException(e); //@todo SonarException has been deprecated, see http://javadocs.sonarsource.org/4.5.2/apidocs/deprecated-list.html
}
CharsetEncoder encoder = Charset.forName(charset.name()).newEncoder();
for (String line : lines) {
Expand Down
Loading