A pre-commit hook to automatically synchronize your Ruff version in .pre-commit-config.yaml with the version locked in uv.lock.
When managing Python dependencies with uv, you have a specific version of ruff locked in your uv.lock file. However, the ruff-pre-commit hook in your .pre-commit-config.yaml is often updated independently, leading to version mismatches between your local environment/CI and the pre-commit hook.
This hook solves that problem by:
- Reading the
ruffversion from youruv.lockfile. - Checking the
ruff-pre-commitrevision in your.pre-commit-config.yaml. - Automatically updating the
revin.pre-commit-config.yamlto match the version inuv.lock.
Add this hook to your .pre-commit-config.yaml. It should run before the main ruff hook to ensure the version is correct.
repos:
- repo: https://github.com/fllesser/ruff-rev-sync-pre-commit
rev: v1.0.0
hooks:
- id: ruff-rev-syncThe hook runs a Python script that:
- Locates
uv.lockand.pre-commit-config.yamlin your project root. - Parses
uv.lockto find the installed version ofruff. - Updates the
revfield forhttps://github.com/astral-sh/ruff-pre-commitin.pre-commit-config.yamltov{version}.
uvpackage manager (foruv.lock).ruffmust be present in youruv.lock.