Introduction to Ruff
Ruff is an extremely fast Python linter that checks Python cofe for programming errors, bugs, stylistic errors, and suspect constructs. The difference between Ruff and other python linters like pylint, flake8 is that it is written in Rust, a language known for its speed and performance. This allows Ruff to provide high-performance solution for linting Python code.
Installing Ruff
You can install Ruff using pip:
pip install ruff
Using Ruff
After installing Ruff, let’s look at few examples of running Ruff on your code base.
Here are some of the examples:
# Lint all files in the current directory (and any subdirectories)
ruff check .
# Lint all files in `/path/to/code` (and any subdirectories)
ruff check path/to/code/
# Lint all `.py` files in `/path/to/code`
ruff check path/to/code/*.py
# Lint `file.py`
ruff check path/to/code/to/file.py
Ruff also supports a handy mode to watch for changes on a folder and re-run when a change is detected.
Here is the command you can use for that:
ruff check path/to/code/ --watch
Note: Ruff is still in beta.