Fix validate-modules to not complain about sys.exit in comments
This commit is contained in:
parent
175f3b51e5
commit
e09196f760
1 changed files with 15 additions and 7 deletions
|
@ -63,6 +63,7 @@ else:
|
|||
BLACKLIST_DIRS = frozenset(('.git', 'test', '.github', '.idea'))
|
||||
INDENT_REGEX = re.compile(r'([\t]*)')
|
||||
TYPE_REGEX = re.compile(r'.*(if|or)(\s+[^"\']*|\s+)(?<!_)(?<!str\()type\(.*')
|
||||
SYS_EXIT_REGEX = re.compile(r'[^#]*sys.exit\s*\(.*')
|
||||
BLACKLIST_IMPORTS = {
|
||||
'requests': {
|
||||
'new_only': True,
|
||||
|
@ -371,12 +372,19 @@ class ModuleValidator(Validator):
|
|||
)
|
||||
|
||||
def _check_for_sys_exit(self):
|
||||
if 'sys.exit(' in self.text:
|
||||
# TODO: Add line/col
|
||||
# Optimize out the happy path
|
||||
if 'sys.exit' not in self.text:
|
||||
return
|
||||
|
||||
for line_no, line in enumerate(self.text.splitlines()):
|
||||
sys_exit_usage = SYS_EXIT_REGEX.match(line)
|
||||
if sys_exit_usage:
|
||||
# TODO: add column
|
||||
self.reporter.error(
|
||||
path=self.object_path,
|
||||
code=205,
|
||||
msg='sys.exit() call found. Should be exit_json/fail_json'
|
||||
msg='sys.exit() call found. Should be exit_json/fail_json',
|
||||
line=line_no + 1
|
||||
)
|
||||
|
||||
def _check_gpl3_header(self):
|
||||
|
|
Loading…
Reference in a new issue