Ruff + diff = Riff
Run Ruff⚡, and filter out violations not caused by your branch.
Riff uses git diff to detect code lines modified in the current branch, and filters Ruff's output accordingly.
Riff only fails when violations are detected in modified lines.
Ruff doesn't have a baseline feature, so Riff can come handy for enforcing Ruff rules in larger repositories quickly, without having to fix every single existing violation.
- Make sure Ruff (>=0.0.291) is installed
- Run
riff, followed by (optional) Riff arguments, and (optional) Ruff arguments. - Running
riffwithout arguments will run it in the current directory. - Riff expects to be run in a repository folder.
Copy this to your .pre-commit-config file
- repo: https://github.com/dorschw/riff
hooks:
- id: riff
rev: v0.1.9.0
additional_dependencies: ["ruff>=0.0.291"] # minimal is 0.0.291
To pass other arguments to Riff (and Ruff), add the args key, e.g.
args: ["--base-branch=origin/master"]
always-fail-on: comma-separated list of Ruff error codes. When detected by Ruff, Riff will consider them as failures, even if they're not in lines modified in the current branch.print-github-annotation: boolean (defaultfalse). When set totrue, will add GitHub Annotations, making the violations more visible when reviewing code in GitHub'sModified Filestab.base-branch: string (defaultorigin/main). Change toorigin/masteror whatever your base branch is named.
- When using Ruff's
--fixfeature, Ruff will fix everything it is configured to, regardless of the modified lines. Riff cannot control this behavior. - Riff cannot currently run Ruff with a
--output-formatconfiguration. (see here)