Skip to main content

Pylint

Install

pip install pylint

Although it is not required, I recommend installing pylint-json2html. This package generates a nice web page of your lint report. Save it as a reference, or upload it as an artifact to your CI system.

pip install pylint-json2html
tip

See the Makefile example below for an example of how to use pylint-json2html.

Lint files

Pylint will recursively lint the Python files in the directory and sub-directories it is given.

For example, lint the Python files in the current directory and sub-directories.

pylint .

Your files may start in a sub-directory like src. Run Pylint there.

pylint src

Makefile example

Create shortcut commands, also known as targets, in your Makefile to ease development tasks.

This file creates two such commands.

  • Lint the source files with pylint.
  • Generate the file pylint.html to lint and view the results.
PYLINT_ROOT = src
REPORTS_DIR = output/reports

lint:
@pylint $(PYLINT_ROOT)

pylint.html:
@mkdir -p $(REPORTS_DIR)
pylint $(PYLINT_ROOT) --output-format=json | pylint-json2html -o $(REPORTS_DIR)/pylint.html

.PHONY lint
tip

You can also use a tool like Poetry to run "shortcut" commands.