mirror of https://github.com/astral-sh/ruff
This commit is contained in:
parent
7c1a6bce7b
commit
82ec884a61
|
|
@ -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(),
|
||||||
));
|
));
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue