From 7a75702237e6f0bc605d3d8e9470c4ca9f37c69e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Riegel?= <96702577+LoicRiegel@users.noreply.github.com> Date: Mon, 8 Sep 2025 18:10:10 +0200 Subject: [PATCH] Ignore deprecated rules unless selected by exact code (#20167) ## Summary Closes #18349 After this change: - All deprecated rules are deselected by default - They are only selected if the user specifically selects them by code, e.g. `--select UP038` - Thus, `--select ALL --select UP --select UP0` won't select the deprecated rule UP038 - Documented the change in version policy. From now on, deprecating a rule should increase the minor version ## Test Plan Integration tests in "integration_tests.rs" Also tested with a temporary test package: ``` ~> ../../ruff/target/debug/ruff.exe check --select UP038 warning: Rule `UP038` is deprecated and will be removed in a future release. warning: Detected debug build without --no-cache. UP038 Use `X | Y` in `isinstance` call instead of `(X, Y)` --> main.py:2:11 | 1 | def main(): 2 | print(isinstance(25, (str, int))) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: Convert to `X | Y` Found 1 error. No fixes available (1 hidden fix can be enabled with the `--unsafe-fixes` option). ~> ../../ruff/target/debug/ruff.exe check --select UP03 warning: Detected debug build without --no-cache. All checks passed! ~> ../../ruff/target/debug/ruff.exe check --select UP0 warning: Detected debug build without --no-cache. All checks passed! ~> ../../ruff/target/debug/ruff.exe check --select UP warning: Detected debug build without --no-cache. All checks passed! ~> ../../ruff/target/debug/ruff.exe check --select ALL # warnings and errors, but because of other errors, UP038 was deselected ``` --- crates/ruff/tests/integration_test.rs | 22 ++++++---------------- crates/ruff_linter/src/rule_selector.rs | 6 ++---- docs/versioning.md | 1 + 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/crates/ruff/tests/integration_test.rs b/crates/ruff/tests/integration_test.rs index f9122e3b5e..4babbb3986 100644 --- a/crates/ruff/tests/integration_test.rs +++ b/crates/ruff/tests/integration_test.rs @@ -1489,6 +1489,8 @@ fn deprecated_direct() { #[test] fn deprecated_multiple_direct() { + // Multiple deprecated rules selected by exact code should be included + // but a warning should be displayed let mut cmd = RuffCheck::default() .args(["--select", "RUF920", "--select", "RUF921"]) .build(); @@ -1516,16 +1518,10 @@ fn deprecated_indirect() { // since it is not a "direct" selection let mut cmd = RuffCheck::default().args(["--select", "RUF92"]).build(); assert_cmd_snapshot!(cmd, @r" - success: false - exit_code: 1 + success: true + exit_code: 0 ----- stdout ----- - RUF920 Hey this is a deprecated test rule. - --> -:1:1 - - RUF921 Hey this is another deprecated test rule. - --> -:1:1 - - Found 2 errors. + All checks passed! ----- stderr ----- "); @@ -2155,16 +2151,10 @@ extend-safe-fixes = ["RUF9"] RUF903 Hey this is a stable test rule with a display only fix. --> -:1:1 - RUF920 Hey this is a deprecated test rule. - --> -:1:1 - - RUF921 Hey this is another deprecated test rule. - --> -:1:1 - RUF950 Hey this is a test rule that was redirected from another. --> -:1:1 - Found 7 errors. + Found 5 errors. [*] 1 fixable with the `--fix` option (1 hidden fix can be enabled with the `--unsafe-fixes` option). ----- stderr ----- diff --git a/crates/ruff_linter/src/rule_selector.rs b/crates/ruff_linter/src/rule_selector.rs index 74f069b976..399c881a34 100644 --- a/crates/ruff_linter/src/rule_selector.rs +++ b/crates/ruff_linter/src/rule_selector.rs @@ -214,10 +214,8 @@ impl RuleSelector { RuleGroup::Preview => { preview_enabled && (self.is_exact() || !preview_require_explicit) } - // Deprecated rules are excluded in preview mode and with 'All' option unless explicitly selected - RuleGroup::Deprecated => { - (!preview_enabled || self.is_exact()) && !matches!(self, RuleSelector::All) - } + // Deprecated rules are excluded by default unless explicitly selected + RuleGroup::Deprecated => !preview_enabled && self.is_exact(), // Removed rules are included if explicitly selected but will error downstream RuleGroup::Removed => self.is_exact(), } diff --git a/docs/versioning.md b/docs/versioning.md index 2740cf2b6e..6c6ad920ba 100644 --- a/docs/versioning.md +++ b/docs/versioning.md @@ -20,6 +20,7 @@ Ruff uses a custom versioning scheme that uses the **minor** version number for - Stable rules are added to the default set - Stable rules are removed from the default set - A safe fix for a rule is promoted to stable + - A rule is deprecated - Formatter: - The stable style changed - Language server: