Skip to content

Commit 77bc665

Browse files
authored
Merge pull request #2437 from robsdedude/fix/ws-insensitive-check
Fix whitespace insensitive check triggering on tabs
2 parents da99709 + 1199141 commit 77bc665

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
@@ -4222,9 +4222,13 @@ def test_to_ensure_empty_line_not_added_to_file_start_issue_889() -> None:
42224222
assert isort.code(test_input) == test_input
42234223

42244224

4225-
def test_to_ensure_correctly_handling_of_whitespace_only_issue_811(capsys) -> None:
4226-
test_input = 'import os\nimport sys\n\n\x0c\ndef my_function():\n print("hi")\n'
4227-
isort.code(test_input, ignore_whitespace=True)
4225+
@pytest.mark.parametrize("ws", ["", " ", "\t", "\f", "\n"])
4226+
def test_to_ensure_correctly_handling_of_whitespace_only_issue_811(
4227+
ws: str,
4228+
capsys: pytest.CaptureFixture[str],
4229+
) -> None:
4230+
test_input = f'import os\nimport sys\n\n{ws}\ndef my_function():\n print("hi")\n'
4231+
assert isort.check_code(test_input, ignore_whitespace=True)
42284232
out, err = capsys.readouterr()
42294233
assert out == ""
42304234
assert err == ""

0 commit comments

Comments
 (0)