Skip to content

Commit ce549e7

Browse files
Update pre-commit documentation (#8545)
I got some feedback on Mastodon that it wasn't clear how to use the linter and formatter together in pre-commit (mostly in the pre-commit repo's documentation, which is even less clear, but the two should be consistent).
1 parent 03303a9 commit ce549e7

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,10 @@ Ruff can also be used as a [pre-commit](https://pre-commit.com/) hook via [`ruff
152152
# Ruff version.
153153
rev: v0.1.4
154154
hooks:
155-
# Run the Ruff linter.
155+
# Run the linter.
156156
- id: ruff
157-
# Run the Ruff formatter.
157+
args: [ --fix ]
158+
# Run the formatter.
158159
- id: ruff-format
159160
```
160161

docs/integrations.md

+22-19
Original file line numberDiff line numberDiff line change
@@ -12,52 +12,55 @@ which supports fix actions, import sorting, and more.
1212
Ruff can be used as a [pre-commit](https://pre-commit.com) hook via [`ruff-pre-commit`](https://github.com/astral-sh/ruff-pre-commit):
1313

1414
```yaml
15-
# Run the Ruff linter.
1615
- repo: https://github.com/astral-sh/ruff-pre-commit
1716
# Ruff version.
18-
rev: v0.0.291
17+
rev: v0.1.4
1918
hooks:
19+
# Run the linter.
2020
- id: ruff
21-
# Run the Ruff formatter.
22-
- repo: https://github.com/astral-sh/ruff-pre-commit
23-
# Ruff version.
24-
rev: v0.0.291
25-
hooks:
21+
# Run the formatter.
2622
- id: ruff-format
2723
```
2824
29-
To enable fixes, add the `--fix` argument to the linter:
25+
To enable lint fixes, add the `--fix` argument to the lint hook:
3026

3127
```yaml
32-
# Run the Ruff linter.
3328
- repo: https://github.com/astral-sh/ruff-pre-commit
3429
# Ruff version.
35-
rev: v0.0.291
30+
rev: v0.1.4
3631
hooks:
32+
# Run the linter.
3733
- id: ruff
38-
args: [ --fix, --exit-non-zero-on-fix ]
34+
args: [ --fix ]
35+
# Run the formatter.
36+
- id: ruff-format
3937
```
4038

4139
To run the hooks over Jupyter Notebooks too, add `jupyter` to the list of allowed filetypes:
4240

4341
```yaml
44-
# Run the Ruff linter.
4542
- repo: https://github.com/astral-sh/ruff-pre-commit
4643
# Ruff version.
47-
rev: v0.0.291
44+
rev: v0.1.4
4845
hooks:
46+
# Run the linter.
4947
- id: ruff
5048
types_or: [ python, pyi, jupyter ]
49+
args: [ --fix ]
50+
# Run the formatter.
51+
- id: ruff-format
52+
types_or: [ python, pyi, jupyter ]
5153
```
5254

53-
Ruff's lint hook should be placed after other formatting tools, such as Ruff's format hook, Black,
54-
or isort, _unless_ you enable autofix, in which case, Ruff's pre-commit hook should run _before_
55-
Black, isort, and other formatting tools, as Ruff's autofix behavior can output code changes that
56-
require reformatting.
55+
When running with `--fix`, Ruff's lint hook should be placed _before_ Ruff's formatter hook, and
56+
_before_ Black, isort, and other formatting tools, as Ruff's fix behavior can output code changes
57+
that require reformatting.
58+
59+
When running without `--fix`, Ruff's formatter hook can be placed before or after Ruff's lint hook.
5760

58-
As long as your Ruff configuration avoids any [linter-formatter incompatibilities](formatter.md#conflicting-lint-rules),
61+
(As long as your Ruff configuration avoids any [linter-formatter incompatibilities](formatter.md#conflicting-lint-rules),
5962
`ruff format` should never introduce new lint errors, so it's safe to run Ruff's format hook _after_
60-
`ruff check --fix`.
63+
`ruff check --fix`.)
6164

6265
## Language Server Protocol (Official)
6366

docs/tutorial.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -341,17 +341,13 @@ This tutorial has focused on Ruff's command-line interface, but Ruff can also be
341341
[pre-commit](https://pre-commit.com) hook via [`ruff-pre-commit`](https://github.com/astral-sh/ruff-pre-commit):
342342

343343
```yaml
344-
# Run the Ruff linter.
345344
- repo: https://github.com/astral-sh/ruff-pre-commit
346345
# Ruff version.
347346
rev: v0.1.4
348347
hooks:
348+
# Run the linter.
349349
- id: ruff
350-
# Run the Ruff formatter.
351-
- repo: https://github.com/astral-sh/ruff-pre-commit
352-
# Ruff version.
353-
rev: v0.1.4
354-
hooks:
350+
# Run the formatter.
355351
- id: ruff-format
356352
```
357353

0 commit comments

Comments
 (0)