# ruff-pre-commit [](https://github.com/astral-sh/ruff) [](https://pypi.python.org/pypi/ruff) [](https://pypi.python.org/pypi/ruff) [](https://pypi.python.org/pypi/ruff) [](https://github.com/astral-sh/ruff-pre-commit/actions) A [pre-commit](https://pre-commit.com/) hook for [Ruff](https://github.com/astral-sh/ruff). Distributed as a standalone repository to enable installing Ruff via prebuilt wheels from [PyPI](https://pypi.org/project/ruff/). ### Using Ruff with pre-commit To run Ruff's [linter](https://docs.astral.sh/ruff/linter) and [formatter](https://docs.astral.sh/ruff/formatter) (available as of Ruff v0.0.289) via pre-commit, add the following to your `.pre-commit-config.yaml`: ```yaml - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. rev: v0.3.4 hooks: # Run the linter. - id: ruff # Run the formatter. - id: ruff-format ``` To enable lint fixes, add the `--fix` argument to the lint hook: ```yaml - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. rev: v0.3.4 hooks: # Run the linter. - id: ruff args: [ --fix ] # Run the formatter. - id: ruff-format ``` To run the hooks over Jupyter Notebooks too, add `jupyter` to the list of allowed filetypes: ```yaml - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. rev: v0.3.4 hooks: # Run the linter. - id: ruff types_or: [ python, pyi, jupyter ] args: [ --fix ] # Run the formatter. - id: ruff-format types_or: [ python, pyi, jupyter ] ``` 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](https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules), `ruff format` should never introduce new lint errors, so it's safe to run Ruff's format hook _after_ `ruff check --fix`.) ## License MIT