Rename return-bool-condition-directly to needless-bool

This commit is contained in:
Martin Fischer 2023-02-11 06:39:09 +01:00 committed by Charlie Marsh
parent 5b54325c81
commit 7e5c19385c
7 changed files with 17 additions and 24 deletions

View file

@ -1490,11 +1490,7 @@ where
self.current_stmt_parent().map(Into::into),
);
}
if self
.settings
.rules
.enabled(&Rule::ReturnBoolConditionDirectly)
{
if self.settings.rules.enabled(&Rule::NeedlessBool) {
flake8_simplify::rules::return_bool_condition_directly(self, stmt);
}
if self.settings.rules.enabled(&Rule::UseTernaryOperator) {

View file

@ -255,7 +255,7 @@ ruff_macros::define_rule_mapping!(
SIM115 => rules::flake8_simplify::rules::OpenFileWithContextHandler,
SIM101 => rules::flake8_simplify::rules::DuplicateIsinstanceCall,
SIM102 => rules::flake8_simplify::rules::NestedIfStatements,
SIM103 => rules::flake8_simplify::rules::ReturnBoolConditionDirectly,
SIM103 => rules::flake8_simplify::rules::NeedlessBool,
SIM105 => rules::flake8_simplify::rules::UseContextlibSuppress,
SIM107 => rules::flake8_simplify::rules::ReturnInTryExceptFinally,
SIM108 => rules::flake8_simplify::rules::UseTernaryOperator,

View file

@ -14,7 +14,7 @@ mod tests {
#[test_case(Rule::DuplicateIsinstanceCall, Path::new("SIM101.py"); "SIM101")]
#[test_case(Rule::NestedIfStatements, Path::new("SIM102.py"); "SIM102")]
#[test_case(Rule::ReturnBoolConditionDirectly, Path::new("SIM103.py"); "SIM103")]
#[test_case(Rule::NeedlessBool, Path::new("SIM103.py"); "SIM103")]
#[test_case(Rule::UseContextlibSuppress, Path::new("SIM105.py"); "SIM105")]
#[test_case(Rule::ReturnInTryExceptFinally, Path::new("SIM107.py"); "SIM107")]
#[test_case(Rule::UseTernaryOperator, Path::new("SIM108.py"); "SIM108")]

View file

@ -39,26 +39,24 @@ impl Violation for NestedIfStatements {
}
define_violation!(
pub struct ReturnBoolConditionDirectly {
pub struct NeedlessBool {
pub condition: String,
pub fixable: bool,
}
);
impl Violation for ReturnBoolConditionDirectly {
impl Violation for NeedlessBool {
const AUTOFIX: Option<AutofixKind> = Some(AutofixKind::new(Availability::Sometimes));
#[derive_message_formats]
fn message(&self) -> String {
let ReturnBoolConditionDirectly { condition, .. } = self;
let NeedlessBool { condition, .. } = self;
format!("Return the condition `{condition}` directly")
}
fn autofix_title_formatter(&self) -> Option<fn(&Self) -> String> {
let ReturnBoolConditionDirectly { fixable, .. } = self;
let NeedlessBool { fixable, .. } = self;
if *fixable {
Some(|ReturnBoolConditionDirectly { condition, .. }| {
format!("Replace with `return {condition}`")
})
Some(|NeedlessBool { condition, .. }| format!("Replace with `return {condition}`"))
} else {
None
}
@ -288,7 +286,7 @@ pub fn return_bool_condition_directly(checker: &mut Checker, stmt: &Stmt) {
&& (matches!(test.node, ExprKind::Compare { .. }) || checker.is_builtin("bool"));
let mut diagnostic = Diagnostic::new(
ReturnBoolConditionDirectly { condition, fixable },
NeedlessBool { condition, fixable },
Range::from_located(stmt),
);
if fixable && checker.patch(diagnostic.kind.rule()) {

View file

@ -6,8 +6,7 @@ pub use ast_expr::{use_capital_environment_variables, UseCapitalEnvironmentVaria
pub use ast_for::{convert_for_loop_to_any_all, ConvertLoopToAll, ConvertLoopToAny};
pub use ast_if::{
nested_if_statements, return_bool_condition_directly, use_dict_get_with_default,
use_ternary_operator, DictGetWithDefault, NestedIfStatements, ReturnBoolConditionDirectly,
UseTernaryOperator,
use_ternary_operator, DictGetWithDefault, NeedlessBool, NestedIfStatements, UseTernaryOperator,
};
pub use ast_ifexp::{
explicit_false_true_in_ifexpr, explicit_true_false_in_ifexpr, twisted_arms_in_ifexpr,

View file

@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_simplify/mod.rs
expression: diagnostics
---
- kind:
ReturnBoolConditionDirectly:
NeedlessBool:
condition: a
fixable: true
location:
@ -23,7 +23,7 @@ expression: diagnostics
column: 20
parent: ~
- kind:
ReturnBoolConditionDirectly:
NeedlessBool:
condition: a == b
fixable: true
location:
@ -43,7 +43,7 @@ expression: diagnostics
column: 20
parent: ~
- kind:
ReturnBoolConditionDirectly:
NeedlessBool:
condition: b
fixable: true
location:
@ -63,7 +63,7 @@ expression: diagnostics
column: 20
parent: ~
- kind:
ReturnBoolConditionDirectly:
NeedlessBool:
condition: b
fixable: true
location:
@ -83,7 +83,7 @@ expression: diagnostics
column: 24
parent: ~
- kind:
ReturnBoolConditionDirectly:
NeedlessBool:
condition: a
fixable: false
location:
@ -95,7 +95,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
ReturnBoolConditionDirectly:
NeedlessBool:
condition: a
fixable: false
location: