diff --git a/scripts/commit_validation/commit_validation/validators/tabs_validator.py b/scripts/commit_validation/commit_validation/validators/tabs_validator.py index 629e74c659a0..6044fab7439f 100755 --- a/scripts/commit_validation/commit_validation/validators/tabs_validator.py +++ b/scripts/commit_validation/commit_validation/validators/tabs_validator.py @@ -27,14 +27,14 @@ 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 - - for line in file_diff.splitlines(): + for index, line in enumerate(file_diff.splitlines()): # we only care about added lines. if line.startswith('+'): if '\t' in line: @@ -44,13 +44,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(index) 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)