Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)

Expand Down