[New Rule] Reduce conditional expressions to boolean expressions
See original GitHub issueExplanation
Sometimes conditional expressions can be replaced with boolean ones, like this:
a if a else b->a or bb if a else a->a and b
This makes the code shorter and removes redundant evaluations of expressions. I think a check to suggest such replacements would fit well in this plugin.
Example
# Bad
x = o.x if o.x else default_x
# Good
x = o.x or default_x
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Simplify conditional expression (IDE0075) - Microsoft Learn
This style rule concerns simplifying conditional expressions that return a constant value of true or false versus retaining conditional ...
Read more >Simplifying Boolean Expressions and Conditionals
Just as it is possible to simplify algebraic expressions by using rules like cancellation, commutativity, associativity, distributivity, etc., ...
Read more >strict-boolean-expressions | typescript-eslint
Disallow certain types in boolean expressions.. Some problems reported by this rule are automatically fixable by the --fix ESLint command line option.
Read more >Compound Booleans with logical operators - Khan Academy
Since that expression is made entirely of OR operators, the expression is true as long as any of the conditions are true. It...
Read more >9. Working with Booleans and Conditional Statements
Some rules for rearranging and reasoning about Boolean expressions. An expression that, when evaluated, will result in either true or false. There are...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

b if a else ais not equivalent tob or a.As the ternary expressions (a if a else b) are easier for me to understand than the logical expressions (a or b), I will not implement this rule.