From 58487eb58bea48ac49d5c6564b427e527a0d9c89 Mon Sep 17 00:00:00 2001 From: NotWearingPants Date: Tue, 12 Oct 2021 20:57:44 +0300 Subject: [PATCH] [mixed_line_ending] convert a loop to max() --- pre_commit_hooks/mixed_line_ending.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/pre_commit_hooks/mixed_line_ending.py b/pre_commit_hooks/mixed_line_ending.py index 0ef8e2c..3c410db 100644 --- a/pre_commit_hooks/mixed_line_ending.py +++ b/pre_commit_hooks/mixed_line_ending.py @@ -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: