Added check to ensure that TODOs all have an associated issue
This commit is contained in:
38
cicd/custom_style_check.py
Executable file
38
cicd/custom_style_check.py
Executable file
@@ -0,0 +1,38 @@
|
||||
#! /usr/bin/env python
|
||||
|
||||
import sys
|
||||
import re
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from termcolor import cprint
|
||||
|
||||
print_re = re.compile(r'print\(.*\)')
|
||||
todo_re = re.compile(r'#\s*TODO:?\s*')
|
||||
accounted_for_todo = re.compile(r'#\s*TODO:?\s*\((#\d+)\)')
|
||||
|
||||
|
||||
def check_file(path):
|
||||
print(f'Checking {path.absolute()}...')
|
||||
file = path.open()
|
||||
valid = True
|
||||
|
||||
for i, line in enumerate(file, start=1):
|
||||
if print_re.search(line) and '# allowprint' not in line:
|
||||
cprint(f'{i}: {line}', 'red', end='', attrs=['bold'])
|
||||
valid = False
|
||||
|
||||
if todo_re.search(line) and not accounted_for_todo.search(line):
|
||||
cprint(f'{i}: {line}', 'red', end='', attrs=['bold'])
|
||||
valid = False
|
||||
|
||||
file.close()
|
||||
return valid
|
||||
|
||||
|
||||
valid = True
|
||||
for path in Path('sublime').glob('**/*.py'):
|
||||
valid &= check_file(path)
|
||||
print()
|
||||
|
||||
sys.exit(0 if valid else 1)
|
@@ -1,11 +0,0 @@
|
||||
#! /bin/bash
|
||||
|
||||
grep -Inre "print(" sublime | while read line; do
|
||||
if [[ $line =~ "# allowprint" ]]; then
|
||||
continue
|
||||
fi
|
||||
echo "Found instance of print statement:"
|
||||
echo $line
|
||||
echo "Use logging instead or add '# allowprint' to the end of the line."
|
||||
exit 1
|
||||
done
|
Reference in New Issue
Block a user