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 opa fmt location for non-key rules #4695

Merged

Conversation

jaspervdj
Copy link
Contributor

Running the following through opa fmt:

package foo

bar {
	# before
	input.bar
	# after
}

Causes the after comment to be moved outside of the rule:

package foo

bar {
	# before
	input.bar
}

# after

This was caused by skipPast in closingLoc being called even when there is no
[key] part in the rule head. Adding a third clause fixed this; it seems
like closingLoc is designed to take 0 in this case because of the
skipOpen > 0.

This did affect one other test case, where I had to add an extra newline
to separate the comment from the rule head. Without that, insertComments
(correctly, I guess) inserts:

} # some special case

Signed-off-by: Jasper Van der Jeugt m@jaspervdj.be

Running the following through `opa fmt`:

    package foo

    bar {
    	# before
    	input.bar
    	# after
    }

Causes the `after` comment to be moved outside of the rule:

    package foo

    bar {
    	# before
    	input.bar
    }

    # after

This was caused by `skipPast` in `closingLoc` being called even when there is no
`[key]` part in the rule head.  Adding a third clause fixed this; it seems
like `closingLoc` is designed to take `0` in this case because of the
`skipOpen > 0`.

This did affect one other test case, where I had to add an extra newline
to separate the comment from the rule head.  Without that, `insertComments`
(correctly, I guess) inserts:

    } # some special case

Signed-off-by: Jasper Van der Jeugt <m@jaspervdj.be>
@srenatus srenatus merged commit 07227f6 into open-policy-agent:main May 16, 2022
@jaspervdj jaspervdj deleted the fix/opa-fmt-end-of-rule-comment branch May 16, 2022 15:49
@srenatus
Copy link
Contributor

Thank you!

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.

None yet

2 participants