Merged in MBP-129-check_fix_white_space-py---fix (pull request #19)

MBP-129 check fix white space py   fix
This commit is contained in:
Torsten Bögershausen
2020-03-04 13:44:50 +00:00
committed by Dominic Oram
2 changed files with 31 additions and 15 deletions
+10 -11
View File
@@ -1,11 +1,10 @@
image: python:3.7.3
options:
max-time: 1
pipelines:
default:
- step:
script:
- git submodule update --init
- git submodule
- python twincat_version_manager.py
- python check_fix_white_space.py
image: python:3.7.3
options:
max-time: 1
pipelines:
default:
- step:
script:
- git submodule update --init
- python twincat_version_manager.py
- python check_fix_white_space.py
+21 -4
View File
@@ -26,6 +26,8 @@ def fix_white_space(debug, fix_files):
for pathname in found_files:
dirty = False
had_TAB = False
had_trailing_WS = False
new_lines = []
if debug >= 1:
print("tab_with=%d pathname=%s" % (tab_width, pathname))
@@ -41,8 +43,16 @@ def fix_white_space(debug, fix_files):
had_crlf = 1 # LF
# Convert all TAB into SPACE
new_line = old_line.expandtabs(tabsize=tab_width)
# Strip of all trailing white space, including the CRLF
new_line = new_line.rstrip("\r\n ")
if new_line != old_line:
had_TAB = True
# Strip the CRLF
new_line = new_line.rstrip("\r\n")
# Strip trailing WS
tmp_line = new_line.rstrip(" ")
if tmp_line != new_line:
had_trailing_WS = True
new_line = tmp_line
if had_crlf == 2:
new_line = new_line + '\r\n'
elif had_crlf == 1:
@@ -61,7 +71,12 @@ def fix_white_space(debug, fix_files):
if debug >= 1:
print("pathname=%s dirty=%d" % (pathname, dirty))
if dirty:
incorrect_files[pathname] = True
if had_TAB and had_trailing_WS:
incorrect_files[pathname] = 'has white space damage'
elif had_TAB:
incorrect_files[pathname] = 'has TAB'
elif had_trailing_WS:
incorrect_files[pathname] = 'has trailing whitespace'
if fix_files:
file = open(pathname, 'w', newline='', encoding="iso-8859-1")
file.writelines(new_lines)
@@ -88,8 +103,10 @@ if __name__ == "__main__":
incorrect_files = fix_white_space(debug, fix_files)
if not fix_files:
for file in incorrect_files:
print("ERROR: '{}' has white space damage".format(file))
message = incorrect_files[file]
print("ERROR: '{}' {}".format(file,message))
if incorrect_files:
print('run %s --fix' % sys.argv[0])
exit(1)
except IOError as e:
print(e) # Likely no files found