4812N/A
4812N/AExtending Pylint
4812N/A****************
4812N/A
4812N/A
4812N/AWriting your own checker
4812N/A========================
4812N/A
4812N/AYou can find some simple examples in the examples directory of the
4812N/Adistribution (custom.py and custom_raw.py). I'll try to quickly
4812N/Aexplain the essentials here.
4812N/A
4812N/AFirst, there are two kinds of checkers:
4812N/A
4812N/A* raw checkers, which are analysing each module as a raw file stream
4812N/A
4812N/A* ast checkers, which are working on an ast representation of the
4812N/A module
4812N/A
4812N/AThe ast representation used is an extension of the one provided with
4812N/Athe standard Python distribution in the ast package. The extension
4812N/Aadds additional information and methods on the tree nodes to ease
4812N/Anavigation and code introspection.
4812N/A
4812N/AAn AST checker is a visitor, and should implement *visit_<lowered
4812N/Aclass name>* or *leave_<lowered class name>* methods for the nodes
4812N/Ait's interested in. To get description of the different classes used
4812N/Ain an ast tree, look at the ast package documentation. Checkers are
4812N/Aordered by priority. For each module, Pylint's engine:
4812N/A
4812N/A1. give the module source file as a stream to raw checkers
4812N/A
4812N/A2. get an ast representation for the module
4812N/A
4812N/A3. make a depth first descent of the tree, calling "visit_<>" on
4812N/A each AST checker when entering a node, and "leave_<>" on the back
4812N/A traversal
4812N/A
4812N/ANotice that the source code is probably the best source of
4812N/Adocumentation, it should be clear and well documented. Don't hesitate
4812N/Ato ask for any information on the code-quality mailing list.