From 79e71cbbcd45f13f78737e7e732e0f518e3b3a0b Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Tue, 7 Jan 2025 15:09:42 -0500 Subject: [PATCH] test: another line terminator bug fix I believe this case is different from the last in that it happens when the end of a *multi-line* annotation occurs after a line terminator. Previously, the diagnostic would render on the next line, which is definitely a bit weird. This new update renders it at the end of the line the annotation ends on. In some cases, the annotation was previously rendered to point at source lines below where the error occurred, which is probably pretty confusing. --- ...__isort__tests__insert_empty_lines.py.snap | 21 ++++----- ..._isort__tests__insert_empty_lines.pyi.snap | 15 +++--- ...s__lines_after_imports_class_after.py.snap | 13 +++-- ...ts_lines_after_imports_class_after.py.snap | 13 +++-- ...r__rules__isort__tests__match_case.py.snap | 6 +-- ...isort__tests__preserve_indentation.py.snap | 6 +-- ...er__rules__isort__tests__two_space.py.snap | 7 ++- ...sts__PLE2502_bidirectional_unicode.py.snap | 47 +++++++++---------- ...linter__linter__tests__import_sorting.snap | 18 +++---- 9 files changed, 70 insertions(+), 76 deletions(-) diff --git a/crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__insert_empty_lines.py.snap b/crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__insert_empty_lines.py.snap index 9690dc9537bf8..fa92501dd7055 100644 --- a/crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__insert_empty_lines.py.snap +++ b/crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__insert_empty_lines.py.snap @@ -1,13 +1,12 @@ --- source: crates/ruff_linter/src/rules/isort/mod.rs -snapshot_kind: text --- insert_empty_lines.py:1:1: I001 [*] Import block is un-sorted or un-formatted | 1 | / import a 2 | | import b -3 | | x = 1 - | |_^ I001 + | |_________^ I001 +3 | x = 1 4 | import os 5 | import sys | @@ -27,8 +26,8 @@ insert_empty_lines.py:4:1: I001 [*] Import block is un-sorted or un-formatted 3 | x = 1 4 | / import os 5 | | import sys -6 | | def f(): - | |_^ I001 + | |___________^ I001 +6 | def f(): 7 | pass 8 | if True: | @@ -50,9 +49,9 @@ insert_empty_lines.py:14:1: I001 [*] Import block is un-sorted or un-formatted 13 | y = 1 14 | / import os 15 | | import sys -16 | | """Docstring""" - | |_^ I001 -17 | + | |___________^ I001 +16 | """Docstring""" +17 | 18 | if True: | = help: Organize imports @@ -69,9 +68,9 @@ insert_empty_lines.py:14:1: I001 [*] Import block is un-sorted or un-formatted insert_empty_lines.py:52:1: I001 [*] Import block is un-sorted or un-formatted | 52 | / import os -53 | | -54 | | # Comment goes here. - | |_^ I001 +53 | | + | |__^ I001 +54 | # Comment goes here. 55 | def f(): 56 | pass | diff --git a/crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__insert_empty_lines.pyi.snap b/crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__insert_empty_lines.pyi.snap index a9a450c2b39e2..7559c9bfb3455 100644 --- a/crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__insert_empty_lines.pyi.snap +++ b/crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__insert_empty_lines.pyi.snap @@ -1,13 +1,12 @@ --- source: crates/ruff_linter/src/rules/isort/mod.rs -snapshot_kind: text --- insert_empty_lines.pyi:1:1: I001 [*] Import block is un-sorted or un-formatted | 1 | / import a 2 | | import b -3 | | x = 1 - | |_^ I001 + | |_________^ I001 +3 | x = 1 4 | import os 5 | import sys | @@ -27,8 +26,8 @@ insert_empty_lines.pyi:4:1: I001 [*] Import block is un-sorted or un-formatted 3 | x = 1 4 | / import os 5 | | import sys -6 | | def f(): - | |_^ I001 + | |___________^ I001 +6 | def f(): 7 | pass 8 | if True: | @@ -49,9 +48,9 @@ insert_empty_lines.pyi:14:1: I001 [*] Import block is un-sorted or un-formatted 13 | y = 1 14 | / import os 15 | | import sys -16 | | """Docstring""" - | |_^ I001 -17 | + | |___________^ I001 +16 | """Docstring""" +17 | 18 | if True: | = help: Organize imports diff --git a/crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__lines_after_imports_class_after.py.snap b/crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__lines_after_imports_class_after.py.snap index 6b12c68c08f4a..d0524b5e0c7d8 100644 --- a/crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__lines_after_imports_class_after.py.snap +++ b/crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__lines_after_imports_class_after.py.snap @@ -1,20 +1,19 @@ --- source: crates/ruff_linter/src/rules/isort/mod.rs -snapshot_kind: text --- lines_after_imports_class_after.py:1:1: I001 [*] Import block is un-sorted or un-formatted | 1 | / from __future__ import annotations - 2 | | + 2 | | 3 | | from typing import Any - 4 | | + 4 | | 5 | | from requests import Session - 6 | | + 6 | | 7 | | from my_first_party import my_first_party_object - 8 | | + 8 | | 9 | | from . import my_local_folder_object -10 | | class Thing(object): - | |_^ I001 + | |_____________________________________^ I001 +10 | class Thing(object): 11 | name: str 12 | def __init__(self, name: str): | diff --git a/crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__lines_after_imports_lines_after_imports_class_after.py.snap b/crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__lines_after_imports_lines_after_imports_class_after.py.snap index 7a01afa39704f..19064fcfc5ee2 100644 --- a/crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__lines_after_imports_lines_after_imports_class_after.py.snap +++ b/crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__lines_after_imports_lines_after_imports_class_after.py.snap @@ -1,20 +1,19 @@ --- source: crates/ruff_linter/src/rules/isort/mod.rs -snapshot_kind: text --- lines_after_imports_class_after.py:1:1: I001 [*] Import block is un-sorted or un-formatted | 1 | / from __future__ import annotations - 2 | | + 2 | | 3 | | from typing import Any - 4 | | + 4 | | 5 | | from requests import Session - 6 | | + 6 | | 7 | | from my_first_party import my_first_party_object - 8 | | + 8 | | 9 | | from . import my_local_folder_object -10 | | class Thing(object): - | |_^ I001 + | |_____________________________________^ I001 +10 | class Thing(object): 11 | name: str 12 | def __init__(self, name: str): | diff --git a/crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__match_case.py.snap b/crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__match_case.py.snap index 67da838e16db8..253619595f106 100644 --- a/crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__match_case.py.snap +++ b/crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__match_case.py.snap @@ -1,6 +1,5 @@ --- source: crates/ruff_linter/src/rules/isort/mod.rs -snapshot_kind: text --- match_case.py:3:1: I001 [*] Import block is un-sorted or un-formatted | @@ -8,8 +7,8 @@ match_case.py:3:1: I001 [*] Import block is un-sorted or un-formatted 2 | case 1: 3 | / import sys 4 | | import os -5 | | case 2: - | |_^ I001 + | |__________________^ I001 +5 | case 2: 6 | import collections 7 | import abc | @@ -31,6 +30,7 @@ match_case.py:6:1: I001 [*] Import block is un-sorted or un-formatted 5 | case 2: 6 | / import collections 7 | | import abc + | |___________________^ I001 | = help: Organize imports diff --git a/crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__preserve_indentation.py.snap b/crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__preserve_indentation.py.snap index 50b7f816b7aae..da983d3af7b83 100644 --- a/crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__preserve_indentation.py.snap +++ b/crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__preserve_indentation.py.snap @@ -1,14 +1,13 @@ --- source: crates/ruff_linter/src/rules/isort/mod.rs -snapshot_kind: text --- preserve_indentation.py:2:1: I001 [*] Import block is un-sorted or un-formatted | 1 | if True: 2 | / import sys 3 | | import os -4 | | else: - | |_^ I001 + | |______________^ I001 +4 | else: 5 | import sys 6 | import os | @@ -29,6 +28,7 @@ preserve_indentation.py:5:1: I001 [*] Import block is un-sorted or un-formatted 4 | else: 5 | / import sys 6 | | import os + | |______________^ I001 | = help: Organize imports diff --git a/crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__two_space.py.snap b/crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__two_space.py.snap index ed6afa3a609cd..43598e088102d 100644 --- a/crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__two_space.py.snap +++ b/crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__two_space.py.snap @@ -1,6 +1,5 @@ --- source: crates/ruff_linter/src/rules/isort/mod.rs -snapshot_kind: text --- two_space.py:2:1: I001 [*] Import block is un-sorted or un-formatted | @@ -12,9 +11,9 @@ two_space.py:2:1: I001 [*] Import block is un-sorted or un-formatted 6 | | nan, 7 | | pi, 8 | | ) - 9 | | -10 | | del sin, cos, tan, pi, nan - | |_^ I001 + 9 | | + | |__^ I001 +10 | del sin, cos, tan, pi, nan | = help: Organize imports diff --git a/crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLE2502_bidirectional_unicode.py.snap b/crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLE2502_bidirectional_unicode.py.snap index abf55695ccd2d..8d11a86388ed4 100644 --- a/crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLE2502_bidirectional_unicode.py.snap +++ b/crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLE2502_bidirectional_unicode.py.snap @@ -1,42 +1,41 @@ --- source: crates/ruff_linter/src/rules/pylint/mod.rs -snapshot_kind: text --- bidirectional_unicode.py:2:1: PLE2502 Contains control characters that can permit obfuscated code | -1 | # E2502 -2 | / print("שלום‬") -3 | | - | |_^ PLE2502 -4 | # E2502 -5 | example = "x‏" * 100 # "‏x" is assigned +1 | # E2502 +2 | print("שלום") + | ^^^^^^^^^^^^^ PLE2502 +3 | +4 | # E2502 +5 | example = "x‏" * 100 # "‏x" is assigned | bidirectional_unicode.py:5:1: PLE2502 Contains control characters that can permit obfuscated code | -4 | # E2502 -5 | / example = "x‏" * 100 # "‏x" is assigned -6 | | - | |_^ PLE2502 -7 | # E2502 -8 | if access_level != "none‮⁦": # Check if admin ⁩⁦' and access_level != 'user +4 | # E2502 +5 | example = "x‏" * 100 # "‏x" is assigned + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLE2502 +6 | +7 | # E2502 +8 | if access_level != "none": # Check if admin ' and access_level != 'user | bidirectional_unicode.py:8:1: PLE2502 Contains control characters that can permit obfuscated code | -7 | # E2502 -8 | / if access_level != "none‮⁦": # Check if admin ⁩⁦' and access_level != 'user -9 | | print("You are an admin.") - | |_^ PLE2502 +7 | # E2502 +8 | if access_level != "none": # Check if admin ' and access_level != 'user + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLE2502 +9 | print("You are an admin.") | bidirectional_unicode.py:14:1: PLE2502 Contains control characters that can permit obfuscated code | -12 | # E2502 -13 | def subtract_funds(account: str, amount: int): -14 | / """Subtract funds from bank account then ⁧""" -15 | | return - | |_^ PLE2502 -16 | bank[account] -= amount -17 | return +12 | # E2502 +13 | def subtract_funds(account: str, amount: int): +14 | """Subtract funds from bank account then """ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLE2502 +15 | return +16 | bank[account] -= amount +17 | return | diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__import_sorting.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__import_sorting.snap index 7f726c2783a91..59672d19b8bc5 100644 --- a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__import_sorting.snap +++ b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__import_sorting.snap @@ -1,14 +1,13 @@ --- source: crates/ruff_linter/src/linter.rs -snapshot_kind: text --- isort.ipynb:cell 1:1:1: I001 [*] Import block is un-sorted or un-formatted | 1 | / from pathlib import Path 2 | | import random 3 | | import math -4 | | from typing import Any - | |_^ I001 + | |____________^ I001 +4 | from typing import Any 5 | import collections 6 | # Newline should be added here | @@ -28,8 +27,8 @@ isort.ipynb:cell 2:1:1: I001 [*] Import block is un-sorted or un-formatted | 1 | / from typing import Any 2 | | import collections -3 | | # Newline should be added here - | |_^ I001 + | |___________________^ I001 +3 | # Newline should be added here 4 | def foo(): 5 | pass | @@ -52,9 +51,9 @@ isort.ipynb:cell 3:1:1: I001 [*] Import block is un-sorted or un-formatted | 1 | / from pathlib import Path 2 | | import sys -3 | | -4 | | %matplotlib \ - | |_^ I001 +3 | | + | |__^ I001 +4 | %matplotlib \ 5 | --inline | = help: Organize imports @@ -73,9 +72,10 @@ isort.ipynb:cell 3:1:1: I001 [*] Import block is un-sorted or un-formatted isort.ipynb:cell 3:7:1: I001 [*] Import block is un-sorted or un-formatted | 5 | --inline -6 | +6 | 7 | / import math 8 | | import abc + | |___________^ I001 | = help: Organize imports