From 651fdc235be5c9fd3b378e6585e7f9f74eb6a123 Mon Sep 17 00:00:00 2001 From: Jonathan Plasse Date: Sun, 21 Apr 2024 21:52:03 +0200 Subject: [PATCH] Fix ecosystem regression --- .../test/fixtures/flake8_return/RET503.py | 8 +++++++ .../src/rules/flake8_return/rules/function.rs | 3 --- ...lake8_return__tests__RET503_RET503.py.snap | 18 +++++++++++++++ ...urn__tests__preview__RET503_RET503.py.snap | 22 +++++++++++++++++++ 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/crates/ruff_linter/resources/test/fixtures/flake8_return/RET503.py b/crates/ruff_linter/resources/test/fixtures/flake8_return/RET503.py index 60091c7eea102b..edb729eb98c23f 100644 --- a/crates/ruff_linter/resources/test/fixtures/flake8_return/RET503.py +++ b/crates/ruff_linter/resources/test/fixtures/flake8_return/RET503.py @@ -368,3 +368,11 @@ def bar() -> NoReturn: if baz() > 3: return 1 bar() + + +def f(): + if a: + return b + else: + with c: + d diff --git a/crates/ruff_linter/src/rules/flake8_return/rules/function.rs b/crates/ruff_linter/src/rules/flake8_return/rules/function.rs index 829d1e79c385c5..4e831e03e8ca5c 100644 --- a/crates/ruff_linter/src/rules/flake8_return/rules/function.rs +++ b/crates/ruff_linter/src/rules/flake8_return/rules/function.rs @@ -534,9 +534,6 @@ fn has_implicit_return(checker: &mut Checker, stmt: &Stmt) -> bool { Stmt::With(ast::StmtWith { body, .. }) => { if let Some(last_stmt) = body.last() { if has_implicit_return(checker, last_stmt) { - if checker.settings.preview.is_disabled() { - add_return_none(checker, stmt); - } return true; } } diff --git a/crates/ruff_linter/src/rules/flake8_return/snapshots/ruff_linter__rules__flake8_return__tests__RET503_RET503.py.snap b/crates/ruff_linter/src/rules/flake8_return/snapshots/ruff_linter__rules__flake8_return__tests__RET503_RET503.py.snap index 85edc6bd38943b..38a77815302b13 100644 --- a/crates/ruff_linter/src/rules/flake8_return/snapshots/ruff_linter__rules__flake8_return__tests__RET503_RET503.py.snap +++ b/crates/ruff_linter/src/rules/flake8_return/snapshots/ruff_linter__rules__flake8_return__tests__RET503_RET503.py.snap @@ -452,3 +452,21 @@ RET503.py:370:5: RET503 [*] Missing explicit `return` at the end of function abl 369 369 | return 1 370 370 | bar() 371 |+ return None +371 372 | +372 373 | +373 374 | def f(): + +RET503.py:378:13: RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value + | +376 | else: +377 | with c: +378 | d + | ^ RET503 + | + = help: Add explicit `return` statement + +ℹ Unsafe fix +376 376 | else: +377 377 | with c: +378 378 | d + 379 |+ return None diff --git a/crates/ruff_linter/src/rules/flake8_return/snapshots/ruff_linter__rules__flake8_return__tests__preview__RET503_RET503.py.snap b/crates/ruff_linter/src/rules/flake8_return/snapshots/ruff_linter__rules__flake8_return__tests__preview__RET503_RET503.py.snap index b0f86341c5d780..fd6cb153280f5f 100644 --- a/crates/ruff_linter/src/rules/flake8_return/snapshots/ruff_linter__rules__flake8_return__tests__preview__RET503_RET503.py.snap +++ b/crates/ruff_linter/src/rules/flake8_return/snapshots/ruff_linter__rules__flake8_return__tests__preview__RET503_RET503.py.snap @@ -471,3 +471,25 @@ RET503.py:370:5: RET503 [*] Missing explicit `return` at the end of function abl 369 369 | return 1 370 370 | bar() 371 |+ return None +371 372 | +372 373 | +373 374 | def f(): + +RET503.py:374:5: RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value + | +373 | def f(): +374 | if a: + | _____^ +375 | | return b +376 | | else: +377 | | with c: +378 | | d + | |_____________^ RET503 + | + = help: Add explicit `return` statement + +ℹ Unsafe fix +376 376 | else: +377 377 | with c: +378 378 | d + 379 |+ return None