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,18 +35,19 @@ 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()) {
let bool_expr = match test.node {
ExprKind::Compare { .. } => test.clone(),
_ => create_expr(ExprKind::Call {
func: Box::new(create_expr(ExprKind::Name {
id: "bool".to_string(),
ctx: ExprContext::Load,
})),
args: vec![test.clone()],
keywords: vec![],
}),
};
diagnostic.amend(Fix::replacement( diagnostic.amend(Fix::replacement(
unparse_expr( unparse_expr(&bool_expr, checker.stylist),
&create_expr(ExprKind::Call {
func: Box::new(create_expr(ExprKind::Name {
id: "bool".to_string(),
ctx: ExprContext::Load,
})),
args: vec![test.clone()],
keywords: vec![],
}),
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