From 6e723594b562583b6eb6e7caa98258d6bac580e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20B=C3=B6gershausen?= Date: Mon, 9 Dec 2019 10:30:41 +0100 Subject: [PATCH 1/4] bitbucket-pipelines.yml: Don't run git submodule The command `git submodule update --init` already shows us the versions of the submodules. There is no need to run `git submodule` after that - renove it. --- bitbucket-pipelines.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index d47cd1d..873f48c 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -6,6 +6,5 @@ pipelines: - step: script: - git submodule update --init - - git submodule - python twincat_version_manager.py - python check_fix_white_space.py From a57ae08ebe526bf7ac1233f9dabae839414b0e23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20B=C3=B6gershausen?= Date: Mon, 9 Dec 2019 11:00:50 +0100 Subject: [PATCH 2/4] check_fix_white_space.py: Hint the user about --fix When the script detects whitespace damage, hint the user that the same script can fix it. --- check_fix_white_space.py | 1 + 1 file changed, 1 insertion(+) diff --git a/check_fix_white_space.py b/check_fix_white_space.py index cf6fe3c..c03a737 100755 --- a/check_fix_white_space.py +++ b/check_fix_white_space.py @@ -90,6 +90,7 @@ if __name__ == "__main__": for file in incorrect_files: print("ERROR: '{}' has white space damage".format(file)) if incorrect_files: + print('run %s --fix' % sys.argv[0]) exit(1) except IOError as e: print(e) # Likely no files found From 608f6c03357cf2b0446cfcd53a6b990844965cfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20B=C3=B6gershausen?= Date: Mon, 9 Dec 2019 11:10:07 +0100 Subject: [PATCH 3/4] check_fix_white_space.py: Tell user about TAB and/or trailing WS Make the output of the script more descriptive: Tell user what was wrong, either TAB or trailing WS (or both) --- check_fix_white_space.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/check_fix_white_space.py b/check_fix_white_space.py index c03a737..854e5e2 100755 --- a/check_fix_white_space.py +++ b/check_fix_white_space.py @@ -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,7 +103,8 @@ 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) From 3edb9fd098fdd09002d60594147ba47790179f26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20B=C3=B6gershausen?= Date: Mon, 9 Dec 2019 11:21:05 +0100 Subject: [PATCH 4/4] check_fix_white_space.py: Fix whitespace damage --- check_fix_white_space.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/check_fix_white_space.py b/check_fix_white_space.py index 854e5e2..6597e58 100755 --- a/check_fix_white_space.py +++ b/check_fix_white_space.py @@ -44,7 +44,7 @@ def fix_white_space(debug, fix_files): # Convert all TAB into SPACE new_line = old_line.expandtabs(tabsize=tab_width) if new_line != old_line: - had_TAB = True + had_TAB = True # Strip the CRLF new_line = new_line.rstrip("\r\n") # Strip trailing WS @@ -104,7 +104,7 @@ if __name__ == "__main__": if not fix_files: for file in incorrect_files: message = incorrect_files[file] - print("ERROR: '{}' {}".format(file,message)) + print("ERROR: '{}' {}".format(file,message)) if incorrect_files: print('run %s --fix' % sys.argv[0]) exit(1)