rust-lang / rust-lang/rustfmt

Attempt to show correct newline style in json emitter

Open
#4,273 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-emitters E-help-wanted
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.

https://github.com/rust-lang/rustfmt/blob/e208a394f58173b4614217d97e460d4f9b79d1b3/src/formatting/newline_style.rs#L26-L36

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.