diff --git a/crates/ruff_linter/resources/test/fixtures/pycodestyle/E30.ipynb b/crates/ruff_linter/resources/test/fixtures/pycodestyle/E30.ipynb index afb4326be3fe7..0f04696499bee 100644 --- a/crates/ruff_linter/resources/test/fixtures/pycodestyle/E30.ipynb +++ b/crates/ruff_linter/resources/test/fixtures/pycodestyle/E30.ipynb @@ -185,8 +185,7 @@ "# Ok\n", "def function1():\n", "\tpass\n", - "\n", - " " + "\n" ] }, { @@ -195,7 +194,7 @@ "metadata": {}, "outputs": [], "source": [ - " \n", + "\n", "def function2():\n", "\tpass\n", "# end" 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 0405621c977fe..792bc3d397864 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/blank_lines.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/blank_lines.rs @@ -747,10 +747,7 @@ impl<'a> BlankLinesChecker<'a> { state.class_status.update(&logical_line); state.fn_status.update(&logical_line); - // Ignore the first logical line (and any comment preceding it) of each cell in notebooks. - if !logical_line.is_beginning_of_cell { - 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 => { @@ -872,6 +869,8 @@ impl<'a> BlankLinesChecker<'a> { && !self.source_type.is_stub() // Do not expect blank lines before the first logical line. && state.is_not_first_logical_line + // Ignore the first logical line (and any comment preceding it) of each cell in notebooks. + && !line.is_beginning_of_cell { // E302 let mut diagnostic = Diagnostic::new( @@ -986,6 +985,8 @@ impl<'a> BlankLinesChecker<'a> { && !line.kind.is_class_function_or_decorator() // Blank lines in stub files are used for grouping, don't enforce blank lines. && !self.source_type.is_stub() + // Ignore the first logical line (and any comment preceding it) of each cell in notebooks. + && !line.is_beginning_of_cell { // E305 let mut diagnostic = Diagnostic::new( diff --git a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__blank_lines_E305_notebook.snap b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__blank_lines_E305_notebook.snap index 4756e514db702..9672329251a92 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__blank_lines_E305_notebook.snap +++ b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__blank_lines_E305_notebook.snap @@ -1,22 +1,22 @@ --- source: crates/ruff_linter/src/rules/pycodestyle/mod.rs --- -E30.ipynb:47:1: E305 [*] Expected 2 blank lines after class or function definition, found (1) +E30.ipynb:55:1: E305 [*] Expected 2 blank lines after class or function definition, found (1) | -46 | # another comment -47 | fn() +54 | # another comment +55 | fn() | ^^ E305 -48 | # end -49 | # E306:3:5 +56 | # end +57 | # E306:3:5 | = help: Add missing blank line(s) ℹ Safe fix -44 44 | # comment -45 45 | -46 46 | # another comment - 47 |+ - 48 |+ -47 49 | fn() -48 50 | # end -49 51 | # E306:3:5 +52 52 | # comment +53 53 | +54 54 | # another comment + 55 |+ + 56 |+ +55 57 | fn() +56 58 | # end +57 59 | # E306:3:5