diff --git a/crates/ruff_linter/resources/test/fixtures/flake8_simplify/SIM114.py b/crates/ruff_linter/resources/test/fixtures/flake8_simplify/SIM114.py index 195efb85e9ff0..c2cb3f2c60be7 100644 --- a/crates/ruff_linter/resources/test/fixtures/flake8_simplify/SIM114.py +++ b/crates/ruff_linter/resources/test/fixtures/flake8_simplify/SIM114.py @@ -143,3 +143,8 @@ def func(): if a: b # here's a comment elif c: b + + +if(x > 200): pass +elif(100 < x and x < 200 and 300 < y and y < 800): + pass diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/if_with_same_arms.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/if_with_same_arms.rs index 3b5be38e31641..ae396192b69d5 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/if_with_same_arms.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/if_with_same_arms.rs @@ -126,19 +126,9 @@ fn merge_branches( return Err(anyhow::anyhow!("Expected colon after test")); }; - let mut following_branch_tokenizer = - SimpleTokenizer::starts_at(following_branch.test.end(), locator.contents()); - - // Identify the colon (`:`) at the end of the following branch's test. - let Some(following_branch_colon) = - following_branch_tokenizer.find(|token| token.kind == SimpleTokenKind::Colon) - else { - return Err(anyhow::anyhow!("Expected colon after test")); - }; - let main_edit = Edit::deletion( - locator.full_line_end(current_branch_colon.end()), - locator.full_line_end(following_branch_colon.end()), + locator.full_line_end(current_branch.end()), + locator.full_line_end(following_branch.end()), ); // If the test isn't parenthesized, consider parenthesizing it. diff --git a/crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__SIM114_SIM114.py.snap b/crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__SIM114_SIM114.py.snap index 781dd3a54a424..8ce27dcdb7046 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__SIM114_SIM114.py.snap +++ b/crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__SIM114_SIM114.py.snap @@ -247,4 +247,13 @@ SIM114.py:144:1: SIM114 Combine `if` branches using logical `or` operator | = help: Combine `if` branches +SIM114.py:148:1: SIM114 Combine `if` branches using logical `or` operator + | +148 | / if(x > 200): pass +149 | | elif(100 < x and x < 200 and 300 < y and y < 800): +150 | | pass + | |________^ SIM114 + | + = help: Combine `if` branches + diff --git a/crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__preview__SIM114_SIM114.py.snap b/crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__preview__SIM114_SIM114.py.snap index 4f62aed944f70..eaf2057160b39 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__preview__SIM114_SIM114.py.snap +++ b/crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__preview__SIM114_SIM114.py.snap @@ -442,5 +442,26 @@ SIM114.py:144:1: SIM114 [*] Combine `if` branches using logical `or` operator 144 |-if a: b # here's a comment 145 |-elif c: b 144 |+if a or c: b # here's a comment +146 145 | +147 146 | +148 147 | if(x > 200): pass + +SIM114.py:148:1: SIM114 [*] Combine `if` branches using logical `or` operator + | +148 | / if(x > 200): pass +149 | | elif(100 < x and x < 200 and 300 < y and y < 800): +150 | | pass + | |________^ SIM114 + | + = help: Combine `if` branches + +ℹ Safe fix +145 145 | elif c: b +146 146 | +147 147 | +148 |-if(x > 200): pass +149 |-elif(100 < x and x < 200 and 300 < y and y < 800): +150 |- pass + 148 |+if(x > 200) or (100 < x and x < 200 and 300 < y and y < 800): pass