Skip to content

Commit fff4953

Browse files
[ty] Preserve blank lines between comments and imports in add-import action (#24066)
Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Co-authored-by: Micha Reiser <micha@reiser.io>
1 parent 11ef7f4 commit fff4953

12 files changed

+93
-51
lines changed

crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__required_import_comment.py.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ I002 [*] Missing required import: `from __future__ import annotations`
55
--> comment.py:1:1
66
help: Insert required import: `from __future__ import annotations`
77
1 | #!/usr/bin/env python3
8-
2 + from __future__ import annotations
9-
3 |
8+
2 |
9+
3 + from __future__ import annotations
1010
4 | x = 1

crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__required_import_comments_and_newlines.py.snap

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ source: crates/ruff_linter/src/rules/isort/mod.rs
44
I002 [*] Missing required import: `from __future__ import annotations`
55
--> comments_and_newlines.py:1:1
66
help: Insert required import: `from __future__ import annotations`
7-
2 | # A copyright notice could go here
87
3 |
98
4 | # A linter directive could go here
10-
5 + from __future__ import annotations
11-
6 |
9+
5 |
10+
6 + from __future__ import annotations
1211
7 | x = 1

crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__required_import_off.py.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ I002 [*] Missing required import: `from __future__ import annotations`
55
--> off.py:1:1
66
help: Insert required import: `from __future__ import annotations`
77
1 | # isort: off
8-
2 + from __future__ import annotations
9-
3 |
8+
2 |
9+
3 + from __future__ import annotations
1010
4 | x = 1
1111
5 | # isort: on

crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__required_import_with_alias_comment.py.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ I002 [*] Missing required import: `from __future__ import annotations as _annota
55
--> comment.py:1:1
66
help: Insert required import: `from __future__ import annotations as _annotations`
77
1 | #!/usr/bin/env python3
8-
2 + from __future__ import annotations as _annotations
9-
3 |
8+
2 |
9+
3 + from __future__ import annotations as _annotations
1010
4 | x = 1

crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__required_import_with_alias_comments_and_newlines.py.snap

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ source: crates/ruff_linter/src/rules/isort/mod.rs
44
I002 [*] Missing required import: `from __future__ import annotations as _annotations`
55
--> comments_and_newlines.py:1:1
66
help: Insert required import: `from __future__ import annotations as _annotations`
7-
2 | # A copyright notice could go here
87
3 |
98
4 | # A linter directive could go here
10-
5 + from __future__ import annotations as _annotations
11-
6 |
9+
5 |
10+
6 + from __future__ import annotations as _annotations
1211
7 | x = 1

crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__required_import_with_alias_off.py.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ I002 [*] Missing required import: `from __future__ import annotations as _annota
55
--> off.py:1:1
66
help: Insert required import: `from __future__ import annotations as _annotations`
77
1 | # isort: off
8-
2 + from __future__ import annotations as _annotations
9-
3 |
8+
2 |
9+
3 + from __future__ import annotations as _annotations
1010
4 | x = 1
1111
5 | # isort: on

crates/ruff_linter/src/rules/refurb/snapshots/ruff_linter__rules__refurb__tests__FURB101_FURB101_2.py.snap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
22
source: crates/ruff_linter/src/rules/refurb/mod.rs
3-
assertion_line: 65
43
---
54
FURB101 [*] `open` and `read` should be replaced by `Path("file.txt").read_text(encoding="utf-8")`
65
--> FURB101_2.py:2:6

crates/ruff_linter/src/rules/refurb/snapshots/ruff_linter__rules__refurb__tests__FURB156_FURB156.py.snap

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ FURB156 [*] Use of hardcoded string charset
1313
|
1414
help: Replace hardcoded charset with `string.digits`
1515
1 | # Errors
16-
2 + import string
17-
3 |
16+
2 |
1817
- _ = "0123456789"
18+
3 + import string
1919
4 + _ = string.digits
2020
5 | _ = "01234567"
2121
6 | _ = "0123456789abcdefABCDEF"
@@ -32,8 +32,8 @@ FURB156 [*] Use of hardcoded string charset
3232
|
3333
help: Replace hardcoded charset with `string.octdigits`
3434
1 | # Errors
35-
2 + import string
36-
3 |
35+
2 |
36+
3 + import string
3737
4 | _ = "0123456789"
3838
- _ = "01234567"
3939
5 + _ = string.octdigits
@@ -53,8 +53,8 @@ FURB156 [*] Use of hardcoded string charset
5353
|
5454
help: Replace hardcoded charset with `string.hexdigits`
5555
1 | # Errors
56-
2 + import string
57-
3 |
56+
2 |
57+
3 + import string
5858
4 | _ = "0123456789"
5959
5 | _ = "01234567"
6060
- _ = "0123456789abcdefABCDEF"
@@ -75,8 +75,8 @@ FURB156 [*] Use of hardcoded string charset
7575
|
7676
help: Replace hardcoded charset with `string.ascii_lowercase`
7777
1 | # Errors
78-
2 + import string
79-
3 |
78+
2 |
79+
3 + import string
8080
4 | _ = "0123456789"
8181
5 | _ = "01234567"
8282
6 | _ = "0123456789abcdefABCDEF"
@@ -98,8 +98,8 @@ FURB156 [*] Use of hardcoded string charset
9898
|
9999
help: Replace hardcoded charset with `string.ascii_uppercase`
100100
1 | # Errors
101-
2 + import string
102-
3 |
101+
2 |
102+
3 + import string
103103
4 | _ = "0123456789"
104104
5 | _ = "01234567"
105105
6 | _ = "0123456789abcdefABCDEF"
@@ -122,8 +122,8 @@ FURB156 [*] Use of hardcoded string charset
122122
|
123123
help: Replace hardcoded charset with `string.ascii_letters`
124124
1 | # Errors
125-
2 + import string
126-
3 |
125+
2 |
126+
3 + import string
127127
4 | _ = "0123456789"
128128
5 | _ = "01234567"
129129
6 | _ = "0123456789abcdefABCDEF"
@@ -146,11 +146,11 @@ FURB156 [*] Use of hardcoded string charset
146146
|
147147
help: Replace hardcoded charset with `string.punctuation`
148148
1 | # Errors
149-
2 + import string
150-
3 |
149+
2 |
150+
3 + import string
151151
4 | _ = "0123456789"
152152
5 | _ = "01234567"
153-
--------------------------------------------------------------------------------
153+
6 | _ = "0123456789abcdefABCDEF"
154154
7 | _ = "abcdefghijklmnopqrstuvwxyz"
155155
8 | _ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
156156
9 | _ = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
@@ -172,10 +172,11 @@ FURB156 [*] Use of hardcoded string charset
172172
|
173173
help: Replace hardcoded charset with `string.whitespace`
174174
1 | # Errors
175-
2 + import string
176-
3 |
175+
2 |
176+
3 + import string
177177
4 | _ = "0123456789"
178178
5 | _ = "01234567"
179+
6 | _ = "0123456789abcdefABCDEF"
179180
--------------------------------------------------------------------------------
180181
8 | _ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
181182
9 | _ = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
@@ -198,10 +199,11 @@ FURB156 [*] Use of hardcoded string charset
198199
|
199200
help: Replace hardcoded charset with `string.printable`
200201
1 | # Errors
201-
2 + import string
202-
3 |
202+
2 |
203+
3 + import string
203204
4 | _ = "0123456789"
204205
5 | _ = "01234567"
206+
6 | _ = "0123456789abcdefABCDEF"
205207
--------------------------------------------------------------------------------
206208
10 | _ = r"""!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~"""
207209
11 | _ = " \t\n\r\v\f"
@@ -225,10 +227,11 @@ FURB156 [*] Use of hardcoded string charset
225227
|
226228
help: Replace hardcoded charset with `string.printable`
227229
1 | # Errors
228-
2 + import string
229-
3 |
230+
2 |
231+
3 + import string
230232
4 | _ = "0123456789"
231233
5 | _ = "01234567"
234+
6 | _ = "0123456789abcdefABCDEF"
232235
--------------------------------------------------------------------------------
233236
12 |
234237
13 | _ = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c'
@@ -255,10 +258,11 @@ FURB156 [*] Use of hardcoded string charset
255258
|
256259
help: Replace hardcoded charset with `string.digits`
257260
1 | # Errors
258-
2 + import string
259-
3 |
261+
2 |
262+
3 + import string
260263
4 | _ = "0123456789"
261264
5 | _ = "01234567"
265+
6 | _ = "0123456789abcdefABCDEF"
262266
--------------------------------------------------------------------------------
263267
15 | '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&'
264268
16 | "'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c"
@@ -281,10 +285,11 @@ FURB156 [*] Use of hardcoded string charset
281285
|
282286
help: Replace hardcoded charset with `string.digits`
283287
1 | # Errors
284-
2 + import string
285-
3 |
288+
2 |
289+
3 + import string
286290
4 | _ = "0123456789"
287291
5 | _ = "01234567"
292+
6 | _ = "0123456789abcdefABCDEF"
288293
--------------------------------------------------------------------------------
289294
20 | "89")
290295
21 |
@@ -306,10 +311,11 @@ FURB156 [*] Use of hardcoded string charset
306311
|
307312
help: Replace hardcoded charset with `string.digits`
308313
1 | # Errors
309-
2 + import string
310-
3 |
314+
2 |
315+
3 + import string
311316
4 | _ = "0123456789"
312317
5 | _ = "01234567"
318+
6 | _ = "0123456789abcdefABCDEF"
313319
--------------------------------------------------------------------------------
314320
24 | ).capitalize()
315321
25 |
@@ -331,10 +337,11 @@ FURB156 [*] Use of hardcoded string charset
331337
|
332338
help: Replace hardcoded charset with `string.digits`
333339
1 | # Errors
334-
2 + import string
335-
3 |
340+
2 |
341+
3 + import string
336342
4 | _ = "0123456789"
337343
5 | _ = "01234567"
344+
6 | _ = "0123456789abcdefABCDEF"
338345
--------------------------------------------------------------------------------
339346
29 | ).capitalize()
340347
30 |

crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__PY39_RUF013_RUF013_1.py.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ RUF013 [*] PEP 484 prohibits implicit `Optional`
1010
|
1111
help: Convert to `Optional[T]`
1212
1 | # No `typing.Optional` import
13-
2 + from typing import Optional
13+
2 |
1414
3 |
15-
4 |
1615
- def f(arg: int = None): # RUF013
16+
4 + from typing import Optional
1717
5 + def f(arg: Optional[int] = None): # RUF013
1818
6 | pass
1919
note: This is an unsafe fix and may change runtime behavior

crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__add_future_import_RUF013_1.py.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ RUF013 [*] PEP 484 prohibits implicit `Optional`
1010
|
1111
help: Convert to `T | None`
1212
1 | # No `typing.Optional` import
13-
2 + from __future__ import annotations
13+
2 |
1414
3 |
15-
4 |
1615
- def f(arg: int = None): # RUF013
16+
4 + from __future__ import annotations
1717
5 + def f(arg: int | None = None): # RUF013
1818
6 | pass
1919
note: This is an unsafe fix and may change runtime behavior

0 commit comments

Comments
 (0)