mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-13 14:24:18 +00:00
[mixed_line_ending] convert a loop to max()
This commit is contained in:
parent
f9ba5db3f1
commit
58487eb58b
1 changed files with 2 additions and 8 deletions
|
|
@ -40,15 +40,9 @@ def fix_filename(filename: str, fix: str) -> int:
|
||||||
return mixed
|
return mixed
|
||||||
|
|
||||||
if fix == 'auto':
|
if fix == 'auto':
|
||||||
max_ending = LF
|
|
||||||
max_lines = 0
|
|
||||||
# ordering is important here such that lf > crlf > cr
|
# ordering is important here such that lf > crlf > cr
|
||||||
for ending_type in ALL_ENDINGS:
|
# max prefers the first item when multiple items are the max
|
||||||
# also important, using >= to find a max that prefers the last
|
max_ending = max(reversed(ALL_ENDINGS), key=counts.get)
|
||||||
if counts[ending_type] >= max_lines:
|
|
||||||
max_ending = ending_type
|
|
||||||
max_lines = counts[ending_type]
|
|
||||||
|
|
||||||
_fix(filename, contents, max_ending)
|
_fix(filename, contents, max_ending)
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue