From 820e82fa6bfa1082c119d80759adb8266c7f9cb5 Mon Sep 17 00:00:00 2001 From: Hoel Bagard Date: Sun, 25 Feb 2024 19:42:03 +0900 Subject: [PATCH] fix: trigger E301 on decorated methods. fixes #10114 --- .../ruff_linter/src/rules/pycodestyle/rules/blank_lines.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/blank_lines.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/blank_lines.rs index 59effe7f944dab..9cbbb556f56b3d 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/blank_lines.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/blank_lines.rs @@ -658,8 +658,10 @@ impl BlankLinesChecker { if self.is_not_first_logical_line { if line.preceding_blank_lines == 0 // Only applies to methods. - && matches!(line.kind, LogicalLineKind::Function) - && matches!(self.class_status, Status::Inside(_)) + && matches!(line.kind, LogicalLineKind::Function | LogicalLineKind::Decorator) + // Allow groups of one-liners. + && !(matches!(state.follows, Follows::Def) && !matches!(line.last_token, TokenKind::Colon)) + && matches!(state.class_status, Status::Inside(_)) // The class/parent method's docstring can directly precede the def. // Allow following a decorator (if there is an error it will be triggered on the first decorator). && !matches!(self.follows, Follows::Docstring | Follows::Decorator)