From 78ca1d23c0c415fd84cbd2c8f0b2077a6c71e0a5 Mon Sep 17 00:00:00 2001 From: Hoel Bagard Date: Wed, 13 Mar 2024 22:08:51 +0900 Subject: [PATCH] Do not skip line check for lines before first logical line. Ignoring all lines until the first logical line does not match the behavior from pycodestyle. Fixes #10374 --- .../ruff_linter/src/rules/pycodestyle/rules/blank_lines.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 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 4879f1e93d069..ad21ee7241cf7 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/blank_lines.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/blank_lines.rs @@ -696,9 +696,7 @@ impl<'a> BlankLinesChecker<'a> { state.class_status.update(&logical_line); state.fn_status.update(&logical_line); - if state.is_not_first_logical_line { - self.check_line(&logical_line, &state, prev_indent_length, diagnostics); - } + self.check_line(&logical_line, &state, prev_indent_length, diagnostics); match logical_line.kind { LogicalLineKind::Class => { @@ -818,6 +816,8 @@ impl<'a> BlankLinesChecker<'a> { && line.kind.is_class_function_or_decorator() // Blank lines in stub files are used to group definitions. Don't enforce blank lines. && !self.source_type.is_stub() + // Do not expect blank lines before the first logical line. + && state.is_not_first_logical_line { // E302 let mut diagnostic = Diagnostic::new(