Skip to content

JSON output for removing blank lines is wrong #4259

@Timmmm

Description

@Timmmm

Rustfmt version: rustfmt 2.0.0-rc.2-nightly (e9b039ea 2020-06-03)

If Rustfmt decides to remove a blank line, the JSON output says that actually nothing needs to change. Trivial repro:

 ~ cat foo.rs
fn foo() {

    let i = 0;
}
 ~ rustfmt --emit json foo.rs | jq
[
  {
    "name": "/Users/me/foo.rs",
    "mismatches": [
      {
        "original_begin_line": 2,
        "original_end_line": 2,
        "expected_begin_line": 2,
        "expected_end_line": 2,
        "original": "",
        "expected": ""
      }
    ]
  }
]

It seems fine at removing newlines in other cases:

 ~ cat foo.rs
fn foo() {
    let i =
    0;
}
 ~ rustfmt --emit json foo.rs | jq
[
  {
    "name": "/Users/timh/foo.rs",
    "mismatches": [
      {
        "original_begin_line": 2,
        "original_end_line": 3,
        "expected_begin_line": 2,
        "expected_end_line": 2,
        "original": "    let i =\n    0;",
        "expected": "    let i = 0;"
      }
    ]
  }
]

So I think the output should be something like this:

[
  {
    "name": "/Users/me/foo.rs",
    "mismatches": [
      {
        "original_begin_line": 2,
        "original_end_line": 3,
        "expected_begin_line": 2,
        "expected_end_line": 2,
        "original": "\n",
        "expected": ""
      }
    ]
  }
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-emittersArea: emittersE-help-wantedCall for participation: help is requested to fix this issuegood first issueIssues up for grabs, also good candidates for new rustfmt contributors

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions