Refactor mixed_line_ending.py

This commit is contained in:
Morgan Courbet 2017-07-20 20:58:53 +02:00
parent f9915cbbe2
commit 0e223bcb15
No known key found for this signature in database
GPG key ID: 467299D324A21B24

View file

@ -94,6 +94,7 @@ def _detect_line_ending(filename):
buf = f.read() buf = f.read()
le_counts = {} le_counts = {}
for le_enum in LineEnding: for le_enum in LineEnding:
le_counts[le_enum] = len(le_enum.regex.findall(buf)) le_counts[le_enum] = len(le_enum.regex.findall(buf))
@ -118,8 +119,10 @@ def _detect_line_ending(filename):
return MixedLineDetection.NOT_MIXED return MixedLineDetection.NOT_MIXED
for mld in MixedLineDetection: for mld in MixedLineDetection:
if mld.line_ending_enum is not None \ if (
and mld.line_ending_enum == most_le: mld.line_ending_enum is not None and
mld.line_ending_enum == most_le
):
return mld return mld
return MixedLineDetection.UNKNOWN return MixedLineDetection.UNKNOWN
@ -154,8 +157,6 @@ def _process_fix_auto(filenames):
if detect_result == MixedLineDetection.NOT_MIXED: if detect_result == MixedLineDetection.NOT_MIXED:
print('The file %s has no mixed line ending', filename) print('The file %s has no mixed line ending', filename)
mle_found |= False
elif detect_result == MixedLineDetection.UNKNOWN: elif detect_result == MixedLineDetection.UNKNOWN:
print( print(
'Could not define most frequent line ending in ' 'Could not define most frequent line ending in '