feat: let SIM210 return expressions without bool() wrapping (#2410) (#2426)

This commit is contained in:
Florian Best 2023-02-01 00:25:22 +01:00 committed by GitHub
parent 7c1a6bce7b
commit 82ec884a61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 12 deletions

View File

@ -35,9 +35,9 @@ pub fn explicit_true_false_in_ifexpr(
Range::from_located(expr), Range::from_located(expr),
); );
if checker.patch(diagnostic.kind.rule()) { if checker.patch(diagnostic.kind.rule()) {
diagnostic.amend(Fix::replacement( let bool_expr = match test.node {
unparse_expr( ExprKind::Compare { .. } => test.clone(),
&create_expr(ExprKind::Call { _ => create_expr(ExprKind::Call {
func: Box::new(create_expr(ExprKind::Name { func: Box::new(create_expr(ExprKind::Name {
id: "bool".to_string(), id: "bool".to_string(),
ctx: ExprContext::Load, ctx: ExprContext::Load,
@ -45,8 +45,9 @@ pub fn explicit_true_false_in_ifexpr(
args: vec![test.clone()], args: vec![test.clone()],
keywords: vec![], keywords: vec![],
}), }),
checker.stylist, };
), diagnostic.amend(Fix::replacement(
unparse_expr(&bool_expr, checker.stylist),
expr.location, expr.location,
expr.end_location.unwrap(), expr.end_location.unwrap(),
)); ));

View File

@ -32,7 +32,7 @@ expression: diagnostics
column: 29 column: 29
fix: fix:
content: content:
- bool(b != c) - b != c
location: location:
row: 3 row: 3
column: 4 column: 4