Add --check support to EOF and Trailing Whitespace fixers

This change adds an advisory mode via `--check` that only warns of
formatting issues with files, but does not address them.

This support is desirable because--while I don't mind the automagic
changes when done in a mechanical way--some individuals who I
described the current behavior of these fixers to were a bit uneasy
about the magic that went along with them. Adding `--check` so
others can opt out (similar to `black --check`) is a compromise on
this front.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
This commit is contained in:
Enji Cooper 2019-12-18 17:25:07 -08:00
parent 5df1a4bf6f
commit a17514d55e
4 changed files with 65 additions and 20 deletions

View file

@ -20,6 +20,20 @@ def test_fixes_trailing_whitespace(input_s, expected, tmpdir):
assert path.read() == expected
@pytest.mark.parametrize(
('input_s'),
(
('foo \nbar \n'),
('bar\t\nbaz\t\n'),
),
)
def test_check(input_s, tmpdir):
path = tmpdir.join('file.md')
path.write(input_s)
assert main(('--check', path.strpath,)) == 1
assert path.read() == input_s
def test_ok_no_newline_end_of_file(tmpdir):
filename = tmpdir.join('f')
filename.write_binary(b'foo\nbar')