Skip to content

Preserve two empty lines when function is commented out #208

@theXYZT

Description

@theXYZT

When you comment out a function in between or after a function, the formatter unnecessarily removes empty lines. Here is an example:

Before:

func f(x: float) -> float:
	return x


func g(x: float) -> float:
	return x


func h(x: float) -> float:
	return x

After commenting out middle function:

func f(x: float) -> float:
	return x

# func g(x: float) -> float:
# 	return x


func h(x: float) -> float:
	return x

This violates the official style guide which says:

Surround functions and class definitions with two blank lines

This also annoyingly bobs functions up and down as you temporarily comment them out, which is not ideal. I assume the problem here is that the formatter treats commented sections following a function as part of the function itself, and thus tries to use a single empty line.

At least on VSCode, comments made with CTRL + / respect the indent level of the commented code. So, it should be possible to detect whether a comment is part of the function or part of a codeblock outside the function using the indent level. However, I am not sure if this convention is universal.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions