Skip to content

Attempt to show correct newline style in json emitter #4273

Open
@calebcartwright

Description

@calebcartwright

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 #3850 (comment))

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.

fn effective_newline_style(
newline_style: NewlineStyle,
raw_input_text: &str,
) -> EffectiveNewlineStyle {
match newline_style {
NewlineStyle::Auto => auto_detect_newline_style(raw_input_text),
NewlineStyle::Native => native_newline_style(),
NewlineStyle::Windows => EffectiveNewlineStyle::Windows,
NewlineStyle::Unix => EffectiveNewlineStyle::Unix,
}
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions