Pylint Per-File Ignores Plugin
A Pylint plugin designed to enable granular control over Pylint error codes, allowing specific messages to be ignored per file or directory pattern. It provides a flexible alternative to littering code with `# pylint: disable` comments. This library is actively maintained, with its current version being 3.2.1.
Warnings
- breaking Prior to version 2.0.0, file patterns used regular expressions. From version 2.0.0 onwards, patterns are matched using globs. Existing configurations from older versions must be reviewed and updated to use glob syntax.
- gotcha The plugin is enabled and configured via Pylint's configuration files (e.g., `pyproject.toml`, `.pylintrc`, `setup.cfg`) by adding it to `load-plugins` and defining rules under `per-file-ignores`. It's not a Python module meant for `import` statements in your code.
- gotcha Pylint's native `--ignore` option might not work as expected with directories, especially when Pylint is invoked on individual files (e.g., by pre-commit hooks or IDEs). This plugin specifically addresses per-file/pattern ignoring when `--ignore` falls short.
Install
-
pip install pylint-per-file-ignores
Imports
- pylint_per_file_ignores
This plugin is loaded via Pylint's configuration, not directly imported into Python code. Add 'pylint_per_file_ignores' to the 'load-plugins' list in your Pylint configuration file.
Quickstart
# pyproject.toml
[tool.pylint.main]
load-plugins = [
"pylint_per_file_ignores",
]
[tool.pylint.'messages control']
per-file-ignores = [
"/tests/*:missing-function-docstring,C0115",
"/src/legacy_code.py:W0621,W0240,E0001"
]