ruff
ruff copied to clipboard
Formatter trims empty lines after `;`
b = """
This looks like a docstring but is not in a notebook because notebooks can't be imported as a module.
Ruff should leave it as is
""";
a = "another normal string"
The formatter should preserve the empty lines between b and a but it does not today.
Giving a quick 10 second look, the issue is probably on this line:
https://github.com/astral-sh/ruff/blob/fe79798c12b4771cee0b0c59964ad7bd751c3779/crates/ruff_python_formatter/src/statement/suite.rs#L419-L420
As lines_after doesn't take into account the ; token which results in the value being 0 and then the hard line break is added instead.
Maybe we should use lines_after_ignoring_end_of_line_trivia but that doesn't ignore ; either.
@MichaReiser, followed what @dhruvmanila suggested. Worked out nicely. Adapted some tests as well. If you find the time, please review the fix. Thanks!