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 improper formatter behavior when comprehension contains comment #7169

Conversation

tjons
Copy link
Contributor

@tjons tjons commented Nov 12, 2024

Why the changes in this PR are needed?

Resolves #6999.

What are the changes in this PR?

When a comprehension is followed by a index retrieving a value from the comprehension, the OPA AST treats that as a ref. refs of this sort may contain comments, but the formatter did not write them inline. Since the formatter did not write them inside the comprehension body, the comments were left over and written at the end of the document.

Notes to assist PR review:

The else handling for the formatter is getting a bit gnarly. Constructing a fake ref for the else feels like something that can be handled better, but is not in scope for this PR imo.

Further comments:

@tjons tjons force-pushed the tjons/6999-formatter-moves-comment branch 2 times, most recently from 7440194 to 41ecf72 Compare November 12, 2024 05:42
Copy link
Member

@anderseknert anderseknert left a comment

Choose a reason for hiding this comment

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

You're killing it! 👏

@tjons tjons force-pushed the tjons/6999-formatter-moves-comment branch 2 times, most recently from 73e4db2 to 6306139 Compare November 12, 2024 18:31
@tjons tjons force-pushed the tjons/6999-formatter-moves-comment branch from 6306139 to f5cd4b6 Compare November 12, 2024 18:40
@ashutosh-narkar ashutosh-narkar merged commit 211b798 into open-policy-agent:main Nov 12, 2024
28 checks passed
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.

Formatter moves comment out of comprehension body
3 participants