Skip to content

file-lines do not reformat parts of a multi-line statement #4053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
athei opened this issue Feb 13, 2020 · 1 comment
Open

file-lines do not reformat parts of a multi-line statement #4053

athei opened this issue Feb 13, 2020 · 1 comment
Labels
a-chains only-with-option requires a non-default option value to reproduce

Comments

@athei
Copy link

athei commented Feb 13, 2020

Imagine the following statement in which one line is wrongly indented:

let diff = repo
.diff_tree_to_workdir(Some(&head), Some(&mut diff_options))
    .unwrap();

I now specify only the second line in my --file-lines.

What I expect to happen
The second line becomes correctly indented to match the same column as the .unwrap().

What actually happens
Nothing. The line is ignored because it is part of a larger statement.

Why this is a problem
I have a use case where a script uses git and --file-lines to only format lines which where changed in a specific commit. This script fails when someone just edits parts of a larger statement because the line is not formatted then. Adding more context to the range is also not viable because then lines are formatted that weren't touched in the commit.

#3397

@athei athei changed the title file-lines do reformat parts of a multi-line statement file-lines do not reformat parts of a multi-line statement Feb 13, 2020
@topecongiro topecongiro added a-chains only-with-option requires a non-default option value to reproduce labels Feb 17, 2020
@singron
Copy link

singron commented Mar 12, 2020

I noticed rustfmt refused to reindent a single line of a multiline match expression unless the --file-lines range included both the start of the match and the misindented line.

Here is a minimal reproduction:

fn main() {
    match 1 { // Line 2 is the start of the match
        1 => (),
        2 => {
let _ = (); // Line 5 isn't indented
        }
    }
}
# This should reindent line 5, but it does nothing
rustfmt +nightly --unstable-features --file-lines '[{"file": "a.rs", "range": [5, 5]}]' a.rs --check
# This does reindent line 5
rustfmt +nightly --unstable-features --file-lines '[{"file": "a.rs", "range": [2, 5]}]' a.rs --check

version rustfmt 1.4.12-nightly (9f53665f 2020-02-10)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-chains only-with-option requires a non-default option value to reproduce
Projects
None yet
Development

No branches or pull requests

3 participants