Attempt to show correct newline style in json emitter
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
The json emit mode currently always appends unix style line endings to the end of the output snippets (#4262 and #4259) .
It may not be possible to provide both the original and expected trailing line endings given our current solution for building the diff between original and expected formatting. rustfmt currently leverages the diff crate which results in the dropping of the trailing newline information (Refs https://github.com/rust-lang/rustfmt/pull/3850#discussion_r332801527)
We could technically determine the correct newline style to apply for the expected formatting even with the current make_diff approach, perhaps by leveraging some of the newline functions like effective_newline_style. However, the challenges with original contents would pose problems for a scenario where the only changes rustfmt would make are newline style conversions.
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 with src/formatting/newline_style.rs, especially effective_newline_style, and inspect how make_diff uses the diff crate. Determine how the emitter can retain trailing newline information for both original and expected contents, including cases where newline style conversion is the only change. Done means JSON output uses the correct trailing newline style without regressing existing diff behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100