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.
This commit is contained in:
Andrew Gallant 2025-01-08 09:58:31 -05:00 committed by Andrew Gallant
parent 79e71cbbcd
commit eed0595b18
17 changed files with 263 additions and 278 deletions

View File

@ -1,6 +1,5 @@
---
source: crates/ruff_linter/src/rules/isort/mod.rs
snapshot_kind: text
---
lines_after_imports.pyi:1:1: I001 [*] Import block is un-sorted or un-formatted
|
@ -16,8 +15,8 @@ lines_after_imports.pyi:1:1: I001 [*] Import block is un-sorted or un-formatted
10 | |
11 | |
12 | |
13 | | class Thing(object):
| |_^ I001
| |__^ I001
13 | class Thing(object):
14 | name: str
15 | def __init__(self, name: str):
|

View File

@ -1,6 +1,5 @@
---
source: crates/ruff_linter/src/rules/isort/mod.rs
snapshot_kind: text
---
lines_after_imports_func_after.py:1:1: I001 [*] Import block is un-sorted or un-formatted
|
@ -24,8 +23,8 @@ lines_after_imports_func_after.py:1:1: I001 [*] Import block is un-sorted or un-
18 | |
19 | |
20 | |
21 | | def main():
| |_^ I001
| |__^ I001
21 | def main():
22 | my_local_folder_object.get()
|
= help: Organize imports

View File

@ -1,6 +1,5 @@
---
source: crates/ruff_linter/src/rules/isort/mod.rs
snapshot_kind: text
---
lines_after_imports.pyi:1:1: I001 [*] Import block is un-sorted or un-formatted
|
@ -16,8 +15,8 @@ lines_after_imports.pyi:1:1: I001 [*] Import block is un-sorted or un-formatted
10 | |
11 | |
12 | |
13 | | class Thing(object):
| |_^ I001
| |__^ I001
13 | class Thing(object):
14 | name: str
15 | def __init__(self, name: str):
|

View File

@ -1,6 +1,5 @@
---
source: crates/ruff_linter/src/rules/isort/mod.rs
snapshot_kind: text
---
lines_after_imports_func_after.py:1:1: I001 [*] Import block is un-sorted or un-formatted
|
@ -24,8 +23,8 @@ lines_after_imports_func_after.py:1:1: I001 [*] Import block is un-sorted or un-
18 | |
19 | |
20 | |
21 | | def main():
| |_^ I001
| |__^ I001
21 | def main():
22 | my_local_folder_object.get()
|
= help: Organize imports

View File

@ -1,6 +1,5 @@
---
source: crates/ruff_linter/src/rules/isort/mod.rs
snapshot_kind: text
---
main_first_party.py:1:1: I001 [*] Import block is un-sorted or un-formatted
|
@ -11,8 +10,8 @@ main_first_party.py:1:1: I001 [*] Import block is un-sorted or un-formatted
5 | |
6 | | import first_party
7 | |
8 | | os.a
| |_^ I001
| |__^ I001
8 | os.a
9 | third_party.a
10 | __main__.a
|

View File

@ -1,6 +1,5 @@
---
source: crates/ruff_linter/src/rules/isort/mod.rs
snapshot_kind: text
---
trailing_comment.py:8:1: I001 [*] Import block is un-sorted or un-formatted
|
@ -13,8 +12,8 @@ trailing_comment.py:8:1: I001 [*] Import block is un-sorted or un-formatted
12 | | bar
13 | | )# some comment
14 | |
15 | | pass
| |_^ I001
| |__^ I001
15 | pass
16 |
17 | from foo import (
|
@ -49,8 +48,8 @@ trailing_comment.py:17:1: I001 [*] Import block is un-sorted or un-formatted
23 | | # some comment
24 | | )
25 | |
26 | | pass
| |_^ I001
| |__^ I001
26 | pass
27 |
28 | from mylib import (
|
@ -77,8 +76,8 @@ trailing_comment.py:35:1: I001 [*] Import block is un-sorted or un-formatted
37 | | # some comment
38 | | )
39 | |
40 | | pass
| |_^ I001
| |__^ I001
40 | pass
41 |
42 | from mylib import (
|
@ -106,8 +105,8 @@ trailing_comment.py:42:1: I001 [*] Import block is un-sorted or un-formatted
44 | | MyClient
45 | | )
46 | |
47 | | pass
| |_^ I001
| |__^ I001
47 | pass
48 |
49 | # a
|
@ -134,6 +133,7 @@ trailing_comment.py:50:1: I001 [*] Import block is un-sorted or un-formatted
52 | | MyClient # d
53 | | # e
54 | | ) # f
| |______^ I001
|
= help: Organize imports

View File

@ -1,6 +1,5 @@
---
source: crates/ruff_linter/src/rules/isort/mod.rs
snapshot_kind: text
---
unicode.py:1:1: I001 [*] Import block is un-sorted or un-formatted
|
@ -9,8 +8,8 @@ unicode.py:1:1: I001 [*] Import block is un-sorted or un-formatted
3 | | import numpy as ℂℇℊℋℌℍℎℐℑℒℓℕℤΩℨKÅℬℭℯℰℱℹℴ
4 | | import numpy as CƐgHHHhIILlNZΩZKÅBCeEFio
5 | |
6 | | h = 2 * π * ℏ
| |_^ I001
| |__^ I001
6 | h = 2 * π * ℏ
|
= help: Organize imports

View File

@ -1,6 +1,5 @@
---
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs
snapshot_kind: text
---
E30_isort.py:1:1: I001 [*] Import block is un-sorted or un-formatted
|
@ -11,8 +10,8 @@ E30_isort.py:1:1: I001 [*] Import block is un-sorted or un-formatted
5 | | from typing import Any, Sequence
6 | |
7 | |
8 | | class MissingCommand(TypeError): ... # noqa: N818
| |_^ I001
| |__^ I001
8 | class MissingCommand(TypeError): ... # noqa: N818
|
= help: Organize imports
@ -53,8 +52,8 @@ E30_isort.py:26:1: I001 [*] Import block is un-sorted or un-formatted
28 | |
29 | |
30 | | from typing_extensions import TypeAlias
31 | |
| |_^ I001
| |____________________________________________^ I001
31 |
32 |
33 | abcd.foo()
|
@ -112,8 +111,8 @@ E30_isort.py:60:1: I001 [*] Import block is un-sorted or un-formatted
|
60 | / from typing import Any, Sequence
61 | |
62 | | class MissingCommand(TypeError): ... # noqa: N818
| |_^ I001
| |__^ I001
62 | class MissingCommand(TypeError): ... # noqa: N818
|
= help: Organize imports

View File

@ -1,6 +1,5 @@
---
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs
snapshot_kind: text
---
E30_isort.py:1:1: I001 [*] Import block is un-sorted or un-formatted
|
@ -11,8 +10,8 @@ E30_isort.py:1:1: I001 [*] Import block is un-sorted or un-formatted
5 | | from typing import Any, Sequence
6 | |
7 | |
8 | | class MissingCommand(TypeError): ... # noqa: N818
| |_^ I001
| |__^ I001
8 | class MissingCommand(TypeError): ... # noqa: N818
|
= help: Organize imports
@ -56,8 +55,8 @@ E30_isort.py:26:1: I001 [*] Import block is un-sorted or un-formatted
28 | |
29 | |
30 | | from typing_extensions import TypeAlias
31 | |
| |_^ I001
| |____________________________________________^ I001
31 |
32 |
33 | abcd.foo()
|
@ -115,8 +114,8 @@ E30_isort.py:60:1: I001 [*] Import block is un-sorted or un-formatted
|
60 | / from typing import Any, Sequence
61 | |
62 | | class MissingCommand(TypeError): ... # noqa: N818
| |_^ I001
| |__^ I001
62 | class MissingCommand(TypeError): ... # noqa: N818
|
= help: Organize imports

View File

@ -1,6 +1,5 @@
---
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs
snapshot_kind: text
---
E30_isort.py:1:1: I001 [*] Import block is un-sorted or un-formatted
|
@ -11,8 +10,8 @@ E30_isort.py:1:1: I001 [*] Import block is un-sorted or un-formatted
5 | | from typing import Any, Sequence
6 | |
7 | |
8 | | class MissingCommand(TypeError): ... # noqa: N818
| |_^ I001
| |__^ I001
8 | class MissingCommand(TypeError): ... # noqa: N818
|
= help: Organize imports
@ -55,8 +54,8 @@ E30_isort.py:26:1: I001 [*] Import block is un-sorted or un-formatted
28 | |
29 | |
30 | | from typing_extensions import TypeAlias
31 | |
| |_^ I001
| |____________________________________________^ I001
31 |
32 |
33 | abcd.foo()
|

View File

@ -1,6 +1,5 @@
---
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs
snapshot_kind: text
---
E30_isort.py:1:1: I001 [*] Import block is un-sorted or un-formatted
|
@ -11,8 +10,8 @@ E30_isort.py:1:1: I001 [*] Import block is un-sorted or un-formatted
5 | | from typing import Any, Sequence
6 | |
7 | |
8 | | class MissingCommand(TypeError): ... # noqa: N818
| |_^ I001
| |__^ I001
8 | class MissingCommand(TypeError): ... # noqa: N818
|
= help: Organize imports
@ -75,8 +74,8 @@ E30_isort.py:26:1: I001 [*] Import block is un-sorted or un-formatted
28 | |
29 | |
30 | | from typing_extensions import TypeAlias
31 | |
| |_^ I001
| |____________________________________________^ I001
31 |
32 |
33 | abcd.foo()
|
@ -134,8 +133,8 @@ E30_isort.py:60:1: I001 [*] Import block is un-sorted or un-formatted
|
60 | / from typing import Any, Sequence
61 | |
62 | | class MissingCommand(TypeError): ... # noqa: N818
| |_^ I001
| |__^ I001
62 | class MissingCommand(TypeError): ... # noqa: N818
|
= help: Organize imports

View File

@ -1,6 +1,5 @@
---
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs
snapshot_kind: text
---
E30_isort.pyi:1:1: I001 [*] Import block is un-sorted or un-formatted
|
@ -11,8 +10,8 @@ E30_isort.pyi:1:1: I001 [*] Import block is un-sorted or un-formatted
5 | | from typing import Any, Sequence
6 | |
7 | |
8 | | class MissingCommand(TypeError): ... # noqa: N818
| |_^ I001
| |__^ I001
8 | class MissingCommand(TypeError): ... # noqa: N818
|
= help: Organize imports
@ -120,8 +119,8 @@ E30_isort.pyi:26:1: I001 [*] Import block is un-sorted or un-formatted
28 | |
29 | |
30 | | from typing_extensions import TypeAlias
31 | |
| |_^ I001
| |____________________________________________^ I001
31 |
32 |
33 | abcd.foo()
|

View File

@ -8,8 +8,8 @@ W391.ipynb:5:1: W391 [*] Too many newlines at end of cell
5 | /
6 | |
7 | |
8 | |
| |_^ W391
| |__^ W391
8 |
9 | 1 + 1
10 | # a comment
|
@ -34,8 +34,8 @@ W391.ipynb:11:1: W391 [*] Too many newlines at end of cell
12 | |
13 | |
14 | |
15 | |
| |_^ W391
| |__^ W391
15 |
16 | 1+1
|
= help: Remove trailing newlines
@ -59,8 +59,8 @@ W391.ipynb:17:1: W391 [*] Too many newlines at end of cell
18 | |
19 | |
20 | |
21 | |
| |_^ W391
| |__^ W391
21 |
|
= help: Remove trailing newlines

View File

@ -1,6 +1,5 @@
---
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs
snapshot_kind: text
---
E30_isort.py:1:1: I001 [*] Import block is un-sorted or un-formatted
|
@ -11,8 +10,8 @@ E30_isort.py:1:1: I001 [*] Import block is un-sorted or un-formatted
5 | | from typing import Any, Sequence
6 | |
7 | |
8 | | class MissingCommand(TypeError): ... # noqa: N818
| |_^ I001
| |__^ I001
8 | class MissingCommand(TypeError): ... # noqa: N818
|
= help: Organize imports
@ -67,8 +66,8 @@ E30_isort.py:26:1: I001 [*] Import block is un-sorted or un-formatted
28 | |
29 | |
30 | | from typing_extensions import TypeAlias
31 | |
| |_^ I001
| |____________________________________________^ I001
31 |
32 |
33 | abcd.foo()
|
@ -123,8 +122,8 @@ E30_isort.py:60:1: I001 [*] Import block is un-sorted or un-formatted
|
60 | / from typing import Any, Sequence
61 | |
62 | | class MissingCommand(TypeError): ... # noqa: N818
| |_^ I001
| |__^ I001
62 | class MissingCommand(TypeError): ... # noqa: N818
|
= help: Organize imports

View File

@ -1,6 +1,5 @@
---
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs
snapshot_kind: text
---
E30_isort.py:1:1: I001 [*] Import block is un-sorted or un-formatted
|
@ -11,8 +10,8 @@ E30_isort.py:1:1: I001 [*] Import block is un-sorted or un-formatted
5 | | from typing import Any, Sequence
6 | |
7 | |
8 | | class MissingCommand(TypeError): ... # noqa: N818
| |_^ I001
| |__^ I001
8 | class MissingCommand(TypeError): ... # noqa: N818
|
= help: Organize imports
@ -87,8 +86,8 @@ E30_isort.py:26:1: I001 [*] Import block is un-sorted or un-formatted
28 | |
29 | |
30 | | from typing_extensions import TypeAlias
31 | |
| |_^ I001
| |____________________________________________^ I001
31 |
32 |
33 | abcd.foo()
|
@ -143,8 +142,8 @@ E30_isort.py:60:1: I001 [*] Import block is un-sorted or un-formatted
|
60 | / from typing import Any, Sequence
61 | |
62 | | class MissingCommand(TypeError): ... # noqa: N818
| |_^ I001
| |__^ I001
62 | class MissingCommand(TypeError): ... # noqa: N818
|
= help: Organize imports

View File

@ -1,6 +1,5 @@
---
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs
snapshot_kind: text
---
E30_isort.py:1:1: I001 [*] Import block is un-sorted or un-formatted
|
@ -11,8 +10,8 @@ E30_isort.py:1:1: I001 [*] Import block is un-sorted or un-formatted
5 | | from typing import Any, Sequence
6 | |
7 | |
8 | | class MissingCommand(TypeError): ... # noqa: N818
| |_^ I001
| |__^ I001
8 | class MissingCommand(TypeError): ... # noqa: N818
|
= help: Organize imports
@ -85,8 +84,8 @@ E30_isort.py:26:1: I001 [*] Import block is un-sorted or un-formatted
28 | |
29 | |
30 | | from typing_extensions import TypeAlias
31 | |
| |_^ I001
| |____________________________________________^ I001
31 |
32 |
33 | abcd.foo()
|

View File

@ -1,6 +1,5 @@
---
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs
snapshot_kind: text
---
E30_isort.py:1:1: I001 [*] Import block is un-sorted or un-formatted
|
@ -11,8 +10,8 @@ E30_isort.py:1:1: I001 [*] Import block is un-sorted or un-formatted
5 | | from typing import Any, Sequence
6 | |
7 | |
8 | | class MissingCommand(TypeError): ... # noqa: N818
| |_^ I001
| |__^ I001
8 | class MissingCommand(TypeError): ... # noqa: N818
|
= help: Organize imports
@ -56,8 +55,8 @@ E30_isort.py:26:1: I001 [*] Import block is un-sorted or un-formatted
28 | |
29 | |
30 | | from typing_extensions import TypeAlias
31 | |
| |_^ I001
| |____________________________________________^ I001
31 |
32 |
33 | abcd.foo()
|
@ -95,8 +94,8 @@ E30_isort.py:60:1: I001 [*] Import block is un-sorted or un-formatted
|
60 | / from typing import Any, Sequence
61 | |
62 | | class MissingCommand(TypeError): ... # noqa: N818
| |_^ I001
| |__^ I001
62 | class MissingCommand(TypeError): ... # noqa: N818
|
= help: Organize imports