From cac9754455cf91e374ded6bd6f7366233e7dbc76 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Mon, 16 Oct 2023 14:34:55 -0400 Subject: [PATCH] Update fix safety FAQ to reflect `--unsafe-fixes` (#7969) --- docs/configuration.md | 4 +--- docs/faq.md | 21 ++++++--------------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 6707b8c71c313..4f91a90563d42 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -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. diff --git a/docs/faq.md b/docs/faq.md index c5563171996f3..2953408cb56c7 100644 --- a/docs/faq.md +++ b/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?