Skip to content

Whitespace before classes not inserted when used with "modificationsIfAvailable" in vscode #19603

@maltevesper

Description

@maltevesper

Summary

I am not sure if this is a vscode plugin or ruff issue, that said:

When using the "editor.formatOnSaveMode": "modificationsIfAvailable" setting, Ruff does not add blank lines around newly added classes. This results in the CI checking the entire file finding new issues in the file.

Example:

def oldCode():
    ...
class InsertedClass:    # New
    pass                        # New
def moreOldCode():
    ...

After formating I get the formated class back as (formatting inside the class I added works as expected):

class InsertedClass:    # New
    pass                        # New

I would like the language server to return the new class with surrounding needed whitespace if that is possible, i.e.:

                                  # ruff add whitespace before
                                  # ruff add whitespace before
class InsertedClass:    # New
    pass                        # New
                                  # ruff add whitespace after
                                  # ruff add whitespace after

I have not dug into the language server protocol and I am not sure if this is feasible (i.e. does the language server get enough context (i.e. code outside the edited area), when modificationsIfAvailable is set?

Version

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingformatterRelated to the formatter

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions