Skip to content

RCS9012: Use IsKind instead of Kind() comparison #1819

Description

@josefpihrt

Summary

Add analyzer RCS9012 (CodeAnalysis.Analyzers) that prefers IsKind(SyntaxKind) over Kind() == SyntaxKind / Kind() != SyntaxKind.

Motivation

In-repo style consistency (backlog A8). IsKind is the idiomatic Roslyn API (null-safe for SyntaxNode) and matches existing CodeAnalysis rules around IsKind (RCS9003, RCS9005).

Behavior

  • Flag: expr.Kind() == SyntaxKind.X, !=, and conditional forms (?.Kind()).
  • Multi-kind: Kind() == A || Kind() == B → same rule; fix to IsKind(A) || IsKind(B) (Microsoft single-param API only).
  • Do not suggest Roslynator multi-param IsKind(A, B).
  • Default severity: Hidden (opt-in style).
  • Code fix recommended.

Out of scope

Comparing two Kind() results (a.Kind() == b.Kind()).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions