Skip to main content

Ruff-adjacent Python legibility rules for readable, reviewable code.

Project description

ruff-legibility

PyPI version CI OpenSSF Scorecard

ruff-legibility is a Ruff-adjacent Python linter for readability and reviewability rules inspired by eslint-plugin-legibility.

Ruff does not currently load third-party rule implementations from Python packages. This package therefore runs beside Ruff and emits Ruff-style diagnostics with LEG### codes.

ruff check .
ruff-legibility check .

To keep # noqa: LEG001 comments valid when Ruff checks unused or unknown noqa codes, add LEG as an external prefix in Ruff:

[tool.ruff.lint]
external = ["LEG"]

Install

pip install ruff-legibility

For local development:

uv sync --all-groups
make check

Usage

ruff-legibility check .
ruff-legibility check src tests --output-format json
ruff-legibility check . --select LEG001,LEG002 --ignore LEG007
ruff-legibility check . --exit-zero

Default text output is intentionally close to Ruff:

example.py:4:8: LEG002 If condition has 2 boolean operators (max 0). Hoist it into a named boolean.

Configuration

Configuration can live in pyproject.toml under [tool.ruff-legibility], or in ruff-legibility.toml / .ruff-legibility.toml.

[tool.ruff-legibility]
select = ["LEG"]
extend-select = []
ignore = ["LEG007"]
extend-ignore = []
exclude = [".venv", "build", "dist"]
max-expression-operators = 4
max-if-operators = 0
max-ternary-operators = 2
max-control-flow-depth = 3

[tool.ruff-legibility.per-file-ignores]
"tests/*" = ["LEG003"]

Standalone config files omit the tool.ruff-legibility wrapper:

select = ["LEG"]
ignore = ["LEG007"]

This repository includes a ruff-legibility.toml for its own source. The default package thresholds stay stricter than the project-local development config.

Rules

Code Rule Default
LEG001 Limit readability operators inside a single expression. on
LEG002 Prefer a named boolean before operator-heavy if / while conditions. on
LEG003 Limit nested control-flow depth. on
LEG004 Avoid complex ternary expressions. on
LEG005 Flag likely quadratic patterns such as nested loops and repeated membership checks in loops. on
LEG006 Avoid redundant boolean comparisons like flag == True. on
LEG007 Prefer positive condition names over names like is_not_ready. on

Pre-commit

repos:
  - repo: local
    hooks:
      - id: ruff-legibility
        name: ruff-legibility
        entry: ruff-legibility check
        language: system
        types: [python]

Development

Common commands:

uv sync --all-groups
uv run ruff check .
uv run ruff-legibility check src tests
uv run pytest
uv build

Release builds should use:

uv build --no-sources

Publishing is configured for PyPI Trusted Publishing:

uv publish

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ruff_legibility-0.1.0.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ruff_legibility-0.1.0-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file ruff_legibility-0.1.0.tar.gz.

File metadata

  • Download URL: ruff_legibility-0.1.0.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for ruff_legibility-0.1.0.tar.gz
Algorithm Hash digest
SHA256 88709365276b6c755c9cf69ed02df2a6035a84cbf3c454264967e4ce92f8ccbf
MD5 10515d0d36ae644fd3967bc7db01d655
BLAKE2b-256 4c80d2557383211cdd6a4b708befd44218a5a23140a8f69f1f2e05cbfc09ccbc

See more details on using hashes here.

File details

Details for the file ruff_legibility-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ruff_legibility-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for ruff_legibility-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dd3264d13c4aaf951495d39450cb8a842da2be8105da8c2c96a639616aa79343
MD5 871944ea7cf57d9803e001b406aa97bc
BLAKE2b-256 cf7bbade42c797b5df108e7be9f8f4ba921471488775af3c49b76501c5678285

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page