diff --git a/crates/ruff/src/rules/flake8_simplify/rules/ast_bool_op.rs b/crates/ruff/src/rules/flake8_simplify/rules/ast_bool_op.rs index 7ad472fb1d..19f07d6105 100644 --- a/crates/ruff/src/rules/flake8_simplify/rules/ast_bool_op.rs +++ b/crates/ruff/src/rules/flake8_simplify/rules/ast_bool_op.rs @@ -13,6 +13,32 @@ use crate::registry::Diagnostic; use crate::violation::AlwaysAutofixableViolation; define_violation!( + /// ## What it does + /// Checks for multiple `isinstance` calls on the same target. + /// + /// ## Why is this bad? + /// To check if an object is an instance of any one of multiple types + /// or classes, it is unnecessary to use multiple `isinstance` calls, as + /// the second argument of the `isinstance` built-in function accepts a + /// tuple of types and classes. + /// + /// Using a single `isinstance` call implements the same behavior with more + /// concise code and clearer intent. + /// + /// ## Example + /// ```python + /// if isinstance(obj, int) or isinstance(obj, float): + /// pass + /// ``` + /// + /// Use instead: + /// ```python + /// if isinstance(obj, (int, float)): + /// pass + /// + /// ## References + /// * [Python: "isinstance"](https://docs.python.org/3/library/functions.html#isinstance) + /// ``` pub struct DuplicateIsinstanceCall { pub name: String, } diff --git a/crates/ruff/src/rules/flake8_simplify/rules/ast_with.rs b/crates/ruff/src/rules/flake8_simplify/rules/ast_with.rs index 33dad0fc17..25a19a067b 100644 --- a/crates/ruff/src/rules/flake8_simplify/rules/ast_with.rs +++ b/crates/ruff/src/rules/flake8_simplify/rules/ast_with.rs @@ -12,6 +12,33 @@ use crate::violation::{AutofixKind, Availability, Violation}; use super::fix_with; define_violation!( + /// ## What it does + /// Checks for the unnecessary nesting of multiple consecutive context + /// managers. + /// + /// ## Why is this bad? + /// In Python 3, a single `with` block can include multiple context + /// managers. + /// + /// Combining multiple context managers into a single `with` statement + /// will minimize the indentation depth of the code, making it more + /// readable. + /// + /// ## Example + /// ```python + /// with A() as a: + /// with B() as b: + /// pass + /// ``` + /// + /// Use instead: + /// ```python + /// with A() as a, B() as b: + /// pass + /// ``` + /// + /// ## References + /// * [Python: "The with statement"](https://docs.python.org/3/reference/compound_stmts.html#the-with-statement) pub struct MultipleWithStatements { pub fixable: bool, }