mirror of https://github.com/astral-sh/ruff
Update C419 to be a suggested fix (#4424)
This commit is contained in:
parent
d6930ca991
commit
2c6efc2f5f
|
|
@ -8,7 +8,7 @@ use libcst_native::{
|
||||||
SimpleString, SimpleWhitespace, TrailingWhitespace, Tuple,
|
SimpleString, SimpleWhitespace, TrailingWhitespace, Tuple,
|
||||||
};
|
};
|
||||||
|
|
||||||
use ruff_diagnostics::Edit;
|
use ruff_diagnostics::{Edit, Fix};
|
||||||
use ruff_python_ast::source_code::{Locator, Stylist};
|
use ruff_python_ast::source_code::{Locator, Stylist};
|
||||||
|
|
||||||
use crate::cst::matchers::{match_expr, match_module};
|
use crate::cst::matchers::{match_expr, match_module};
|
||||||
|
|
@ -1142,7 +1142,7 @@ pub(crate) fn fix_unnecessary_comprehension_any_all(
|
||||||
locator: &Locator,
|
locator: &Locator,
|
||||||
stylist: &Stylist,
|
stylist: &Stylist,
|
||||||
expr: &rustpython_parser::ast::Expr,
|
expr: &rustpython_parser::ast::Expr,
|
||||||
) -> Result<Edit> {
|
) -> Result<Fix> {
|
||||||
// Expr(ListComp) -> Expr(GeneratorExp)
|
// Expr(ListComp) -> Expr(GeneratorExp)
|
||||||
let module_text = locator.slice(expr.range());
|
let module_text = locator.slice(expr.range());
|
||||||
let mut tree = match_module(module_text)?;
|
let mut tree = match_module(module_text)?;
|
||||||
|
|
@ -1312,5 +1312,8 @@ pub(crate) fn fix_unnecessary_comprehension_any_all(
|
||||||
};
|
};
|
||||||
tree.codegen(&mut state);
|
tree.codegen(&mut state);
|
||||||
|
|
||||||
Ok(Edit::range_replacement(state.to_string(), expr.range()))
|
Ok(Fix::suggested(Edit::range_replacement(
|
||||||
|
state.to_string(),
|
||||||
|
expr.range(),
|
||||||
|
)))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -81,8 +81,7 @@ pub(crate) fn unnecessary_comprehension_any_all(
|
||||||
}
|
}
|
||||||
let mut diagnostic = Diagnostic::new(UnnecessaryComprehensionAnyAll, args[0].range());
|
let mut diagnostic = Diagnostic::new(UnnecessaryComprehensionAnyAll, args[0].range());
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
#[allow(deprecated)]
|
diagnostic.try_set_fix(|| {
|
||||||
diagnostic.try_set_fix_from_edit(|| {
|
|
||||||
fixes::fix_unnecessary_comprehension_any_all(checker.locator, checker.stylist, expr)
|
fixes::fix_unnecessary_comprehension_any_all(checker.locator, checker.stylist, expr)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue