Respond to review feedback
diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index d501d50..eea7bed 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml
@@ -110,7 +110,7 @@ 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. entry: file-contents-sorter language: python - files: '' + files: '^$' - id: fix-encoding-pragma name: Fix python encoding pragma language: python
diff --git a/pre_commit_hooks/file_contents_sorter.py b/pre_commit_hooks/file_contents_sorter.py index 06c6d3a..e01eb8c 100644 --- a/pre_commit_hooks/file_contents_sorter.py +++ b/pre_commit_hooks/file_contents_sorter.py
@@ -18,7 +18,7 @@ def sort_file_contents(f): - before = [line for line in f] + before = list(f) after = sorted(before) before_string = b''.join(before)
diff --git a/requirements-dev.txt b/requirements-dev.txt index 4070e66..2922ef5 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt
@@ -2,7 +2,6 @@ coverage flake8 -ipdb mock pre-commit pytest
diff --git a/tests/file_contents_sorter_test.py b/tests/file_contents_sorter_test.py index 4e65629..e8f1ea8 100644 --- a/tests/file_contents_sorter_test.py +++ b/tests/file_contents_sorter_test.py
@@ -6,21 +6,17 @@ from pre_commit_hooks.file_contents_sorter import PASS -def _n(*strs): - return b'\n'.join(strs) + b'\n' - - # Input, expected return value, expected output TESTS = ( (b'', PASS, b''), - (_n(b'lonesome'), PASS, _n(b'lonesome')), + (b'lonesome\n', PASS, b'lonesome\n'), (b'missing_newline', PASS, b'missing_newline'), - (_n(b'alpha', b'beta'), PASS, _n(b'alpha', b'beta')), - (_n(b'beta', b'alpha'), FAIL, _n(b'alpha', b'beta')), - (_n(b'C', b'c'), PASS, _n(b'C', b'c')), - (_n(b'c', b'C'), FAIL, _n(b'C', b'c')), - (_n(b'mag ical ', b' tre vor'), FAIL, _n(b' tre vor', b'mag ical ')), - (_n(b'@', b'-', b'_', b'#'), FAIL, _n(b'#', b'-', b'@', b'_')), + (b'alpha\nbeta\n', PASS, b'alpha\nbeta\n'), + (b'beta\nalpha\n', FAIL, b'alpha\nbeta\n'), + (b'C\nc\n', PASS, b'C\nc\n'), + (b'c\nC\n', FAIL, b'C\nc\n'), + (b'mag ical \n tre vor\n', FAIL, b' tre vor\nmag ical \n'), + (b'@\n-\n_\n#\n', FAIL, b'#\n-\n@\n_\n'), )