User Guide
Developer Guide
Additional tools
Changelog
Support
Pylint provides support for writing two types of extensions.First, there is the concept ofcheckers,which can be used for finding problems in your code.Secondly, there is also the concept oftransform plugin,which represents a way through which the inference andthe capabilities of Pylint can be enhancedand tailored to a particular module, library of framework.
In general, a plugin is a module which should have a functionregister
,which takes an instance ofpylint.lint.PyLinter
as input.
A plugin can optionally define a function,load_configuration
,which takes an instance ofpylint.lint.PyLinter
as input. Thisfunction is called after Pylint loads configuration from configurationfile and command line interface. This function should load additionalplugin specific configuration to Pylint.
So a basic hello-world plugin can be implemented as:
# Inside hello_plugin.pyfromtypingimportTYPE_CHECKINGimportastroidifTYPE_CHECKING:frompylint.lintimportPyLinterdefregister(linter:"PyLinter")->None:"""This required method auto registers the checker during initialization. :param linter: The linter to register the checker to. """print('Hello world')
We can run this plugin by placing this module in the PYTHONPATH and invokingpylint as:
$pylint-E--load-pluginshello_pluginfoo.pyHelloworld
We can extend hello-world plugin to ignore some specific names usingload_configuration
function:
# Inside hello_plugin.pyfromtypingimportTYPE_CHECKINGimportastroidifTYPE_CHECKING:frompylint.lintimportPyLinterdefregister(linter:"PyLinter")->None:"""This required method auto registers the checker during initialization. :param linter: The linter to register the checker to. """print('Hello world')defload_configuration(linter):name_checker=get_checker(linter,NameChecker)# We consider as good names of variables Hello and Worldname_checker.config.good_names+=('Hello','World')# We ignore bin directorylinter.config.black_list+=('bin',)
Depending if we need atransform plugin or achecker, this might notbe enough. For the former, this is enough to declare the module as a plugin,but in the case of the latter, we need to register our checker with the linterobject, by calling the following inside theregister
function:
linter.register_checker(OurChecker(linter))
For more information on writing a checker seeHow to Write a Checker.