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

S2971: Split rule in multiple rules #7463

Open
mary-georgiou-sonarsource opened this issue Jun 19, 2023 · 0 comments
Open

S2971: Split rule in multiple rules #7463

mary-georgiou-sonarsource opened this issue Jun 19, 2023 · 0 comments
Labels
Area: C# C# rules related issues. Type: Improvement Making existing code better.

Comments

@mary-georgiou-sonarsource
Copy link
Contributor

Rule S2971 seems like multiple rules folded into one. It would be better to split the rule into multiple ones and re-evaluate.
This way users can enable and disable the parts that are useful to their codebase.

Potential split:

  1. Use OfType instead of using Select with as to typecast elements and then null-checking in a query expression to choose elements based on type.
  2. Use OfType instead of using Where and the is operator, followed by a cast in a Select
  3. Use an expression in Any instead of Where(element => [expression]).Any().
  4. Use Count instead of Count() when it’s available.
  5. Don’t call ToArray() or ToList() in the middle of a query chain.

Related community post.

@mary-georgiou-sonarsource mary-georgiou-sonarsource added Type: Improvement Making existing code better. Area: C# C# rules related issues. labels Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: C# C# rules related issues. Type: Improvement Making existing code better.
Projects
None yet
Development

No branches or pull requests

1 participant