third_party.pylibs.pylint.src/doc/extend.rst

36 lines
1.5 KiB
ReStructuredText
Raw Normal View History

2013-04-06 19:45:15 +00:00
Extending Pylint
================
Writing your own checker
------------------------
You can find some simple examples in the examples
directory of the distribution (custom.py and custom_raw.py). I'll try to
quickly explain the essentials here.
First, there are two kinds of checkers :
* raw checkers, which are analysing each module as a raw file stream
* ast checkers, which are working on an ast representation of the module
The ast representation used is an extension of the one provided with the
2013-04-29 13:31:03 +00:00
standard Python distribution in the `ast package`_. The extension
2013-04-06 19:45:15 +00:00
adds additional information and methods on the tree nodes to ease
2013-04-29 13:31:03 +00:00
navigation and code introspection.
2013-04-06 19:45:15 +00:00
An AST checker is a visitor, and should implement
2013-04-29 13:31:03 +00:00
`visit_<lowered class name>` or `leave_<lowered class name>`
2013-04-06 19:45:15 +00:00
methods for the nodes it's interested in. To get description of the different
classes used in an ast tree, look at the `ast package`_ documentation.
2013-04-06 19:45:15 +00:00
Checkers are ordered by priority. For each module, Pylint's engine:
1. give the module source file as a stream to raw checkers
2. get an ast representation for the module
3. make a depth first descent of the tree, calling visit_<> on each AST
checker when entering a node, and living_<> on the back traversal
Notice that the source code is probably the best source of
documentation, it should be clear and well documented. Don't hesitate to
2013-04-29 13:31:03 +00:00
ask for any information on the code-quality mailing list.
2013-04-06 19:45:15 +00:00
2013-04-29 13:31:03 +00:00
.. _`ast package`: http://docs.python.org/2/library/ast