mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-03-30 02:16:52 +00:00
Merge pull request #341 from gimbo/improvement/mix-line-endings-reporting
Report failing filenames when --fix=no in mixed-line-endings
This commit is contained in:
commit
c65fcd3fc5
2 changed files with 15 additions and 4 deletions
|
|
@ -76,7 +76,12 @@ def main(argv=None):
|
|||
|
||||
retv = 0
|
||||
for filename in args.filenames:
|
||||
retv |= fix_filename(filename, args.fix)
|
||||
if fix_filename(filename, args.fix):
|
||||
if args.fix == 'no':
|
||||
print('{}: mixed line endings'.format(filename))
|
||||
else:
|
||||
print('{}: fixed mixed line endings'.format(filename))
|
||||
retv = 1
|
||||
return retv
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -66,16 +66,18 @@ def test_mixed_no_newline_end_of_file(tmpdir):
|
|||
('--fix=lf', b'foo\nbar\nbaz\n'),
|
||||
),
|
||||
)
|
||||
def test_line_endings_ok(fix_option, input_s, tmpdir):
|
||||
def test_line_endings_ok(fix_option, input_s, tmpdir, capsys):
|
||||
path = tmpdir.join('input.txt')
|
||||
path.write_binary(input_s)
|
||||
ret = main((fix_option, path.strpath))
|
||||
|
||||
assert ret == 0
|
||||
assert path.read_binary() == input_s
|
||||
out, _ = capsys.readouterr()
|
||||
assert out == ''
|
||||
|
||||
|
||||
def test_no_fix_does_not_modify(tmpdir):
|
||||
def test_no_fix_does_not_modify(tmpdir, capsys):
|
||||
path = tmpdir.join('input.txt')
|
||||
contents = b'foo\r\nbar\rbaz\nwomp\n'
|
||||
path.write_binary(contents)
|
||||
|
|
@ -83,15 +85,19 @@ def test_no_fix_does_not_modify(tmpdir):
|
|||
|
||||
assert ret == 1
|
||||
assert path.read_binary() == contents
|
||||
out, _ = capsys.readouterr()
|
||||
assert out == '{}: mixed line endings\n'.format(path)
|
||||
|
||||
|
||||
def test_fix_lf(tmpdir):
|
||||
def test_fix_lf(tmpdir, capsys):
|
||||
path = tmpdir.join('input.txt')
|
||||
path.write_binary(b'foo\r\nbar\rbaz\n')
|
||||
ret = main(('--fix=lf', path.strpath))
|
||||
|
||||
assert ret == 1
|
||||
assert path.read_binary() == b'foo\nbar\nbaz\n'
|
||||
out, _ = capsys.readouterr()
|
||||
assert out == '{}: fixed mixed line endings\n'.format(path)
|
||||
|
||||
|
||||
def test_fix_crlf(tmpdir):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue