Skip to content

Commit c65fcd3

Browse files
authored
Merge pull request #341 from gimbo/improvement/mix-line-endings-reporting
Report failing filenames when --fix=no in mixed-line-endings
2 parents e32adb4 + 1566cf9 commit c65fcd3

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

pre_commit_hooks/mixed_line_ending.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,12 @@ def main(argv=None):
7676

7777
retv = 0
7878
for filename in args.filenames:
79-
retv |= fix_filename(filename, args.fix)
79+
if fix_filename(filename, args.fix):
80+
if args.fix == 'no':
81+
print('{}: mixed line endings'.format(filename))
82+
else:
83+
print('{}: fixed mixed line endings'.format(filename))
84+
retv = 1
8085
return retv
8186

8287

tests/mixed_line_ending_test.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,32 +66,38 @@ def test_mixed_no_newline_end_of_file(tmpdir):
6666
('--fix=lf', b'foo\nbar\nbaz\n'),
6767
),
6868
)
69-
def test_line_endings_ok(fix_option, input_s, tmpdir):
69+
def test_line_endings_ok(fix_option, input_s, tmpdir, capsys):
7070
path = tmpdir.join('input.txt')
7171
path.write_binary(input_s)
7272
ret = main((fix_option, path.strpath))
7373

7474
assert ret == 0
7575
assert path.read_binary() == input_s
76+
out, _ = capsys.readouterr()
77+
assert out == ''
7678

7779

78-
def test_no_fix_does_not_modify(tmpdir):
80+
def test_no_fix_does_not_modify(tmpdir, capsys):
7981
path = tmpdir.join('input.txt')
8082
contents = b'foo\r\nbar\rbaz\nwomp\n'
8183
path.write_binary(contents)
8284
ret = main(('--fix=no', path.strpath))
8385

8486
assert ret == 1
8587
assert path.read_binary() == contents
88+
out, _ = capsys.readouterr()
89+
assert out == '{}: mixed line endings\n'.format(path)
8690

8791

88-
def test_fix_lf(tmpdir):
92+
def test_fix_lf(tmpdir, capsys):
8993
path = tmpdir.join('input.txt')
9094
path.write_binary(b'foo\r\nbar\rbaz\n')
9195
ret = main(('--fix=lf', path.strpath))
9296

9397
assert ret == 1
9498
assert path.read_binary() == b'foo\nbar\nbaz\n'
99+
out, _ = capsys.readouterr()
100+
assert out == '{}: fixed mixed line endings\n'.format(path)
95101

96102

97103
def test_fix_crlf(tmpdir):

0 commit comments

Comments
 (0)