Skip to content

Commit 7561101

Browse files
authored
Remove tabs using the default expand tabs behaviour. #60 (#62)
1 parent e079e43 commit 7561101

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ repos:
3333
- id: check-executables-have-shebangs
3434
- id: check-shebang-scripts-are-executable
3535
- repo: https://github.com/asottile/pyupgrade
36-
rev: v2.32.1
36+
rev: v2.37.3
3737
hooks:
3838
- id: pyupgrade
3939
args:
@@ -64,7 +64,7 @@ repos:
6464
- id: python-bandit-vulnerability-check
6565
args: [--skip, 'B101', --recursive, .]
6666
- repo: https://github.com/pre-commit/mirrors-mypy
67-
rev: v0.961
67+
rev: v0.971
6868
hooks:
6969
- id: mypy
7070
args:

pre_commit_hooks/remove_tabs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def contains_tabs(filename):
88
def removes_tabs_in_file(filename, whitespaces_count):
99
with open(filename, mode='rb') as file_processed:
1010
lines = file_processed.readlines()
11-
lines = [line.replace(b'\t', b' ' * whitespaces_count) for line in lines]
11+
lines = [line.expandtabs(whitespaces_count) for line in lines]
1212
with open(filename, mode='wb') as file_processed:
1313
for line in lines:
1414
file_processed.write(line)

tests/remove_tabs_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
(
99
('foo \t\nbar', 'foo \nbar'),
1010
('bar\n\tbaz\n', 'bar\n baz\n'),
11+
('No leading\ttab\n\tleading\ttab\n \tSpace then\tTab\n', 'No leading tab\n leading tab\n Space then Tab\n'),
12+
('Tabs\tbetween\tevery\tword\tin\tthe\tline.\n', 'Tabs between every word in the line.\n',),
13+
('Space \tthen \ttab \tbetween \tevery \tword \tin \tthe \tline.',
14+
'Space then tab between every word in the line.'),
1115
),
1216
)
1317
def test_remove_tabs(input_s, expected, tmpdir):

0 commit comments

Comments
 (0)