mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 22:31:23 +00:00
Rename nested-if-statements to collapsible-if
This commit is contained in:
parent
7e5c19385c
commit
c3c5d9a852
7 changed files with 19 additions and 19 deletions
|
@ -1217,7 +1217,7 @@ For more, see [flake8-simplify](https://pypi.org/project/flake8-simplify/) on Py
|
||||||
| Code | Name | Message | Fix |
|
| Code | Name | Message | Fix |
|
||||||
| ---- | ---- | ------- | --- |
|
| ---- | ---- | ------- | --- |
|
||||||
| SIM101 | duplicate-isinstance-call | Multiple `isinstance` calls for `{name}`, merge into a single call | 🛠 |
|
| SIM101 | duplicate-isinstance-call | Multiple `isinstance` calls for `{name}`, merge into a single call | 🛠 |
|
||||||
| SIM102 | nested-if-statements | Use a single `if` statement instead of nested `if` statements | 🛠 |
|
| SIM102 | collapsible-if | Use a single `if` statement instead of nested `if` statements | 🛠 |
|
||||||
| SIM103 | needless-bool | Return the condition `{condition}` directly | 🛠 |
|
| SIM103 | needless-bool | Return the condition `{condition}` directly | 🛠 |
|
||||||
| SIM105 | use-contextlib-suppress | Use `contextlib.suppress({exception})` instead of try-except-pass | |
|
| SIM105 | use-contextlib-suppress | Use `contextlib.suppress({exception})` instead of try-except-pass | |
|
||||||
| SIM107 | return-in-try-except-finally | Don't use `return` in `try`/`except` and `finally` | |
|
| SIM107 | return-in-try-except-finally | Don't use `return` in `try`/`except` and `finally` | |
|
||||||
|
|
|
@ -1480,7 +1480,7 @@ where
|
||||||
if self.settings.rules.enabled(&Rule::IfTuple) {
|
if self.settings.rules.enabled(&Rule::IfTuple) {
|
||||||
pyflakes::rules::if_tuple(self, stmt, test);
|
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(
|
flake8_simplify::rules::nested_if_statements(
|
||||||
self,
|
self,
|
||||||
stmt,
|
stmt,
|
||||||
|
|
|
@ -254,7 +254,7 @@ ruff_macros::define_rule_mapping!(
|
||||||
// flake8-simplify
|
// flake8-simplify
|
||||||
SIM115 => rules::flake8_simplify::rules::OpenFileWithContextHandler,
|
SIM115 => rules::flake8_simplify::rules::OpenFileWithContextHandler,
|
||||||
SIM101 => rules::flake8_simplify::rules::DuplicateIsinstanceCall,
|
SIM101 => rules::flake8_simplify::rules::DuplicateIsinstanceCall,
|
||||||
SIM102 => rules::flake8_simplify::rules::NestedIfStatements,
|
SIM102 => rules::flake8_simplify::rules::CollapsibleIf,
|
||||||
SIM103 => rules::flake8_simplify::rules::NeedlessBool,
|
SIM103 => rules::flake8_simplify::rules::NeedlessBool,
|
||||||
SIM105 => rules::flake8_simplify::rules::UseContextlibSuppress,
|
SIM105 => rules::flake8_simplify::rules::UseContextlibSuppress,
|
||||||
SIM107 => rules::flake8_simplify::rules::ReturnInTryExceptFinally,
|
SIM107 => rules::flake8_simplify::rules::ReturnInTryExceptFinally,
|
||||||
|
|
|
@ -13,7 +13,7 @@ mod tests {
|
||||||
use crate::{assert_yaml_snapshot, settings};
|
use crate::{assert_yaml_snapshot, settings};
|
||||||
|
|
||||||
#[test_case(Rule::DuplicateIsinstanceCall, Path::new("SIM101.py"); "SIM101")]
|
#[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::NeedlessBool, Path::new("SIM103.py"); "SIM103")]
|
||||||
#[test_case(Rule::UseContextlibSuppress, Path::new("SIM105.py"); "SIM105")]
|
#[test_case(Rule::UseContextlibSuppress, Path::new("SIM105.py"); "SIM105")]
|
||||||
#[test_case(Rule::ReturnInTryExceptFinally, Path::new("SIM107.py"); "SIM107")]
|
#[test_case(Rule::ReturnInTryExceptFinally, Path::new("SIM107.py"); "SIM107")]
|
||||||
|
|
|
@ -16,11 +16,11 @@ use crate::rules::flake8_simplify::rules::fix_if;
|
||||||
use crate::violation::{AutofixKind, Availability, Violation};
|
use crate::violation::{AutofixKind, Availability, Violation};
|
||||||
|
|
||||||
define_violation!(
|
define_violation!(
|
||||||
pub struct NestedIfStatements {
|
pub struct CollapsibleIf {
|
||||||
pub fixable: bool,
|
pub fixable: bool,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
impl Violation for NestedIfStatements {
|
impl Violation for CollapsibleIf {
|
||||||
const AUTOFIX: Option<AutofixKind> = Some(AutofixKind::new(Availability::Sometimes));
|
const AUTOFIX: Option<AutofixKind> = Some(AutofixKind::new(Availability::Sometimes));
|
||||||
|
|
||||||
#[derive_message_formats]
|
#[derive_message_formats]
|
||||||
|
@ -29,7 +29,7 @@ impl Violation for NestedIfStatements {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn autofix_title_formatter(&self) -> Option<fn(&Self) -> String> {
|
fn autofix_title_formatter(&self) -> Option<fn(&Self) -> String> {
|
||||||
let NestedIfStatements { fixable, .. } = self;
|
let CollapsibleIf { fixable, .. } = self;
|
||||||
if *fixable {
|
if *fixable {
|
||||||
Some(|_| format!("Combine `if` statements using `and`"))
|
Some(|_| format!("Combine `if` statements using `and`"))
|
||||||
} else {
|
} else {
|
||||||
|
@ -209,7 +209,7 @@ pub fn nested_if_statements(
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut diagnostic = Diagnostic::new(
|
let mut diagnostic = Diagnostic::new(
|
||||||
NestedIfStatements { fixable },
|
CollapsibleIf { fixable },
|
||||||
colon.map_or_else(
|
colon.map_or_else(
|
||||||
|| Range::from_located(stmt),
|
|| Range::from_located(stmt),
|
||||||
|colon| Range::new(stmt.location, colon.end_location),
|
|colon| Range::new(stmt.location, colon.end_location),
|
||||||
|
|
|
@ -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_for::{convert_for_loop_to_any_all, ConvertLoopToAll, ConvertLoopToAny};
|
||||||
pub use ast_if::{
|
pub use ast_if::{
|
||||||
nested_if_statements, return_bool_condition_directly, use_dict_get_with_default,
|
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::{
|
pub use ast_ifexp::{
|
||||||
explicit_false_true_in_ifexpr, explicit_true_false_in_ifexpr, twisted_arms_in_ifexpr,
|
explicit_false_true_in_ifexpr, explicit_true_false_in_ifexpr, twisted_arms_in_ifexpr,
|
||||||
|
|
|
@ -3,7 +3,7 @@ source: crates/ruff/src/rules/flake8_simplify/mod.rs
|
||||||
expression: diagnostics
|
expression: diagnostics
|
||||||
---
|
---
|
||||||
- kind:
|
- kind:
|
||||||
NestedIfStatements:
|
CollapsibleIf:
|
||||||
fixable: true
|
fixable: true
|
||||||
location:
|
location:
|
||||||
row: 2
|
row: 2
|
||||||
|
@ -24,7 +24,7 @@ expression: diagnostics
|
||||||
column: 0
|
column: 0
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
NestedIfStatements:
|
CollapsibleIf:
|
||||||
fixable: true
|
fixable: true
|
||||||
location:
|
location:
|
||||||
row: 7
|
row: 7
|
||||||
|
@ -46,7 +46,7 @@ expression: diagnostics
|
||||||
column: 0
|
column: 0
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
NestedIfStatements:
|
CollapsibleIf:
|
||||||
fixable: true
|
fixable: true
|
||||||
location:
|
location:
|
||||||
row: 15
|
row: 15
|
||||||
|
@ -67,7 +67,7 @@ expression: diagnostics
|
||||||
column: 0
|
column: 0
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
NestedIfStatements:
|
CollapsibleIf:
|
||||||
fixable: false
|
fixable: false
|
||||||
location:
|
location:
|
||||||
row: 20
|
row: 20
|
||||||
|
@ -78,7 +78,7 @@ expression: diagnostics
|
||||||
fix: ~
|
fix: ~
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
NestedIfStatements:
|
CollapsibleIf:
|
||||||
fixable: true
|
fixable: true
|
||||||
location:
|
location:
|
||||||
row: 26
|
row: 26
|
||||||
|
@ -100,7 +100,7 @@ expression: diagnostics
|
||||||
column: 0
|
column: 0
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
NestedIfStatements:
|
CollapsibleIf:
|
||||||
fixable: true
|
fixable: true
|
||||||
location:
|
location:
|
||||||
row: 51
|
row: 51
|
||||||
|
@ -131,7 +131,7 @@ expression: diagnostics
|
||||||
column: 0
|
column: 0
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
NestedIfStatements:
|
CollapsibleIf:
|
||||||
fixable: true
|
fixable: true
|
||||||
location:
|
location:
|
||||||
row: 67
|
row: 67
|
||||||
|
@ -162,7 +162,7 @@ expression: diagnostics
|
||||||
column: 0
|
column: 0
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
NestedIfStatements:
|
CollapsibleIf:
|
||||||
fixable: true
|
fixable: true
|
||||||
location:
|
location:
|
||||||
row: 83
|
row: 83
|
||||||
|
@ -185,7 +185,7 @@ expression: diagnostics
|
||||||
column: 0
|
column: 0
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
NestedIfStatements:
|
CollapsibleIf:
|
||||||
fixable: true
|
fixable: true
|
||||||
location:
|
location:
|
||||||
row: 90
|
row: 90
|
||||||
|
@ -208,7 +208,7 @@ expression: diagnostics
|
||||||
column: 0
|
column: 0
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
NestedIfStatements:
|
CollapsibleIf:
|
||||||
fixable: true
|
fixable: true
|
||||||
location:
|
location:
|
||||||
row: 117
|
row: 117
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue