Update C419 to be a suggested fix (#4424)

This commit is contained in:
Zanie Adkins 2023-05-15 03:30:40 -05:00 committed by GitHub
parent d6930ca991
commit 2c6efc2f5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View File

@ -8,7 +8,7 @@ use libcst_native::{
SimpleString, SimpleWhitespace, TrailingWhitespace, Tuple,
};
use ruff_diagnostics::Edit;
use ruff_diagnostics::{Edit, Fix};
use ruff_python_ast::source_code::{Locator, Stylist};
use crate::cst::matchers::{match_expr, match_module};
@ -1142,7 +1142,7 @@ pub(crate) fn fix_unnecessary_comprehension_any_all(
locator: &Locator,
stylist: &Stylist,
expr: &rustpython_parser::ast::Expr,
) -> Result<Edit> {
) -> Result<Fix> {
// Expr(ListComp) -> Expr(GeneratorExp)
let module_text = locator.slice(expr.range());
let mut tree = match_module(module_text)?;
@ -1312,5 +1312,8 @@ pub(crate) fn fix_unnecessary_comprehension_any_all(
};
tree.codegen(&mut state);
Ok(Edit::range_replacement(state.to_string(), expr.range()))
Ok(Fix::suggested(Edit::range_replacement(
state.to_string(),
expr.range(),
)))
}

View File

@ -81,8 +81,7 @@ pub(crate) fn unnecessary_comprehension_any_all(
}
let mut diagnostic = Diagnostic::new(UnnecessaryComprehensionAnyAll, args[0].range());
if checker.patch(diagnostic.kind.rule()) {
#[allow(deprecated)]
diagnostic.try_set_fix_from_edit(|| {
diagnostic.try_set_fix(|| {
fixes::fix_unnecessary_comprehension_any_all(checker.locator, checker.stylist, expr)
});
}