Skip to content

Commit

Permalink
Update fix safety FAQ to reflect --unsafe-fixes (#7969)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh authored Oct 16, 2023
1 parent 134def0 commit cac9754
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
4 changes: 1 addition & 3 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down Expand Up @@ -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.
Expand Down
21 changes: 6 additions & 15 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down

0 comments on commit cac9754

Please sign in to comment.