[Pydev-cvs] org.python.pydev/PySrc/ThirdParty/logilab/pylint/examples custom_raw.py,NONE,1.1 custom.
Brought to you by:
fabioz
|
From: Fabio Z. <fa...@us...> - 2005-02-16 16:46:02
|
Update of /cvsroot/pydev/org.python.pydev/PySrc/ThirdParty/logilab/pylint/examples In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7532/PySrc/ThirdParty/logilab/pylint/examples Added Files: custom_raw.py custom.py Log Message: New pylint version --- NEW FILE: custom_raw.py --- from logilab.pylint.interfaces import IRawChecker from logilab.pylint.checkers import BaseChecker class MyRawChecker(BaseChecker): """check for line continuations with '\' instead of using triple quoted string or parenthesis """ __implements__ = IRawChecker name = 'custom_raw' msgs = {'W9901': ('use \\ for line continuation', ('Used when a \\ is used for a line continuation instead' ' of using triple quoted string or parenthesis.')), } options = () def process_module(self, stream): """process a module the module's content is accessible via the stream object """ for (lineno, line) in enumerate(stream): if line.rstrip().endswith('\\'): self.add_message('W9901', line=lineno) def register(linter): """required method to auto register this checker""" linter.register_checker(MyRawChecker(linter)) --- NEW FILE: custom.py --- from logilab.common import astng from logilab.pylint.interfaces import IASTNGChecker from logilab.pylint.checkers import BaseChecker class MyASTNGChecker(BaseChecker): """add member attributes defined using my own "properties" function to the class locals dictionary """ __implements__ = IASTNGChecker name = 'custom' msgs = {} 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. See compiler.ast documentation for a description of available nodes: http://www.python.org/doc/current/lib/module-compiler.ast.html ) """ if not (isinstance(node.node, astng.Getattr) and isinstance(node.node.expr, astng.Name) and node.node.expr.name == 'properties' and node.node.attrname == 'create'): return in_class = node.get_frame() for param in node.args: in_class.locals[param.name] = node def register(linter): """required method to auto register this checker""" linter.register_checker(MyASTNGChecker(linter)) |