mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:24 +00:00
[ruff
] Stabilize useless-if-else
(RUF034
) (#15351)
This commit is contained in:
parent
d645525afc
commit
29f6653318
2 changed files with 2 additions and 7 deletions
|
@ -982,7 +982,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
|
|||
(Ruff, "031") => (RuleGroup::Preview, rules::ruff::rules::IncorrectlyParenthesizedTupleInSubscript),
|
||||
(Ruff, "032") => (RuleGroup::Stable, rules::ruff::rules::DecimalFromFloatLiteral),
|
||||
(Ruff, "033") => (RuleGroup::Stable, rules::ruff::rules::PostInitDefault),
|
||||
(Ruff, "034") => (RuleGroup::Preview, rules::ruff::rules::UselessIfElse),
|
||||
(Ruff, "034") => (RuleGroup::Stable, rules::ruff::rules::UselessIfElse),
|
||||
(Ruff, "035") => (RuleGroup::Preview, rules::ruff::rules::UnsafeMarkupUse),
|
||||
(Ruff, "036") => (RuleGroup::Preview, rules::ruff::rules::NoneNotAtEndOfUnion),
|
||||
(Ruff, "037") => (RuleGroup::Preview, rules::ruff::rules::UnnecessaryEmptyIterableWithinDequeCall),
|
||||
|
|
|
@ -9,20 +9,15 @@ use ruff_python_ast::comparable::ComparableExpr;
|
|||
///
|
||||
/// ## Why is this bad?
|
||||
/// Useless `if`-`else` conditions add unnecessary complexity to the code without
|
||||
/// providing any logical benefit.
|
||||
///
|
||||
/// Assigning the value directly is clearer and more explicit, and
|
||||
/// should be preferred.
|
||||
/// providing any logical benefit. Assigning the value directly is clearer.
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
/// # Bad
|
||||
/// foo = x if y else x
|
||||
/// ```
|
||||
///
|
||||
/// Use instead:
|
||||
/// ```python
|
||||
/// # Good
|
||||
/// foo = x
|
||||
/// ```
|
||||
#[derive(ViolationMetadata)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue