Skip to content

Commit b941d0e

Browse files
author
Daniel Gallagher
committed
Respond to review feedback
1 parent 4af7451 commit b941d0e

File tree

4 files changed

+9
-14
lines changed

4 files changed

+9
-14
lines changed

.pre-commit-hooks.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
description: Sort the lines in specified files (defaults to alphabetical). You must provide list of target files as input in your .pre-commit-config.yaml file.
111111
entry: file-contents-sorter
112112
language: python
113-
files: ''
113+
files: '^$'
114114
- id: fix-encoding-pragma
115115
name: Fix python encoding pragma
116116
language: python

pre_commit_hooks/file_contents_sorter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919

2020
def sort_file_contents(f):
21-
before = [line for line in f]
21+
before = list(f)
2222
after = sorted(before)
2323

2424
before_string = b''.join(before)

requirements-dev.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
coverage
44
flake8
5-
ipdb
65
mock
76
pre-commit
87
pytest

tests/file_contents_sorter_test.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,17 @@
66
from pre_commit_hooks.file_contents_sorter import PASS
77

88

9-
def _n(*strs):
10-
return b'\n'.join(strs) + b'\n'
11-
12-
139
# Input, expected return value, expected output
1410
TESTS = (
1511
(b'', PASS, b''),
16-
(_n(b'lonesome'), PASS, _n(b'lonesome')),
12+
(b'lonesome\n', PASS, b'lonesome\n'),
1713
(b'missing_newline', PASS, b'missing_newline'),
18-
(_n(b'alpha', b'beta'), PASS, _n(b'alpha', b'beta')),
19-
(_n(b'beta', b'alpha'), FAIL, _n(b'alpha', b'beta')),
20-
(_n(b'C', b'c'), PASS, _n(b'C', b'c')),
21-
(_n(b'c', b'C'), FAIL, _n(b'C', b'c')),
22-
(_n(b'mag ical ', b' tre vor'), FAIL, _n(b' tre vor', b'mag ical ')),
23-
(_n(b'@', b'-', b'_', b'#'), FAIL, _n(b'#', b'-', b'@', b'_')),
14+
(b'alpha\nbeta\n', PASS, b'alpha\nbeta\n'),
15+
(b'beta\nalpha\n', FAIL, b'alpha\nbeta\n'),
16+
(b'C\nc\n', PASS, b'C\nc\n'),
17+
(b'c\nC\n', FAIL, b'C\nc\n'),
18+
(b'mag ical \n tre vor\n', FAIL, b' tre vor\nmag ical \n'),
19+
(b'@\n-\n_\n#\n', FAIL, b'#\n-\n@\n_\n'),
2420
)
2521

2622

0 commit comments

Comments
 (0)