Commit c8fd0cf
committed
Fix wrong indenting with hard tabs in binop pairs
When rewriting pairs of multi-line binary operations, we would check the
length of a line to see if we can snuggle the current line into the
previous one. We compute the length of the previous line using
`last_line_width` which is not aware of indentation widths (i.e.
`config.tab_spaces`), so if we were formatting something like:
if some_long_name {
foo
} | if some_other_name {
bar
}
Then when we get to the line for `| if some_other_name {` we check the
previous line, which is:
* `\s\s\s\s\s\s\s\s}' if we are not using hard tabs (and 1 tab = 4
spaces), and
* `\t\t}` if we are using hard-tabs
`last_line_width` would return 9 for the first one, and 3 for the
second. Meaning if we're using hard tabs we could conclude that it
should fit on the previous line, leading to inconsistent behaviour
between the two.
To fix this, create a version of `last_line_width` that is aware of
`config.tab_spaces`.1 parent 1faf402 commit c8fd0cf
3 files changed
Lines changed: 36 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
132 | 133 | | |
133 | 134 | | |
134 | 135 | | |
135 | | - | |
| 136 | + | |
136 | 137 | | |
137 | 138 | | |
138 | 139 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
222 | 222 | | |
223 | 223 | | |
224 | 224 | | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
225 | 233 | | |
226 | 234 | | |
227 | 235 | | |
| |||
697 | 705 | | |
698 | 706 | | |
699 | 707 | | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
700 | 722 | | |
701 | 723 | | |
702 | 724 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
0 commit comments