Skip to content

Commit 276f1d0

Browse files
authored
Remove duplicate preview tests for FURB101 and FURB103 (#21303)
Summary -- These rules are themselves in preview, so we don't need the additional preview checks on the fixes or the separate preview tests. This has confused me in a couple of reviews of changes to the fixes. Test Plan -- Existing tests, with the fixes previously only shown in the preview tests now in the "non-preview" tests.
1 parent ed18112 commit 276f1d0

9 files changed

+336
-533
lines changed

crates/ruff_linter/src/preview.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -261,16 +261,6 @@ pub(crate) const fn is_b006_unsafe_fix_preserve_assignment_expr_enabled(
261261
settings.preview.is_enabled()
262262
}
263263

264-
// https://github.com/astral-sh/ruff/pull/20520
265-
pub(crate) const fn is_fix_read_whole_file_enabled(settings: &LinterSettings) -> bool {
266-
settings.preview.is_enabled()
267-
}
268-
269-
// https://github.com/astral-sh/ruff/pull/20520
270-
pub(crate) const fn is_fix_write_whole_file_enabled(settings: &LinterSettings) -> bool {
271-
settings.preview.is_enabled()
272-
}
273-
274264
pub(crate) const fn is_typing_extensions_str_alias_enabled(settings: &LinterSettings) -> bool {
275265
settings.preview.is_enabled()
276266
}

crates/ruff_linter/src/rules/refurb/mod.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ mod tests {
1212
use test_case::test_case;
1313

1414
use crate::registry::Rule;
15-
use crate::settings::types::PreviewMode;
1615
use crate::test::test_path;
1716
use crate::{assert_diagnostics, settings};
1817

@@ -63,25 +62,6 @@ mod tests {
6362
Ok(())
6463
}
6564

66-
#[test_case(Rule::ReadWholeFile, Path::new("FURB101.py"))]
67-
#[test_case(Rule::WriteWholeFile, Path::new("FURB103.py"))]
68-
fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> {
69-
let snapshot = format!(
70-
"preview_{}_{}",
71-
rule_code.noqa_code(),
72-
path.to_string_lossy()
73-
);
74-
let diagnostics = test_path(
75-
Path::new("refurb").join(path).as_path(),
76-
&settings::LinterSettings {
77-
preview: PreviewMode::Enabled,
78-
..settings::LinterSettings::for_rule(rule_code)
79-
},
80-
)?;
81-
assert_diagnostics!(snapshot, diagnostics);
82-
Ok(())
83-
}
84-
8565
#[test]
8666
fn write_whole_file_python_39() -> Result<()> {
8767
let diagnostics = test_path(

crates/ruff_linter/src/rules/refurb/rules/read_whole_file.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,6 @@ impl<'a> Visitor<'a> for ReadMatcher<'a, '_> {
125125
open.item.range(),
126126
);
127127

128-
if !crate::preview::is_fix_read_whole_file_enabled(self.checker.settings()) {
129-
return;
130-
}
131-
132128
let target = match self.with_stmt.body.first() {
133129
Some(Stmt::Assign(assign))
134130
if assign.value.range().contains_range(expr.range()) =>

crates/ruff_linter/src/rules/refurb/rules/write_whole_file.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,6 @@ impl<'a> Visitor<'a> for WriteMatcher<'a, '_> {
141141
open.item.range(),
142142
);
143143

144-
if !crate::preview::is_fix_write_whole_file_enabled(self.checker.settings()) {
145-
return;
146-
}
147-
148144
if let Some(fix) =
149145
generate_fix(self.checker, &open, self.with_stmt, &suggestion)
150146
{

crates/ruff_linter/src/rules/refurb/snapshots/ruff_linter__rules__refurb__tests__FURB101_FURB101.py.snap

Lines changed: 91 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
source: crates/ruff_linter/src/rules/refurb/mod.rs
33
---
4-
FURB101 `open` and `read` should be replaced by `Path("file.txt").read_text()`
4+
FURB101 [*] `open` and `read` should be replaced by `Path("file.txt").read_text()`
55
--> FURB101.py:12:6
66
|
77
11 | # FURB101
@@ -10,8 +10,22 @@ FURB101 `open` and `read` should be replaced by `Path("file.txt").read_text()`
1010
13 | x = f.read()
1111
|
1212
help: Replace with `Path("file.txt").read_text()`
13+
1 + import pathlib
14+
2 | def foo():
15+
3 | ...
16+
4 |
17+
--------------------------------------------------------------------------------
18+
10 | # Errors.
19+
11 |
20+
12 | # FURB101
21+
- with open("file.txt") as f:
22+
- x = f.read()
23+
13 + x = pathlib.Path("file.txt").read_text()
24+
14 |
25+
15 | # FURB101
26+
16 | with open("file.txt", "rb") as f:
1327

14-
FURB101 `open` and `read` should be replaced by `Path("file.txt").read_bytes()`
28+
FURB101 [*] `open` and `read` should be replaced by `Path("file.txt").read_bytes()`
1529
--> FURB101.py:16:6
1630
|
1731
15 | # FURB101
@@ -20,8 +34,22 @@ FURB101 `open` and `read` should be replaced by `Path("file.txt").read_bytes()`
2034
17 | x = f.read()
2135
|
2236
help: Replace with `Path("file.txt").read_bytes()`
37+
1 + import pathlib
38+
2 | def foo():
39+
3 | ...
40+
4 |
41+
--------------------------------------------------------------------------------
42+
14 | x = f.read()
43+
15 |
44+
16 | # FURB101
45+
- with open("file.txt", "rb") as f:
46+
- x = f.read()
47+
17 + x = pathlib.Path("file.txt").read_bytes()
48+
18 |
49+
19 | # FURB101
50+
20 | with open("file.txt", mode="rb") as f:
2351

24-
FURB101 `open` and `read` should be replaced by `Path("file.txt").read_bytes()`
52+
FURB101 [*] `open` and `read` should be replaced by `Path("file.txt").read_bytes()`
2553
--> FURB101.py:20:6
2654
|
2755
19 | # FURB101
@@ -30,8 +58,22 @@ FURB101 `open` and `read` should be replaced by `Path("file.txt").read_bytes()`
3058
21 | x = f.read()
3159
|
3260
help: Replace with `Path("file.txt").read_bytes()`
61+
1 + import pathlib
62+
2 | def foo():
63+
3 | ...
64+
4 |
65+
--------------------------------------------------------------------------------
66+
18 | x = f.read()
67+
19 |
68+
20 | # FURB101
69+
- with open("file.txt", mode="rb") as f:
70+
- x = f.read()
71+
21 + x = pathlib.Path("file.txt").read_bytes()
72+
22 |
73+
23 | # FURB101
74+
24 | with open("file.txt", encoding="utf8") as f:
3375

34-
FURB101 `open` and `read` should be replaced by `Path("file.txt").read_text(encoding="utf8")`
76+
FURB101 [*] `open` and `read` should be replaced by `Path("file.txt").read_text(encoding="utf8")`
3577
--> FURB101.py:24:6
3678
|
3779
23 | # FURB101
@@ -40,8 +82,22 @@ FURB101 `open` and `read` should be replaced by `Path("file.txt").read_text(enco
4082
25 | x = f.read()
4183
|
4284
help: Replace with `Path("file.txt").read_text(encoding="utf8")`
85+
1 + import pathlib
86+
2 | def foo():
87+
3 | ...
88+
4 |
89+
--------------------------------------------------------------------------------
90+
22 | x = f.read()
91+
23 |
92+
24 | # FURB101
93+
- with open("file.txt", encoding="utf8") as f:
94+
- x = f.read()
95+
25 + x = pathlib.Path("file.txt").read_text(encoding="utf8")
96+
26 |
97+
27 | # FURB101
98+
28 | with open("file.txt", errors="ignore") as f:
4399

44-
FURB101 `open` and `read` should be replaced by `Path("file.txt").read_text(errors="ignore")`
100+
FURB101 [*] `open` and `read` should be replaced by `Path("file.txt").read_text(errors="ignore")`
45101
--> FURB101.py:28:6
46102
|
47103
27 | # FURB101
@@ -50,8 +106,22 @@ FURB101 `open` and `read` should be replaced by `Path("file.txt").read_text(erro
50106
29 | x = f.read()
51107
|
52108
help: Replace with `Path("file.txt").read_text(errors="ignore")`
109+
1 + import pathlib
110+
2 | def foo():
111+
3 | ...
112+
4 |
113+
--------------------------------------------------------------------------------
114+
26 | x = f.read()
115+
27 |
116+
28 | # FURB101
117+
- with open("file.txt", errors="ignore") as f:
118+
- x = f.read()
119+
29 + x = pathlib.Path("file.txt").read_text(errors="ignore")
120+
30 |
121+
31 | # FURB101
122+
32 | with open("file.txt", mode="r") as f: # noqa: FURB120
53123

54-
FURB101 `open` and `read` should be replaced by `Path("file.txt").read_text()`
124+
FURB101 [*] `open` and `read` should be replaced by `Path("file.txt").read_text()`
55125
--> FURB101.py:32:6
56126
|
57127
31 | # FURB101
@@ -60,6 +130,21 @@ FURB101 `open` and `read` should be replaced by `Path("file.txt").read_text()`
60130
33 | x = f.read()
61131
|
62132
help: Replace with `Path("file.txt").read_text()`
133+
1 + import pathlib
134+
2 | def foo():
135+
3 | ...
136+
4 |
137+
--------------------------------------------------------------------------------
138+
30 | x = f.read()
139+
31 |
140+
32 | # FURB101
141+
- with open("file.txt", mode="r") as f: # noqa: FURB120
142+
- x = f.read()
143+
33 + x = pathlib.Path("file.txt").read_text()
144+
34 |
145+
35 | # FURB101
146+
36 | with open(foo(), "rb") as f:
147+
note: This is an unsafe fix and may change runtime behavior
63148

64149
FURB101 `open` and `read` should be replaced by `Path(foo()).read_bytes()`
65150
--> FURB101.py:36:6

0 commit comments

Comments
 (0)