third_party.pylibs.pylint.src/examples/custom.py

41 lines
1.2 KiB
Python
Raw Normal View History

2013-06-17 13:06:48 +00:00
import astroid
2006-04-26 10:48:09 +00:00
2013-06-17 13:06:48 +00:00
from pylint.interfaces import IAstroidChecker
2006-04-26 10:48:09 +00:00
from pylint.checkers import BaseChecker
2013-06-17 13:06:48 +00:00
class MyAstroidChecker(BaseChecker):
2006-04-26 10:48:09 +00:00
"""add member attributes defined using my own "properties" function
to the class locals dictionary
"""
2013-06-17 13:06:48 +00:00
__implements__ = IAstroidChecker
2006-04-26 10:48:09 +00:00
name = 'custom'
msgs = {
'W0001': ('Message that will be emitted',
'message-symbol',
'Message help')
}
2006-04-26 10:48:09 +00:00
options = ()
# this is important so that your checker is executed before others
priority = -1
def visit_callfunc(self, node):
"""called when a CallFunc node is encountered.
2013-06-17 13:06:48 +00:00
See astroid for the description of available nodes."""
if not (isinstance(node.func, astroid.Getattr)
and isinstance(node.func.expr, astroid.Name)
and node.func.expr.name == 'properties'
and node.func.attrname == 'create'):
2006-04-26 10:48:09 +00:00
return
in_class = node.frame()
for param in node.args:
in_class.locals[param.name] = node
def register(linter):
"""required method to auto register this checker"""
2013-06-17 13:06:48 +00:00
linter.register_checker(MyAstroidChecker(linter))
2006-04-26 10:48:09 +00:00