diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9d18e36..1d7e726 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -33,7 +33,7 @@ repos: - id: check-executables-have-shebangs - id: check-shebang-scripts-are-executable - repo: https://github.com/asottile/pyupgrade - rev: v2.32.1 + rev: v2.37.3 hooks: - id: pyupgrade args: @@ -64,7 +64,7 @@ repos: - id: python-bandit-vulnerability-check args: [--skip, 'B101', --recursive, .] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.961 + rev: v0.971 hooks: - id: mypy args: diff --git a/pre_commit_hooks/remove_tabs.py b/pre_commit_hooks/remove_tabs.py index f394b6e..397b089 100644 --- a/pre_commit_hooks/remove_tabs.py +++ b/pre_commit_hooks/remove_tabs.py @@ -8,7 +8,7 @@ def contains_tabs(filename): def removes_tabs_in_file(filename, whitespaces_count): with open(filename, mode='rb') as file_processed: lines = file_processed.readlines() - lines = [line.replace(b'\t', b' ' * whitespaces_count) for line in lines] + lines = [line.expandtabs(whitespaces_count) for line in lines] with open(filename, mode='wb') as file_processed: for line in lines: file_processed.write(line) diff --git a/tests/remove_tabs_test.py b/tests/remove_tabs_test.py index ac87d1e..3dca9e1 100644 --- a/tests/remove_tabs_test.py +++ b/tests/remove_tabs_test.py @@ -8,6 +8,10 @@ ( ('foo \t\nbar', 'foo \nbar'), ('bar\n\tbaz\n', 'bar\n baz\n'), + ('No leading\ttab\n\tleading\ttab\n \tSpace then\tTab\n', 'No leading tab\n leading tab\n Space then Tab\n'), + ('Tabs\tbetween\tevery\tword\tin\tthe\tline.\n', 'Tabs between every word in the line.\n',), + ('Space \tthen \ttab \tbetween \tevery \tword \tin \tthe \tline.', + 'Space then tab between every word in the line.'), ), ) def test_remove_tabs(input_s, expected, tmpdir):