Skip to content

Commit 2c7cd4b

Browse files
authored
Add Ruff documentation for Python linting and formatting
Added documentation for Ruff, a Python linter and formatter, including installation and usage instructions.
1 parent 48b93f4 commit 2c7cd4b

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

programming-notes/python/ruff.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Ruff - Python linter and code formatter
2+
3+
## Installing
4+
5+
Ruff can be invoked directly with `uvx`:
6+
7+
```bash
8+
$ uvx ruff check # Lint all files in the current directory.
9+
$ uvx ruff format # Format all files in the current directory.
10+
```
11+
12+
This runs `ruff` as a `uv` tool without installing it (it's installed in a temporary environment and deleted after use).
13+
14+
Alternatively you can install with `uv` (recommended):
15+
16+
To install Ruff globally.
17+
18+
```bash
19+
$ uv tool install ruff@latest
20+
```
21+
22+
## Usage
23+
24+
### Lint
25+
26+
```bash
27+
$ ruff check # Lint files in the current directory.
28+
$ ruff check --fix # Lint files in the current directory and fix any fixable errors.
29+
$ ruff check --watch # Lint files in the current directory and re-lint on change.
30+
$ ruff check path/to/code/ # Lint files in `path/to/code`.
31+
```
32+
33+
For the full list of supported options, run `ruff check --help`.
34+
35+
36+
### Formatter
37+
38+
```bash
39+
$ ruff format # Format all files in the current directory.
40+
$ ruff format path/to/code/ # Format all files in `path/to/code` (and any subdirectories).
41+
$ ruff format path/to/file.py # Format a single file.
42+
```
43+
44+
For the full list of supported options, run `ruff format --help`.
45+
46+
47+
### Sorting imports
48+
49+
```bash
50+
$ ruff check --select I --fix
51+
$ ruff format
52+
```

0 commit comments

Comments
 (0)