From ae9f08d1e50a103dfb72dc8059f7a72be2273a53 Mon Sep 17 00:00:00 2001 From: Steve C Date: Sun, 3 Nov 2024 06:49:03 -0500 Subject: [PATCH] [`ruff`] - fix false positive for decorators (`RUF028`) (#14061) --- .../resources/test/fixtures/ruff/RUF028.py | 14 ++++++++++++++ .../rules/invalid_formatter_suppression_comment.rs | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/RUF028.py b/crates/ruff_linter/resources/test/fixtures/ruff/RUF028.py index 267bb4b5d87a3..e53962c9ee52e 100644 --- a/crates/ruff_linter/resources/test/fixtures/ruff/RUF028.py +++ b/crates/ruff_linter/resources/test/fixtures/ruff/RUF028.py @@ -87,3 +87,17 @@ def match_case_and_elif(): pass elif string == "Hello": # fmt: skip pass + + +# Regression test for decorators +import pytest + +@pytest.mark.parametrize( + "test_input,expected", + [ + ("3+5", 8 ), + ("17+2", 19), + ], +) # fmt: skip +def test_eval(test_input, expected): + assert eval(test_input) == expected diff --git a/crates/ruff_linter/src/rules/ruff/rules/invalid_formatter_suppression_comment.rs b/crates/ruff_linter/src/rules/ruff/rules/invalid_formatter_suppression_comment.rs index a8f525869533a..7b6f1d1856175 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/invalid_formatter_suppression_comment.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/invalid_formatter_suppression_comment.rs @@ -278,6 +278,7 @@ const fn is_valid_enclosing_node(node: AnyNodeRef) -> bool { | AnyNodeRef::StmtIpyEscapeCommand(_) | AnyNodeRef::ExceptHandlerExceptHandler(_) | AnyNodeRef::MatchCase(_) + | AnyNodeRef::Decorator(_) | AnyNodeRef::ElifElseClause(_) => true, AnyNodeRef::ExprBoolOp(_) @@ -333,7 +334,6 @@ const fn is_valid_enclosing_node(node: AnyNodeRef) -> bool { | AnyNodeRef::Keyword(_) | AnyNodeRef::Alias(_) | AnyNodeRef::WithItem(_) - | AnyNodeRef::Decorator(_) | AnyNodeRef::TypeParams(_) | AnyNodeRef::TypeParamTypeVar(_) | AnyNodeRef::TypeParamTypeVarTuple(_)