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

caddyfile: Fix caddy fmt nesting not decrementing #4157

Merged
merged 3 commits into from
May 10, 2021

Conversation

matthewpi
Copy link
Member

This is an extremely weird edge-case where if you had a environment variable {}
on one line, a comment on the next line, and the closing of the block on the
following line; the rest of the Caddyfile would be indented further than it
should've been.

ref; caddyserver/vscode-caddyfile#13


A preview of what happens without this fix can be seen at https://streamable.com/ouziak

Formatting the file shown in the video worked fine before 635f075

Additional testing (or even a better way to handle this edge-case) would be appreciated.

This is an extremely weird edge-case where if you had a environment variable {}
on one line, a comment on the next line, and the closing of the block on the
following line; the rest of the Caddyfile would be indented further than it
should've been.

ref; caddyserver/vscode-caddyfile#13
@francislavoie francislavoie added the bug 🐞 Something isn't working label May 10, 2021
@francislavoie francislavoie added this to the v2.4.0 milestone May 10, 2021
@francislavoie francislavoie changed the title caddyfile(formatter): fix nesting not decrementing fmt: Fix nesting not decrementing May 10, 2021
@francislavoie francislavoie changed the title fmt: Fix nesting not decrementing caddyfile: Fix caddy fmt nesting not decrementing May 10, 2021
@mholt
Copy link
Member

mholt commented May 10, 2021

Thanks for the quick PR! I don't really understand the bug yet, but I wonder if there's a more elegant way to fix this.

i.e. What is causing this condition case nesting == 1 && wasComment && ch == '}': to be so special... why is the nesting not getting decremented when it should be?

@mholt mholt modified the milestones: v2.4.0, 2.x May 10, 2021
@matthewpi
Copy link
Member Author

Thanks for the quick PR! I don't really understand the bug yet, but I wonder if there's a more elegant way to fix this.

i.e. What is causing this condition case nesting == 1 && wasComment && ch == '}': to be so special... why is the nesting not getting decremented when it should be?

I don't understand it either tbh, but I think I figured it out now with the latest commit. (Apologies for the not so wonderful commit names)

Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I LIKE THIS. 😄 (Indeed, a newline is a whitespace.)

Much better 👍 Thanks @matthewpi, good work! Appreciate your contribution.

@mholt mholt merged commit bc22102 into caddyserver:master May 10, 2021
@francislavoie francislavoie modified the milestones: 2.x, v2.4.0 May 10, 2021
@matthewpi matthewpi deleted the matthewpi/fmt-patch branch May 10, 2021 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐞 Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants