Skip to content

Commit 63a5a12

Browse files
Improve documentation around linter-formatter conflicts (#8257)
Closes #8245.
1 parent c32f943 commit 63a5a12

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

docs/formatter.md

+14-3
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,10 @@ comments, which are treated equivalently to `# fmt: off` and `# fmt: on`, respec
180180

181181
Ruff's formatter is designed to be used alongside the linter. However, the linter includes
182182
some rules that, when enabled, can cause conflicts with the formatter, leading to unexpected
183-
behavior.
183+
behavior. When configured appropriately, the goal of Ruff's formatter-linter compatibility is
184+
such that running the formatter should never introduce new lint errors.
184185

185-
When using Ruff as a formatter, we recommend disabling the following rules:
186+
As such, when using Ruff as a formatter, we recommend avoiding the following lint rules:
186187

187188
- [`tab-indentation`](rules/tab-indentation.md) (`W191`)
188189
- [`indentation-with-invalid-multiple`](rules/indentation-with-invalid-multiple.md) (`E111`)
@@ -199,7 +200,11 @@ When using Ruff as a formatter, we recommend disabling the following rules:
199200
- [`single-line-implicit-string-concatenation`](rules/single-line-implicit-string-concatenation.md) (`ISC001`)
200201
- [`multi-line-implicit-string-concatenation`](rules/multi-line-implicit-string-concatenation.md) (`ISC002`)
201202

202-
Similarly, we recommend disabling the following isort settings, which are incompatible with the
203+
None of the above are included in Ruff's default configuration. However, if you've enabled
204+
any of these rules or their parent categories (like `Q`), we recommend disabling them via the
205+
linter's [`ignore`](settings.md#ignore) setting.
206+
207+
Similarly, we recommend avoiding the following isort settings, which are incompatible with the
203208
formatter's treatment of import statements when set to non-default values:
204209

205210
- [`force-single-line`](settings.md#isort-force-single-line)
@@ -208,6 +213,12 @@ formatter's treatment of import statements when set to non-default values:
208213
- [`lines-between-types`](settings.md#isort-lines-between-types)
209214
- [`split-on-trailing-comma`](settings.md#isort-split-on-trailing-comma)
210215

216+
If you've configured any of these settings to take on non-default values, we recommend removing
217+
them from your Ruff configuration.
218+
219+
When an incompatible lint rule or setting is enabled, `ruff format` will emit a warning. If your
220+
`ruff format` is free of warnings, you're good to go!
221+
211222
## Exit codes
212223

213224
`ruff format` exits with the following status codes:

docs/integrations.md

+4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ or isort, _unless_ you enable autofix, in which case, Ruff's pre-commit hook sho
5555
Black, isort, and other formatting tools, as Ruff's autofix behavior can output code changes that
5656
require reformatting.
5757

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

6064
Ruff supports the [Language Server Protocol](https://microsoft.github.io/language-server-protocol/)

0 commit comments

Comments
 (0)