mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-29 16:03:50 +00:00
[flake8-simplify
]: combine-if-conditions (#2823)
This commit is contained in:
parent
1666e8ba1e
commit
1f07ad6e61
11 changed files with 323 additions and 3 deletions
23
docs/rules/combine-if-conditions.md
Normal file
23
docs/rules/combine-if-conditions.md
Normal file
|
@ -0,0 +1,23 @@
|
|||
# combine-if-conditions (SIM114)
|
||||
|
||||
Derived from the **flake8-simplify** linter.
|
||||
|
||||
### What it does
|
||||
Checks if consecutive `if` branches have the same body.
|
||||
|
||||
### Why is this bad?
|
||||
These branches can be combine using the python `or` statement
|
||||
|
||||
### Example
|
||||
```python
|
||||
if x = 1:
|
||||
print("Hello")
|
||||
elif x = 2:
|
||||
print("Hello")
|
||||
```
|
||||
|
||||
Use instead:
|
||||
```python
|
||||
if x = 1 or x = 2
|
||||
print("Hello")
|
||||
```
|
24
docs/rules/if-with-same-arms.md
Normal file
24
docs/rules/if-with-same-arms.md
Normal file
|
@ -0,0 +1,24 @@
|
|||
# if-with-same-arms (SIM114)
|
||||
|
||||
Derived from the **flake8-simplify** linter.
|
||||
|
||||
### What it does
|
||||
Checks for `if` branches with identical arm bodies.
|
||||
|
||||
### Why is this bad?
|
||||
If multiple arms of an `if` statement have the same body, using `or`
|
||||
better signals the intent of the statement.
|
||||
|
||||
### Example
|
||||
```python
|
||||
if x = 1:
|
||||
print("Hello")
|
||||
elif x = 2:
|
||||
print("Hello")
|
||||
```
|
||||
|
||||
Use instead:
|
||||
```python
|
||||
if x = 1 or x = 2
|
||||
print("Hello")
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue