GDQuest / GDQuest/GDScript-formatter

Preserve two empty lines when function is commented out

Offen
#208 2 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Rust
Sterne
455
Forks
39
Ø Merge
1 T. 15 Std.
Gemergte PRs (30 T.)
4

Beschreibung

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

Before:

```gdscript
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:

```gdscript
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.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.