Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update C419 to be a suggested fix #4424

Merged
merged 1 commit into from
May 15, 2023
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
9 changes: 6 additions & 3 deletions crates/ruff/src/rules/flake8_comprehensions/fixes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not entirely clear to me if the applicability should be decided here in fixes.rs or rules/...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think either is fine since the method is only used in unnecessary_comprehension_any_all (that's why I personally would move the function and co-locate it with the rule).

Another reasoning: If we always know that a certain Edit is potentially unsafe, then it's okay to decide in the helper method.

state.to_string(),
expr.range(),
)))
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
});
}
Expand Down