-
Couldn't load subscription status.
- Fork 109
Fix formatter handling of blank lines #870
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
Conversation
|
Marking as ready-for-review since the code is in a reviewable state & CI is passing. I plan on running the formatter fuzzing targets later today -- will add a comment here with the results. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look pretty good.
|
Ran the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks a lot for fixing it.
|
Update: |
Co-authored-by: Kesha Hietala <[email protected]>
Description of changes
The cause of #862 was the call to
remove_empty_lines, which removed empty lines from the formatted policy -- including those in string literals.Attempt 1: It was simple enough to remove the
remove_empty_linescall, but this makes formatted policies ugly since the current code introduces extra newlines around comments. I imagine the reasonremove_empty_lineswas originally introduced was to handle these extra newlines.Attempt 2: I tried to get rid of the extra newlines by adjusting how
RcDocs are constructed, but that ended up being a pain in the butt.Attempt 3 (current PR): I added a new function
remove_empty_lines_safe, which does some light parsing to avoid removing newlines in strings.Summary
remove_empty_lines_safefunction ← the important changeRcDoc::textin cases where the call toto_stringwas unnecessaryThe last two changes are just edits I made while getting familiar with the codebase. I think they're harmless.
We had previously discussed not using
RcDoc::textorRcDoc::as_stringfor string parsing. But I think it’s actually ok: newlines are used in the tests. I think the way to interpret the "must not contain line breaks" guidance is that indentation will not be handled correctly when you do this, which is actually what we want for string literals.Issue #, if available
Resolves #862
Checklist for requesting a review
The change in this PR is (choose one, and delete the other options):
cedar-policy.I confirm that this PR (choose one, and delete the other options):
I confirm that
cedar-spec(choose one, and delete the other options):