Skip to content

Commit 1199141

Browse files
committed
Fix whitespace insensitive check triggering on tabs
1 parent 17746ba commit 1199141

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

isort/format.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ def ask_whether_to_apply_changes_to_file(file_path: str) -> bool:
8686

8787

8888
def remove_whitespace(content: str, line_separator: str = "\n") -> str:
89-
content = content.replace(line_separator, "").replace(" ", "").replace("\x0c", "")
89+
content = (
90+
content.replace(line_separator, "").replace(" ", "").replace("\t", "").replace("\f", "")
91+
)
9092
return content
9193

9294

tests/unit/test_isort.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4211,9 +4211,13 @@ def test_to_ensure_empty_line_not_added_to_file_start_issue_889() -> None:
42114211
assert isort.code(test_input) == test_input
42124212

42134213

4214-
def test_to_ensure_correctly_handling_of_whitespace_only_issue_811(capsys) -> None:
4215-
test_input = 'import os\nimport sys\n\n\x0c\ndef my_function():\n print("hi")\n'
4216-
isort.code(test_input, ignore_whitespace=True)
4214+
@pytest.mark.parametrize("ws", ["", " ", "\t", "\f", "\n"])
4215+
def test_to_ensure_correctly_handling_of_whitespace_only_issue_811(
4216+
ws: str,
4217+
capsys: pytest.CaptureFixture[str],
4218+
) -> None:
4219+
test_input = f'import os\nimport sys\n\n{ws}\ndef my_function():\n print("hi")\n'
4220+
assert isort.check_code(test_input, ignore_whitespace=True)
42174221
out, err = capsys.readouterr()
42184222
assert out == ""
42194223
assert err == ""

0 commit comments

Comments
 (0)