Skip to main content

Logo

ruffruleannotator

ruffruleannotator is a small tool designed to enhance the readability of Ruff configuration files by annotating all rule IDs with their corresponding titles. This allows users to easily understand the purpose of each ignored/selected rule within their codebase. Additionally, ruffruleannotator can sort the rule IDs within the relevant sections of the TOML file, ensuring a well-organized and readable configuration.

Example

Consider the following pyproject.toml:

[project]
name = "packagename"

[tool.ruff.lint]
select = ["D100", "D103", "ERA001", "PLR2004", "F"]

ignore = ["E501", "B"]

[tool.ruff.format]
quote-style = "single"

Executing ruffruleannotator yield a reformatted config with annotated rule IDs:

[project]
name = "packagename"

[tool.ruff.lint]
select = [
    "D100",      # undocumented-public-module (pydocstyle)
    "D103",      # undocumented-public-function (pydocstyle)
    "ERA001",    # commented-out-code (eradicate)
    "F",         # Pyflakes
    "PLR2004",   # magic-value-comparison (Pylint (Refactor))
]

ignore = [
    "B",         # flake8-bugbear
    "E501",      # line-too-long (pycodestyle errors)
]

[tool.ruff.format]
quote-style = "single"

Installation

pip install ruffruleannotator

Usage

The tool automatically recognizes ruff configs inside pyproject.toml and ruff.toml. The entries select, ignore, fixable and unfixable inside the Ruff lint section of the config are supported for reformatting. All other parts of the file stay unchanged.

Execute the tool inside project root directory:

ruffruleannotator

Keep order of entries

By default ruffruleannotator sorts the rule IDs within the sections alphabetically. The order of entries can be preserved:

ruffruleannotator --no-sort

Check

ruffruleannotator can be easily integrated in a CI/CD pipeline by checking if changes would be applied or not. Running

ruffruleannotator --check

will return with exit code 0 or 1 respectively without applying any changes.

Interactive mode

By default ruffruleannotator shows changes and waits for user confirmation before actually changing the config:

Found ruff config in 'pyproject.toml'

--- 
+++ 
@@ -2,9 +2,18 @@
 name = "packagename"
 
 [tool.ruff.lint]
-select = ["D100", "D103", "ERA001", "PLR2004", "F"]
+select = [
+    "D100",      # undocumented-public-module (pydocstyle)
+    "D103",      # undocumented-public-function (pydocstyle)
+    "ERA001",    # commented-out-code (eradicate)
+    "F",         # Pyflakes
+    "PLR2004",   # magic-value-comparison (Pylint [Refactor])
+]
 
-ignore = ["E501", "B"]
+ignore = [
+    "B",         # flake8-bugbear
+    "E501",      # line-too-long (pycodestyle errors)
+]
 
 [tool.ruff.format]
 quote-style = "single"

Press enter to apply changes

Changes can be applied without user confirmation by calling

ruffruleannotator --yes

Complex formattings

Consider the following config file:

[tool.ruff.lint]
select = ["F404",
    "F403",
    # Comment lines break the sorting. Rule IDs are sorted
    # seperately above and below the comment line.
    "F406", # already commented lines are not annotated
    "F402",
    # Lines with multiple rule ids are split
    "E112", "E111",
    "E113"]

After reformatting:

[tool.ruff.lint]
select = [
    "F403",      # undefined-local-with-import-star (Pyflakes)
    "F404",      # late-future-import (Pyflakes)
    # Comment lines break the sorting. Rule IDs are sorted
    # seperately above and below the comment line.
    "F402",      # import-shadowed-by-loop-var (Pyflakes)
    "F406", # already commented lines are not annotated
    # Lines with multiple rule ids are split
    "E111",      # indentation-with-invalid-multiple (pycodestyle errors)
    "E112",      # no-indented-block (pycodestyle errors)
    "E113",      # unexpected-indentation (pycodestyle errors)
]

Contributing

  • Create virtual environment
    python3 -m venv venv
    source venv/bin/activate
    pip install -r requirements-dev.txt
    
  • Setup pre-commit
    pre-commit install
    
  • Build package
    python -m build
    

Metadata

Release files for ruffruleannotator 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ruffruleannotator 0.1.3
File Size Uploaded
ruffruleannotator-0.1.3.tar.gz 7.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ruffruleannotator 0.1.3
File Interpreter ABI Platform
ruffruleannotator-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 16.4 kB

Release files / ruffruleannotator-0.1.3.tar.gz

Download URL ruffruleannotator-0.1.3.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c8274e5dd4afa395a936ddf2cbfbf6b927e1a5af6e9ac53f0b6f398817fb9a5c
BLAKE2b-256 checksum
How to use checksums
02743ce47ab30af41c004ac8891fd35152396230e6dd9c7edb29023087d605f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.5

Release files / ruffruleannotator-0.1.3-py3-none-any.whl

Download URL ruffruleannotator-0.1.3-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2cc9e9091cad6c10c4ebd338128d4eaef4022b3a628ed57ee4a6dae7a47210da
BLAKE2b-256 checksum
How to use checksums
b91c40fb29e07ded954c8d0fddf1db96e60db855e6267794725d4b4bcf8b4803
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.5

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page