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

fix quality flaws #1269

Merged
merged 1 commit into from
Oct 28, 2017
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
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,8 @@ public void visitNode(AstNode node) {
}

private static boolean hasBooleanLiteralOperand(AstNode node) {
return node.select()
.children(CxxGrammarImpl.LITERAL)
.children(CxxGrammarImpl.BOOL)
.descendants(CxxKeyword.TRUE, CxxKeyword.FALSE)
.isNotEmpty();
return node.hasDirectChildren(CxxGrammarImpl.LITERAL,CxxGrammarImpl.BOOL)
&& node.hasDescendant(CxxKeyword.TRUE, CxxKeyword.FALSE);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
package org.sonar.cxx.checks;

import java.util.List;

import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.check.RuleProperty;
Expand Down Expand Up @@ -51,18 +53,21 @@ public class TooManyParametersCheck extends SquidCheck<Grammar> {

@Override
public void init() {
subscribeTo(CxxGrammarImpl.parameterDeclarationClause, CxxGrammarImpl.lambdaDeclarator, CxxGrammarImpl.cliParameterArray);
subscribeTo(CxxGrammarImpl.parameterDeclarationClause,
CxxGrammarImpl.lambdaDeclarator,
CxxGrammarImpl.cliParameterArray);
}

@Override
public void visitNode(AstNode node) {
int nbParameters = node.select()
.children(CxxGrammarImpl.parameterDeclarationList)
.children(CxxGrammarImpl.parameterDeclaration)
.size();
if (nbParameters > max) {
String message = "parameter list has {0} parameters, which is greater than the {1} authorized.";
getContext().createLineViolation(this, message, node, nbParameters, max);
int nbParameters = 0;
AstNode parameterList = node.getFirstChild(CxxGrammarImpl.parameterDeclarationList);
if (parameterList != null) {
nbParameters = parameterList.getChildren(CxxGrammarImpl.parameterDeclaration).size();
if (nbParameters > max) {
String message = "parameter list has {0} parameters, which is greater than the {1} authorized.";
getContext().createLineViolation(this, message, node, nbParameters, max);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,16 @@
@SqaleConstantRemediation("5min")
public class UseCorrectIncludeCheck extends SquidCheck<Grammar> implements CxxCharsetAwareVisitor {

public static final String regularExpression = "#include\\s+(?>\"|\\<)[\\\\/\\.]+";
public static final String message = "Use correct #include directives";
private static final String REGULAR_EXPRESSION = "#include\\s+(?>\"|\\<)[\\\\/\\.]+";
private Pattern pattern = null;
private Charset charset = Charset.forName("UTF-8");

@Override
public void init() {
if (null != regularExpression && !regularExpression.isEmpty()) {
try {
pattern = Pattern.compile(regularExpression, Pattern.DOTALL);
} catch (RuntimeException e) {
throw new IllegalStateException("Unable to compile regular expression: " + regularExpression, e);
}
try {
pattern = Pattern.compile(REGULAR_EXPRESSION, Pattern.DOTALL);
} catch (RuntimeException e) {
throw new IllegalStateException("Unable to compile regular expression: " + REGULAR_EXPRESSION, e);
}
}

Expand Down
27 changes: 24 additions & 3 deletions cxx-lint/src/main/java/org/sonar/cxx/cxxlint/CheckerData.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,30 @@
* @author jocs
*/
public class CheckerData {
public String id = "";
public String templateId = "";
public boolean enabled = true;
private String id = "";
private String templateId = "";
private boolean enabled = true;
public HashMap<String, String> parameterData = new HashMap<String, String>();

public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}

public String getTemplateId() {
return templateId;
}
public void setTemplateId(String templateId) {
this.templateId = templateId;
}

public boolean isEnabled() {
return enabled;
}
public void setEnable(boolean active) {
this.enabled = active;
}
}

Loading