Skip to content

Commit d7d2764

Browse files
committed
Make tools/line_endings.py print out content in the location where bad line endings exist for easy examination.
1 parent 01de07e commit d7d2764

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

tools/line_endings.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@ def check_line_endings(filename, print_errors=True):
1313
if print_errors: print >> sys.stderr, "Unable to read file '" + filename + "', or file was empty!"
1414
return 1
1515

16-
if "\r\r\n" in data:
17-
if print_errors: print >> sys.stderr, "File '" + filename + "' contains BAD line endings of form \\r\\r\\n!"
16+
bad_line_ending_index = data.find("\r\r\n")
17+
if bad_line_ending_index != -1:
18+
if print_errors:
19+
print >> sys.stderr, "File '" + filename + "' contains BAD line endings of form \\r\\r\\n!"
20+
bad_line = data[max(0,bad_line_ending_index-50):min(len(data), bad_line_ending_index+50)]
21+
bad_line = bad_line.replace('\r', '\\r').replace('\n', '\\n')
22+
print >> sys.stderr, "Content around the location: '" + bad_line + "'"
1823
return 1 # Bad line endings in file, return a non-zero process exit code.
1924

2025
has_dos_line_endings = False

0 commit comments

Comments
 (0)