Skip to content

Commit

Permalink
fix first line of each cell being ignored for all rules in notebooks.
Browse files Browse the repository at this point in the history
  • Loading branch information
hoel-bagard committed Mar 22, 2024
1 parent bce6989 commit 559b030
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,7 @@
"# Ok\n",
"def function1():\n",
"\tpass\n",
"\n",
" "
"\n"
]
},
{
Expand All @@ -195,7 +194,7 @@
"metadata": {},
"outputs": [],
"source": [
" \n",
"\n",
"def function2():\n",
"\tpass\n",
"# end"
Expand Down
9 changes: 5 additions & 4 deletions crates/ruff_linter/src/rules/pycodestyle/rules/blank_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 559b030

Please sign in to comment.