ruff/docs/installation-and-usage.md

1.9 KiB

Installation

Ruff is available as ruff on PyPI:

pip install ruff

For macOS Homebrew and Linuxbrew users, Ruff is also available as ruff on Homebrew:

brew install ruff

For Conda users, Ruff is also available as ruff on conda-forge:

conda install -c conda-forge ruff

For Arch Linux users, Ruff is also available as ruff on the official repositories:

pacman -S ruff

For Alpine users, Ruff is also available as ruff on the testing repositories:

apk add ruff

Packaging status

Usage

To run Ruff, try any of the following:

ruff check .                        # Lint all files in the current directory (and any subdirectories)
ruff check path/to/code/            # Lint all files in `/path/to/code` (and any subdirectories)
ruff check path/to/code/*.py        # Lint all `.py` files in `/path/to/code`
ruff check path/to/code/to/file.py  # Lint `file.py`

You can run Ruff in --watch mode to automatically re-run on-change:

ruff check path/to/code/ --watch

Ruff also works with pre-commit:

- repo: https://github.com/charliermarsh/ruff-pre-commit
  # Ruff version.
  rev: 'v0.0.252'
  hooks:
    - id: ruff

Or, to enable autofix:

- repo: https://github.com/charliermarsh/ruff-pre-commit
  # Ruff version.
  rev: 'v0.0.252'
  hooks:
    - id: ruff
      args: [--fix, --exit-non-zero-on-fix]

Note that Ruff's pre-commit hook should run before Black, isort, and other formatting tools.