{"id":51417079,"url":"https://github.com/tsvikas/ruff-fix-and-commit","last_synced_at":"2026-07-04T20:30:35.453Z","repository":{"id":354163190,"uuid":"1222429026","full_name":"tsvikas/ruff-fix-and-commit","owner":"tsvikas","description":"Run ruff check --fix for selected rules and commit the result with a per-rule summary.","archived":false,"fork":false,"pushed_at":"2026-05-09T08:36:29.000Z","size":189,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-09T10:35:13.087Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tsvikas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-27T11:04:25.000Z","updated_at":"2026-05-09T08:36:27.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/tsvikas/ruff-fix-and-commit","commit_stats":null,"previous_names":["tsvikas/ruff-fix-and-commit"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tsvikas/ruff-fix-and-commit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsvikas%2Fruff-fix-and-commit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsvikas%2Fruff-fix-and-commit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsvikas%2Fruff-fix-and-commit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsvikas%2Fruff-fix-and-commit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tsvikas","download_url":"https://codeload.github.com/tsvikas/ruff-fix-and-commit/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsvikas%2Fruff-fix-and-commit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35135341,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-04T02:00:05.987Z","response_time":113,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-07-04T20:30:34.706Z","updated_at":"2026-07-04T20:30:35.437Z","avatar_url":"https://github.com/tsvikas.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ruff-fix-and-commit\n\n[![Tests][tests-badge]][tests-link]\n[![uv][uv-badge]][uv-link]\n[![Ruff][ruff-badge]][ruff-link]\n[![codecov][codecov-badge]][codecov-link]\n\\\n[![Made Using tsvikas/python-template][template-badge]][template-link]\n[![GitHub Discussion][github-discussions-badge]][github-discussions-link]\n[![PRs Welcome][prs-welcome-badge]][prs-welcome-link]\n\n## Overview\n\nRun `ruff check --fix` for selected rule(s) and produce a single git commit with a per-rule summary.\n\n## Install\n\nInstall this tool using pipx (or uv):\n\n```bash\npipx install git+https://github.com/tsvikas/ruff-fix-and-commit.git\n```\n\nOr, from a checkout:\n\n```bash\nuv tool install .\n```\n\n## Usage\n\n```bash\nruff-fix-and-commit [TARGET...] [--select RULES] [--unsafe-fixes] [--statistics SELECTOR] [--ignore RULES]\n```\n\n`TARGET` is a path that scopes the run to tracked Python files under it; pass more than one to scope to a union of paths. Defaults to the current directory.\n\n`--select RULES` is a comma-separated ruff rule selector (codes or category prefixes), passed verbatim to `ruff --select`. If omitted, the tool runs in **status mode** (see below) instead of fixing.\n\nThe `--statistics` value accepts the same syntax plus a `DEFAULT` token: bare `DEFAULT` means \"use the repo's configured selection\", and `DEFAULT,X` means \"the repo's configuration plus X\" (translated to `--extend-select X`).\n\nUse `ruff-fix-and-commit --help` to learn more.\n\n### Examples\n\n```bash\n# fix all auto-fixable B-rules and the specific C212\nruff-fix-and-commit --select B,C212\n\n# scope the fix to a subdirectory (or several)\nruff-fix-and-commit src/ --select A001\nruff-fix-and-commit src/ tests/ --select A001\n\n# include unsafe fixes (e.g. for E731 lambda-assignment)\nruff-fix-and-commit --select E731 --unsafe-fixes\n\n# after fixing B009, show stats for everything in the repo's lint config\nruff-fix-and-commit --select B009 --statistics DEFAULT\n\n# repo's lint config plus extra rules (DEFAULT,X mixes --extend-select)\nruff-fix-and-commit --select B009 --statistics DEFAULT,E\n\n# after fixing B009, show stats for any selector, suppressing noisy families\nruff-fix-and-commit --select B009 --statistics ALL --ignore D,ANN\n\n# status mode: format check, induced-rule cleanliness, and a remaining-issues\n# breakdown under the repo's configured selection (implicit --statistics DEFAULT)\nruff-fix-and-commit\n```\n\n### Commit message format\n\nSingle rule fixed:\n\n```\nlint: fix B009 (get-attr-with-constant) x2\n\nAuto-fixed with ruff: https://docs.astral.sh/ruff/\nCommitted by ruff-fix-and-commit: https://github.com/tsvikas/ruff-fix-and-commit\n```\n\nMultiple rules fixed (header shows the rules input verbatim and the total fix count):\n\n```\nlint: fix A,B001,C212 x20\n\n- A123 (builtin-attribute-shadowing) x10\n- B001 (mutable-default-value) x7\n- C212 (unnecessary-iterable-comprehension) x3\n\nAuto-fixed with ruff: https://docs.astral.sh/ruff/\nCommitted by ruff-fix-and-commit: https://github.com/tsvikas/ruff-fix-and-commit\n```\n\n## Guarantees\n\nThe tool **refuses to run a fix** when:\n\n- The current directory is not inside a git repository.\n- Any tracked file has uncommitted changes (untracked files are ignored).\n\nThe dirty-tree gate is **skipped in status mode** (no `--select`) since that path is read-only.\n\nThe tool **never modifies**:\n\n- Untracked files (only tracked Python files are passed to ruff).\n- Files inside git submodules.\n\n`--unsafe-fixes` is forwarded explicitly to ruff in both directions: when the flag is omitted, the tool sends `--no-unsafe-fixes` so a repo's `[tool.ruff] unsafe-fixes = true` cannot silently apply unsafe fixes.\n\n### Silent cleanup of induced rules\n\nA ruff fix can introduce I001 (unsorted-imports) or F401 (unused-import) violations as a side effect of fixing something else. To avoid leaving the tree dirtier than it was found, the tool runs a follow-up `--fix` pass for these \"induced rules\" — but **only** under conditions that match user intent:\n\n- The induced rule had **zero** violations before the fix (so any new violations were introduced by the run), **or**\n- The induced rule was **included in the user's selector** (so the user opted into fixing it).\n\nOtherwise, pre-existing I001/F401 violations are left alone.\n\nAfter the silent cleanup, if the tree was already formatted before the fix, `ruff format` is re-run so the resulting commit stays formatted.\n\n## Status mode\n\nWhen invoked **without** `--select`, the tool reports the format-check state, induced-rule cleanliness, and a remaining-issues breakdown under the repo's configured rule selection (status mode implies `--statistics DEFAULT`):\n\n```\nformatted: yes\nI001 unsorted-imports: clean\nF401 unused-import: clean\nremaining: none\n```\n\nEach induced rule shows either `clean` or its current violation count, and the breakdown lists every rule that's currently violating:\n\n```\nformatted: no\nI001 unsorted-imports: 3\nF401 unused-import: 1\nremaining:\n  ...per-rule table...\n```\n\nStatus mode never fixes and never commits. Pass `--statistics RULES` to override the implicit `DEFAULT` and scope the breakdown to a specific selector.\n\n## Output cases\n\nThe tool's output is intentionally minimal. The exact stdout depends on the outcome:\n\n| Outcome                                           | Output                                                                                                         |\n| ------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- |\n| Repo has no tracked Python files (under `TARGET`) | `No Python files to check.`                                                                                    |\n| Files exist, no violations of `--select` rules    | `No matching violations.`                                                                                      |\n| Files exist, violations exist but none fixed      | `no fixes applied:` + per-rule counts; `hint: N hidden fixes can be enabled with --unsafe-fixes` if applicable |\n| Some violations fixed, others remain              | Commit message + `N violations remain.` (or `1 violation remains.`) footer                                     |\n| All violations fixed                              | Commit message only                                                                                            |\n\nAdd `--statistics SELECTOR` for a per-rule breakdown of what's left after the fix; combine with `--ignore D,ANN` to drop noisy families from that view.\n\nExample of the unfixable + hint path:\n\n```\n$ ruff-fix-and-commit --select E731\nno fixes applied:\n9       E731    [ ] lambda-assignment\nhint: 9 hidden fixes can be enabled with --unsafe-fixes\n```\n\nThe marker on each row indicates how many of that rule's violations are auto-fixable: `[*]` all of them, `[~]` some of them, `[ ]` none of them.\n\n## Exit codes\n\n| Code | Meaning                                      |\n| ---- | -------------------------------------------- |\n| `0`  | Success, or nothing to fix                   |\n| `1`  | Refused (not in a repo, dirty tracked files) |\n| `2`  | ruff failed (invalid selector, etc.)         |\n\n## Contributing\n\nInterested in contributing?\nSee [CONTRIBUTING.md](CONTRIBUTING.md) for development setup and guideline.\n\n[codecov-badge]: https://codecov.io/gh/tsvikas/ruff-fix-and-commit/graph/badge.svg\n[codecov-link]: https://codecov.io/gh/tsvikas/ruff-fix-and-commit\n[github-discussions-badge]: https://img.shields.io/static/v1?label=Discussions\u0026message=Ask\u0026color=blue\u0026logo=github\n[github-discussions-link]: https://github.com/tsvikas/ruff-fix-and-commit/discussions\n[prs-welcome-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg\n[prs-welcome-link]: https://opensource.guide/how-to-contribute/\n[ruff-badge]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json\n[ruff-link]: https://github.com/astral-sh/ruff\n[template-badge]: https://img.shields.io/badge/%F0%9F%9A%80_Made_Using-tsvikas%2Fpython--template-gold\n[template-link]: https://github.com/tsvikas/python-template\n[tests-badge]: https://github.com/tsvikas/ruff-fix-and-commit/actions/workflows/ci.yml/badge.svg\n[tests-link]: https://github.com/tsvikas/ruff-fix-and-commit/actions/workflows/ci.yml\n[uv-badge]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json\n[uv-link]: https://github.com/astral-sh/uv\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftsvikas%2Fruff-fix-and-commit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftsvikas%2Fruff-fix-and-commit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftsvikas%2Fruff-fix-and-commit/lists"}