mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-01 17:32:25 +00:00
Update fix safety FAQ to reflect --unsafe-fixes
(#7969)
This commit is contained in:
parent
134def0119
commit
cac9754455
2 changed files with 7 additions and 18 deletions
|
@ -109,8 +109,6 @@ If you're wondering how to configure Ruff, here are some **recommended guideline
|
|||
- Start with a small set of rules (`select = ["E", "F"]`) and add a category at-a-time. For example,
|
||||
you might consider expanding to `select = ["E", "F", "B"]` to enable the popular flake8-bugbear
|
||||
extension.
|
||||
- By default, Ruff's fixes are aggressive. If you find that it's too aggressive for your liking,
|
||||
consider turning off fixes for specific rules or categories (see [_FAQ_](faq.md#ruff-tried-to-fix-something--but-it-broke-my-code)).
|
||||
|
||||
## Using `ruff.toml`
|
||||
|
||||
|
@ -430,7 +428,7 @@ Ruff only enables safe fixes by default. Unsafe fixes can be enabled by settings
|
|||
ruff check . --unsafe-fixes
|
||||
|
||||
# Apply unsafe fixes
|
||||
ruff check . --fix --unsafe-fixes
|
||||
ruff check . --fix --unsafe-fixes
|
||||
```
|
||||
|
||||
The safety of fixes can be adjusted per rule using the [`extend-safe-fixes`](settings.md#extend-safe-fixes) and [`extend-unsafe-fixes`](settings.md#extend-unsafe-fixes) settings.
|
||||
|
|
21
docs/faq.md
21
docs/faq.md
|
@ -436,22 +436,13 @@ For more, see the [`dirs`](https://docs.rs/dirs/4.0.0/dirs/fn.config_dir.html) c
|
|||
|
||||
## Ruff tried to fix something — but it broke my code?
|
||||
|
||||
Ruff's fixes are a best-effort mechanism. Given the dynamic nature of Python, it's difficult to
|
||||
have _complete_ certainty when making changes to code, even for the seemingly trivial fixes.
|
||||
Ruff labels fixes as "safe" and "unsafe". By default, Ruff will fix all violations for which safe
|
||||
fixes are available, while unsafe fixes can be enabled via the [`unsafe-fixes`](settings.md#unsafe-fixes)
|
||||
setting, or passing the `--unsafe-fixes` flag to `ruff check`. For more, see [the fix documentation](configuration.md#fixes).
|
||||
|
||||
In the future, Ruff will support enabling fix behavior based on the safety of the patch.
|
||||
|
||||
In the meantime, if you find that the fixes are too aggressive, you can disable it on a per-rule or
|
||||
per-category basis using the [`unfixable`](settings.md#unfixable) mechanic.
|
||||
For example, to disable the fix for some possibly-unsafe rules, you could add the following to your
|
||||
`pyproject.toml`:
|
||||
|
||||
```toml
|
||||
[tool.ruff]
|
||||
unfixable = ["B", "SIM", "TRY", "RUF"]
|
||||
```
|
||||
|
||||
If you find a case where Ruff's fix breaks your code, please file an Issue!
|
||||
Even still, given the dynamic nature of Python, it's difficult to have _complete_ certainty when
|
||||
making changes to code, even for seemingly trivial fixes. If a "safe" fix breaks your code, please
|
||||
[file an Issue](https://github.com/astral-sh/ruff/issues/new).
|
||||
|
||||
## How can I disable Ruff's color output?
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue