Commit 7fdb556
authored
Strip form feeds from indent passed to
When adjusting "simple" indentation in the formation of edits, we
attempt to dedent manually rather than deferring to LibCST. To do so we
must provide a desired indentation, in the form of a string. We often
grab this from source code by slicing the text in a range beginning at
the start of a line.
In Python, the start of a line may contain form feeds but these do not
contribute to the indentation. In this PR, we strip the provided
indentation of its leading form feeds in order to get the correct
indentation amount for use in `dedent_to`. This avoids the introduction
of a syntax error in the edit
[`adjust_indentation`](https://github.com/astral-sh/ruff/blob/1f430e68af6e627569776dfbcd03b98ac7c29eb6/crates/ruff_linter/src/fix/edits.rs#L429).
Note: We could try to stay closer to the user's intent by prepending the
form feed prefix of the provided indentation _everywhere_ in the
resulting edit, but that seems a little unwieldy and this is a bit of an
edge case anyway.
Closes #24373dedent_to (#24381)1 parent 1f430e6 commit 7fdb556
3 files changed
Lines changed: 50 additions & 1 deletion
File tree
- crates
- ruff_linter
- resources/test/fixtures/ruff
- src/rules/ruff/snapshots
- ruff_python_trivia/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
179 | | - | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
Lines changed: 22 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
349 | 349 | | |
350 | 350 | | |
351 | 351 | | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
206 | 211 | | |
207 | 212 | | |
208 | 213 | | |
| |||
753 | 758 | | |
754 | 759 | | |
755 | 760 | | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
756 | 775 | | |
0 commit comments