Skip to content

Add RCS9012: Call IsKind instead of comparing Kind - #1820

Open
josefpihrt wants to merge 6 commits into
mainfrom
feature/rcs9012-use-iskind
Open

Add RCS9012: Call IsKind instead of comparing Kind#1820
josefpihrt wants to merge 6 commits into
mainfrom
feature/rcs9012-use-iskind

Conversation

@josefpihrt

Copy link
Copy Markdown
Collaborator

Summary

  • Add RCS9012 (UseIsKindInsteadOfKindComparison) to Roslynator.CodeAnalysis.Analyzers with code fix and tests.
  • Default severity Info; repo .editorconfig sets warning.
  • Fixes Kind() == / != (and ?.Kind()), including same-receiver || chains → chained Microsoft IsKind (not Roslynator multi-param overloads).

Fixes #1819

Test plan

  • dotnet test filter FullyQualifiedName~RCS9012 (8 tests)
  • CI green on PR
  • Spot-check code fix on Kind() == and Kind() == A || Kind() == B

Made with Cursor

Ship a CodeAnalysis analyzer (Info by default, Warning in-repo) that
rewrites Kind() ==/!= SyntaxKind to Microsoft's single-parameter IsKind.

Co-authored-by: Cursor <cursoragent@cursor.com>
Comment thread .editorconfig

@josefpihrt josefpihrt left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Review

Bugbot found no bugs. Manual review:

Must fix

  • pre_build / RCS0039 — test class base list must be on one line (inline comment).

Suggestions

  • Code fix: guard IsKindExpressionInfo.Success before rewriting.
  • Document / follow up: no coverage for SyntaxToken / SyntaxTrivia .Kind() comparisons (common in this repo).
  • .editorconfig warning is forward-looking until the CodeAnalysis.Analyzers package pin is bumped.

Otherwise the analyzer/fix shape looks solid (single + || chains, constant SyntaxKind only, Microsoft single-param IsKind only).

@josefpihrt josefpihrt left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Review

Bugbot found no bugs. Manual review:

Must fix

  • pre_build / RCS0039 — test class base list must be on one line (inline comment).

Suggestions

  • Code fix: guard IsKindExpressionInfo.Success before rewriting.
  • Document / follow up: no coverage for SyntaxToken / SyntaxTrivia .Kind() comparisons (common in this repo).
  • .editorconfig warning is forward-looking until the CodeAnalysis.Analyzers package pin is bumped.

Otherwise the analyzer/fix shape looks solid (single + || chains, constant SyntaxKind only, Microsoft single-param IsKind only).

Josef Pihrt and others added 2 commits August 15, 2026 13:54
Put the test class base list on one line for RCS0039, and bail out
when IsKindExpressionInfo parsing fails in the code fix.

Co-authored-by: Cursor <cursoragent@cursor.com>
Recognize Microsoft Kind/IsKind extensions for Token, Trivia, and
NodeOrToken so IsKindExpressionInfo and RCS9012 cover those receivers.

Co-authored-by: Cursor <cursoragent@cursor.com>
@josefpihrt

Copy link
Copy Markdown
Collaborator Author

Included Token/Trivia coverage in this PR: Kind()/IsKind recognition now covers SyntaxNode, SyntaxToken, SyntaxTrivia, and SyntaxNodeOrToken.

Co-authored-by: Cursor <cursoragent@cursor.com>
@josefpihrt josefpihrt changed the title Add RCS9012: Call IsKind instead of comparing Kind [5.0] Add RCS9012: Call IsKind instead of comparing Kind Aug 15, 2026
@josefpihrt josefpihrt changed the title [5.0] Add RCS9012: Call IsKind instead of comparing Kind Add RCS9012: Call IsKind instead of comparing Kind Aug 16, 2026
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.

RCS9012: Use IsKind instead of Kind() comparison

1 participant