Skip to content

Fix for W391 does not Work for Notebooks #22797

@m472

Description

@m472

Summary

Notebooks containing multiple empty cells in a row trigger the warning W391 which is reported as fixable.
When running ruff --isolated check --select W391 --preview --fix Two_empty_cells.ipynb ruff will report the error W391 "Extra newline at end of cell" and reports it as fixed. However the cell is not removed, running the command multiple times results in ruff reporting the error every time and each time saying 0 remaining errors:

$ ruff --isolated check --select W391 --preview --fix Two_empty_cells.ipynb 
Found 1 error (1 fixed, 0 remaining).

$ ruff --isolated check --select W391 --preview --fix Two_empty_cells.ipynb 
Found 1 error (1 fixed, 0 remaining).

$ ruff --isolated check --select W391 --preview --fix Two_empty_cells.ipynb
Found 1 error (1 fixed, 0 remaining).

If there are more than two empty cells the --fix option causes ruff to panic:

$ ruff --isolated check --select W391 --preview --fix Three_empty_cells.ipynb                                                                                                            (base) 
panic: Panicked at crates/ruff_notebook/src/notebook.rs:281:21 when checking `Three_empty_cells.ipynb`: `Transformed content out of bounds (25..24) for cell at 2`
--> Three_empty_cells.ipynb:1:1
info: This indicates a bug in Ruff.
info: If you could open an issue at https://github.com/astral-sh/ruff/issues/new?title=%5Bpanic%5D, we'd be very appreciative!
info: run with `RUST_BACKTRACE=1` environment variable to show the full backtrace information

Found 1 error.
error: Panic during linting indicates a bug in Ruff. If you could open an issue at:

https://github.com/astral-sh/ruff/issues/new?title=%5BLinter%20panic%5D

...with the relevant file contents, the `pyproject.toml` settings, and the stack trace above, we'd be very appreciative!

Notebook files:
Two_empty_cells.ipynb
Three_empty_cells.ipynb

Version

ruff 0.14.13

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingnotebookRelated to (Jupyter) notebooks

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions