Skip to content

fix(no-unsafe-enum-comparison): flag string literal unions#937

Merged
graphite-app[bot] merged 1 commit into
mainfrom
codex/fix-unsafe-enum-union-comparison
May 9, 2026
Merged

fix(no-unsafe-enum-comparison): flag string literal unions#937
graphite-app[bot] merged 1 commit into
mainfrom
codex/fix-unsafe-enum-union-comparison

Conversation

@camc314

@camc314 camc314 commented May 9, 2026

Copy link
Copy Markdown
Contributor

fixes #934

Copilot AI review requested due to automatic review settings May 9, 2026 09:47
@camc314 camc314 self-assigned this May 9, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the no-unsafe-enum-comparison rule to correctly detect unsafe comparisons when the non-enum side is a string-literal union (e.g. 'asc' | 'desc') being compared to a string enum member, and adds regression coverage for that case.

Changes:

  • Extend primitive-like detection to traverse both union and intersection type parts when evaluating comparison safety.
  • Add an invalid test case covering string, named string-literal unions, and inline string-literal unions compared against a string enum member.
  • Update the rule snapshot to reflect the newly reported diagnostics.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
internal/rules/no_unsafe_enum_comparison/no_unsafe_enum_comparison.go Adds typeHasPrimitiveLikePart to detect primitive-like flags within union/intersection parts so comparisons against string-literal unions are flagged.
internal/rules/no_unsafe_enum_comparison/no_unsafe_enum_comparison_test.go Adds a regression test ensuring string-literal unions compared to string enum members produce mismatchedCondition.
internal/rule_tester/snapshots/no-unsafe-enum-comparison.snap Updates expected diagnostics output for the new invalid test case.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@camc314 camc314 force-pushed the codex/fix-unsafe-enum-union-comparison branch 2 times, most recently from 40ae50d to 278ad0d Compare May 9, 2026 10:04
@camc314 camc314 requested a review from Copilot May 9, 2026 10:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@camc314 camc314 added the 0-merge label May 9, 2026

camc314 commented May 9, 2026

Copy link
Copy Markdown
Contributor Author

Merge activity

@graphite-app graphite-app Bot force-pushed the codex/fix-unsafe-enum-union-comparison branch from 278ad0d to 8a2e65a Compare May 9, 2026 10:19
@graphite-app graphite-app Bot merged commit 8a2e65a into main May 9, 2026
9 checks passed
@graphite-app graphite-app Bot removed the 0-merge label May 9, 2026
@graphite-app graphite-app Bot deleted the codex/fix-unsafe-enum-union-comparison branch May 9, 2026 10:26
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.

no-unsafe-enum-comparison misses string literal union types

2 participants