Fix validate-modules to not complain about sys.exit in comments

This commit is contained in:
Toshio Kuratomi 2018-09-10 10:25:34 -07:00
parent 175f3b51e5
commit e09196f760

View file

@ -63,6 +63,7 @@ else:
BLACKLIST_DIRS = frozenset(('.git', 'test', '.github', '.idea')) BLACKLIST_DIRS = frozenset(('.git', 'test', '.github', '.idea'))
INDENT_REGEX = re.compile(r'([\t]*)') INDENT_REGEX = re.compile(r'([\t]*)')
TYPE_REGEX = re.compile(r'.*(if|or)(\s+[^"\']*|\s+)(?<!_)(?<!str\()type\(.*') TYPE_REGEX = re.compile(r'.*(if|or)(\s+[^"\']*|\s+)(?<!_)(?<!str\()type\(.*')
SYS_EXIT_REGEX = re.compile(r'[^#]*sys.exit\s*\(.*')
BLACKLIST_IMPORTS = { BLACKLIST_IMPORTS = {
'requests': { 'requests': {
'new_only': True, 'new_only': True,
@ -371,13 +372,20 @@ class ModuleValidator(Validator):
) )
def _check_for_sys_exit(self): def _check_for_sys_exit(self):
if 'sys.exit(' in self.text: # Optimize out the happy path
# TODO: Add line/col if 'sys.exit' not in self.text:
self.reporter.error( return
path=self.object_path,
code=205, for line_no, line in enumerate(self.text.splitlines()):
msg='sys.exit() call found. Should be exit_json/fail_json' 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',
line=line_no + 1
)
def _check_gpl3_header(self): def _check_gpl3_header(self):
header = '\n'.join(self.text.split('\n')[:20]) header = '\n'.join(self.text.split('\n')[:20])