Skip to content

Commit

Permalink
Remove tabs using the default expand tabs behaviour. #60 (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
GadgetSteve committed Jan 21, 2023
1 parent e079e43 commit 7561101
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pre_commit_hooks/remove_tabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions tests/remove_tabs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 7561101

Please sign in to comment.