mirror of https://github.com/astral-sh/ruff
[`ruff`] Stabilize `useless-if-else` (`RUF034`) (#15351)
This commit is contained in:
parent
d645525afc
commit
29f6653318
|
|
@ -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, "031") => (RuleGroup::Preview, rules::ruff::rules::IncorrectlyParenthesizedTupleInSubscript),
|
||||||
(Ruff, "032") => (RuleGroup::Stable, rules::ruff::rules::DecimalFromFloatLiteral),
|
(Ruff, "032") => (RuleGroup::Stable, rules::ruff::rules::DecimalFromFloatLiteral),
|
||||||
(Ruff, "033") => (RuleGroup::Stable, rules::ruff::rules::PostInitDefault),
|
(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, "035") => (RuleGroup::Preview, rules::ruff::rules::UnsafeMarkupUse),
|
||||||
(Ruff, "036") => (RuleGroup::Preview, rules::ruff::rules::NoneNotAtEndOfUnion),
|
(Ruff, "036") => (RuleGroup::Preview, rules::ruff::rules::NoneNotAtEndOfUnion),
|
||||||
(Ruff, "037") => (RuleGroup::Preview, rules::ruff::rules::UnnecessaryEmptyIterableWithinDequeCall),
|
(Ruff, "037") => (RuleGroup::Preview, rules::ruff::rules::UnnecessaryEmptyIterableWithinDequeCall),
|
||||||
|
|
|
||||||
|
|
@ -9,20 +9,15 @@ use ruff_python_ast::comparable::ComparableExpr;
|
||||||
///
|
///
|
||||||
/// ## Why is this bad?
|
/// ## Why is this bad?
|
||||||
/// Useless `if`-`else` conditions add unnecessary complexity to the code without
|
/// Useless `if`-`else` conditions add unnecessary complexity to the code without
|
||||||
/// providing any logical benefit.
|
/// providing any logical benefit. Assigning the value directly is clearer.
|
||||||
///
|
|
||||||
/// Assigning the value directly is clearer and more explicit, and
|
|
||||||
/// should be preferred.
|
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
/// ```python
|
/// ```python
|
||||||
/// # Bad
|
|
||||||
/// foo = x if y else x
|
/// foo = x if y else x
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
/// ```python
|
/// ```python
|
||||||
/// # Good
|
|
||||||
/// foo = x
|
/// foo = x
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(ViolationMetadata)]
|
#[derive(ViolationMetadata)]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue