Skip to content

Commit 4149d64

Browse files
authored
Ignore deprecated rules unless selected by exact code (#20167)
<!-- Thank you for contributing to Ruff/ty! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? (Please prefix with `[ty]` for ty pull requests.) - Does this pull request include references to any relevant issues? --> ## 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 ```
1 parent d615fa7 commit 4149d64

File tree

3 files changed

+9
-20
lines changed

3 files changed

+9
-20
lines changed

crates/ruff/tests/integration_test.rs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,8 @@ fn deprecated_direct() {
14891489

14901490
#[test]
14911491
fn deprecated_multiple_direct() {
1492+
// Multiple deprecated rules selected by exact code should be included
1493+
// but a warning should be displayed
14921494
let mut cmd = RuffCheck::default()
14931495
.args(["--select", "RUF920", "--select", "RUF921"])
14941496
.build();
@@ -1516,16 +1518,10 @@ fn deprecated_indirect() {
15161518
// since it is not a "direct" selection
15171519
let mut cmd = RuffCheck::default().args(["--select", "RUF92"]).build();
15181520
assert_cmd_snapshot!(cmd, @r"
1519-
success: false
1520-
exit_code: 1
1521+
success: true
1522+
exit_code: 0
15211523
----- stdout -----
1522-
RUF920 Hey this is a deprecated test rule.
1523-
--> -:1:1
1524-
1525-
RUF921 Hey this is another deprecated test rule.
1526-
--> -:1:1
1527-
1528-
Found 2 errors.
1524+
All checks passed!
15291525
15301526
----- stderr -----
15311527
");
@@ -2155,16 +2151,10 @@ extend-safe-fixes = ["RUF9"]
21552151
RUF903 Hey this is a stable test rule with a display only fix.
21562152
--> -:1:1
21572153
2158-
RUF920 Hey this is a deprecated test rule.
2159-
--> -:1:1
2160-
2161-
RUF921 Hey this is another deprecated test rule.
2162-
--> -:1:1
2163-
21642154
RUF950 Hey this is a test rule that was redirected from another.
21652155
--> -:1:1
21662156
2167-
Found 7 errors.
2157+
Found 5 errors.
21682158
[*] 1 fixable with the `--fix` option (1 hidden fix can be enabled with the `--unsafe-fixes` option).
21692159
21702160
----- stderr -----

crates/ruff_linter/src/rule_selector.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,8 @@ impl RuleSelector {
214214
RuleGroup::Preview => {
215215
preview_enabled && (self.is_exact() || !preview_require_explicit)
216216
}
217-
// Deprecated rules are excluded in preview mode and with 'All' option unless explicitly selected
218-
RuleGroup::Deprecated => {
219-
(!preview_enabled || self.is_exact()) && !matches!(self, RuleSelector::All)
220-
}
217+
// Deprecated rules are excluded by default unless explicitly selected
218+
RuleGroup::Deprecated => !preview_enabled && self.is_exact(),
221219
// Removed rules are included if explicitly selected but will error downstream
222220
RuleGroup::Removed => self.is_exact(),
223221
}

docs/versioning.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Ruff uses a custom versioning scheme that uses the **minor** version number for
2020
- Stable rules are added to the default set
2121
- Stable rules are removed from the default set
2222
- A safe fix for a rule is promoted to stable
23+
- A rule is deprecated
2324
- Formatter:
2425
- The stable style changed
2526
- Language server:

0 commit comments

Comments
 (0)