Skip to content

fix: report precise error line numbers in --show-errors#51

Merged
frankieyan merged 2 commits intomainfrom
frankieyan/fix-error-line-nums
Jan 30, 2026
Merged

fix: report precise error line numbers in --show-errors#51
frankieyan merged 2 commits intomainfrom
frankieyan/fix-error-line-nums

Conversation

@frankieyan
Copy link
Copy Markdown
Member

Previously, --show-errors reported the line number where the function starts rather than the exact line where the React compiler violation occurs. This made it harder to locate and fix issues.

Now --show-errors displays precise error locations:

🔍 Checking 1 file for React Compiler errors…
Errors:
    - src/bad-hook.ts: Line 9: Cannot access refs during render (x2)
    - src/bad-hook.ts: Line 10: Cannot access refs during render
❌ React Compiler errors have increased in:
  • src/bad-hook.ts: +3

The fix uses primaryLocation() for CompileError events to get the precise error location, falling back to the function location if unavailable.

Test plan

Test locally by running against the sample project fixtures:

npm run build
cd src/__fixtures__/sample-project
  • Verify precise line numbers are shown

    node ../../../dist/index.mjs --show-errors --check-files src/bad-hook.ts

    Should show Line 9 and Line 10 (the actual error lines), not Line 6 (the function start).

  • Verify all commands with --show-errors show precise locations

    node ../../../dist/index.mjs --show-errors
    node ../../../dist/index.mjs --overwrite --show-errors

frankieyan and others added 2 commits January 29, 2026 21:20
minimatch was being imported directly but only available as a transitive
dependency through glob. This caused build failures with pnpm's strict
dependency resolution.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Previously, --show-errors reported the line number where the function
starts (event.fnLoc) rather than the exact line where the React compiler
violation occurs.

Now uses:
- event.detail.primaryLocation() for CompileError events
- event.loc for CompileSkip events

This provides users with accurate line numbers pointing to the exact
location of violations, making it easier to find and fix issues.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@frankieyan frankieyan requested a review from a team as a code owner January 30, 2026 05:44
@frankieyan frankieyan requested review from craigcarlyle and removed request for a team January 30, 2026 05:44
Copy link
Copy Markdown

@doistbot-app doistbot-app Bot left a comment

Choose a reason for hiding this comment

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

Thanks for this improvement to error reporting, which now shows the precise line number for React compiler violations instead of just the start of the function. This change will make it significantly easier for developers to locate and fix issues. It looks like there may be a potential runtime crash if an error's location data is incomplete, and a new dependency may have been added that appears to be unused.

Comment thread src/index.mts
// primaryLocation() may return a symbol (GeneratedSource), so check for object
const loc = event.detail.primaryLocation()
line =
(loc && typeof loc === 'object' ? loc.start.line : null) ??
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P1] Possible runtime crash when primaryLocation object lacks start. primaryLocation() can return an object without a start (or with start undefined), so loc.start.line will throw at runtime. This will surface when the compiler provides a location object that doesn't include start (or uses a different shape), breaking --show-errors. Use optional chaining or a guard like loc && typeof loc === 'object' && loc.start ? loc.start.line : null to avoid throwing.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

If we are to trust the types, then then start is a non-nullable property on the object returned from primaryLocation (SourceLocation type from Babel), if it's a non-null and non-symbol value.

@frankieyan frankieyan added the 👀 Show PR PR must be reviewed before or after merging label Jan 30, 2026
@frankieyan frankieyan merged commit d4ee776 into main Jan 30, 2026
2 checks passed
@frankieyan frankieyan deleted the frankieyan/fix-error-line-nums branch January 30, 2026 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

👀 Show PR PR must be reviewed before or after merging

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant