You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Distributed as a standalone repository to enable installing Ruff via prebuilt wheels from
PyPI.
Using Ruff with pre-commit
To run Ruff's linter and formatter
(available as of Ruff v0.0.289) via pre-commit, add the following to your .pre-commit-config.yaml:
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit# Ruff version.rev: v0.12.4hooks:
# Run the linter.
- id: ruff-check# Run the formatter.
- id: ruff-format
To enable lint fixes, add the --fix argument to the lint hook:
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit# Ruff version.rev: v0.12.4hooks:
# Run the linter.
- id: ruff-checkargs: [ --fix ]# Run the formatter.
- id: ruff-format
To avoid running on Jupyter Notebooks, remove jupyter from the list of allowed filetypes:
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit# Ruff version.rev: v0.12.4hooks:
# Run the linter.
- id: ruff-checktypes_or: [ python, pyi ]args: [ --fix ]# Run the formatter.
- id: ruff-formattypes_or: [ python, pyi ]
When running with --fix, Ruff's lint hook should be placed before Ruff's formatter hook, and
before Black, isort, and other formatting tools, as Ruff's fix behavior can output code changes
that require reformatting.
When running without --fix, Ruff's formatter hook can be placed before or after Ruff's lint hook.
(As long as your Ruff configuration avoids any linter-formatter incompatibilities,
ruff format should never introduce new lint errors, so it's safe to run Ruff's format hook afterruff check --fix.)
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in ruff-pre-commit by you, as defined in the Apache-2.0 license, shall be
dually licensed as above, without any additional terms or conditions.