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 S1125 FN: recognize "is" and "is not" keyword with constant pattern #7687

Merged
merged 26 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
607dcf0
First implementation
CristianAmbrosini Jul 25, 2023
7b9dfb9
Add ternary exception
CristianAmbrosini Jul 25, 2023
ff56b70
Fix CheckForNullabilityAndBooleanConstantsReport
CristianAmbrosini Jul 26, 2023
2f773ca
Add code fix
CristianAmbrosini Jul 26, 2023
4ebcf3e
Add link to C#9 issue
CristianAmbrosini Jul 26, 2023
dffbc9f
Fix UTs
CristianAmbrosini Jul 26, 2023
689bb62
Fix code smells
CristianAmbrosini Jul 26, 2023
8252f7f
Merge IsPatternExpression check with IsEqual
CristianAmbrosini Jul 31, 2023
20539ad
Move methods around
CristianAmbrosini Jul 31, 2023
3dc5275
Fix AD0001
CristianAmbrosini Jul 31, 2023
3997b6c
Add more UTs
CristianAmbrosini Jul 31, 2023
87af3f8
Fix quickFixes for "is" and "is not" (one issue still pending)
CristianAmbrosini Jul 31, 2023
58934be
Fix non-defined quick-fixes
CristianAmbrosini Jul 31, 2023
cffb15c
Static local function
CristianAmbrosini Jul 31, 2023
35a7cb6
Remove TBinaryExpression
CristianAmbrosini Aug 1, 2023
8679ce3
Add UTs
CristianAmbrosini Aug 1, 2023
25f48ea
Move to IsTrue/IsFalse to SyntaxNodeExtension
CristianAmbrosini Aug 1, 2023
1678236
Support basic cases on SyntaxNodeExtension methods
CristianAmbrosini Aug 1, 2023
f088cd2
Fix quick-fix
CristianAmbrosini Aug 2, 2023
b9988d5
Remove useless using
CristianAmbrosini Aug 2, 2023
b58a7ce
Remove whitespace
CristianAmbrosini Aug 2, 2023
04bc0c9
Update expected issues location
CristianAmbrosini Aug 2, 2023
fe3996c
Add support for parenthesized expressions
CristianAmbrosini Aug 2, 2023
52ad42e
Remove stuff from GetOperatorToken
CristianAmbrosini Aug 2, 2023
81901f7
Address more comments
CristianAmbrosini Aug 3, 2023
019043e
Add .WithAdditionalAnnotations(Simplifier.Annotation) on code fix
CristianAmbrosini Aug 3, 2023
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
Prev Previous commit
Add .WithAdditionalAnnotations(Simplifier.Annotation) on code fix
  • Loading branch information
CristianAmbrosini committed Aug 3, 2023
commit 019043e2b02693c1e8499a83741c480bd05d6c06
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Simplification;

namespace SonarAnalyzer.Rules.CSharp
{
Expand Down Expand Up @@ -139,7 +140,7 @@ private static void RegisterBinaryExpressionRemoval(SonarCodeFixContext context,
Title,
c =>
{
var newExpression = GetNegatedExpression(otherNode);
var newExpression = GetNegatedExpression(otherNode).WithAdditionalAnnotations(Simplifier.Annotation);
var newRoot = root.ReplaceNode(binaryParent, newExpression
.WithAdditionalAnnotations(Formatter.Annotation));

Expand Down Expand Up @@ -171,7 +172,7 @@ private static void RegisterBinaryExpressionReplacement(SonarCodeFixContext cont
Title,
c =>
{
var keepThisNode = FindNodeToKeep(binary);
var keepThisNode = FindNodeToKeep(binary).WithAdditionalAnnotations(Simplifier.Annotation);
var newRoot = root.ReplaceNode(syntaxNode, keepThisNode
.WithAdditionalAnnotations(Formatter.Annotation));
return Task.FromResult(context.Document.WithSyntaxRoot(newRoot));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ public BooleanLiteralUnnecessary(bool a, bool b, bool? c, Item item)
var x = false; // Fixed
x = true; // Fixed
x = true; // Fixed
x = (a) // Fixed
; // Fixed
x = (!a) // Fixed
; // Fixed
x = a; // Fixed
x = !a; // Fixed

x = a; // Fixed
x = a; // Fixed
Expand Down