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

Fix empty lines & trailing comments #278

Merged
merged 8 commits into from
Jun 5, 2021
Merged

Fix empty lines & trailing comments #278

merged 8 commits into from
Jun 5, 2021

Conversation

eemeli
Copy link
Owner

@eemeli eemeli commented May 31, 2021

Fixes #244
Fixes #277

I think I finally figured out a way to make comments and empty lines more usable. This hinges on refactoring the representation of completely empty lines vs. comment lines that terminate immediately after the #.

At the moment, empty lines in source are parsed into spaceBefore boolean values or completely dropped, and comments consisting of just a # are represented by an empty line in the comment or commentBefore value.

However, let's change that a bit. With this PR, an empty line in the source is represented by an empty line in the comment or commentBefore value, and a bare # is represented by a line consisting of a single space character. This relatively small change allows for any combination of comment and blank lines to be cleanly represented by a single string, with the cost of a comment consisting of a single space character being unrepresentable.

At least for now, an empty line before comments remains represented as the boolean spaceBefore property, but that property could be dropped entirely as it's equivalent to a commentBefore value of '\n'.

Simultaneously, the handling of trailing comments is simplified somewhat; they now need to be more indented than their parent collection to attach to the preceding rather than the following node.

@eemeli eemeli changed the title Fix emptiness Fix empty lines & trailing comments May 31, 2021
@eemeli eemeli merged commit ed6843b into master Jun 5, 2021
@eemeli eemeli deleted the fix-emptiness branch June 5, 2021 06:44
@gixlg
Copy link

gixlg commented Jun 6, 2021

Oh wow thanks for the awesome work!
This fix will be included in the next release (2.0.0-6)?

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.

Comment on the last line is moved on the line above Trailing comments are not well assigned
2 participants