Skip to content

feat: Indent backslash continuation lines according to style guide#218

Merged
NathanLovato merged 2 commits intoGDQuest:mainfrom
dmlary:indent-line-continuation
Apr 11, 2026
Merged

feat: Indent backslash continuation lines according to style guide#218
NathanLovato merged 2 commits intoGDQuest:mainfrom
dmlary:indent-line-continuation

Conversation

@dmlary
Copy link
Copy Markdown
Contributor

@dmlary dmlary commented Apr 6, 2026

Please check if the PR fulfills these requirements:

  • The commit message follows our guidelines.
    • Where are these guidelines? They're not in the README.md, there's no CONTRIBUTORS.md
  • For bug fixes and features:
    • You tested the changes.

Related issue (if applicable): #180

What kind of change does this PR introduce?

Feature, implement proper line continuation indention.
From gdscript style guide1:

Use 2 indent levels to distinguish continuation lines from regular code blocks.

Does this PR introduce a breaking change?

It does change the indentation of one existing test. I don't consider that breaking, but it's unclear.

New feature or change

What is the current behavior?
Currently the formatter indents continuation lines to the same level as the first line:

func test(thing):
    thing.calling(1) \
    .a(12314) \
    .long() \
    .chain("a string breaks things") \
    .of() \
    .functions()

What is the new behavior?

With this change, continuation lines (joined with a backslash) are formatted with double indention:

func test(thing):
    thing.calling(1) \
            .a(12314) \
            .long() \
            .chain("a string breaks things") \
            .of() \
            .functions()

Other information

Footnotes

  1. https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_styleguide.html#indentation

From gdscript style guide[^1]:
> Use 2 indent levels to distinguish continuation lines from regular code blocks.

Currently the formatter indents continuation lines to the same level as
the first line:

```gdscript
func test(thing):
    thing.calling(1) \
    .a(12314) \
    .long() \
    .chain("a string breaks things") \
    .of() \
    .functions()
```

With this change, continuation lines (joined with a backslash) are
formatted with double indention:

```gdscript
func test(thing):
    thing.calling(1) \
            .a(12314) \
            .long() \
            .chain("a string breaks things") \
            .of() \
            .functions()
```

fixes GDQuest#180

[^1]: https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_styleguide.html#indentation
@NathanLovato
Copy link
Copy Markdown
Contributor

Thank you very much for the contribution! Have you tried with queries before using a regular expression? Regular expressions should generally be a last resort for when something cannot be solved with queries because it's too easy to miss some context like nested functions etc. I'll try on my end

@NathanLovato NathanLovato merged commit 007b666 into GDQuest:main Apr 11, 2026
@NathanLovato
Copy link
Copy Markdown
Contributor

Thank you for the help. I always appreciate people taking time to attempt a fix. In general, the only thing is we should favor using queries or modifying the parsed tree with plain procedural code and move away from regular expressions, because while they're very convenient and look short, using them is very prone to edge cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants