diff --git a/crates/ruff_linter/resources/test/fixtures/refurb/FURB105.py b/crates/ruff_linter/resources/test/fixtures/refurb/FURB105.py index 167ee675b8c61f..2e58dc46b17668 100644 --- a/crates/ruff_linter/resources/test/fixtures/refurb/FURB105.py +++ b/crates/ruff_linter/resources/test/fixtures/refurb/FURB105.py @@ -31,3 +31,4 @@ print("foo", "", sep=",") print("foo", "", "bar", "", sep=",") print("", "", **kwargs) +print(*args, sep=",") diff --git a/crates/ruff_linter/src/rules/refurb/rules/print_empty_string.rs b/crates/ruff_linter/src/rules/refurb/rules/print_empty_string.rs index e450cf30987ad2..5c4370503d8675 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/print_empty_string.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/print_empty_string.rs @@ -7,13 +7,17 @@ use ruff_text_size::Ranged; use crate::checkers::ast::Checker; /// ## What it does -/// Checks for `print` calls with an empty string as the only positional -/// argument. +/// Checks for `print` calls with unnecessary empty strings as positional +/// arguments and unnecessary `sep` keyword arguments. /// /// ## Why is this bad? /// Prefer calling `print` without any positional arguments, which is /// equivalent and more concise. /// +/// Similarly, when printing one or fewer items, the `sep` keyword argument, +/// (used to define the string that separates the `print` arguments) can be +/// omitted. +/// /// ## Example /// ```python /// print("") @@ -95,6 +99,10 @@ pub(crate) fn print_empty_string(checker: &mut Checker, call: &ast::ExprCall) { checker.diagnostics.push(diagnostic); } + [arg] if arg.is_starred_expr() => { + // If there's a starred argument, we can't remove the empty string. + } + // Ex) `print(sep="\t")` or `print(obj, sep="\t")` [] | [_] => { // If there's a `sep` argument, remove it, regardless of what it is.