Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions crates/ruff_linter/src/preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,6 @@ pub(crate) const fn is_future_required_preview_generics_enabled(settings: &Linte
settings.preview.is_enabled()
}

// https://github.com/astral-sh/ruff/pull/19851
pub(crate) const fn is_maxsplit_without_separator_fix_enabled(settings: &LinterSettings) -> bool {
settings.preview.is_enabled()
}

// https://github.com/astral-sh/ruff/pull/20027
pub(crate) const fn is_unnecessary_default_type_args_stubs_enabled(
settings: &LinterSettings,
Expand Down
1 change: 0 additions & 1 deletion crates/ruff_linter/src/rules/flake8_simplify/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ mod tests {
Ok(())
}

#[test_case(Rule::SplitStaticString, Path::new("SIM905.py"))]
#[test_case(Rule::DictGetWithNoneDefault, Path::new("SIM910.py"))]
#[test_case(Rule::EnumerateForLoop, Path::new("SIM113.py"))]
fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ use std::cmp::Ordering;
use std::fmt::{Display, Formatter};

use crate::checkers::ast::Checker;
use crate::preview::is_maxsplit_without_separator_fix_enabled;
use crate::settings::LinterSettings;
use crate::{Applicability, Edit, Fix, FixAvailability, Violation};

/// ## What it does
Expand Down Expand Up @@ -113,9 +111,7 @@ pub(crate) fn split_static_string(
let sep_arg = arguments.find_argument_value("sep", 0);
let split_replacement = if let Some(sep) = sep_arg {
match sep {
Expr::NoneLiteral(_) => {
split_default(str_value, maxsplit_value, method, checker.settings())
}
Expr::NoneLiteral(_) => split_default(str_value, maxsplit_value, method),
Expr::StringLiteral(sep_value) => {
let sep_value_str = sep_value.value.to_str();
Some(split_sep(str_value, sep_value_str, maxsplit_value, method))
Expand All @@ -126,7 +122,7 @@ pub(crate) fn split_static_string(
}
}
} else {
split_default(str_value, maxsplit_value, method, checker.settings())
split_default(str_value, maxsplit_value, method)
};

let mut diagnostic = checker.report_diagnostic(SplitStaticString { method }, call.range());
Expand Down Expand Up @@ -196,15 +192,9 @@ fn construct_replacement(elts: &[&str], flags: StringLiteralFlags) -> Expr {
})
}

fn split_default(
str_value: &StringLiteralValue,
max_split: i32,
method: Method,
settings: &LinterSettings,
) -> Option<Expr> {
fn split_default(str_value: &StringLiteralValue, max_split: i32, method: Method) -> Option<Expr> {
let string_val = str_value.to_str();
match max_split.cmp(&0) {
Ordering::Greater if !is_maxsplit_without_separator_fix_enabled(settings) => None,
Ordering::Greater | Ordering::Equal => {
let Ok(max_split) = usize::try_from(max_split) else {
return None;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ help: Replace with list literal
16 | "a,b,c,d".split(sep=",")
17 | "a,b,c,d".split(sep=None)

SIM905 Consider using a list literal instead of `str.split`
SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:15:1
|
13 | "a,b,c,d".split(None)
Expand All @@ -98,6 +98,14 @@ SIM905 Consider using a list literal instead of `str.split`
17 | "a,b,c,d".split(sep=None)
|
help: Replace with list literal
12 | "a,b,c,d".split(",")
13 | "a,b,c,d".split(None)
14 | "a,b,c,d".split(",", 1)
- "a,b,c,d".split(None, 1)
15 + ["a,b,c,d"]
16 | "a,b,c,d".split(sep=",")
17 | "a,b,c,d".split(sep=None)
18 | "a,b,c,d".split(sep=",", maxsplit=1)

SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:16:1
Expand Down Expand Up @@ -159,7 +167,7 @@ help: Replace with list literal
20 | "a,b,c,d".split(maxsplit=1, sep=",")
21 | "a,b,c,d".split(maxsplit=1, sep=None)

SIM905 Consider using a list literal instead of `str.split`
SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:19:1
|
17 | "a,b,c,d".split(sep=None)
Expand All @@ -170,6 +178,14 @@ SIM905 Consider using a list literal instead of `str.split`
21 | "a,b,c,d".split(maxsplit=1, sep=None)
|
help: Replace with list literal
16 | "a,b,c,d".split(sep=",")
17 | "a,b,c,d".split(sep=None)
18 | "a,b,c,d".split(sep=",", maxsplit=1)
- "a,b,c,d".split(sep=None, maxsplit=1)
19 + ["a,b,c,d"]
20 | "a,b,c,d".split(maxsplit=1, sep=",")
21 | "a,b,c,d".split(maxsplit=1, sep=None)
22 | "a,b,c,d".split(",", maxsplit=1)

SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:20:1
Expand All @@ -191,7 +207,7 @@ help: Replace with list literal
22 | "a,b,c,d".split(",", maxsplit=1)
23 | "a,b,c,d".split(None, maxsplit=1)

SIM905 Consider using a list literal instead of `str.split`
SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:21:1
|
19 | "a,b,c,d".split(sep=None, maxsplit=1)
Expand All @@ -202,6 +218,14 @@ SIM905 Consider using a list literal instead of `str.split`
23 | "a,b,c,d".split(None, maxsplit=1)
|
help: Replace with list literal
18 | "a,b,c,d".split(sep=",", maxsplit=1)
19 | "a,b,c,d".split(sep=None, maxsplit=1)
20 | "a,b,c,d".split(maxsplit=1, sep=",")
- "a,b,c,d".split(maxsplit=1, sep=None)
21 + ["a,b,c,d"]
22 | "a,b,c,d".split(",", maxsplit=1)
23 | "a,b,c,d".split(None, maxsplit=1)
24 | "a,b,c,d".split(maxsplit=1)

SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:22:1
Expand All @@ -223,7 +247,7 @@ help: Replace with list literal
24 | "a,b,c,d".split(maxsplit=1)
25 | "a,b,c,d".split(maxsplit=1.0)

SIM905 Consider using a list literal instead of `str.split`
SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:23:1
|
21 | "a,b,c,d".split(maxsplit=1, sep=None)
Expand All @@ -234,8 +258,16 @@ SIM905 Consider using a list literal instead of `str.split`
25 | "a,b,c,d".split(maxsplit=1.0)
|
help: Replace with list literal
20 | "a,b,c,d".split(maxsplit=1, sep=",")
21 | "a,b,c,d".split(maxsplit=1, sep=None)
22 | "a,b,c,d".split(",", maxsplit=1)
- "a,b,c,d".split(None, maxsplit=1)
23 + ["a,b,c,d"]
24 | "a,b,c,d".split(maxsplit=1)
25 | "a,b,c,d".split(maxsplit=1.0)
26 | "a,b,c,d".split(maxsplit=1)

SIM905 Consider using a list literal instead of `str.split`
SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:24:1
|
22 | "a,b,c,d".split(",", maxsplit=1)
Expand All @@ -246,8 +278,16 @@ SIM905 Consider using a list literal instead of `str.split`
26 | "a,b,c,d".split(maxsplit=1)
|
help: Replace with list literal
21 | "a,b,c,d".split(maxsplit=1, sep=None)
22 | "a,b,c,d".split(",", maxsplit=1)
23 | "a,b,c,d".split(None, maxsplit=1)
- "a,b,c,d".split(maxsplit=1)
24 + ["a,b,c,d"]
25 | "a,b,c,d".split(maxsplit=1.0)
26 | "a,b,c,d".split(maxsplit=1)
27 | "a,b,c,d".split(maxsplit=0)

SIM905 Consider using a list literal instead of `str.split`
SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:26:1
|
24 | "a,b,c,d".split(maxsplit=1)
Expand All @@ -258,6 +298,14 @@ SIM905 Consider using a list literal instead of `str.split`
28 | "VERB AUX PRON ADP DET".split(" ")
|
help: Replace with list literal
23 | "a,b,c,d".split(None, maxsplit=1)
24 | "a,b,c,d".split(maxsplit=1)
25 | "a,b,c,d".split(maxsplit=1.0)
- "a,b,c,d".split(maxsplit=1)
26 + ["a,b,c,d"]
27 | "a,b,c,d".split(maxsplit=0)
28 | "VERB AUX PRON ADP DET".split(" ")
29 | ' 1 2 3 '.split()

SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:27:1
Expand Down Expand Up @@ -1365,7 +1413,7 @@ help: Replace with list literal
170 | # leading/trailing whitespace should not count towards maxsplit
171 | " a b c d ".split(maxsplit=2) # ["a", "b", "c d "]

SIM905 Consider using a list literal instead of `str.split`
SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:171:1
|
170 | # leading/trailing whitespace should not count towards maxsplit
Expand All @@ -1375,8 +1423,15 @@ SIM905 Consider using a list literal instead of `str.split`
173 | "a b".split(maxsplit=1) # ["a", "b"]
|
help: Replace with list literal
168 | print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0))
169 |
170 | # leading/trailing whitespace should not count towards maxsplit
- " a b c d ".split(maxsplit=2) # ["a", "b", "c d "]
171 + ["a", "b", "c d "] # ["a", "b", "c d "]
172 | " a b c d ".rsplit(maxsplit=2) # [" a b", "c", "d"]
173 | "a b".split(maxsplit=1) # ["a", "b"]

SIM905 Consider using a list literal instead of `str.rsplit`
SIM905 [*] Consider using a list literal instead of `str.rsplit`
--> SIM905.py:172:1
|
170 | # leading/trailing whitespace should not count towards maxsplit
Expand All @@ -1386,8 +1441,14 @@ SIM905 Consider using a list literal instead of `str.rsplit`
173 | "a b".split(maxsplit=1) # ["a", "b"]
|
help: Replace with list literal
169 |
170 | # leading/trailing whitespace should not count towards maxsplit
171 | " a b c d ".split(maxsplit=2) # ["a", "b", "c d "]
- " a b c d ".rsplit(maxsplit=2) # [" a b", "c", "d"]
172 + [" a b", "c", "d"] # [" a b", "c", "d"]
173 | "a b".split(maxsplit=1) # ["a", "b"]

SIM905 Consider using a list literal instead of `str.split`
SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:173:1
|
171 | " a b c d ".split(maxsplit=2) # ["a", "b", "c d "]
Expand All @@ -1396,3 +1457,8 @@ SIM905 Consider using a list literal instead of `str.split`
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
help: Replace with list literal
170 | # leading/trailing whitespace should not count towards maxsplit
171 | " a b c d ".split(maxsplit=2) # ["a", "b", "c d "]
172 | " a b c d ".rsplit(maxsplit=2) # [" a b", "c", "d"]
- "a b".split(maxsplit=1) # ["a", "b"]
173 + ["a", "b"] # ["a", "b"]
Loading