Initial work on new pylint checker

This commit is contained in:
Florian Bruhin 2017-06-09 19:54:25 +02:00
parent 52f6ea2525
commit c856f6d97b

View File

@ -36,9 +36,12 @@ class ConfigChecker(checkers.BaseChecker):
__implements__ = interfaces.IAstroidChecker __implements__ = interfaces.IAstroidChecker
name = 'config' name = 'config'
msgs = { msgs = {
'E0000': ('"%s -> %s" is no valid config option.', # flake8: disable=S001 'E0000': ('%s is no valid config option.', # flake8: disable=S001
'bad-config-call', 'bad-config-call',
None), None),
'E0001': ('old config call', # flake8: disable=S001
'old-config-call',
None),
} }
priority = -1 priority = -1
@ -53,23 +56,25 @@ class ConfigChecker(checkers.BaseChecker):
def _check_config(self, node): def _check_config(self, node):
"""Check that the arguments to config.get(...) are valid.""" """Check that the arguments to config.get(...) are valid."""
try: # try:
sect_arg = utils.get_argument_from_call(node, position=0, # sect_arg = utils.get_argument_from_call(node, position=0,
keyword='sectname') # keyword='sectname')
opt_arg = utils.get_argument_from_call(node, position=1, # opt_arg = utils.get_argument_from_call(node, position=1,
keyword='optname') # keyword='optname')
except utils.NoSuchArgumentError: # except utils.NoSuchArgumentError:
return # return
sect_arg = utils.safe_infer(sect_arg) # sect_arg = utils.safe_infer(sect_arg)
opt_arg = utils.safe_infer(opt_arg) # opt_arg = utils.safe_infer(opt_arg)
if not (isinstance(sect_arg, astroid.Const) and # if not (isinstance(sect_arg, astroid.Const) and
isinstance(opt_arg, astroid.Const)): # isinstance(opt_arg, astroid.Const)):
return # return
try: # try:
configdata.DATA[sect_arg.value][opt_arg.value] # configdata.DATA[sect_arg.value][opt_arg.value]
except KeyError: # except KeyError:
self.add_message('bad-config-call', node=node, # self.add_message('bad-config-call', node=node,
args=(sect_arg.value, opt_arg.value)) # args=(sect_arg.value, opt_arg.value))
self.add_message('old-config-call', node=node)
def register(linter): def register(linter):