Skip to content

Add row and column numbers to formatted parse errors#9321

Merged
charliermarsh merged 1 commit intomainfrom
charlie/display-parse-error
Dec 31, 2023
Merged

Add row and column numbers to formatted parse errors#9321
charliermarsh merged 1 commit intomainfrom
charlie/display-parse-error

Conversation

@charliermarsh
Copy link
Copy Markdown
Member

@charliermarsh charliermarsh commented Dec 30, 2023

Summary

We now render parse errors in the formatter identically to those in the linter, e.g.:

❯ cargo run -p ruff_cli -- format foo.py
error: Failed to parse foo.py:1:17: Unexpected token '='

Closes #8338.

Closes #9311.

Comment thread crates/ruff_cli/tests/format.rs Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Dec 30, 2023

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@charliermarsh charliermarsh force-pushed the charlie/display-parse-error branch from 380a61b to a043daa Compare December 30, 2023 21:18
@charliermarsh charliermarsh requested a review from zanieb December 30, 2023 21:18
@charliermarsh charliermarsh added bug Something isn't working cli Related to the command-line interface labels Dec 30, 2023
@charliermarsh charliermarsh force-pushed the charlie/display-parse-error branch from a043daa to 34d8bdd Compare December 30, 2023 21:20
@charliermarsh charliermarsh marked this pull request as ready for review December 30, 2023 21:20
@charliermarsh charliermarsh merged commit 48e04cc into main Dec 31, 2023
@charliermarsh charliermarsh deleted the charlie/display-parse-error branch December 31, 2023 12:10
charliermarsh added a commit that referenced this pull request Dec 31, 2023
## Summary

This is a non-behavior-changing refactor to follow-up
#9321 by modifying
`DisplayParseError` to use owned data and make it useable as a
standalone error type (rather than using references and implementing
`Display`). I don't feel very strongly either way. I thought it was
awkward that the `FormatCommandError` had two branches in the display
path, and wanted to represent the `Parse` vs. other cases as a separate
enum, so here we are.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working cli Related to the command-line interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Formatter: Improve handling of syntax errors The formatter's ParseError indicates the offset within the file but not the line number

2 participants