-
Notifications
You must be signed in to change notification settings - Fork 2
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
SONARGO-113 Rewrite tests IdenticalBinaryOperandCheckTest - OctalValuesCheckTest #86
base: master
Are you sure you want to change the base?
Conversation
Quality Gate passed for 'Go'Issues Measures |
Coverage is 100%, no follow-up ticket to rework the checks needed |
SwitchCaseTooBigCheck.class, | ||
SwitchWithoutDefaultCheck.class, | ||
NestedSwitchCheck.class, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed to be more Go-specific
@@ -29,17 +29,16 @@ | |||
@Rule(key = "S1764") | |||
public class IdenticalBinaryOperandCheck implements SlangCheck { | |||
|
|||
public static final String MESSAGE = "Correct one of the identical sub-expressions on both sides this operator"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To trigger SQS coverage
@@ -57,19 +56,19 @@ private static List<Tree> collectConditions(MatchTree matchTree) { | |||
|
|||
private static List<Tree> collectConditions(IfTree ifTree, List<Tree> list) { | |||
list.add(skipParentheses(ifTree.condition())); | |||
Tree elseBranch = ifTree.elseBranch(); | |||
var elseBranch = ifTree.elseBranch(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To trigger SQS coverage
@@ -44,16 +44,16 @@ public class IfConditionalAlwaysTrueOrFalseCheck implements SlangCheck { | |||
@Override | |||
public void initialize(InitContext init) { | |||
init.register(IfTree.class, (ctx, ifTree) -> { | |||
Tree condition = ifTree.condition(); | |||
var condition = ifTree.condition(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To trigger SQS coverage
.ifPresent(parentMatch -> reportIssue(ctx, matchTree))); | ||
} | ||
|
||
private static void reportIssue(CheckContext ctx, MatchTree matchTree) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To trigger SQS coverage
@@ -42,7 +42,7 @@ public void initialize(InitContext init) { | |||
|
|||
private static boolean isException(IntegerLiteralTree literalTree) { | |||
// octal literal < 8 are authorized, as well as octal literals with 3 digits, as they are often used for file permissions | |||
BigInteger value = literalTree.getIntegerValue(); | |||
var value = literalTree.getIntegerValue(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To trigger SQS coverage
@@ -40,7 +40,7 @@ public class MatchCaseTooBigCheck implements SlangCheck { | |||
@Override | |||
public void initialize(InitContext init) { | |||
init.register(MatchCaseTree.class, (ctx, matchCaseTree) -> { | |||
int linesOfCode = matchCaseTree.metaData().linesOfCode().size(); | |||
var linesOfCode = matchCaseTree.metaData().linesOfCode().size(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To trigger SQS coverage
|
||
@Override | ||
public void initialize(InitContext init) { | ||
init.register(MatchTree.class, (ctx, tree) -> { | ||
if (tree.cases().stream().noneMatch(matchCase -> matchCase.expression() == null)) { | ||
Token keyword = tree.keyword(); | ||
String message = String.format("Add a default clause to this \"%s\" statement.", keyword.text()); | ||
var keyword = tree.keyword(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To trigger SQS coverage
return 1 | ||
} | ||
|
||
if n := 3; true { // False negative |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created SONARGO-119
return 1 | ||
} else if cond && false { // Noncompliant | ||
return 1 | ||
} else if isFoo() && false { // Compliant, isFoo can have a side-effect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if it's a correct exception or if we should raise an issue (and create a follow-up ticket)
In the original Slang tests, this case was not documented. It's not a properly defined exception in the check's code either 🤔
SONARGO-113