checks.linting.LintingCheck

checks.linting.LintingCheck()

Run linting tools on the package.

Executes a linting tool to check code quality and style. Supports ruff, flake8, and pylint, and by default runs the one the project has configured. A project that has configured none is skipped.

Attributes

name :

The check identifier (“linting”).

description :

Human-readable description of this check.

rules :

The codes of the findings this check can report.

hints :

What to do about each code.

SUPPORTED_TOOLS :

List of supported linting tools.

Configuration Options

tool (str): Linter to use (“auto”, “ruff”, “flake8”, or “pylint”). Defaults to “auto”, the linter the project has configured. args (list[str]): Additional arguments to pass to the linter. timeout (float): Seconds the linter may run. Defaults to 120 (300 for pylint).

Examples

Run the linter the project has configured:

>>> from pathlib import Path
>>> check = LintingCheck()
>>> result = check.run(Path("."), {"enabled": True})
>>> result.name
'linting'

Run flake8, whatever the project has configured:

>>> config = {"enabled": True, "tool": "flake8"}
>>> result = check.run(Path("."), config)

Pass additional ruff arguments:

>>> config = {"enabled": True, "tool": "ruff", "args": ["--select", "E,W"]}
>>> result = check.run(Path("."), config)

Methods

Name Description
run Run linting check on the package.

run

checks.linting.LintingCheck.run(package_path, config)

Run linting check on the package.

Executes the linting tool and collects any issues found. With tool = "auto" that is the linter the project has configured, and a project that has configured none is skipped. Issues are reported in the result details (the first MAX_DETAIL_LINES of them). The linter never modifies files.

Parameters

package_path : Path

Path to the package directory to lint.

config : dict[str, Any]

Configuration dictionary with options: - tool (str): “auto”, “ruff”, “flake8”, or “pylint” (default: “auto”) - args (list[str]): Additional arguments for the linter - timeout (float): Time limit in seconds

Returns

: CheckResult

A CheckResult with:

: CheckResult
  • OK status if no linting issues found
: CheckResult
  • WARNING status if linting issues found, or if the linter is installed but could not run
: CheckResult
  • ERROR status if the linter times out or an unsupported tool or an invalid option is specified
: CheckResult
  • SKIPPED status if the project has configured no linter, the linting tool is not installed, or pyproject.toml could not be read and no other file configures a linter, which the metadata check reports (“prerequisite-failed”)