Rename nested-if-statements to collapsible-if

This commit is contained in:
Martin Fischer 2023-02-11 06:43:23 +01:00 committed by Charlie Marsh
parent 7e5c19385c
commit c3c5d9a852
7 changed files with 19 additions and 19 deletions

View file

@ -1480,7 +1480,7 @@ where
if self.settings.rules.enabled(&Rule::IfTuple) {
pyflakes::rules::if_tuple(self, stmt, test);
}
if self.settings.rules.enabled(&Rule::NestedIfStatements) {
if self.settings.rules.enabled(&Rule::CollapsibleIf) {
flake8_simplify::rules::nested_if_statements(
self,
stmt,

View file

@ -254,7 +254,7 @@ ruff_macros::define_rule_mapping!(
// flake8-simplify
SIM115 => rules::flake8_simplify::rules::OpenFileWithContextHandler,
SIM101 => rules::flake8_simplify::rules::DuplicateIsinstanceCall,
SIM102 => rules::flake8_simplify::rules::NestedIfStatements,
SIM102 => rules::flake8_simplify::rules::CollapsibleIf,
SIM103 => rules::flake8_simplify::rules::NeedlessBool,
SIM105 => rules::flake8_simplify::rules::UseContextlibSuppress,
SIM107 => rules::flake8_simplify::rules::ReturnInTryExceptFinally,

View file

@ -13,7 +13,7 @@ mod tests {
use crate::{assert_yaml_snapshot, settings};
#[test_case(Rule::DuplicateIsinstanceCall, Path::new("SIM101.py"); "SIM101")]
#[test_case(Rule::NestedIfStatements, Path::new("SIM102.py"); "SIM102")]
#[test_case(Rule::CollapsibleIf, Path::new("SIM102.py"); "SIM102")]
#[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")]

View file

@ -16,11 +16,11 @@ use crate::rules::flake8_simplify::rules::fix_if;
use crate::violation::{AutofixKind, Availability, Violation};
define_violation!(
pub struct NestedIfStatements {
pub struct CollapsibleIf {
pub fixable: bool,
}
);
impl Violation for NestedIfStatements {
impl Violation for CollapsibleIf {
const AUTOFIX: Option<AutofixKind> = Some(AutofixKind::new(Availability::Sometimes));
#[derive_message_formats]
@ -29,7 +29,7 @@ impl Violation for NestedIfStatements {
}
fn autofix_title_formatter(&self) -> Option<fn(&Self) -> String> {
let NestedIfStatements { fixable, .. } = self;
let CollapsibleIf { fixable, .. } = self;
if *fixable {
Some(|_| format!("Combine `if` statements using `and`"))
} else {
@ -209,7 +209,7 @@ pub fn nested_if_statements(
);
let mut diagnostic = Diagnostic::new(
NestedIfStatements { fixable },
CollapsibleIf { fixable },
colon.map_or_else(
|| Range::from_located(stmt),
|colon| Range::new(stmt.location, colon.end_location),

View file

@ -6,7 +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, NeedlessBool, NestedIfStatements, UseTernaryOperator,
use_ternary_operator, CollapsibleIf, DictGetWithDefault, NeedlessBool, 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:
NestedIfStatements:
CollapsibleIf:
fixable: true
location:
row: 2
@ -24,7 +24,7 @@ expression: diagnostics
column: 0
parent: ~
- kind:
NestedIfStatements:
CollapsibleIf:
fixable: true
location:
row: 7
@ -46,7 +46,7 @@ expression: diagnostics
column: 0
parent: ~
- kind:
NestedIfStatements:
CollapsibleIf:
fixable: true
location:
row: 15
@ -67,7 +67,7 @@ expression: diagnostics
column: 0
parent: ~
- kind:
NestedIfStatements:
CollapsibleIf:
fixable: false
location:
row: 20
@ -78,7 +78,7 @@ expression: diagnostics
fix: ~
parent: ~
- kind:
NestedIfStatements:
CollapsibleIf:
fixable: true
location:
row: 26
@ -100,7 +100,7 @@ expression: diagnostics
column: 0
parent: ~
- kind:
NestedIfStatements:
CollapsibleIf:
fixable: true
location:
row: 51
@ -131,7 +131,7 @@ expression: diagnostics
column: 0
parent: ~
- kind:
NestedIfStatements:
CollapsibleIf:
fixable: true
location:
row: 67
@ -162,7 +162,7 @@ expression: diagnostics
column: 0
parent: ~
- kind:
NestedIfStatements:
CollapsibleIf:
fixable: true
location:
row: 83
@ -185,7 +185,7 @@ expression: diagnostics
column: 0
parent: ~
- kind:
NestedIfStatements:
CollapsibleIf:
fixable: true
location:
row: 90
@ -208,7 +208,7 @@ expression: diagnostics
column: 0
parent: ~
- kind:
NestedIfStatements:
CollapsibleIf:
fixable: true
location:
row: 117