Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatter trims empty lines after ; #9958

Open
MichaReiser opened this issue Feb 12, 2024 · 2 comments · May be fixed by #10639
Open

Formatter trims empty lines after ; #9958

MichaReiser opened this issue Feb 12, 2024 · 2 comments · May be fixed by #10639
Labels
bug Something isn't working formatter Related to the formatter

Comments

@MichaReiser
Copy link
Member

MichaReiser commented Feb 12, 2024

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.

Playground

@MichaReiser MichaReiser added bug Something isn't working formatter Related to the formatter labels Feb 12, 2024
@dhruvmanila
Copy link
Member

Giving a quick 10 second look, the issue is probably on this line:

NodeLevel::TopLevel(_) => match lines_after(end, source) {
0 | 1 => hard_line_break().fmt(f)?,

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.

@robincaloudis robincaloudis linked a pull request Mar 27, 2024 that will close this issue
@robincaloudis
Copy link
Contributor

robincaloudis commented Mar 27, 2024

@MichaReiser, followed what @dhruvmanila suggested. Worked out nicely. Adapted some tests as well. If you find the time, please review the fix. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working formatter Related to the formatter
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants