ruffruleannotator


Nameruffruleannotator JSON
Version 0.1.3 PyPI version JSON
download
home_pageNone
SummarySmall tool to annotate and sort rule IDs inside a ruff config for better readability.
upload_time2024-10-13 08:53:02
maintainerNone
docs_urlNone
authorY. Lieder
requires_pythonNone
licenseMIT License Copyright (c) 2024 Yannic Lieder Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords ruff formatter annotator
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <!-- Image URL must be absolute path on main branch in order to be shown in PyPI -->
![Logo](https://raw.githubusercontent.com/ylieder/ruffruleannotator/main/docs/logo.png)

# 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`:
```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:
```toml
[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
```shell
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:
```shell
ruffruleannotator
```

### Keep order of entries
By default `ruffruleannotator` sorts the rule IDs within the sections alphabetically. The order of entries can be preserved: 
```shell
ruffruleannotator --no-sort
```

### Check
`ruffruleannotator` can be easily integrated in a CI/CD pipeline by checking if changes
would be applied or not. Running
```shell
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:
```diff
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
```shell
ruffruleannotator --yes
```

### Complex formattings
Consider the following config file:
```toml
[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:
```toml
[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
    ```shell
    python3 -m venv venv
    source venv/bin/activate
    pip install -r requirements-dev.txt
    ```
- Setup pre-commit
    ```shell
    pre-commit install
    ```
- Build package
    ```
    python -m build
    ```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "ruffruleannotator",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "ruff, formatter, annotator",
    "author": "Y. Lieder",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/02/74/3ce47ab30af41c004ac8891fd35152396230e6dd9c7edb29023087d605f5/ruffruleannotator-0.1.3.tar.gz",
    "platform": null,
    "description": "<!-- Image URL must be absolute path on main branch in order to be shown in PyPI -->\n![Logo](https://raw.githubusercontent.com/ylieder/ruffruleannotator/main/docs/logo.png)\n\n# ruffruleannotator\n\nruffruleannotator 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.\n\n## Example \nConsider the following `pyproject.toml`:\n```toml\n[project]\nname = \"packagename\"\n\n[tool.ruff.lint]\nselect = [\"D100\", \"D103\", \"ERA001\", \"PLR2004\", \"F\"]\n\nignore = [\"E501\", \"B\"]\n\n[tool.ruff.format]\nquote-style = \"single\"\n```\nExecuting `ruffruleannotator` yield a reformatted config with annotated rule IDs:\n```toml\n[project]\nname = \"packagename\"\n\n[tool.ruff.lint]\nselect = [\n    \"D100\",      # undocumented-public-module (pydocstyle)\n    \"D103\",      # undocumented-public-function (pydocstyle)\n    \"ERA001\",    # commented-out-code (eradicate)\n    \"F\",         # Pyflakes\n    \"PLR2004\",   # magic-value-comparison (Pylint (Refactor))\n]\n\nignore = [\n    \"B\",         # flake8-bugbear\n    \"E501\",      # line-too-long (pycodestyle errors)\n]\n\n[tool.ruff.format]\nquote-style = \"single\"\n```\n\n## Installation\n```shell\npip install ruffruleannotator\n```\n\n## Usage\nThe 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.\n\nExecute the tool inside project root directory:\n```shell\nruffruleannotator\n```\n\n### Keep order of entries\nBy default `ruffruleannotator` sorts the rule IDs within the sections alphabetically. The order of entries can be preserved: \n```shell\nruffruleannotator --no-sort\n```\n\n### Check\n`ruffruleannotator` can be easily integrated in a CI/CD pipeline by checking if changes\nwould be applied or not. Running\n```shell\nruffruleannotator --check\n```\nwill return with exit code 0 or 1 respectively without applying any changes.\n\n\n### Interactive mode\nBy default `ruffruleannotator` shows changes and waits for user confirmation before actually changing the config:\n```diff\nFound ruff config in 'pyproject.toml'\n\n--- \n+++ \n@@ -2,9 +2,18 @@\n name = \"packagename\"\n \n [tool.ruff.lint]\n-select = [\"D100\", \"D103\", \"ERA001\", \"PLR2004\", \"F\"]\n+select = [\n+    \"D100\",      # undocumented-public-module (pydocstyle)\n+    \"D103\",      # undocumented-public-function (pydocstyle)\n+    \"ERA001\",    # commented-out-code (eradicate)\n+    \"F\",         # Pyflakes\n+    \"PLR2004\",   # magic-value-comparison (Pylint [Refactor])\n+]\n \n-ignore = [\"E501\", \"B\"]\n+ignore = [\n+    \"B\",         # flake8-bugbear\n+    \"E501\",      # line-too-long (pycodestyle errors)\n+]\n \n [tool.ruff.format]\n quote-style = \"single\"\n\nPress enter to apply changes\n```\n\nChanges can be applied without user confirmation by calling\n```shell\nruffruleannotator --yes\n```\n\n### Complex formattings\nConsider the following config file:\n```toml\n[tool.ruff.lint]\nselect = [\"F404\",\n    \"F403\",\n    # Comment lines break the sorting. Rule IDs are sorted\n    # seperately above and below the comment line.\n    \"F406\", # already commented lines are not annotated\n    \"F402\",\n    # Lines with multiple rule ids are split\n    \"E112\", \"E111\",\n    \"E113\"]\n```\nAfter reformatting:\n```toml\n[tool.ruff.lint]\nselect = [\n    \"F403\",      # undefined-local-with-import-star (Pyflakes)\n    \"F404\",      # late-future-import (Pyflakes)\n    # Comment lines break the sorting. Rule IDs are sorted\n    # seperately above and below the comment line.\n    \"F402\",      # import-shadowed-by-loop-var (Pyflakes)\n    \"F406\", # already commented lines are not annotated\n    # Lines with multiple rule ids are split\n    \"E111\",      # indentation-with-invalid-multiple (pycodestyle errors)\n    \"E112\",      # no-indented-block (pycodestyle errors)\n    \"E113\",      # unexpected-indentation (pycodestyle errors)\n]\n```\n\n## Contributing\n\n- Create virtual environment\n    ```shell\n    python3 -m venv venv\n    source venv/bin/activate\n    pip install -r requirements-dev.txt\n    ```\n- Setup pre-commit\n    ```shell\n    pre-commit install\n    ```\n- Build package\n    ```\n    python -m build\n    ```\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2024 Yannic Lieder  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Small tool to annotate and sort rule IDs inside a ruff config for better readability.",
    "version": "0.1.3",
    "project_urls": {
        "Repository": "https://github.com/ylieder/ruffruleannotator"
    },
    "split_keywords": [
        "ruff",
        " formatter",
        " annotator"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b91c40fb29e07ded954c8d0fddf1db96e60db855e6267794725d4b4bcf8b4803",
                "md5": "631b3ae4b0d06c6fa45503d5856a3f76",
                "sha256": "2cc9e9091cad6c10c4ebd338128d4eaef4022b3a628ed57ee4a6dae7a47210da"
            },
            "downloads": -1,
            "filename": "ruffruleannotator-0.1.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "631b3ae4b0d06c6fa45503d5856a3f76",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 8471,
            "upload_time": "2024-10-13T08:53:00",
            "upload_time_iso_8601": "2024-10-13T08:53:00.847275Z",
            "url": "https://files.pythonhosted.org/packages/b9/1c/40fb29e07ded954c8d0fddf1db96e60db855e6267794725d4b4bcf8b4803/ruffruleannotator-0.1.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "02743ce47ab30af41c004ac8891fd35152396230e6dd9c7edb29023087d605f5",
                "md5": "58b910927071d85474eb83ecc7c6e9e0",
                "sha256": "c8274e5dd4afa395a936ddf2cbfbf6b927e1a5af6e9ac53f0b6f398817fb9a5c"
            },
            "downloads": -1,
            "filename": "ruffruleannotator-0.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "58b910927071d85474eb83ecc7c6e9e0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 7948,
            "upload_time": "2024-10-13T08:53:02",
            "upload_time_iso_8601": "2024-10-13T08:53:02.428218Z",
            "url": "https://files.pythonhosted.org/packages/02/74/3ce47ab30af41c004ac8891fd35152396230e6dd9c7edb29023087d605f5/ruffruleannotator-0.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-13 08:53:02",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ylieder",
    "github_project": "ruffruleannotator",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "ruffruleannotator"
}
        
Elapsed time: 1.02616s