-
Notifications
You must be signed in to change notification settings - Fork 237
Fix S1871 FN: Support single line conditional block #9408
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
Conversation
| } | ||
|
|
||
| // https://github.com/SonarSource/sonar-dotnet/issues/1255 | ||
| public void ExceptionOfException(int a) |
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.
Let's add also a test case exactly like this one but with an else clause at the end.
Same for VB and the switch cases (add a default clause).
b787554 to
04bec24
Compare
analyzers/src/SonarAnalyzer.CSharp/Rules/ConditionalStructureSameImplementation.cs
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.CSharp/Rules/ConditionalStructureSameImplementation.cs
Outdated
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.CSharp/Rules/ConditionalStructureSameImplementation.cs
Outdated
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.CSharp/Rules/ConditionalStructureSameImplementation.cs
Outdated
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.CSharp/Rules/ConditionalStructureSameImplementation.cs
Outdated
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.VisualBasic/Rules/ConditionalStructureSameImplementation.cs
Show resolved
Hide resolved
analyzers/its/expected/akka.net/S1871-Akka.Remote.TestKit-netstandard2.0.json
Show resolved
Hide resolved
analyzers/its/expected/akka.net/S1871-Akka.Cluster.Sharding-netstandard2.0.json
Show resolved
Hide resolved
analyzers/its/expected/Ember-MM/S1871-generic.EmberCore.Notifications.json
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.CSharp/Rules/ConditionalStructureSameImplementation.cs
Outdated
Show resolved
Hide resolved
168c83e to
b2af07b
Compare
Tim-Pohlmann
left a comment
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.
Review 1
| ? switchSection.Statements.OfType<BlockSyntax>().SelectMany(x => x.Statements) | ||
| .Union(switchSection.Statements.Where(x => !x.IsKind(SyntaxKind.Block))) |
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.
This looks wild. Can it be simplified? Otherwise, it needs a comment explaining what's going on.
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.
Good comment! Now that I understand it, I can propose a simplification :D
| ? switchSection.Statements.OfType<BlockSyntax>().SelectMany(x => x.Statements) | |
| .Union(switchSection.Statements.Where(x => !x.IsKind(SyntaxKind.Block))) | |
| ? switchSection.Statements.SelectMany(x => x is BlockSyntax block ? block.Statements : x) |
analyzers/src/SonarAnalyzer.CSharp/Rules/ConditionalStructureSameImplementation.cs
Outdated
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.CSharp/Rules/ConditionalStructureSameImplementation.cs
Outdated
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.CSharp/Rules/ConditionalStructureSameImplementation.cs
Outdated
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.CSharp/Rules/ConditionalStructureSameImplementation.cs
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.VisualBasic/Rules/ConditionalStructureSameImplementation.cs
Show resolved
Hide resolved
| [TestMethod] | ||
| public void ConditionalStructureSameImplementation_Switch_CSharp() => | ||
| builderCS.AddPaths("ConditionalStructureSameImplementation_Switch.cs").Verify(); | ||
| builderCS.AddPaths("ConditionalStructureSameImplementation_Switch.cs").WithOptions(ParseOptionsHelper.FromCSharp8).Verify(); |
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.
The tests should follow Proposal B from the test case circle.
817ece2 to
d05150d
Compare
d05150d to
747168d
Compare
|
|
Tim-Pohlmann
left a comment
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!
| ? switchSection.Statements.OfType<BlockSyntax>().SelectMany(x => x.Statements) | ||
| .Union(switchSection.Statements.Where(x => !x.IsKind(SyntaxKind.Block))) |
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.
Good comment! Now that I understand it, I can propose a simplification :D
| ? switchSection.Statements.OfType<BlockSyntax>().SelectMany(x => x.Statements) | |
| .Union(switchSection.Statements.Where(x => !x.IsKind(SyntaxKind.Block))) | |
| ? switchSection.Statements.SelectMany(x => x is BlockSyntax block ? block.Statements : x) |
martin-strecker-sonarsource
left a comment
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




Fixes #1255