Update README.md about file-contents-sorter

This commit is contained in:
Daniel Gallagher 2017-06-23 11:32:05 -07:00
parent 8b41c575db
commit 4af7451154
2 changed files with 13 additions and 14 deletions

View file

@ -51,6 +51,7 @@ Add this to your `.pre-commit-config.yaml`
with single quoted strings. with single quoted strings.
- `end-of-file-fixer` - Makes sure files end in a newline and only a newline. - `end-of-file-fixer` - Makes sure files end in a newline and only a newline.
- `fix-encoding-pragma` - Add `# -*- coding: utf-8 -*-` to the top of python files. - `fix-encoding-pragma` - Add `# -*- coding: utf-8 -*-` to the top of python files.
- `file-contents-sorter` - Sort the lines in specified files (defaults to alphabetical). You must provide list of target files as input to it.
- To remove the coding pragma pass `--remove` (useful in a python3-only codebase) - To remove the coding pragma pass `--remove` (useful in a python3-only codebase)
- `flake8` - Run flake8 on your python files. - `flake8` - Run flake8 on your python files.
- `forbid-new-submodules` - Prevent addition of new git submodules. - `forbid-new-submodules` - Prevent addition of new git submodules.

View file

@ -1,29 +1,26 @@
from argparse import ArgumentError
import pytest import pytest
from pre_commit_hooks.file_contents_sorter import FAIL from pre_commit_hooks.file_contents_sorter import FAIL
from pre_commit_hooks.file_contents_sorter import main from pre_commit_hooks.file_contents_sorter import main
from pre_commit_hooks.file_contents_sorter import parse_commandline_input from pre_commit_hooks.file_contents_sorter import parse_commandline_input
from pre_commit_hooks.file_contents_sorter import PASS from pre_commit_hooks.file_contents_sorter import PASS
from pre_commit_hooks.file_contents_sorter import sort_file_contents
def _n(*strs): def _n(*strs):
return b'\n'.join(strs) + '\n' return b'\n'.join(strs) + b'\n'
# Input, expected return value, expected output # Input, expected return value, expected output
TESTS = ( TESTS = (
(b'', PASS, b''), (b'', PASS, b''),
(_n('lonesome'), PASS, _n('lonesome')), (_n(b'lonesome'), PASS, _n(b'lonesome')),
(b'missing_newline', PASS, b'missing_newline'), (b'missing_newline', PASS, b'missing_newline'),
(_n('alpha', 'beta'), PASS, _n('alpha', 'beta')), (_n(b'alpha', b'beta'), PASS, _n(b'alpha', b'beta')),
(_n('beta', 'alpha'), FAIL, _n('alpha', 'beta')), (_n(b'beta', b'alpha'), FAIL, _n(b'alpha', b'beta')),
(_n('C', 'c'), PASS, _n('C', 'c')), (_n(b'C', b'c'), PASS, _n(b'C', b'c')),
(_n('c', 'C'), FAIL, _n('C', 'c')), (_n(b'c', b'C'), FAIL, _n(b'C', b'c')),
(_n('mag ical ', ' tre vor'), FAIL, _n(' tre vor', 'mag ical ')), (_n(b'mag ical ', b' tre vor'), FAIL, _n(b' tre vor', b'mag ical ')),
(_n('@', '-', '_', '#'), FAIL, _n('#', '-', '@', '_')), (_n(b'@', b'-', b'_', b'#'), FAIL, _n(b'#', b'-', b'@', b'_')),
) )
@ -42,6 +39,7 @@ def test_parse_commandline_input_errors_without_args():
with pytest.raises(SystemExit): with pytest.raises(SystemExit):
parse_commandline_input([]) parse_commandline_input([])
@pytest.mark.parametrize( @pytest.mark.parametrize(
('filename_list'), ('filename_list'),
( (