Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/astral-sh/ruff-pre-commit
A pre-commit hook for Ruff.
https://github.com/astral-sh/ruff-pre-commit
Last synced: 6 days ago
JSON representation
A pre-commit hook for Ruff.
- Host: GitHub
- URL: https://github.com/astral-sh/ruff-pre-commit
- Owner: astral-sh
- License: apache-2.0
- Created: 2022-09-20T02:52:35.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-11-29T03:34:50.000Z (15 days ago)
- Last Synced: 2024-12-01T12:16:04.012Z (13 days ago)
- Language: Python
- Homepage:
- Size: 173 KB
- Stars: 1,011
- Watchers: 16
- Forks: 45
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
- stars - astral-sh/ruff-pre-commit - A pre-commit hook for Ruff. (Python)
README
# ruff-pre-commit
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![image](https://img.shields.io/pypi/v/ruff/0.8.2.svg)](https://pypi.python.org/pypi/ruff)
[![image](https://img.shields.io/pypi/l/ruff/0.8.2.svg)](https://pypi.python.org/pypi/ruff)
[![image](https://img.shields.io/pypi/pyversions/ruff/0.8.2.svg)](https://pypi.python.org/pypi/ruff)
[![Actions status](https://github.com/astral-sh/ruff-pre-commit/workflows/main/badge.svg)](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
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.8.2
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
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.8.2
hooks:
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
```To avoid running on Jupyter Notebooks, remove `jupyter` from the list of allowed filetypes:
```yaml
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.8.2
hooks:
# Run the linter.
- id: ruff
types_or: [ python, pyi ]
args: [ --fix ]
# Run the formatter.
- id: ruff-format
types_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](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
ruff-pre-commit is licensed under either of
- Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or )
- MIT license ([LICENSE-MIT](LICENSE-MIT) or )at your option.
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.