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 S2252 FP: Rule raises issue in case of non integer value in for loop. #5523

Merged
merged 3 commits into from
Apr 1, 2022

Conversation

csaba-sagi-sonarsource
Copy link
Contributor

Fixes #5428

{
var loopInitializerValues = new Dictionary<string, int>();
var loopInitializerValues = new Dictionary<string, double>();
if (variableDeclarationSyntax != null)
{
foreach (var variableDeclaration in variableDeclarationSyntax.Variables)
{
if (variableDeclaration.Initializer is EqualsValueClauseSyntax initializer

Choose a reason for hiding this comment

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

We can simplify this to if (variableDeclaration.Initializer is { } initializer

Comment on lines 176 to 177
&& initializer is AssignmentExpressionSyntax assignment
&& assignment.Left is SimpleNameSyntax simpleName

Choose a reason for hiding this comment

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

pedantic: we can use pattern matching and simplify this a bit:

&& initializer is AssignmentExpressionSyntax { Left: SimpleNameSyntax simpleName } assignment

Copy link
Member

Choose a reason for hiding this comment

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

LGTM!

@sonarqubecloud
Copy link

sonarqubecloud bot commented Apr 1, 2022

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 Apr 1, 2022

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

@csaba-sagi-sonarsource csaba-sagi-sonarsource merged commit 13cdb8f into master Apr 1, 2022
@csaba-sagi-sonarsource csaba-sagi-sonarsource deleted the čaba/S2252 branch April 1, 2022 08:41
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.

S2252 FP: Rule raises issue in case of non integer value in for loop.
2 participants