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 S1643 FN: consider simple assignments with variable not on the innermost add expression #7716

Merged
merged 4 commits into from
Aug 3, 2023

Conversation

cristian-ambrosini-sonarsource
Copy link
Contributor

Fixes #7713

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. If you like, you can expand to more expressions, but I don't see much value in it. You may want to document the FNs if you like (all optional).

}

nestedLeft = Language.Syntax.BinaryExpressionLeft(nestedBinary);
expression = left;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit more precise is this (with the while removed of course):

Suggested change
expression = left;
return
IsIdentifierOnTheRight(SyntaxNode identifier, left)
|| IsIdentifierOnTheRight(SyntaxNode identifier, right);

But this is only necessary if we also would step into parenthesis or other expressions: _ = "a" + (s + "b");. I don't think we need to support that as the parenthesis are superfluous. Just add comment here:

// No need to recurse into the right branch as the only useful concatenation is flat `"a" + "b" + s` 
// `"a" + (s  + "b")` seems not worth to support.

This also means we have FNs for cases like this:

s = "a" + (s == null ? "Empty" : s);

I leave it to you to decide if you want to add support for this.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Aug 3, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sonarqubecloud
Copy link

sonarqubecloud bot commented Aug 3, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

warning The version of Java (11.0.16.1) you have used to run this analysis is deprecated and we will stop accepting it soon. Please update to at least Java 17.
Read more here

@cristian-ambrosini-sonarsource cristian-ambrosini-sonarsource deleted the cristian/fix-S1643-FN branch August 3, 2023 13:07
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.

Fix S1643 FN: consider simple assignments with variable not on the innermost add expression
3 participants