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

SONARGO-113 Rewrite tests IdenticalBinaryOperandCheckTest - OctalValuesCheckTest #86

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

GabinL21
Copy link
Contributor

@GabinL21 GabinL21 commented Jan 10, 2025

@GabinL21 GabinL21 self-assigned this Jan 10, 2025
Copy link

@GabinL21
Copy link
Contributor Author

Coverage is 100%, no follow-up ticket to rework the checks needed

Comment on lines +50 to +52
SwitchCaseTooBigCheck.class,
SwitchWithoutDefaultCheck.class,
NestedSwitchCheck.class,
Copy link
Contributor Author

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";
Copy link
Contributor Author

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();
Copy link
Contributor Author

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();
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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();
Copy link
Contributor Author

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();
Copy link
Contributor Author

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();
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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 🤔

@GabinL21 GabinL21 requested a review from petertrr January 10, 2025 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant