Aller au contenu

Pylint

Pylint is a static code analyser.

Configuration dans un projet

pyproject.toml
[tool.pylint]
ignore-paths = ["venv"]
max-line-length = 88
output-format = "colorized"
disable = [
    "missing-class-docstring",
    "missing-function-docstring",
    "missing-module-docstring",
]

Pour régler les problèmes d'imports dans les tests, ajouter la config suivante :

pyproject.toml
[tool.pylint]
init-hook = 'import sys; sys.path.append("src")' # fix imports in tests

Configuration globale

~/.pylintrc
[MESSAGES CONTROL]
disable = duplicate-code, missing-module-docstring
max-line-length = 88

Utilisation

pylint .

Utilisation avec pre-commit

Configuration

.pre-commit-config.yaml
repos:
  - repo: https://github.com/pycqa/pylint
    rev: v3.3.2
    hooks:
      - id: pylint
        additional_dependencies:
          [
            # Same dependencies as in 'pyproject.toml'.
          ]

Utilisation

pre-commit run --all-files pylint

Intégration à Visual Studio Code

.vscode/extensions.json
{
    "recommendations": [
        "ms-python.pylint",
    ],
}
.vscode/settings.json
{
    "pylint.path": [
        "${workspaceFolder}/venv/bin/python",
        "-m",
        "pylint"
    ]
}

Ressources