Skip to content

Commit b11906d

Browse files
committed
test: another set of updates related to line terminator handling
This group of updates is similar to the last one, but they call out the fact that while the change is an improvement, it does still seem to be a little buggy. As one example, previously we would have this: | 1 | / from __future__ import annotations 2 | | 3 | | from typing import Any 4 | | 5 | | from requests import Session 6 | | 7 | | from my_first_party import my_first_party_object 8 | | 9 | | from . import my_local_folder_object 10 | | 11 | | 12 | | 13 | | class Thing(object): | |_^ I001 14 | name: str 15 | def __init__(self, name: str): | = help: Organize imports And now here's what it looks like after: | 1 | / from __future__ import annotations 2 | | 3 | | from typing import Any 4 | | 5 | | from requests import Session 6 | | 7 | | from my_first_party import my_first_party_object 8 | | 9 | | from . import my_local_folder_object 10 | | 11 | | 12 | | | |__^ Organize imports 13 | class Thing(object): 14 | name: str 15 | def __init__(self, name: str): | = help: Organize imports So at least now, the diagnostic is not pointing to a completely unrelated thing (`class Thing`), but it's still not quite pointing to the imports directly. And the `^` is a bit offset. After looking at some examples more closely, I think this is probably more of a bug with how we're generating offsets, since we are actually pointing to a location that is a few empty lines _below_ the last import. And `annotate-snippets` is rendering that part correctly. However, the offset from the left (the `^` is pointing at `r` instead of `f` or even at the end of `from . import my_local_folder_object`) appears to be a problem with `annotate-snippets` itself. We accept this under the reasoning that it's an improvement, albeit not perfect.
1 parent 77d4545 commit b11906d

File tree

17 files changed

+263
-278
lines changed

17 files changed

+263
-278
lines changed

crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__lines_after_imports.pyi.snap

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
---
22
source: crates/ruff_linter/src/rules/isort/mod.rs
3-
snapshot_kind: text
43
---
54
lines_after_imports.pyi:1:1: I001 [*] Import block is un-sorted or un-formatted
65
|
76
1 | / from __future__ import annotations
8-
2 | |
7+
2 | |
98
3 | | from typing import Any
10-
4 | |
9+
4 | |
1110
5 | | from requests import Session
12-
6 | |
11+
6 | |
1312
7 | | from my_first_party import my_first_party_object
14-
8 | |
13+
8 | |
1514
9 | | from . import my_local_folder_object
16-
10 | |
17-
11 | |
18-
12 | |
19-
13 | | class Thing(object):
20-
| |_^ I001
15+
10 | |
16+
11 | |
17+
12 | |
18+
| |__^ I001
19+
13 | class Thing(object):
2120
14 | name: str
2221
15 | def __init__(self, name: str):
2322
|

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

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
11
---
22
source: crates/ruff_linter/src/rules/isort/mod.rs
3-
snapshot_kind: text
43
---
54
lines_after_imports_func_after.py:1:1: I001 [*] Import block is un-sorted or un-formatted
65
|
76
1 | / from __future__ import annotations
8-
2 | |
7+
2 | |
98
3 | | from typing import Any
10-
4 | |
9+
4 | |
1110
5 | | from requests import Session
12-
6 | |
11+
6 | |
1312
7 | | from my_first_party import my_first_party_object
14-
8 | |
13+
8 | |
1514
9 | | from . import my_local_folder_object
16-
10 | |
17-
11 | |
18-
12 | |
19-
13 | |
20-
14 | |
21-
15 | |
22-
16 | |
23-
17 | |
24-
18 | |
25-
19 | |
26-
20 | |
27-
21 | | def main():
28-
| |_^ I001
15+
10 | |
16+
11 | |
17+
12 | |
18+
13 | |
19+
14 | |
20+
15 | |
21+
16 | |
22+
17 | |
23+
18 | |
24+
19 | |
25+
20 | |
26+
| |__^ I001
27+
21 | def main():
2928
22 | my_local_folder_object.get()
3029
|
3130
= help: Organize imports

crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__lines_after_imports_lines_after_imports.pyi.snap

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
---
22
source: crates/ruff_linter/src/rules/isort/mod.rs
3-
snapshot_kind: text
43
---
54
lines_after_imports.pyi:1:1: I001 [*] Import block is un-sorted or un-formatted
65
|
76
1 | / from __future__ import annotations
8-
2 | |
7+
2 | |
98
3 | | from typing import Any
10-
4 | |
9+
4 | |
1110
5 | | from requests import Session
12-
6 | |
11+
6 | |
1312
7 | | from my_first_party import my_first_party_object
14-
8 | |
13+
8 | |
1514
9 | | from . import my_local_folder_object
16-
10 | |
17-
11 | |
18-
12 | |
19-
13 | | class Thing(object):
20-
| |_^ I001
15+
10 | |
16+
11 | |
17+
12 | |
18+
| |__^ I001
19+
13 | class Thing(object):
2120
14 | name: str
2221
15 | def __init__(self, name: str):
2322
|

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

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
11
---
22
source: crates/ruff_linter/src/rules/isort/mod.rs
3-
snapshot_kind: text
43
---
54
lines_after_imports_func_after.py:1:1: I001 [*] Import block is un-sorted or un-formatted
65
|
76
1 | / from __future__ import annotations
8-
2 | |
7+
2 | |
98
3 | | from typing import Any
10-
4 | |
9+
4 | |
1110
5 | | from requests import Session
12-
6 | |
11+
6 | |
1312
7 | | from my_first_party import my_first_party_object
14-
8 | |
13+
8 | |
1514
9 | | from . import my_local_folder_object
16-
10 | |
17-
11 | |
18-
12 | |
19-
13 | |
20-
14 | |
21-
15 | |
22-
16 | |
23-
17 | |
24-
18 | |
25-
19 | |
26-
20 | |
27-
21 | | def main():
28-
| |_^ I001
15+
10 | |
16+
11 | |
17+
12 | |
18+
13 | |
19+
14 | |
20+
15 | |
21+
16 | |
22+
17 | |
23+
18 | |
24+
19 | |
25+
20 | |
26+
| |__^ I001
27+
21 | def main():
2928
22 | my_local_folder_object.get()
3029
|
3130
= help: Organize imports

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
---
22
source: crates/ruff_linter/src/rules/isort/mod.rs
3-
snapshot_kind: text
43
---
54
main_first_party.py:1:1: I001 [*] Import block is un-sorted or un-formatted
65
|
76
1 | / import os
8-
2 | |
7+
2 | |
98
3 | | import __main__
109
4 | | import third_party
11-
5 | |
10+
5 | |
1211
6 | | import first_party
13-
7 | |
14-
8 | | os.a
15-
| |_^ I001
12+
7 | |
13+
| |__^ I001
14+
8 | os.a
1615
9 | third_party.a
1716
10 | __main__.a
1817
|

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

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
---
22
source: crates/ruff_linter/src/rules/isort/mod.rs
3-
snapshot_kind: text
43
---
54
trailing_comment.py:8:1: I001 [*] Import block is un-sorted or un-formatted
65
|
76
6 | pass
8-
7 |
7+
7 |
98
8 | / from mylib import (
109
9 | | MyClient,
1110
10 | | MyMgmtClient,
1211
11 | | ); from foo import (
1312
12 | | bar
1413
13 | | )# some comment
15-
14 | |
16-
15 | | pass
17-
| |_^ I001
18-
16 |
14+
14 | |
15+
| |__^ I001
16+
15 | pass
17+
16 |
1918
17 | from foo import (
2019
|
2120
= help: Organize imports
@@ -39,7 +38,7 @@ trailing_comment.py:8:1: I001 [*] Import block is un-sorted or un-formatted
3938
trailing_comment.py:17:1: I001 [*] Import block is un-sorted or un-formatted
4039
|
4140
15 | pass
42-
16 |
41+
16 |
4342
17 | / from foo import (
4443
18 | | bar
4544
19 | | )
@@ -48,10 +47,10 @@ trailing_comment.py:17:1: I001 [*] Import block is un-sorted or un-formatted
4847
22 | | MyMgmtClient,
4948
23 | | # some comment
5049
24 | | )
51-
25 | |
52-
26 | | pass
53-
| |_^ I001
54-
27 |
50+
25 | |
51+
| |__^ I001
52+
26 | pass
53+
27 |
5554
28 | from mylib import (
5655
|
5756
= help: Organize imports
@@ -71,15 +70,15 @@ trailing_comment.py:17:1: I001 [*] Import block is un-sorted or un-formatted
7170
trailing_comment.py:35:1: I001 [*] Import block is un-sorted or un-formatted
7271
|
7372
33 | pass
74-
34 |
73+
34 |
7574
35 | / from mylib import (
7675
36 | | MyClient
7776
37 | | # some comment
7877
38 | | )
79-
39 | |
80-
40 | | pass
81-
| |_^ I001
82-
41 |
78+
39 | |
79+
| |__^ I001
80+
40 | pass
81+
41 |
8382
42 | from mylib import (
8483
|
8584
= help: Organize imports
@@ -100,15 +99,15 @@ trailing_comment.py:35:1: I001 [*] Import block is un-sorted or un-formatted
10099
trailing_comment.py:42:1: I001 [*] Import block is un-sorted or un-formatted
101100
|
102101
40 | pass
103-
41 |
102+
41 |
104103
42 | / from mylib import (
105104
43 | | # some comment
106105
44 | | MyClient
107106
45 | | )
108-
46 | |
109-
47 | | pass
110-
| |_^ I001
111-
48 |
107+
46 | |
108+
| |__^ I001
109+
47 | pass
110+
48 |
112111
49 | # a
113112
|
114113
= help: Organize imports
@@ -134,6 +133,7 @@ trailing_comment.py:50:1: I001 [*] Import block is un-sorted or un-formatted
134133
52 | | MyClient # d
135134
53 | | # e
136135
54 | | ) # f
136+
| |______^ I001
137137
|
138138
= help: Organize imports
139139

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
---
22
source: crates/ruff_linter/src/rules/isort/mod.rs
3-
snapshot_kind: text
43
---
54
unicode.py:1:1: I001 [*] Import block is un-sorted or un-formatted
65
|
76
1 | / from astropy.constants import hbar as
87
2 | | from numpy import pi as π
98
3 | | import numpy as ℂℇℊℋℌℍℎℐℑℒℓℕℤΩℨKÅℬℭℯℰℱℹℴ
109
4 | | import numpy as CƐgHHHhIILlNZΩZKÅBCeEFio
11-
5 | |
12-
6 | | h = 2 * π *
13-
| |_^ I001
10+
5 | |
11+
| |__^ I001
12+
6 | h = 2 * π *
1413
|
1514
= help: Organize imports
1615

0 commit comments

Comments
 (0)