Skip to content

feat: enrich no-unsafe-type-assertion diagnostics#868

Open
camc314 wants to merge 1 commit intomainfrom
c/codex/issue-648-no-unsafe-type-assertion-diagnostics
Open

feat: enrich no-unsafe-type-assertion diagnostics#868
camc314 wants to merge 1 commit intomainfrom
c/codex/issue-648-no-unsafe-type-assertion-diagnostics

Conversation

@camc314
Copy link
Copy Markdown
Contributor

@camc314 camc314 commented Apr 4, 2026

No description provided.

@camc314 camc314 marked this pull request as ready for review April 4, 2026 16:59
Copilot AI review requested due to automatic review settings April 4, 2026 16:59
Copy link
Copy Markdown
Contributor Author

camc314 commented Apr 4, 2026


How to use the Graphite Merge Queue

Add the label 0-merge to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@camc314 camc314 force-pushed the c/codex/issue-648-no-unsafe-type-assertion-diagnostics branch from 40e475e to 8af50a2 Compare April 4, 2026 17:06
Copy link
Copy Markdown

Copilot AI left a comment

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 enhances the no-unsafe-type-assertion rule’s diagnostics by adding richer guidance (Help) and attaching labeled source ranges that show the original vs asserted types to make reports more actionable.

Changes:

  • Add Help text to all no-unsafe-type-assertion rule messages.
  • Switch from ReportNode to ReportDiagnostic and emit LabeledRanges for the assertion expression/type.
  • Update rule-tester snapshots to include Help and labeled range renderings.

Reviewed changes

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

File Description
internal/rules/no_unsafe_type_assertion/no_unsafe_type_assertion.go Adds Help strings and emits enriched diagnostics with labeled ranges (original vs asserted type).
internal/rule_tester/snapshots/no-unsafe-type-assertion.snap Updates snapshots to reflect Help lines and labeled range snippets.
e2e/snapshots/snapshot.test.ts.snap Updates e2e snapshot output (currently appears inconsistent with the implemented rule changes).

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

Comment on lines +71 to +79
LabeledRanges: []rule.RuleLabeledRange{
{
Label: "Original type: " + ctx.TypeChecker.TypeToString(expressionType),
Range: utils.TrimNodeTextRange(ctx.SourceFile, expression),
},
{
Label: "Asserted type: " + ctx.TypeChecker.TypeToString(assertedType),
Range: utils.TrimNodeTextRange(ctx.SourceFile, typeAnnotation),
},
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

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

For the isUnsafeExpressionAny / isUnsafeAssertedAny branches, the user-facing message can mention an intrinsic error any (via getAnyTypeName(sender)), but the labeled range here always prints TypeToString(expressionType) / TypeToString(assertedType), which renders as plain any in snapshots. That makes the new labeled ranges inconsistent with the diagnostic message. Consider passing the sender type (or a precomputed display string such as getAnyTypeName(sender)) into buildUnsafeTypeAssertionDiagnostic so the label matches the message in these cases.

Copilot uses AI. Check for mistakes.
Comment on lines 2048 to 2075
"kind": 0,
"message": {
"description": "Unsafe call of a(n) \`any\` typed value.",
"id": "unsafeCall",
},
"range": {
"end": 245,
"pos": 222,
},
"rule": "no-unsafe-call",
},
{
"file_path": "fixtures/basic/rules/no-unsafe-call/index.ts",
"kind": 0,
"message": {
"description": "Unsafe member access .then on an \`any\` value.",
"id": "unsafeMemberExpression",
},
"range": {
"end": 237,
"pos": 233,
},
"rule": "no-unsafe-member-access",
},
{
"file_path": "fixtures/basic/rules/no-unsafe-call/index.ts",
"kind": 0,
"message": {
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

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

This snapshot change adds message.help and labeled_ranges to a no-unsafe-enum-comparison diagnostic, but the rule currently reports via ctx.ReportNode(..., buildMismatchedConditionMessage()) and that message does not set Help nor any labeled ranges. Conversely, this PR adds Help + labeled ranges for no-unsafe-type-assertion diagnostics, but the e2e snapshot entries for fixtures/basic/rules/no-unsafe-type-assertion/index.ts still don’t show those new fields. Please regenerate/update the e2e snapshot from actual headless output so it matches the code changes (and avoid introducing fields for rules that don’t emit them).

Copilot uses AI. Check for mistakes.
@camc314 camc314 force-pushed the c/codex/issue-648-no-unsafe-type-assertion-diagnostics branch from 8af50a2 to 1658624 Compare April 4, 2026 17:09
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.

2 participants