@@ -12,52 +12,55 @@ which supports fix actions, import sorting, and more.
12
12
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 ) :
13
13
14
14
``` yaml
15
- # Run the Ruff linter.
16
15
- repo : https://github.com/astral-sh/ruff-pre-commit
17
16
# Ruff version.
18
- rev : v0.0.291
17
+ rev : v0.1.4
19
18
hooks :
19
+ # Run the linter.
20
20
- 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.
26
22
- id : ruff-format
27
23
` ` `
28
24
29
- To enable fixes, add the ` --fix` argument to the linter :
25
+ To enable lint fixes, add the ` --fix` argument to the lint hook :
30
26
31
27
` ` ` yaml
32
- # Run the Ruff linter.
33
28
- repo: https://github.com/astral-sh/ruff-pre-commit
34
29
# Ruff version.
35
- rev: v0.0.291
30
+ rev: v0.1.4
36
31
hooks:
32
+ # Run the linter.
37
33
- id: ruff
38
- args: [ --fix, --exit-non-zero-on-fix ]
34
+ args: [ --fix ]
35
+ # Run the formatter.
36
+ - id: ruff-format
39
37
` ` `
40
38
41
39
To run the hooks over Jupyter Notebooks too, add `jupyter` to the list of allowed filetypes :
42
40
43
41
` ` ` yaml
44
- # Run the Ruff linter.
45
42
- repo: https://github.com/astral-sh/ruff-pre-commit
46
43
# Ruff version.
47
- rev: v0.0.291
44
+ rev: v0.1.4
48
45
hooks:
46
+ # Run the linter.
49
47
- id: ruff
50
48
types_or: [ python, pyi, jupyter ]
49
+ args: [ --fix ]
50
+ # Run the formatter.
51
+ - id: ruff-format
52
+ types_or: [ python, pyi, jupyter ]
51
53
` ` `
52
54
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.
57
60
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),
59
62
` 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` .)
61
64
62
65
# # Language Server Protocol (Official)
63
66
0 commit comments