Skip to content

Conversation

@sebastien-marichal
Copy link
Contributor

Fixes #1255

}

// https://github.com/SonarSource/sonar-dotnet/issues/1255
public void ExceptionOfException(int a)
Copy link
Contributor

@mary-georgiou-sonarsource mary-georgiou-sonarsource Jun 5, 2024

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).

Copy link
Contributor

@Tim-Pohlmann Tim-Pohlmann left a comment

Choose a reason for hiding this comment

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

Review 1

Comment on lines +111 to +108
? switchSection.Statements.OfType<BlockSyntax>().SelectMany(x => x.Statements)
.Union(switchSection.Statements.Where(x => !x.IsKind(SyntaxKind.Block)))
Copy link
Contributor

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.

Copy link
Contributor

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

Suggested change
? 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)

[TestMethod]
public void ConditionalStructureSameImplementation_Switch_CSharp() =>
builderCS.AddPaths("ConditionalStructureSameImplementation_Switch.cs").Verify();
builderCS.AddPaths("ConditionalStructureSameImplementation_Switch.cs").WithOptions(ParseOptionsHelper.FromCSharp8).Verify();
Copy link
Contributor

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.

@sebastien-marichal sebastien-marichal force-pushed the sma/1871-fn branch 2 times, most recently from 817ece2 to d05150d Compare June 11, 2024 09:42
@sonarqubecloud
Copy link

Quality Gate Passed Quality Gate passed for 'Sonar .NET Java Plugin'

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@sonarqubecloud
Copy link

Copy link
Contributor

@Tim-Pohlmann Tim-Pohlmann left a comment

Choose a reason for hiding this comment

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

LGTM!

Comment on lines +111 to +108
? switchSection.Statements.OfType<BlockSyntax>().SelectMany(x => x.Statements)
.Union(switchSection.Statements.Where(x => !x.IsKind(SyntaxKind.Block)))
Copy link
Contributor

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

Suggested change
? 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)

Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM

@sebastien-marichal sebastien-marichal merged commit 4e0822f into master Jun 12, 2024
@sebastien-marichal sebastien-marichal deleted the sma/1871-fn branch June 12, 2024 08:24
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 S1871 FN: Support single line conditional block

4 participants