-
Notifications
You must be signed in to change notification settings - Fork 70
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-pluginscommand line options are processed first, because following parts of the program may be dependent on them.preprocess_optionssearches the arguments fromargvfor those three options, and calls their associated callback functions (as defined byRun) to load the values fromargvinto variables used by the linter. - Initialising PyLinter: Call
PyLinter.__init__with a series of "external" options (and option groups), as well as thercfilefound. - Reading into the linter: Register all checkers, plugins, help documents, etc. Then run
read_config_file()(anOptionsManagerMixInmethod) on the linter to read and record (but not run) the options in thepylintrcfile.-
OptionsManagerMixInis responsible for handling configurations (from both command line andpylintrc). Itsread_config_filemethod uses aConfigParserto read thepylintrcfile, 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-hookandload-pluginsoptions that must be executed before any other options. - Loading the linter: Call
OptionsManagerMixIn.load_config_file()to set each option up.-
load_config_fileadds 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']