mirror of https://github.com/astral-sh/ruff
Wrap return-bool-condition-directly fixes in bool() (#2240)
This commit is contained in:
parent
615e62ae24
commit
093f9156e1
|
|
@ -178,7 +178,14 @@ pub fn return_bool_condition_directly(checker: &mut Checker, stmt: &Stmt) {
|
||||||
&& !has_comments_in(Range::from_located(stmt), checker.locator)
|
&& !has_comments_in(Range::from_located(stmt), checker.locator)
|
||||||
{
|
{
|
||||||
let return_stmt = create_stmt(StmtKind::Return {
|
let return_stmt = create_stmt(StmtKind::Return {
|
||||||
value: Some(test.clone()),
|
value: Some(Box::new(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_stmt(&return_stmt, checker.stylist),
|
unparse_stmt(&return_stmt, checker.stylist),
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ pub fn explicit_true_false_in_ifexpr(
|
||||||
id: "bool".to_string(),
|
id: "bool".to_string(),
|
||||||
ctx: ExprContext::Load,
|
ctx: ExprContext::Load,
|
||||||
})),
|
})),
|
||||||
args: vec![create_expr(test.node.clone())],
|
args: vec![test.clone()],
|
||||||
keywords: vec![],
|
keywords: vec![],
|
||||||
}),
|
}),
|
||||||
checker.stylist,
|
checker.stylist,
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ expression: diagnostics
|
||||||
column: 20
|
column: 20
|
||||||
fix:
|
fix:
|
||||||
content:
|
content:
|
||||||
- return a
|
- return bool(a)
|
||||||
location:
|
location:
|
||||||
row: 3
|
row: 3
|
||||||
column: 4
|
column: 4
|
||||||
|
|
@ -30,7 +30,7 @@ expression: diagnostics
|
||||||
column: 20
|
column: 20
|
||||||
fix:
|
fix:
|
||||||
content:
|
content:
|
||||||
- return b
|
- return bool(b)
|
||||||
location:
|
location:
|
||||||
row: 13
|
row: 13
|
||||||
column: 4
|
column: 4
|
||||||
|
|
@ -48,7 +48,7 @@ expression: diagnostics
|
||||||
column: 24
|
column: 24
|
||||||
fix:
|
fix:
|
||||||
content:
|
content:
|
||||||
- return b
|
- return bool(b)
|
||||||
location:
|
location:
|
||||||
row: 24
|
row: 24
|
||||||
column: 8
|
column: 8
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue