From 6fd6e0e2c8384360849c5ed6db35799ddfd71f77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Riegel?= Date: Sat, 30 Aug 2025 14:17:20 +0200 Subject: [PATCH 1/9] docs: versioning policy states that a rule deprecation should result in a minor version increase --- docs/versioning.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/versioning.md b/docs/versioning.md index 2740cf2b6efc7..6c6ad920ba4c9 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: From b3b1419a39cffeb5837c3de007abfa71393ebe30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Riegel?= Date: Sat, 30 Aug 2025 15:56:01 +0200 Subject: [PATCH 2/9] feat: exclude deprecated rules by default unless selected by exact code --- crates/ruff/tests/integration_test.rs | 65 ++++++++++--------------- crates/ruff_linter/src/rule_selector.rs | 6 +-- 2 files changed, 28 insertions(+), 43 deletions(-) diff --git a/crates/ruff/tests/integration_test.rs b/crates/ruff/tests/integration_test.rs index f9122e3b5e624..a614226b2ea5b 100644 --- a/crates/ruff/tests/integration_test.rs +++ b/crates/ruff/tests/integration_test.rs @@ -1469,8 +1469,8 @@ fn redirect_prefix() { } #[test] -fn deprecated_direct() { - // Selection of a deprecated rule without preview enabled should still work +fn deprecated_selected_exact() { + // A deprecated rule should be included if selected by exact code // but a warning should be displayed let mut cmd = RuffCheck::default().args(["--select", "RUF920"]).build(); assert_cmd_snapshot!(cmd, @r" @@ -1488,7 +1488,7 @@ fn deprecated_direct() { } #[test] -fn deprecated_multiple_direct() { +fn deprecated_selected_exact_multiple() { let mut cmd = RuffCheck::default() .args(["--select", "RUF920", "--select", "RUF921"]) .build(); @@ -1511,28 +1511,21 @@ fn deprecated_multiple_direct() { } #[test] -fn deprecated_indirect() { - // `RUF92` includes deprecated rules but should not warn - // since it is not a "direct" selection +fn deprecated_selected_prefix() { + // A deprecated rule should not be included if selected by rule prefix 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 ----- "); } #[test] -fn deprecated_direct_preview_enabled() { +fn deprecated_selected_exact_preview_enabled() { // Direct selection of a deprecated rule in preview should fail let mut cmd = RuffCheck::default() .args(["--select", "RUF920", "--preview"]) @@ -1549,38 +1542,38 @@ fn deprecated_direct_preview_enabled() { } #[test] -fn deprecated_indirect_preview_enabled() { - // `RUF920` is deprecated and should be off by default in preview. +fn deprecated_selected_exact_multiple_preview_enabled() { + // Direct selection of the deprecated rules in preview should fail with + // a message listing all of the rule codes let mut cmd = RuffCheck::default() - .args(["--select", "RUF92", "--preview"]) + .args(["--select", "RUF920", "--select", "RUF921", "--preview"]) .build(); assert_cmd_snapshot!(cmd, @r" - success: true - exit_code: 0 + success: false + exit_code: 2 ----- stdout ----- - All checks passed! ----- stderr ----- + ruff failed + Cause: Selection of deprecated rules is not allowed when preview is enabled. Remove selection of: + - RUF920 + - RUF921 "); } #[test] -fn deprecated_multiple_direct_preview_enabled() { - // Direct selection of the deprecated rules in preview should fail with - // a message listing all of the rule codes +fn deprecated_selected_prefix_preview_enabled() { + // `RUF920` is deprecated and should be off by default in preview. let mut cmd = RuffCheck::default() - .args(["--select", "RUF920", "--select", "RUF921", "--preview"]) + .args(["--select", "RUF92", "--preview"]) .build(); assert_cmd_snapshot!(cmd, @r" - success: false - exit_code: 2 + success: true + exit_code: 0 ----- stdout ----- + All checks passed! ----- stderr ----- - ruff failed - Cause: Selection of deprecated rules is not allowed when preview is enabled. Remove selection of: - - RUF920 - - RUF921 "); } @@ -2155,16 +2148,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 74f069b976497..399c881a34032 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(), } From 13578a76cd05960c8940dea6ec7a61022bb262b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Riegel?= Date: Wed, 3 Sep 2025 22:42:25 +0200 Subject: [PATCH 3/9] revert tests --- crates/ruff/tests/integration_test.rs | 57 +++++++++++++++------------ 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/crates/ruff/tests/integration_test.rs b/crates/ruff/tests/integration_test.rs index a614226b2ea5b..2335b29002c0c 100644 --- a/crates/ruff/tests/integration_test.rs +++ b/crates/ruff/tests/integration_test.rs @@ -1469,8 +1469,8 @@ fn redirect_prefix() { } #[test] -fn deprecated_selected_exact() { - // A deprecated rule should be included if selected by exact code +fn deprecated_direct() { + // Selection of a deprecated rule without preview enabled should still work // but a warning should be displayed let mut cmd = RuffCheck::default().args(["--select", "RUF920"]).build(); assert_cmd_snapshot!(cmd, @r" @@ -1488,7 +1488,7 @@ fn deprecated_selected_exact() { } #[test] -fn deprecated_selected_exact_multiple() { +fn deprecated_multiple_direct() { let mut cmd = RuffCheck::default() .args(["--select", "RUF920", "--select", "RUF921"]) .build(); @@ -1511,21 +1511,28 @@ fn deprecated_selected_exact_multiple() { } #[test] -fn deprecated_selected_prefix() { - // A deprecated rule should not be included if selected by rule prefix +fn deprecated_indirect() { + // `RUF92` includes deprecated rules but should not warn + // since it is not a "direct" selection let mut cmd = RuffCheck::default().args(["--select", "RUF92"]).build(); assert_cmd_snapshot!(cmd, @r" - success: true - exit_code: 0 + success: false + exit_code: 1 ----- stdout ----- - All checks passed! + RUF920 Hey this is a deprecated test rule. + --> -:1:1 + + RUF921 Hey this is another deprecated test rule. + --> -:1:1 + + Found 2 errors. ----- stderr ----- "); } #[test] -fn deprecated_selected_exact_preview_enabled() { +fn deprecated_direct_preview_enabled() { // Direct selection of a deprecated rule in preview should fail let mut cmd = RuffCheck::default() .args(["--select", "RUF920", "--preview"]) @@ -1542,38 +1549,38 @@ fn deprecated_selected_exact_preview_enabled() { } #[test] -fn deprecated_selected_exact_multiple_preview_enabled() { - // Direct selection of the deprecated rules in preview should fail with - // a message listing all of the rule codes +fn deprecated_indirect_preview_enabled() { + // `RUF920` is deprecated and should be off by default in preview. let mut cmd = RuffCheck::default() - .args(["--select", "RUF920", "--select", "RUF921", "--preview"]) + .args(["--select", "RUF92", "--preview"]) .build(); assert_cmd_snapshot!(cmd, @r" - success: false - exit_code: 2 + success: true + exit_code: 0 ----- stdout ----- + All checks passed! ----- stderr ----- - ruff failed - Cause: Selection of deprecated rules is not allowed when preview is enabled. Remove selection of: - - RUF920 - - RUF921 "); } #[test] -fn deprecated_selected_prefix_preview_enabled() { - // `RUF920` is deprecated and should be off by default in preview. +fn deprecated_multiple_direct_preview_enabled() { + // Direct selection of the deprecated rules in preview should fail with + // a message listing all of the rule codes let mut cmd = RuffCheck::default() - .args(["--select", "RUF92", "--preview"]) + .args(["--select", "RUF920", "--select", "RUF921", "--preview"]) .build(); assert_cmd_snapshot!(cmd, @r" - success: true - exit_code: 0 + success: false + exit_code: 2 ----- stdout ----- - All checks passed! ----- stderr ----- + ruff failed + Cause: Selection of deprecated rules is not allowed when preview is enabled. Remove selection of: + - RUF920 + - RUF921 "); } From 8f18183e2382e75969afe86356dac6ca97e6416c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Riegel?= Date: Wed, 3 Sep 2025 23:35:49 +0200 Subject: [PATCH 4/9] harmonize test comments --- crates/ruff/tests/integration_test.rs | 28 ++++++++++++--------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/crates/ruff/tests/integration_test.rs b/crates/ruff/tests/integration_test.rs index 2335b29002c0c..a91fb7b3cf2c7 100644 --- a/crates/ruff/tests/integration_test.rs +++ b/crates/ruff/tests/integration_test.rs @@ -1470,7 +1470,7 @@ fn redirect_prefix() { #[test] fn deprecated_direct() { - // Selection of a deprecated rule without preview enabled should still work + // A deprecated rule selected by exact code should be included // but a warning should be displayed let mut cmd = RuffCheck::default().args(["--select", "RUF920"]).build(); assert_cmd_snapshot!(cmd, @r" @@ -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(); @@ -1512,20 +1514,13 @@ fn deprecated_multiple_direct() { #[test] fn deprecated_indirect() { - // `RUF92` includes deprecated rules but should not warn - // since it is not a "direct" selection + // A deprecated rule selected by prefix should not be included 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 ----- "); @@ -1533,7 +1528,8 @@ fn deprecated_indirect() { #[test] fn deprecated_direct_preview_enabled() { - // Direct selection of a deprecated rule in preview should fail + // A deprecated rule selected by exact code should be included in preview + // but a warning should be displayed let mut cmd = RuffCheck::default() .args(["--select", "RUF920", "--preview"]) .build(); @@ -1550,7 +1546,7 @@ fn deprecated_direct_preview_enabled() { #[test] fn deprecated_indirect_preview_enabled() { - // `RUF920` is deprecated and should be off by default in preview. + // A deprecated rule selected by prefix should not be included in preview let mut cmd = RuffCheck::default() .args(["--select", "RUF92", "--preview"]) .build(); @@ -1566,8 +1562,8 @@ fn deprecated_indirect_preview_enabled() { #[test] fn deprecated_multiple_direct_preview_enabled() { - // Direct selection of the deprecated rules in preview should fail with - // a message listing all of the rule codes + // Multiple deprecated rules selected by exact code should be included in preview + // but a warning should be displayed let mut cmd = RuffCheck::default() .args(["--select", "RUF920", "--select", "RUF921", "--preview"]) .build(); From 97131adbe099fa3b53463f4f65ba4f6fc5708958 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Riegel?= Date: Wed, 3 Sep 2025 23:37:40 +0200 Subject: [PATCH 5/9] reorder tests for consistency --- crates/ruff/tests/integration_test.rs | 31 +++++++++++++-------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/crates/ruff/tests/integration_test.rs b/crates/ruff/tests/integration_test.rs index a91fb7b3cf2c7..3e936b2c33902 100644 --- a/crates/ruff/tests/integration_test.rs +++ b/crates/ruff/tests/integration_test.rs @@ -1544,22 +1544,6 @@ fn deprecated_direct_preview_enabled() { "); } -#[test] -fn deprecated_indirect_preview_enabled() { - // A deprecated rule selected by prefix should not be included in preview - let mut cmd = RuffCheck::default() - .args(["--select", "RUF92", "--preview"]) - .build(); - assert_cmd_snapshot!(cmd, @r" - success: true - exit_code: 0 - ----- stdout ----- - All checks passed! - - ----- stderr ----- - "); -} - #[test] fn deprecated_multiple_direct_preview_enabled() { // Multiple deprecated rules selected by exact code should be included in preview @@ -1579,6 +1563,21 @@ fn deprecated_multiple_direct_preview_enabled() { - RUF921 "); } +#[test] +fn deprecated_indirect_preview_enabled() { + // A deprecated rule selected by prefix should not be included in preview + let mut cmd = RuffCheck::default() + .args(["--select", "RUF92", "--preview"]) + .build(); + assert_cmd_snapshot!(cmd, @r" + success: true + exit_code: 0 + ----- stdout ----- + All checks passed! + + ----- stderr ----- + "); +} /// An unreadable pyproject.toml in non-isolated mode causes ruff to hard-error trying to build up /// configuration globs From e0f217cb19c8f5d614ecf8c0c1378dd4600b40a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Riegel?= Date: Sun, 7 Sep 2025 12:54:07 +0200 Subject: [PATCH 6/9] Revert "reorder tests for consistency" This reverts commit 97131adbe099fa3b53463f4f65ba4f6fc5708958. --- crates/ruff/tests/integration_test.rs | 31 ++++++++++++++------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/crates/ruff/tests/integration_test.rs b/crates/ruff/tests/integration_test.rs index 3e936b2c33902..a91fb7b3cf2c7 100644 --- a/crates/ruff/tests/integration_test.rs +++ b/crates/ruff/tests/integration_test.rs @@ -1544,6 +1544,22 @@ fn deprecated_direct_preview_enabled() { "); } +#[test] +fn deprecated_indirect_preview_enabled() { + // A deprecated rule selected by prefix should not be included in preview + let mut cmd = RuffCheck::default() + .args(["--select", "RUF92", "--preview"]) + .build(); + assert_cmd_snapshot!(cmd, @r" + success: true + exit_code: 0 + ----- stdout ----- + All checks passed! + + ----- stderr ----- + "); +} + #[test] fn deprecated_multiple_direct_preview_enabled() { // Multiple deprecated rules selected by exact code should be included in preview @@ -1563,21 +1579,6 @@ fn deprecated_multiple_direct_preview_enabled() { - RUF921 "); } -#[test] -fn deprecated_indirect_preview_enabled() { - // A deprecated rule selected by prefix should not be included in preview - let mut cmd = RuffCheck::default() - .args(["--select", "RUF92", "--preview"]) - .build(); - assert_cmd_snapshot!(cmd, @r" - success: true - exit_code: 0 - ----- stdout ----- - All checks passed! - - ----- stderr ----- - "); -} /// An unreadable pyproject.toml in non-isolated mode causes ruff to hard-error trying to build up /// configuration globs From 5fe9232da13d1b8132a6ba5b453768dc568a74f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Riegel?= Date: Sun, 7 Sep 2025 12:56:36 +0200 Subject: [PATCH 7/9] Revert "harmonize test comments" This reverts commit 8f18183e2382e75969afe86356dac6ca97e6416c. --- crates/ruff/tests/integration_test.rs | 28 +++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/crates/ruff/tests/integration_test.rs b/crates/ruff/tests/integration_test.rs index a91fb7b3cf2c7..2335b29002c0c 100644 --- a/crates/ruff/tests/integration_test.rs +++ b/crates/ruff/tests/integration_test.rs @@ -1470,7 +1470,7 @@ fn redirect_prefix() { #[test] fn deprecated_direct() { - // A deprecated rule selected by exact code should be included + // Selection of a deprecated rule without preview enabled should still work // but a warning should be displayed let mut cmd = RuffCheck::default().args(["--select", "RUF920"]).build(); assert_cmd_snapshot!(cmd, @r" @@ -1489,8 +1489,6 @@ 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(); @@ -1514,13 +1512,20 @@ fn deprecated_multiple_direct() { #[test] fn deprecated_indirect() { - // A deprecated rule selected by prefix should not be included + // `RUF92` includes deprecated rules but should not warn + // since it is not a "direct" selection let mut cmd = RuffCheck::default().args(["--select", "RUF92"]).build(); assert_cmd_snapshot!(cmd, @r" - success: true - exit_code: 0 + success: false + exit_code: 1 ----- stdout ----- - All checks passed! + RUF920 Hey this is a deprecated test rule. + --> -:1:1 + + RUF921 Hey this is another deprecated test rule. + --> -:1:1 + + Found 2 errors. ----- stderr ----- "); @@ -1528,8 +1533,7 @@ fn deprecated_indirect() { #[test] fn deprecated_direct_preview_enabled() { - // A deprecated rule selected by exact code should be included in preview - // but a warning should be displayed + // Direct selection of a deprecated rule in preview should fail let mut cmd = RuffCheck::default() .args(["--select", "RUF920", "--preview"]) .build(); @@ -1546,7 +1550,7 @@ fn deprecated_direct_preview_enabled() { #[test] fn deprecated_indirect_preview_enabled() { - // A deprecated rule selected by prefix should not be included in preview + // `RUF920` is deprecated and should be off by default in preview. let mut cmd = RuffCheck::default() .args(["--select", "RUF92", "--preview"]) .build(); @@ -1562,8 +1566,8 @@ fn deprecated_indirect_preview_enabled() { #[test] fn deprecated_multiple_direct_preview_enabled() { - // Multiple deprecated rules selected by exact code should be included in preview - // but a warning should be displayed + // Direct selection of the deprecated rules in preview should fail with + // a message listing all of the rule codes let mut cmd = RuffCheck::default() .args(["--select", "RUF920", "--select", "RUF921", "--preview"]) .build(); From 3229f3dd0b9b4fade37c630af898436f681e5e73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Riegel?= Date: Sun, 7 Sep 2025 13:01:00 +0200 Subject: [PATCH 8/9] fix tests --- crates/ruff/tests/integration_test.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/crates/ruff/tests/integration_test.rs b/crates/ruff/tests/integration_test.rs index 2335b29002c0c..54445c9faab67 100644 --- a/crates/ruff/tests/integration_test.rs +++ b/crates/ruff/tests/integration_test.rs @@ -1516,16 +1516,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 ----- "); From 072c7bf8979582c55d4d964ac12af3969a9cdc97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Riegel?= Date: Sun, 7 Sep 2025 13:09:40 +0200 Subject: [PATCH 9/9] add comment in test --- crates/ruff/tests/integration_test.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/ruff/tests/integration_test.rs b/crates/ruff/tests/integration_test.rs index 54445c9faab67..4babbb39862f9 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();