mirror of https://github.com/astral-sh/ruff
Restructure signatures of `flake8_comprehensions` fixers (#7186)
This commit is contained in:
parent
a3a531e0d4
commit
f0ea40a68d
|
|
@ -12,6 +12,7 @@ use ruff_text_size::{Ranged, TextRange};
|
||||||
|
|
||||||
use ruff_diagnostics::{Edit, Fix};
|
use ruff_diagnostics::{Edit, Fix};
|
||||||
use ruff_python_codegen::Stylist;
|
use ruff_python_codegen::Stylist;
|
||||||
|
use ruff_python_semantic::SemanticModel;
|
||||||
use ruff_source_file::Locator;
|
use ruff_source_file::Locator;
|
||||||
|
|
||||||
use crate::autofix::codemods::CodegenStylist;
|
use crate::autofix::codemods::CodegenStylist;
|
||||||
|
|
@ -27,9 +28,9 @@ use crate::{
|
||||||
|
|
||||||
/// (C400) Convert `list(x for x in y)` to `[x for x in y]`.
|
/// (C400) Convert `list(x for x in y)` to `[x for x in y]`.
|
||||||
pub(crate) fn fix_unnecessary_generator_list(
|
pub(crate) fn fix_unnecessary_generator_list(
|
||||||
|
expr: &Expr,
|
||||||
locator: &Locator,
|
locator: &Locator,
|
||||||
stylist: &Stylist,
|
stylist: &Stylist,
|
||||||
expr: &Expr,
|
|
||||||
) -> Result<Edit> {
|
) -> Result<Edit> {
|
||||||
// Expr(Call(GeneratorExp)))) -> Expr(ListComp)))
|
// Expr(Call(GeneratorExp)))) -> Expr(ListComp)))
|
||||||
let module_text = locator.slice(expr);
|
let module_text = locator.slice(expr);
|
||||||
|
|
@ -59,7 +60,7 @@ pub(crate) fn fix_unnecessary_generator_list(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// (C401) Convert `set(x for x in y)` to `{x for x in y}`.
|
/// (C401) Convert `set(x for x in y)` to `{x for x in y}`.
|
||||||
pub(crate) fn fix_unnecessary_generator_set(checker: &Checker, expr: &Expr) -> Result<Edit> {
|
pub(crate) fn fix_unnecessary_generator_set(expr: &Expr, checker: &Checker) -> Result<Edit> {
|
||||||
let locator = checker.locator();
|
let locator = checker.locator();
|
||||||
let stylist = checker.stylist();
|
let stylist = checker.stylist();
|
||||||
|
|
||||||
|
|
@ -87,14 +88,14 @@ pub(crate) fn fix_unnecessary_generator_set(checker: &Checker, expr: &Expr) -> R
|
||||||
let content = tree.codegen_stylist(stylist);
|
let content = tree.codegen_stylist(stylist);
|
||||||
|
|
||||||
Ok(Edit::range_replacement(
|
Ok(Edit::range_replacement(
|
||||||
pad_expression(content, expr.range(), checker),
|
pad_expression(content, expr.range(), checker.locator(), checker.semantic()),
|
||||||
expr.range(),
|
expr.range(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// (C402) Convert `dict((x, x) for x in range(3))` to `{x: x for x in
|
/// (C402) Convert `dict((x, x) for x in range(3))` to `{x: x for x in
|
||||||
/// range(3)}`.
|
/// range(3)}`.
|
||||||
pub(crate) fn fix_unnecessary_generator_dict(checker: &Checker, expr: &Expr) -> Result<Edit> {
|
pub(crate) fn fix_unnecessary_generator_dict(expr: &Expr, checker: &Checker) -> Result<Edit> {
|
||||||
let locator = checker.locator();
|
let locator = checker.locator();
|
||||||
let stylist = checker.stylist();
|
let stylist = checker.stylist();
|
||||||
|
|
||||||
|
|
@ -138,15 +139,20 @@ pub(crate) fn fix_unnecessary_generator_dict(checker: &Checker, expr: &Expr) ->
|
||||||
}));
|
}));
|
||||||
|
|
||||||
Ok(Edit::range_replacement(
|
Ok(Edit::range_replacement(
|
||||||
pad_expression(tree.codegen_stylist(stylist), expr.range(), checker),
|
pad_expression(
|
||||||
|
tree.codegen_stylist(stylist),
|
||||||
|
expr.range(),
|
||||||
|
checker.locator(),
|
||||||
|
checker.semantic(),
|
||||||
|
),
|
||||||
expr.range(),
|
expr.range(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// (C403) Convert `set([x for x in y])` to `{x for x in y}`.
|
/// (C403) Convert `set([x for x in y])` to `{x for x in y}`.
|
||||||
pub(crate) fn fix_unnecessary_list_comprehension_set(
|
pub(crate) fn fix_unnecessary_list_comprehension_set(
|
||||||
checker: &Checker,
|
|
||||||
expr: &Expr,
|
expr: &Expr,
|
||||||
|
checker: &Checker,
|
||||||
) -> Result<Edit> {
|
) -> Result<Edit> {
|
||||||
let locator = checker.locator();
|
let locator = checker.locator();
|
||||||
let stylist = checker.stylist();
|
let stylist = checker.stylist();
|
||||||
|
|
@ -173,7 +179,12 @@ pub(crate) fn fix_unnecessary_list_comprehension_set(
|
||||||
}));
|
}));
|
||||||
|
|
||||||
Ok(Edit::range_replacement(
|
Ok(Edit::range_replacement(
|
||||||
pad_expression(tree.codegen_stylist(stylist), expr.range(), checker),
|
pad_expression(
|
||||||
|
tree.codegen_stylist(stylist),
|
||||||
|
expr.range(),
|
||||||
|
checker.locator(),
|
||||||
|
checker.semantic(),
|
||||||
|
),
|
||||||
expr.range(),
|
expr.range(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
@ -181,8 +192,8 @@ pub(crate) fn fix_unnecessary_list_comprehension_set(
|
||||||
/// (C404) Convert `dict([(i, i) for i in range(3)])` to `{i: i for i in
|
/// (C404) Convert `dict([(i, i) for i in range(3)])` to `{i: i for i in
|
||||||
/// range(3)}`.
|
/// range(3)}`.
|
||||||
pub(crate) fn fix_unnecessary_list_comprehension_dict(
|
pub(crate) fn fix_unnecessary_list_comprehension_dict(
|
||||||
checker: &Checker,
|
|
||||||
expr: &Expr,
|
expr: &Expr,
|
||||||
|
checker: &Checker,
|
||||||
) -> Result<Edit> {
|
) -> Result<Edit> {
|
||||||
let locator = checker.locator();
|
let locator = checker.locator();
|
||||||
let stylist = checker.stylist();
|
let stylist = checker.stylist();
|
||||||
|
|
@ -218,7 +229,12 @@ pub(crate) fn fix_unnecessary_list_comprehension_dict(
|
||||||
}));
|
}));
|
||||||
|
|
||||||
Ok(Edit::range_replacement(
|
Ok(Edit::range_replacement(
|
||||||
pad_expression(tree.codegen_stylist(stylist), expr.range(), checker),
|
pad_expression(
|
||||||
|
tree.codegen_stylist(stylist),
|
||||||
|
expr.range(),
|
||||||
|
checker.locator(),
|
||||||
|
checker.semantic(),
|
||||||
|
),
|
||||||
expr.range(),
|
expr.range(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
@ -267,7 +283,7 @@ fn drop_trailing_comma<'a>(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// (C405) Convert `set((1, 2))` to `{1, 2}`.
|
/// (C405) Convert `set((1, 2))` to `{1, 2}`.
|
||||||
pub(crate) fn fix_unnecessary_literal_set(checker: &Checker, expr: &Expr) -> Result<Edit> {
|
pub(crate) fn fix_unnecessary_literal_set(expr: &Expr, checker: &Checker) -> Result<Edit> {
|
||||||
let locator = checker.locator();
|
let locator = checker.locator();
|
||||||
let stylist = checker.stylist();
|
let stylist = checker.stylist();
|
||||||
|
|
||||||
|
|
@ -302,13 +318,18 @@ pub(crate) fn fix_unnecessary_literal_set(checker: &Checker, expr: &Expr) -> Res
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Edit::range_replacement(
|
Ok(Edit::range_replacement(
|
||||||
pad_expression(tree.codegen_stylist(stylist), expr.range(), checker),
|
pad_expression(
|
||||||
|
tree.codegen_stylist(stylist),
|
||||||
|
expr.range(),
|
||||||
|
checker.locator(),
|
||||||
|
checker.semantic(),
|
||||||
|
),
|
||||||
expr.range(),
|
expr.range(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// (C406) Convert `dict([(1, 2)])` to `{1: 2}`.
|
/// (C406) Convert `dict([(1, 2)])` to `{1: 2}`.
|
||||||
pub(crate) fn fix_unnecessary_literal_dict(checker: &Checker, expr: &Expr) -> Result<Edit> {
|
pub(crate) fn fix_unnecessary_literal_dict(expr: &Expr, checker: &Checker) -> Result<Edit> {
|
||||||
let locator = checker.locator();
|
let locator = checker.locator();
|
||||||
let stylist = checker.stylist();
|
let stylist = checker.stylist();
|
||||||
|
|
||||||
|
|
@ -365,13 +386,18 @@ pub(crate) fn fix_unnecessary_literal_dict(checker: &Checker, expr: &Expr) -> Re
|
||||||
}));
|
}));
|
||||||
|
|
||||||
Ok(Edit::range_replacement(
|
Ok(Edit::range_replacement(
|
||||||
pad_expression(tree.codegen_stylist(stylist), expr.range(), checker),
|
pad_expression(
|
||||||
|
tree.codegen_stylist(stylist),
|
||||||
|
expr.range(),
|
||||||
|
checker.locator(),
|
||||||
|
checker.semantic(),
|
||||||
|
),
|
||||||
expr.range(),
|
expr.range(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// (C408)
|
/// (C408)
|
||||||
pub(crate) fn fix_unnecessary_collection_call(checker: &Checker, expr: &Expr) -> Result<Edit> {
|
pub(crate) fn fix_unnecessary_collection_call(expr: &Expr, checker: &Checker) -> Result<Edit> {
|
||||||
enum Collection {
|
enum Collection {
|
||||||
Tuple,
|
Tuple,
|
||||||
List,
|
List,
|
||||||
|
|
@ -481,7 +507,12 @@ pub(crate) fn fix_unnecessary_collection_call(checker: &Checker, expr: &Expr) ->
|
||||||
|
|
||||||
Ok(Edit::range_replacement(
|
Ok(Edit::range_replacement(
|
||||||
if matches!(collection, Collection::Dict) {
|
if matches!(collection, Collection::Dict) {
|
||||||
pad_expression(tree.codegen_stylist(stylist), expr.range(), checker)
|
pad_expression(
|
||||||
|
tree.codegen_stylist(stylist),
|
||||||
|
expr.range(),
|
||||||
|
checker.locator(),
|
||||||
|
checker.semantic(),
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
tree.codegen_stylist(stylist)
|
tree.codegen_stylist(stylist)
|
||||||
},
|
},
|
||||||
|
|
@ -501,19 +532,24 @@ pub(crate) fn fix_unnecessary_collection_call(checker: &Checker, expr: &Expr) ->
|
||||||
/// However, this is a syntax error under the f-string grammar. As such,
|
/// However, this is a syntax error under the f-string grammar. As such,
|
||||||
/// this method will pad the start and end of an expression as needed to
|
/// this method will pad the start and end of an expression as needed to
|
||||||
/// avoid producing invalid syntax.
|
/// avoid producing invalid syntax.
|
||||||
fn pad_expression(content: String, range: TextRange, checker: &Checker) -> String {
|
fn pad_expression(
|
||||||
if !checker.semantic().in_f_string() {
|
content: String,
|
||||||
|
range: TextRange,
|
||||||
|
locator: &Locator,
|
||||||
|
semantic: &SemanticModel,
|
||||||
|
) -> String {
|
||||||
|
if !semantic.in_f_string() {
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the expression is immediately preceded by an opening brace, then
|
// If the expression is immediately preceded by an opening brace, then
|
||||||
// we need to add a space before the expression.
|
// we need to add a space before the expression.
|
||||||
let prefix = checker.locator().up_to(range.start());
|
let prefix = locator.up_to(range.start());
|
||||||
let left_pad = matches!(prefix.chars().next_back(), Some('{'));
|
let left_pad = matches!(prefix.chars().next_back(), Some('{'));
|
||||||
|
|
||||||
// If the expression is immediately preceded by an opening brace, then
|
// If the expression is immediately preceded by an opening brace, then
|
||||||
// we need to add a space before the expression.
|
// we need to add a space before the expression.
|
||||||
let suffix = checker.locator().after(range.end());
|
let suffix = locator.after(range.end());
|
||||||
let right_pad = matches!(suffix.chars().next(), Some('}'));
|
let right_pad = matches!(suffix.chars().next(), Some('}'));
|
||||||
|
|
||||||
if left_pad && right_pad {
|
if left_pad && right_pad {
|
||||||
|
|
@ -529,9 +565,9 @@ fn pad_expression(content: String, range: TextRange, checker: &Checker) -> Strin
|
||||||
|
|
||||||
/// (C409) Convert `tuple([1, 2])` to `tuple(1, 2)`
|
/// (C409) Convert `tuple([1, 2])` to `tuple(1, 2)`
|
||||||
pub(crate) fn fix_unnecessary_literal_within_tuple_call(
|
pub(crate) fn fix_unnecessary_literal_within_tuple_call(
|
||||||
|
expr: &Expr,
|
||||||
locator: &Locator,
|
locator: &Locator,
|
||||||
stylist: &Stylist,
|
stylist: &Stylist,
|
||||||
expr: &Expr,
|
|
||||||
) -> Result<Edit> {
|
) -> Result<Edit> {
|
||||||
let module_text = locator.slice(expr);
|
let module_text = locator.slice(expr);
|
||||||
let mut tree = match_expression(module_text)?;
|
let mut tree = match_expression(module_text)?;
|
||||||
|
|
@ -579,9 +615,9 @@ pub(crate) fn fix_unnecessary_literal_within_tuple_call(
|
||||||
|
|
||||||
/// (C410) Convert `list([1, 2])` to `[1, 2]`
|
/// (C410) Convert `list([1, 2])` to `[1, 2]`
|
||||||
pub(crate) fn fix_unnecessary_literal_within_list_call(
|
pub(crate) fn fix_unnecessary_literal_within_list_call(
|
||||||
|
expr: &Expr,
|
||||||
locator: &Locator,
|
locator: &Locator,
|
||||||
stylist: &Stylist,
|
stylist: &Stylist,
|
||||||
expr: &Expr,
|
|
||||||
) -> Result<Edit> {
|
) -> Result<Edit> {
|
||||||
let module_text = locator.slice(expr);
|
let module_text = locator.slice(expr);
|
||||||
let mut tree = match_expression(module_text)?;
|
let mut tree = match_expression(module_text)?;
|
||||||
|
|
@ -631,9 +667,9 @@ pub(crate) fn fix_unnecessary_literal_within_list_call(
|
||||||
|
|
||||||
/// (C411) Convert `list([i * i for i in x])` to `[i * i for i in x]`.
|
/// (C411) Convert `list([i * i for i in x])` to `[i * i for i in x]`.
|
||||||
pub(crate) fn fix_unnecessary_list_call(
|
pub(crate) fn fix_unnecessary_list_call(
|
||||||
|
expr: &Expr,
|
||||||
locator: &Locator,
|
locator: &Locator,
|
||||||
stylist: &Stylist,
|
stylist: &Stylist,
|
||||||
expr: &Expr,
|
|
||||||
) -> Result<Edit> {
|
) -> Result<Edit> {
|
||||||
// Expr(Call(List|Tuple)))) -> Expr(List|Tuple)))
|
// Expr(Call(List|Tuple)))) -> Expr(List|Tuple)))
|
||||||
let module_text = locator.slice(expr);
|
let module_text = locator.slice(expr);
|
||||||
|
|
@ -653,9 +689,9 @@ pub(crate) fn fix_unnecessary_list_call(
|
||||||
/// (C413) Convert `reversed(sorted([2, 3, 1]))` to `sorted([2, 3, 1],
|
/// (C413) Convert `reversed(sorted([2, 3, 1]))` to `sorted([2, 3, 1],
|
||||||
/// reverse=True)`.
|
/// reverse=True)`.
|
||||||
pub(crate) fn fix_unnecessary_call_around_sorted(
|
pub(crate) fn fix_unnecessary_call_around_sorted(
|
||||||
|
expr: &Expr,
|
||||||
locator: &Locator,
|
locator: &Locator,
|
||||||
stylist: &Stylist,
|
stylist: &Stylist,
|
||||||
expr: &Expr,
|
|
||||||
) -> Result<Edit> {
|
) -> Result<Edit> {
|
||||||
let module_text = locator.slice(expr);
|
let module_text = locator.slice(expr);
|
||||||
let mut tree = match_expression(module_text)?;
|
let mut tree = match_expression(module_text)?;
|
||||||
|
|
@ -765,9 +801,9 @@ pub(crate) fn fix_unnecessary_call_around_sorted(
|
||||||
|
|
||||||
/// (C414) Convert `sorted(list(foo))` to `sorted(foo)`
|
/// (C414) Convert `sorted(list(foo))` to `sorted(foo)`
|
||||||
pub(crate) fn fix_unnecessary_double_cast_or_process(
|
pub(crate) fn fix_unnecessary_double_cast_or_process(
|
||||||
|
expr: &Expr,
|
||||||
locator: &Locator,
|
locator: &Locator,
|
||||||
stylist: &Stylist,
|
stylist: &Stylist,
|
||||||
expr: &Expr,
|
|
||||||
) -> Result<Edit> {
|
) -> Result<Edit> {
|
||||||
let module_text = locator.slice(expr);
|
let module_text = locator.slice(expr);
|
||||||
let mut tree = match_expression(module_text)?;
|
let mut tree = match_expression(module_text)?;
|
||||||
|
|
@ -796,9 +832,9 @@ pub(crate) fn fix_unnecessary_double_cast_or_process(
|
||||||
|
|
||||||
/// (C416) Convert `[i for i in x]` to `list(x)`.
|
/// (C416) Convert `[i for i in x]` to `list(x)`.
|
||||||
pub(crate) fn fix_unnecessary_comprehension(
|
pub(crate) fn fix_unnecessary_comprehension(
|
||||||
|
expr: &Expr,
|
||||||
locator: &Locator,
|
locator: &Locator,
|
||||||
stylist: &Stylist,
|
stylist: &Stylist,
|
||||||
expr: &Expr,
|
|
||||||
) -> Result<Edit> {
|
) -> Result<Edit> {
|
||||||
let module_text = locator.slice(expr);
|
let module_text = locator.slice(expr);
|
||||||
let mut tree = match_expression(module_text)?;
|
let mut tree = match_expression(module_text)?;
|
||||||
|
|
@ -883,11 +919,11 @@ pub(crate) fn fix_unnecessary_comprehension(
|
||||||
|
|
||||||
/// (C417) Convert `map(lambda x: x * 2, bar)` to `(x * 2 for x in bar)`.
|
/// (C417) Convert `map(lambda x: x * 2, bar)` to `(x * 2 for x in bar)`.
|
||||||
pub(crate) fn fix_unnecessary_map(
|
pub(crate) fn fix_unnecessary_map(
|
||||||
locator: &Locator,
|
|
||||||
stylist: &Stylist,
|
|
||||||
expr: &Expr,
|
expr: &Expr,
|
||||||
parent: Option<&Expr>,
|
parent: Option<&Expr>,
|
||||||
object_type: ObjectType,
|
object_type: ObjectType,
|
||||||
|
locator: &Locator,
|
||||||
|
stylist: &Stylist,
|
||||||
) -> Result<Edit> {
|
) -> Result<Edit> {
|
||||||
let module_text = locator.slice(expr);
|
let module_text = locator.slice(expr);
|
||||||
let mut tree = match_expression(module_text)?;
|
let mut tree = match_expression(module_text)?;
|
||||||
|
|
@ -1024,9 +1060,9 @@ pub(crate) fn fix_unnecessary_map(
|
||||||
|
|
||||||
/// (C418) Convert `dict({"a": 1})` to `{"a": 1}`
|
/// (C418) Convert `dict({"a": 1})` to `{"a": 1}`
|
||||||
pub(crate) fn fix_unnecessary_literal_within_dict_call(
|
pub(crate) fn fix_unnecessary_literal_within_dict_call(
|
||||||
|
expr: &Expr,
|
||||||
locator: &Locator,
|
locator: &Locator,
|
||||||
stylist: &Stylist,
|
stylist: &Stylist,
|
||||||
expr: &Expr,
|
|
||||||
) -> Result<Edit> {
|
) -> Result<Edit> {
|
||||||
let module_text = locator.slice(expr);
|
let module_text = locator.slice(expr);
|
||||||
let mut tree = match_expression(module_text)?;
|
let mut tree = match_expression(module_text)?;
|
||||||
|
|
@ -1043,9 +1079,9 @@ pub(crate) fn fix_unnecessary_literal_within_dict_call(
|
||||||
|
|
||||||
/// (C419) Convert `[i for i in a]` into `i for i in a`
|
/// (C419) Convert `[i for i in a]` into `i for i in a`
|
||||||
pub(crate) fn fix_unnecessary_comprehension_any_all(
|
pub(crate) fn fix_unnecessary_comprehension_any_all(
|
||||||
|
expr: &Expr,
|
||||||
locator: &Locator,
|
locator: &Locator,
|
||||||
stylist: &Stylist,
|
stylist: &Stylist,
|
||||||
expr: &Expr,
|
|
||||||
) -> Result<Fix> {
|
) -> Result<Fix> {
|
||||||
// Expr(ListComp) -> Expr(GeneratorExp)
|
// Expr(ListComp) -> Expr(GeneratorExp)
|
||||||
let module_text = locator.slice(expr);
|
let module_text = locator.slice(expr);
|
||||||
|
|
|
||||||
|
|
@ -85,9 +85,9 @@ pub(crate) fn unnecessary_call_around_sorted(
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic.try_set_fix(|| {
|
diagnostic.try_set_fix(|| {
|
||||||
let edit = fixes::fix_unnecessary_call_around_sorted(
|
let edit = fixes::fix_unnecessary_call_around_sorted(
|
||||||
|
expr,
|
||||||
checker.locator(),
|
checker.locator(),
|
||||||
checker.stylist(),
|
checker.stylist(),
|
||||||
expr,
|
|
||||||
)?;
|
)?;
|
||||||
if outer.id == "reversed" {
|
if outer.id == "reversed" {
|
||||||
Ok(Fix::suggested(edit))
|
Ok(Fix::suggested(edit))
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ pub(crate) fn unnecessary_collection_call(
|
||||||
);
|
);
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic.try_set_fix(|| {
|
diagnostic.try_set_fix(|| {
|
||||||
fixes::fix_unnecessary_collection_call(checker, expr).map(Fix::suggested)
|
fixes::fix_unnecessary_collection_call(expr, checker).map(Fix::suggested)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
checker.diagnostics.push(diagnostic);
|
checker.diagnostics.push(diagnostic);
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ fn add_diagnostic(checker: &mut Checker, expr: &Expr) {
|
||||||
);
|
);
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic.try_set_fix(|| {
|
diagnostic.try_set_fix(|| {
|
||||||
fixes::fix_unnecessary_comprehension(checker.locator(), checker.stylist(), expr)
|
fixes::fix_unnecessary_comprehension(expr, checker.locator(), checker.stylist())
|
||||||
.map(Fix::suggested)
|
.map(Fix::suggested)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ pub(crate) fn unnecessary_comprehension_any_all(
|
||||||
let mut diagnostic = Diagnostic::new(UnnecessaryComprehensionAnyAll, arg.range());
|
let mut diagnostic = Diagnostic::new(UnnecessaryComprehensionAnyAll, arg.range());
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic.try_set_fix(|| {
|
diagnostic.try_set_fix(|| {
|
||||||
fixes::fix_unnecessary_comprehension_any_all(checker.locator(), checker.stylist(), expr)
|
fixes::fix_unnecessary_comprehension_any_all(expr, checker.locator(), checker.stylist())
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
checker.diagnostics.push(diagnostic);
|
checker.diagnostics.push(diagnostic);
|
||||||
|
|
|
||||||
|
|
@ -133,9 +133,9 @@ pub(crate) fn unnecessary_double_cast_or_process(
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic.try_set_fix(|| {
|
diagnostic.try_set_fix(|| {
|
||||||
fixes::fix_unnecessary_double_cast_or_process(
|
fixes::fix_unnecessary_double_cast_or_process(
|
||||||
|
expr,
|
||||||
checker.locator(),
|
checker.locator(),
|
||||||
checker.stylist(),
|
checker.stylist(),
|
||||||
expr,
|
|
||||||
)
|
)
|
||||||
.map(Fix::suggested)
|
.map(Fix::suggested)
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ pub(crate) fn unnecessary_generator_dict(
|
||||||
let mut diagnostic = Diagnostic::new(UnnecessaryGeneratorDict, expr.range());
|
let mut diagnostic = Diagnostic::new(UnnecessaryGeneratorDict, expr.range());
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic.try_set_fix(|| {
|
diagnostic.try_set_fix(|| {
|
||||||
fixes::fix_unnecessary_generator_dict(checker, expr).map(Fix::suggested)
|
fixes::fix_unnecessary_generator_dict(expr, checker).map(Fix::suggested)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
checker.diagnostics.push(diagnostic);
|
checker.diagnostics.push(diagnostic);
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ pub(crate) fn unnecessary_generator_list(
|
||||||
let mut diagnostic = Diagnostic::new(UnnecessaryGeneratorList, expr.range());
|
let mut diagnostic = Diagnostic::new(UnnecessaryGeneratorList, expr.range());
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic.try_set_fix(|| {
|
diagnostic.try_set_fix(|| {
|
||||||
fixes::fix_unnecessary_generator_list(checker.locator(), checker.stylist(), expr)
|
fixes::fix_unnecessary_generator_list(expr, checker.locator(), checker.stylist())
|
||||||
.map(Fix::suggested)
|
.map(Fix::suggested)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ pub(crate) fn unnecessary_generator_set(
|
||||||
let mut diagnostic = Diagnostic::new(UnnecessaryGeneratorSet, expr.range());
|
let mut diagnostic = Diagnostic::new(UnnecessaryGeneratorSet, expr.range());
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic.try_set_fix(|| {
|
diagnostic.try_set_fix(|| {
|
||||||
fixes::fix_unnecessary_generator_set(checker, expr).map(Fix::suggested)
|
fixes::fix_unnecessary_generator_set(expr, checker).map(Fix::suggested)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
checker.diagnostics.push(diagnostic);
|
checker.diagnostics.push(diagnostic);
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ pub(crate) fn unnecessary_list_call(
|
||||||
let mut diagnostic = Diagnostic::new(UnnecessaryListCall, expr.range());
|
let mut diagnostic = Diagnostic::new(UnnecessaryListCall, expr.range());
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic.try_set_fix(|| {
|
diagnostic.try_set_fix(|| {
|
||||||
fixes::fix_unnecessary_list_call(checker.locator(), checker.stylist(), expr)
|
fixes::fix_unnecessary_list_call(expr, checker.locator(), checker.stylist())
|
||||||
.map(Fix::suggested)
|
.map(Fix::suggested)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ pub(crate) fn unnecessary_list_comprehension_dict(
|
||||||
let mut diagnostic = Diagnostic::new(UnnecessaryListComprehensionDict, expr.range());
|
let mut diagnostic = Diagnostic::new(UnnecessaryListComprehensionDict, expr.range());
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic.try_set_fix(|| {
|
diagnostic.try_set_fix(|| {
|
||||||
fixes::fix_unnecessary_list_comprehension_dict(checker, expr).map(Fix::suggested)
|
fixes::fix_unnecessary_list_comprehension_dict(expr, checker).map(Fix::suggested)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
checker.diagnostics.push(diagnostic);
|
checker.diagnostics.push(diagnostic);
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ pub(crate) fn unnecessary_list_comprehension_set(
|
||||||
let mut diagnostic = Diagnostic::new(UnnecessaryListComprehensionSet, expr.range());
|
let mut diagnostic = Diagnostic::new(UnnecessaryListComprehensionSet, expr.range());
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic.try_set_fix(|| {
|
diagnostic.try_set_fix(|| {
|
||||||
fixes::fix_unnecessary_list_comprehension_set(checker, expr).map(Fix::suggested)
|
fixes::fix_unnecessary_list_comprehension_set(expr, checker).map(Fix::suggested)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
checker.diagnostics.push(diagnostic);
|
checker.diagnostics.push(diagnostic);
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ pub(crate) fn unnecessary_literal_dict(
|
||||||
);
|
);
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic
|
diagnostic
|
||||||
.try_set_fix(|| fixes::fix_unnecessary_literal_dict(checker, expr).map(Fix::suggested));
|
.try_set_fix(|| fixes::fix_unnecessary_literal_dict(expr, checker).map(Fix::suggested));
|
||||||
}
|
}
|
||||||
checker.diagnostics.push(diagnostic);
|
checker.diagnostics.push(diagnostic);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ pub(crate) fn unnecessary_literal_set(
|
||||||
);
|
);
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic
|
diagnostic
|
||||||
.try_set_fix(|| fixes::fix_unnecessary_literal_set(checker, expr).map(Fix::suggested));
|
.try_set_fix(|| fixes::fix_unnecessary_literal_set(expr, checker).map(Fix::suggested));
|
||||||
}
|
}
|
||||||
checker.diagnostics.push(diagnostic);
|
checker.diagnostics.push(diagnostic);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -94,9 +94,9 @@ pub(crate) fn unnecessary_literal_within_dict_call(
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic.try_set_fix(|| {
|
diagnostic.try_set_fix(|| {
|
||||||
fixes::fix_unnecessary_literal_within_dict_call(
|
fixes::fix_unnecessary_literal_within_dict_call(
|
||||||
|
expr,
|
||||||
checker.locator(),
|
checker.locator(),
|
||||||
checker.stylist(),
|
checker.stylist(),
|
||||||
expr,
|
|
||||||
)
|
)
|
||||||
.map(Fix::suggested)
|
.map(Fix::suggested)
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -96,9 +96,9 @@ pub(crate) fn unnecessary_literal_within_list_call(
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic.try_set_fix(|| {
|
diagnostic.try_set_fix(|| {
|
||||||
fixes::fix_unnecessary_literal_within_list_call(
|
fixes::fix_unnecessary_literal_within_list_call(
|
||||||
|
expr,
|
||||||
checker.locator(),
|
checker.locator(),
|
||||||
checker.stylist(),
|
checker.stylist(),
|
||||||
expr,
|
|
||||||
)
|
)
|
||||||
.map(Fix::suggested)
|
.map(Fix::suggested)
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -98,9 +98,9 @@ pub(crate) fn unnecessary_literal_within_tuple_call(
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic.try_set_fix(|| {
|
diagnostic.try_set_fix(|| {
|
||||||
fixes::fix_unnecessary_literal_within_tuple_call(
|
fixes::fix_unnecessary_literal_within_tuple_call(
|
||||||
|
expr,
|
||||||
checker.locator(),
|
checker.locator(),
|
||||||
checker.stylist(),
|
checker.stylist(),
|
||||||
expr,
|
|
||||||
)
|
)
|
||||||
.map(Fix::suggested)
|
.map(Fix::suggested)
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -224,11 +224,11 @@ pub(crate) fn unnecessary_map(
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
diagnostic.try_set_fix(|| {
|
diagnostic.try_set_fix(|| {
|
||||||
fixes::fix_unnecessary_map(
|
fixes::fix_unnecessary_map(
|
||||||
checker.locator(),
|
|
||||||
checker.stylist(),
|
|
||||||
expr,
|
expr,
|
||||||
parent,
|
parent,
|
||||||
object_type,
|
object_type,
|
||||||
|
checker.locator(),
|
||||||
|
checker.stylist(),
|
||||||
)
|
)
|
||||||
.map(Fix::suggested)
|
.map(Fix::suggested)
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue