-
Notifications
You must be signed in to change notification settings - Fork 59
Pylint
Pylint is a static analysis tool used for linting code for syntax and style errors. Its versatile and open-source nature makes it both easy to use and easy to extend. Python TA is a custom setup of pylint that has written new checkers, reporters, and configuration in the pylint style.
For more information about the pylint system, see the page for individual elements of pylint:
Usually you call Pylint from the command line, which means you do something like:
> pylint --option-1 --option-2 <module to check>
And this makes a call to __main__.py
, which calls pylint.run_pylint()
(inside __init__.py
). run_pylint
then calls pylint.lint.Run(sys.argv[1:])
, where sys.argv[1:]
is every command line argument except the call to pylint itself. Unless only calling pylint for information, the last element of sys.argv
is the module or filename to be linted.
Run
in turn loads up the PyLinter:
- Pre-processing (command line): the
init-hook
(standalone Python code),rcfile
, andload-plugins
command line options are processed first, because following parts of the program may be dependent on them.preprocess_options
searches the arguments fromargv
for those three options, and calls their associated callback functions (as defined byRun
) to load the values fromargv
into variables used by the linter. - Initialising PyLinter: Call
PyLinter.__init__
with a series of "external" options (and option groups), as well as thercfile
found. - Reading into the linter: Register all checkers, plugins, help documents, etc. Then run
read_config_file()
(anOptionsManagerMixIn
method) on the linter to read and record (but not run) the options in thepylintrc
file.-
OptionsManagerMixIn
is responsible for handling configurations (from both command line andpylintrc
). Itsread_config_file
method uses aConfigParser
to read thepylintrc
file, which stores the sections, keys, and values from the file in_sections
.
-
- Pre-processing (config file): As before when pre-processing the command line options, the config file can have
init-hook
andload-plugins
options that must be executed before any other options. - Loading the linter: Call
OptionsManagerMixIn.load_config_file()
to set each option up.-
load_config_file
adds every registered/read option to the list of options to be followed when the linter is linting.
-
- Loading command line options: Alter configuration based on command line arguments using
load_command_line_configurations(args)
.
- Default pylint sections: ['MASTER', 'MESSAGES CONTROL', 'REPORTS', 'BASIC', 'ELIF', 'FORMAT', 'LOGGING', 'MISCELLANEOUS', 'SIMILARITIES', 'SPELLING', 'TYPECHECK', 'VARIABLES', 'CLASSES', 'DESIGN', 'IMPORTS', 'EXCEPTIONS']
- Current PyTA sections: ['ELIF', 'FORMAT', 'FORBIDDEN IMPORT', 'FORBIDDEN IO', 'MESSAGES CONTROL']