Add JSON output for errors
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
There is already an --emit json option that emits formatting changes as JSON. However if Rustfmt encounters a parse error it prints the error to stderr in human readable form and exits with error code 1.
$ rustfmt --emit json lib.rs
error: expected one of `!` or `::`, found `<eof>`
--> /.../src/lib.rs:16:1
|
16 | sdf
| ^^^ expected one of `!` or `::`
failed to parse Real("/.../src/lib.rs")
It would be helpful in some situations to be able to have these errors in JSON format too. For example for IDE integration or CI. (One of my coworkers is using a horrible regex to parse this, against my advice!)
I think an --emit-errors json option would be reasonable.
- rustfmt version:
rustfmt 2.0.0-rc.2-nightly (e91edf56 2020-08-04) - From where did you install rustfmt?: Git
master, from yesterday.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the existing --emit json handling and the parse-error path that currently writes human-readable diagnostics to stderr. Determine the JSON error shape and how an --emit-errors json option should behave; done means parse errors are emitted in JSON while preserving the documented failure status.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100