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

S2743: Add support for record struct #5607

Merged
merged 3 commits into from
May 2, 2022

Conversation

pavel-mikula-sonarsource
Copy link
Contributor

No description provided.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's a nice rule. Just some minor suggestions.

Comment on lines 48 to 49
|| typeDeclaration.TypeParameterList == null
|| typeDeclaration.TypeParameterList.Parameters.Count < 1)

Choose a reason for hiding this comment

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

Suggested change
|| typeDeclaration.TypeParameterList == null
|| typeDeclaration.TypeParameterList.Parameters.Count < 1)
|| c.Node is not TypeDeclarationSyntax { TypeParameterList: { Parameters: { Count: > 0 } } } typeDeclaration)

Choose a reason for hiding this comment

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

@csaba-sagi-sonarsource That's one of the places where C#10 would remove some clutter:

// C# 9
c.Node is not TypeDeclarationSyntax { TypeParameterList: { Parameters: { Count: > 0 } } } typeDeclaration)
// C# 10
c.Node is not TypeDeclarationSyntax { TypeParameterList.Parameters.Count: > 0  } typeDeclaration)

Comment on lines 54 to 58
var fields = typeDeclaration.Members.OfType<FieldDeclarationSyntax>().Where(x => x.Modifiers.Any(SyntaxKind.StaticKeyword));
foreach (var field in fields.Where(x => !HasGenericType(c, x.Declaration.Type, typeParameterNames)))
{
field.Declaration.Variables.ToList().ForEach(variable => CheckMember(variable, variable.Identifier.GetLocation(), typeParameterNames, c));
field.Declaration.Variables.ToList().ForEach(variable => CheckMember(c, variable, variable.Identifier.GetLocation(), typeParameterNames));
}

Choose a reason for hiding this comment

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

Can be simplified:

                    var variables = typeDeclaration.Members
                        .OfType<FieldDeclarationSyntax>()
                        .Where(x => x.Modifiers.Any(SyntaxKind.StaticKeyword) && !HasGenericType(c, x.Declaration.Type, typeParameterNames))
                        .SelectMany(x => x.Declaration.Variables);
                    foreach (var variable in variables)
                    {
                        CheckMember(c, variable, variable.Identifier.GetLocation(), typeParameterNames);
                    }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice

@sonarqubecloud
Copy link

sonarqubecloud bot commented May 2, 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 May 2, 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

94.7% 94.7% Coverage
0.0% 0.0% Duplication

@pavel-mikula-sonarsource pavel-mikula-sonarsource merged commit bcb8877 into master May 2, 2022
@pavel-mikula-sonarsource pavel-mikula-sonarsource deleted the Pavel/S2743-RecordStruct branch May 2, 2022 13:14
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.

2 participants