Skip to content

S2971: Split rule in multiple rules #7463

Open
@mary-georgiou-sonarsource

Description

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions