-
Notifications
You must be signed in to change notification settings - Fork 231
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
Conversation
…nermost add expression
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.
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; |
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.
A bit more precise is this (with the while
removed of course):
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.
Kudos, SonarCloud Quality Gate passed! |
Kudos, SonarCloud Quality Gate passed!
|
Fixes #7713