From 287e197dc2ea567034c84c7118357b220e5d9d71 Mon Sep 17 00:00:00 2001 From: Mike Chang Date: Mon, 12 Dec 2022 15:15:48 -0800 Subject: [PATCH 1/5] Update tabs_validator.py Signed-off-by: Mike Chang --- .../commit_validation/validators/tabs_validator.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/commit_validation/commit_validation/validators/tabs_validator.py b/scripts/commit_validation/commit_validation/validators/tabs_validator.py index 629e74c659a0..56306056be38 100755 --- a/scripts/commit_validation/commit_validation/validators/tabs_validator.py +++ b/scripts/commit_validation/commit_validation/validators/tabs_validator.py @@ -33,8 +33,10 @@ def run(self, commit: Commit, errors: List[str]) -> bool: # or the entire file is full of tabs. # So we count the tabs, but we only print the first one in full. first_tab_line_found = None - + line_number = 0 + line_number_found = [] for line in file_diff.splitlines(): + line_number++ # we only care about added lines. if line.startswith('+'): if '\t' in line: @@ -44,13 +46,16 @@ def run(self, commit: Commit, errors: List[str]) -> bool: f' {previous_line_context}\n' f'---> {line}\n') tab_line_count = tab_line_count + 1 + line_number_found.append(line_number) previous_line_context = line if tab_line_count: error_message = str( - f'{file_name}::{self.__class__.__name__} FAILED TabsValidator - {tab_line_count} tabs in this file\n' + f'{file_name}::{self.__class__.__name__} FAILED TabsValidator - {tab_line_count} tabs in this file on line {line_number_found}\n' f'First instance of a tab: \n' - f'{first_tab_line_found}') + f'{first_tab_line_found} \n') + f'Note: Tabs are often converted to spaces by IDE and text editors. Verify this before overriding the error' + errors.append(error_message) if VERBOSE: print(error_message) From 4429a1a816b140698f3ea4400fd3334f7d11e0ef Mon Sep 17 00:00:00 2001 From: Mike Chang Date: Mon, 12 Dec 2022 15:24:44 -0800 Subject: [PATCH 2/5] Increment line number Signed-off-by: Mike Chang --- .../commit_validation/validators/tabs_validator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/commit_validation/commit_validation/validators/tabs_validator.py b/scripts/commit_validation/commit_validation/validators/tabs_validator.py index 56306056be38..268060a32dcd 100755 --- a/scripts/commit_validation/commit_validation/validators/tabs_validator.py +++ b/scripts/commit_validation/commit_validation/validators/tabs_validator.py @@ -36,7 +36,7 @@ def run(self, commit: Commit, errors: List[str]) -> bool: line_number = 0 line_number_found = [] for line in file_diff.splitlines(): - line_number++ + line_number += 1 # we only care about added lines. if line.startswith('+'): if '\t' in line: From 20ff992190e08702f19a95a4d45cf36749d12905 Mon Sep 17 00:00:00 2001 From: Mike Chang Date: Mon, 12 Dec 2022 15:27:03 -0800 Subject: [PATCH 3/5] Fix typo Signed-off-by: Mike Chang --- .../commit_validation/validators/tabs_validator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/commit_validation/commit_validation/validators/tabs_validator.py b/scripts/commit_validation/commit_validation/validators/tabs_validator.py index 268060a32dcd..b01cc75a5efe 100755 --- a/scripts/commit_validation/commit_validation/validators/tabs_validator.py +++ b/scripts/commit_validation/commit_validation/validators/tabs_validator.py @@ -53,8 +53,8 @@ def run(self, commit: Commit, errors: List[str]) -> bool: error_message = str( f'{file_name}::{self.__class__.__name__} FAILED TabsValidator - {tab_line_count} tabs in this file on line {line_number_found}\n' f'First instance of a tab: \n' - f'{first_tab_line_found} \n') - f'Note: Tabs are often converted to spaces by IDE and text editors. Verify this before overriding the error' + f'{first_tab_line_found} \n' + f'Note: Tabs are often converted to spaces by IDE and text editors. Verify this before overriding the error') errors.append(error_message) if VERBOSE: print(error_message) From 7e5da5b5b2db4e63953952022ef5b01f9638928f Mon Sep 17 00:00:00 2001 From: Mike Chang Date: Mon, 12 Dec 2022 15:55:09 -0800 Subject: [PATCH 4/5] Enumerate loop Signed-off-by: Mike Chang --- .../commit_validation/validators/tabs_validator.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/commit_validation/commit_validation/validators/tabs_validator.py b/scripts/commit_validation/commit_validation/validators/tabs_validator.py index b01cc75a5efe..08b4b7de4a5f 100755 --- a/scripts/commit_validation/commit_validation/validators/tabs_validator.py +++ b/scripts/commit_validation/commit_validation/validators/tabs_validator.py @@ -27,16 +27,15 @@ def run(self, commit: Commit, errors: List[str]) -> bool: break else: tab_line_count = 0 + line_number_found = [] file_diff = commit.get_file_diff(file_name) # Usually, code either has a very small number of tabs in the file by accident, # or the entire file is full of tabs. # So we count the tabs, but we only print the first one in full. first_tab_line_found = None - line_number = 0 - line_number_found = [] - for line in file_diff.splitlines(): - line_number += 1 + for index, line in enumerate(file_diff.splitlines()): + line_number = line_number + 1 # we only care about added lines. if line.startswith('+'): if '\t' in line: @@ -46,7 +45,7 @@ def run(self, commit: Commit, errors: List[str]) -> bool: f' {previous_line_context}\n' f'---> {line}\n') tab_line_count = tab_line_count + 1 - line_number_found.append(line_number) + line_number_found.append(index) previous_line_context = line if tab_line_count: From 6c451445bbf7dcd86ccf7bc5e8cfb4237269fe14 Mon Sep 17 00:00:00 2001 From: Mike Chang Date: Mon, 12 Dec 2022 15:59:28 -0800 Subject: [PATCH 5/5] Removed unused variable Signed-off-by: Mike Chang --- .../commit_validation/validators/tabs_validator.py | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/commit_validation/commit_validation/validators/tabs_validator.py b/scripts/commit_validation/commit_validation/validators/tabs_validator.py index 08b4b7de4a5f..6044fab7439f 100755 --- a/scripts/commit_validation/commit_validation/validators/tabs_validator.py +++ b/scripts/commit_validation/commit_validation/validators/tabs_validator.py @@ -35,7 +35,6 @@ def run(self, commit: Commit, errors: List[str]) -> bool: # So we count the tabs, but we only print the first one in full. first_tab_line_found = None for index, line in enumerate(file_diff.splitlines()): - line_number = line_number + 1 # we only care about added lines. if line.startswith('+'): if '\t' in line: