mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-09 21:04:17 +00:00
In mixed-line-endings, move check/print to main() as suggested by asottile (PR 341)
This commit is contained in:
parent
f3c65bcd20
commit
59ed512020
1 changed files with 7 additions and 8 deletions
|
|
@ -37,15 +37,9 @@ def fix_filename(filename, fix):
|
||||||
# Some amount of mixed line endings
|
# Some amount of mixed line endings
|
||||||
mixed = sum(bool(x) for x in counts.values()) > 1
|
mixed = sum(bool(x) for x in counts.values()) > 1
|
||||||
|
|
||||||
if fix == 'no':
|
if fix == 'no' or (fix == 'auto' and not mixed):
|
||||||
if mixed:
|
|
||||||
# Not fixing, just report problematic file
|
|
||||||
print('Mixed line endings: {filename}'.format(filename=filename))
|
|
||||||
return mixed
|
return mixed
|
||||||
|
|
||||||
if fix == 'auto' and not mixed:
|
|
||||||
return False
|
|
||||||
|
|
||||||
if fix == 'auto':
|
if fix == 'auto':
|
||||||
max_ending = LF
|
max_ending = LF
|
||||||
max_lines = 0
|
max_lines = 0
|
||||||
|
|
@ -82,7 +76,12 @@ def main(argv=None):
|
||||||
|
|
||||||
retv = 0
|
retv = 0
|
||||||
for filename in args.filenames:
|
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
|
return retv
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue