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` ruff check @file_paths.txt # Lint using an input file and treat its contents as command-line arguments (newline delimiter)
You can run Ruff in
--watch mode to automatically re-run on-change:
Ruff can also be used as a pre-commit hook:
Or, to enable autofix:
Or, to run the hook on Jupyter Notebooks too:
Ruff's pre-commit hook should be placed after other formatting tools, such as Black and isort, unless you enable autofix, in which case, Ruff's pre-commit hook should run before Black, isort, and other formatting tools, as Ruff's autofix behavior can output code changes that require reformatting.
Ruff can also be used as a GitHub Action via
ruff-action runs as a pass-fail test to ensure that a given repository doesn't contain
any lint rule violations as per its configuration.
ruff-action installs and runs
ruff directly, so it can be used to
execute any supported
ruff command (e.g.,
ruff check --fix).
ruff-action supports all GitHub-hosted runners, and can be used with any published Ruff version
(i.e., any version available on PyPI).
ruff-action, create a file (e.g.,
.github/workflows/ruff.yml) inside your repository
Alternatively, you can include
ruff-action as a step in any other workflow file:
ruff-action accepts optional configuration parameters via
version: The Ruff version to install (default: latest).
options: The command-line arguments to pass to Ruff (default:
src: The source paths to pass to Ruff (default:
For example, to run
ruff check --select B ./src using Ruff version