-
Notifications
You must be signed in to change notification settings - Fork 59
Pylint Configuration
Pylint features can be enabled, disabled, and altered using a pylintrc
file. This file contains configuration options that Pylint interprets using the Python standard configparser
library. These features can also be altered when pylint is run directly from the command line, using command line arguments starting with --
, which pylint interprets using the optparse
library (now deprecated, replaced with argparse
) and stores using the configparser
library.
The complete list of pylint features that can be altered using options/switches can be found on the official pylint documentation. (You can see examples of the exact syntax by running pylint --generate-rcfile
in the command line, or by checking pylint's pylintrc
file on Github.) Most importantly, however, command line flags should be prefixed with --
(or just -
for shortened commands), but this prefix should be omitted when specifying commands in a pylintrc
file.
Since pylint has been designed ideally to be used from the command line, it is simple to configure the running of the tool after calling pylint
but before passing the name of the module to be checked. The typical format of a call to pylint, then, will appear like this:
pylint --<option-1-name>=<option-1-value> --<switch-name> <module name>
Pylint can also be called with commands that do not start a check, but rather return information, such as --version
, --help
(or -h
), --generate-rcfile
, --list-msgs
, and --full-documentation
.
The same options that pylint can be configured with from the command line can also be set in a pylintrc
(or .pylintrc
) file. Pylint can also automatically generate a properly-formatted pylintrc
file: in the command line, calling --generate-rcfile
will standard-output the default option values along with any changes specified with options appearing before --generate-rcfile
in the command line.
Pylint's config.py
can search automatically for pylintrc
(or .pylintrc
) files within your computer's file system. However, pylint only checks the usual locations:
- the current directory pylint is running in,
- any parent directories of the current directory that contain an
__init__.py
file (that is, are recognisable by Python as package directories), - the
PYLINTRC
environment variable (if given), - the user's home directory or within
.config
in the home directory, or - the
etc
directory within the current directory (if it exists).
If the pylintrc
file is not contained in any of the following locations, pylint should be called with the location of a pylintrc
file explicitly stated using the --rcfile=<config file>
option; otherwise, pylint will use the default configuration (plus options from the command line, if any).
This is the main checker amongst all checkers. It overrides/extends OptionsManagerMixIn.set_option
to add config options not internal to other checkers: enable
and disable
, and add a custom reporter (uses PyLinter._load_reporter()
).
Extended by PyLinter to provide config file reading / option storing functionality.
Uses ConfigParser
to parse the pylintrc
configuration file, if one exists.
Main method: set_option
: Stores checker options in an optparse.Values
object config
. This method is overridden by its subclasses that want to add options additional to the default ones (that is, by checkers).
Extended by checkers to provide option storing and managing functionality. Checkers access the sections
attribute defined by an OptionsProviderMixIn
to look for options they should follow. Reporters do not inherit from OptionsProviderMixIn
, so they cannot directly request custom options. However, the pylintrc
example file does indicate a msg-template
option that can be used to customise the message format that reporters output, which is accessed by TextReporter
and HTMLReporter
using self.linter.config.msg_template
. Aside from this seemingly hard-coded exception though, pylint reporters do not have a mechanism to set up custom options as checkers do.
-
python_ta._check
does lots of things that apylintrc
file can do:- reporter: use
--output-format=<reporter module>
- level: currently sent to reporter's
print_messages
, but as mentioned on the reporters page, reporters should actually overrideBaseReporter.display_messages
. Also, level is currently used to indicate "display code errors, display style errors, or all", but this should instead be given using--disable=<category>
inpylintrc
, where<category>
is one of "C, W, E, F, R, standing for Convention, Warning, Error, Fatal and Refactoring" (Pylint docs). - local_config_file: doesn't need to be indicated in
pylintrc
, but can be indicated in the command line using--rcfile=<config file>
.
- reporter: use