Skip to content

Commit

Permalink
Add Applicability to flake8_simplify (#5348)
Browse files Browse the repository at this point in the history
  • Loading branch information
evanrittenhouse authored Jun 23, 2023
1 parent adf5cb5 commit e0a507e
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 54 deletions.
18 changes: 6 additions & 12 deletions crates/ruff/src/rules/flake8_simplify/rules/ast_bool_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,7 @@ pub(crate) fn duplicate_isinstance_call(checker: &mut Checker, expr: &Expr) {

// Populate the `Fix`. Replace the _entire_ `BoolOp`. Note that if we have
// multiple duplicates, the fixes will conflict.
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
checker.generator().expr(&bool_op),
expr.range(),
)));
Expand Down Expand Up @@ -530,8 +529,7 @@ pub(crate) fn compare_with_tuple(checker: &mut Checker, expr: &Expr) {
};
node.into()
};
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
checker.generator().expr(&in_expr),
expr.range(),
)));
Expand Down Expand Up @@ -583,8 +581,7 @@ pub(crate) fn expr_and_not_expr(checker: &mut Checker, expr: &Expr) {
expr.range(),
);
if checker.patch(diagnostic.kind.rule()) {
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
"False".to_string(),
expr.range(),
)));
Expand Down Expand Up @@ -638,8 +635,7 @@ pub(crate) fn expr_or_not_expr(checker: &mut Checker, expr: &Expr) {
expr.range(),
);
if checker.patch(diagnostic.kind.rule()) {
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
"True".to_string(),
expr.range(),
)));
Expand Down Expand Up @@ -762,8 +758,7 @@ pub(crate) fn expr_or_true(checker: &mut Checker, expr: &Expr) {
edit.range(),
);
if checker.patch(diagnostic.kind.rule()) {
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(edit));
diagnostic.set_fix(Fix::suggested(edit));
}
checker.diagnostics.push(diagnostic);
}
Expand All @@ -780,8 +775,7 @@ pub(crate) fn expr_and_false(checker: &mut Checker, expr: &Expr) {
edit.range(),
);
if checker.patch(diagnostic.kind.rule()) {
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(edit));
diagnostic.set_fix(Fix::suggested(edit));
}
checker.diagnostics.push(diagnostic);
}
Expand Down
6 changes: 2 additions & 4 deletions crates/ruff/src/rules/flake8_simplify/rules/ast_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ fn check_os_environ_subscript(checker: &mut Checker, expr: &Expr) {
range: TextRange::default(),
};
let new_env_var = node.into();
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
checker.generator().expr(&new_env_var),
slice.range(),
)));
Expand Down Expand Up @@ -229,8 +228,7 @@ pub(crate) fn dict_get_with_none_default(checker: &mut Checker, expr: &Expr) {
);

if checker.patch(diagnostic.kind.rule()) {
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
expected,
expr.range(),
)));
Expand Down
15 changes: 5 additions & 10 deletions crates/ruff/src/rules/flake8_simplify/rules/ast_if.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,7 @@ pub(crate) fn nested_if_statements(
<= checker.settings.line_length
})
{
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(edit));
diagnostic.set_fix(Fix::suggested(edit));
}
}
Err(err) => error!("Failed to fix nested if: {err}"),
Expand Down Expand Up @@ -457,8 +456,7 @@ pub(crate) fn needless_bool(checker: &mut Checker, stmt: &Stmt) {
value: Some(test.clone()),
range: TextRange::default(),
};
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
checker.generator().stmt(&node.into()),
stmt.range(),
)));
Expand All @@ -480,8 +478,7 @@ pub(crate) fn needless_bool(checker: &mut Checker, stmt: &Stmt) {
value: Some(Box::new(node1.into())),
range: TextRange::default(),
};
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
checker.generator().stmt(&node2.into()),
stmt.range(),
)));
Expand Down Expand Up @@ -621,8 +618,7 @@ pub(crate) fn use_ternary_operator(checker: &mut Checker, stmt: &Stmt, parent: O
);
if checker.patch(diagnostic.kind.rule()) {
if !has_comments(stmt, checker.locator) {
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
contents,
stmt.range(),
)));
Expand Down Expand Up @@ -978,8 +974,7 @@ pub(crate) fn use_dict_get_with_default(
);
if checker.patch(diagnostic.kind.rule()) {
if !has_comments(stmt, checker.locator) {
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
contents,
stmt.range(),
)));
Expand Down
12 changes: 4 additions & 8 deletions crates/ruff/src/rules/flake8_simplify/rules/ast_ifexp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ pub(crate) fn explicit_true_false_in_ifexpr(
);
if checker.patch(diagnostic.kind.rule()) {
if matches!(test, Expr::Compare(_)) {
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
checker.generator().expr(&test.clone()),
expr.range(),
)));
Expand All @@ -179,8 +178,7 @@ pub(crate) fn explicit_true_false_in_ifexpr(
keywords: vec![],
range: TextRange::default(),
};
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
checker.generator().expr(&node1.into()),
expr.range(),
)));
Expand Down Expand Up @@ -223,8 +221,7 @@ pub(crate) fn explicit_false_true_in_ifexpr(
operand: Box::new(node),
range: TextRange::default(),
};
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
checker.generator().expr(&node1.into()),
expr.range(),
)));
Expand Down Expand Up @@ -275,8 +272,7 @@ pub(crate) fn twisted_arms_in_ifexpr(
orelse: Box::new(node),
range: TextRange::default(),
};
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
checker.generator().expr(&node3.into()),
expr.range(),
)));
Expand Down
12 changes: 4 additions & 8 deletions crates/ruff/src/rules/flake8_simplify/rules/ast_unary_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,7 @@ pub(crate) fn negation_with_equal_op(
comparators: comparators.clone(),
range: TextRange::default(),
};
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
checker.generator().expr(&node.into()),
expr.range(),
)));
Expand Down Expand Up @@ -231,8 +230,7 @@ pub(crate) fn negation_with_not_equal_op(
comparators: comparators.clone(),
range: TextRange::default(),
};
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
checker.generator().expr(&node.into()),
expr.range(),
)));
Expand Down Expand Up @@ -260,8 +258,7 @@ pub(crate) fn double_negation(checker: &mut Checker, expr: &Expr, op: UnaryOp, o
);
if checker.patch(diagnostic.kind.rule()) {
if checker.semantic().in_boolean_test() {
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
checker.generator().expr(operand),
expr.range(),
)));
Expand All @@ -277,8 +274,7 @@ pub(crate) fn double_negation(checker: &mut Checker, expr: &Expr, op: UnaryOp, o
keywords: vec![],
range: TextRange::default(),
};
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
checker.generator().expr(&node1.into()),
expr.range(),
)));
Expand Down
3 changes: 1 addition & 2 deletions crates/ruff/src/rules/flake8_simplify/rules/ast_with.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ pub(crate) fn multiple_with_statements(
<= checker.settings.line_length
})
{
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(edit));
diagnostic.set_fix(Fix::suggested(edit));
}
}
Err(err) => error!("Failed to fix nested with: {err}"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ pub(crate) fn suppressible_exception(
);
let handler_line_begin = checker.locator.line_start(handler.start());
let remove_handler = Edit::deletion(handler_line_begin, handler.end());
#[allow(deprecated)]
Ok(Fix::unspecified_edits(
Ok(Fix::suggested_edits(
import_edit,
[replace_try, remove_handler],
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SIM201.py:2:4: SIM201 [*] Use `a != b` instead of `not a == b`
|
= help: Replace with `!=` operator

Suggested fix
Fix
1 1 | # SIM201
2 |-if not a == b:
2 |+if a != b:
Expand All @@ -27,7 +27,7 @@ SIM201.py:6:4: SIM201 [*] Use `a != b + c` instead of `not a == b + c`
|
= help: Replace with `!=` operator

Suggested fix
Fix
3 3 | pass
4 4 |
5 5 | # SIM201
Expand All @@ -46,7 +46,7 @@ SIM201.py:10:4: SIM201 [*] Use `a + b != c` instead of `not a + b == c`
|
= help: Replace with `!=` operator

Suggested fix
Fix
7 7 | pass
8 8 |
9 9 | # SIM201
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ SIM910.py:2:1: SIM910 [*] Use `{}.get(key)` instead of `{}.get(key, None)`
|
= help: Replace `{}.get(key, None)` with `{}.get(key)`

Suggested fix
Fix
1 1 | # SIM910
2 |-{}.get(key, None)
2 |+{}.get(key)
Expand All @@ -29,7 +29,7 @@ SIM910.py:5:1: SIM910 [*] Use `{}.get("key")` instead of `{}.get("key", None)`
|
= help: Replace `{}.get("key", None)` with `{}.get("key")`

Suggested fix
Fix
2 2 | {}.get(key, None)
3 3 |
4 4 | # SIM910
Expand All @@ -48,7 +48,7 @@ SIM910.py:20:9: SIM910 [*] Use `{}.get(key)` instead of `{}.get(key, None)`
|
= help: Replace `{}.get(key, None)` with `{}.get(key)`

Suggested fix
Fix
17 17 | {}.get("key", False)
18 18 |
19 19 | # SIM910
Expand All @@ -68,7 +68,7 @@ SIM910.py:24:5: SIM910 [*] Use `{}.get(key)` instead of `{}.get(key, None)`
|
= help: Replace `{}.get(key, None)` with `{}.get(key)`

Suggested fix
Fix
21 21 | pass
22 22 |
23 23 | # SIM910
Expand All @@ -86,7 +86,7 @@ SIM910.py:27:1: SIM910 [*] Use `({}).get(key)` instead of `({}).get(key, None)`
|
= help: Replace `({}).get(key, None)` with `({}).get(key)`

Suggested fix
Fix
24 24 | a = {}.get(key, None)
25 25 |
26 26 | # SIM910
Expand Down

0 comments on commit e0a507e

Please sign in to comment.