mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-05 19:46:54 +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
|
||||
|
||||
if fix == 'auto':
|
||||
max_ending = LF
|
||||
max_lines = 0
|
||||
# ordering is important here such that lf > crlf > cr
|
||||
for ending_type in ALL_ENDINGS:
|
||||
# also important, using >= to find a max that prefers the last
|
||||
if counts[ending_type] >= max_lines:
|
||||
max_ending = ending_type
|
||||
max_lines = counts[ending_type]
|
||||
|
||||
# max prefers the first item when multiple items are the max
|
||||
max_ending = max(reversed(ALL_ENDINGS), key=counts.get)
|
||||
_fix(filename, contents, max_ending)
|
||||
return 1
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue