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

format: keep new lines in between function arguments #3864

Conversation

srenatus
Copy link
Contributor

@srenatus srenatus commented Oct 6, 2021

This snippet,

r = contains(
    input.x,
    "y",
)

would have been formatted as

r = contains(input.x, "y")

before. Now, any new lines added between function arguments will be kept, and
the snippet will not be reformatted.

As a consequence, comments on the separate arguments we OK:

r = contains(
    input.x, # haystack
    "y",     # needle
)

and don't freak out the formatter.

Fixes #3836.


Changes to the formatter often have the potential to be annoying, but with this, anything that had been formatted with a previous version should still be formatted the same way. I.e., there would not be any breakage in people's CI running opa fmt on committed files.

It does, however, broaden the domain of accepted inputs, by not forcing all function arguments to be on one line.

anderseknert
anderseknert previously approved these changes Oct 6, 2021

p {
x := count(
[1, 2, 3]
Copy link
Member

Choose a reason for hiding this comment

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

What happens to a comment after the array?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's appended at the end, just like before. added it to the test case just to be sure.

This snippet,

    r = contains(
        input.x,
        "y",
    )

would have been formatted as

    r = contains(input.x, "y")

before. Now, any new lines added between function arguments will be kept, and
the snippet will not be reformatted.

As a consequence, comments on the separate arguments we OK:

    r = contains(
        input.x, # haystack
        "y",     # needle
    )

and don't freak out the formatter.

Fixes open-policy-agent#3836.

Signed-off-by: Stephan Renatus <[email protected]>
@srenatus srenatus merged commit 0871e16 into open-policy-agent:main Oct 6, 2021
@srenatus srenatus deleted the sr/formatter/newlines-in-fun-arguments branch October 6, 2021 14:27
dolevf pushed a commit to dolevf/opa that referenced this pull request Nov 4, 2021
…nt#3864)

This snippet,

    r = contains(
        input.x,
        "y",
    )

would have been formatted as

    r = contains(input.x, "y")

before. Now, any new lines added between function arguments will be kept, and
the snippet will not be reformatted.

As a consequence, comments on the separate arguments we OK:

    r = contains(
        input.x, # haystack
        "y",     # needle
    )

and don't freak out the formatter.

Fixes open-policy-agent#3836.

Signed-off-by: Stephan Renatus <[email protected]>
Signed-off-by: Dolev Farhi <[email protected]>
Trolloldem added a commit to Trolloldem/opa that referenced this pull request May 30, 2023
Priot to this change, the `fmt` command panicked when
rego files processed contained a comprehension written
on multiple lines with comments in these lines. An
example of such comprehension is presented in open-policy-agent#5798.

After this change, comprehensions on multiple lines are
not moved in a single line, in order to correcly handle
comments, similarly to what has been already done in open-policy-agent#3864.

Fixes: open-policy-agent#5798

Signed-off-by: Gianluca Oldani <[email protected]>
ashutosh-narkar pushed a commit that referenced this pull request May 30, 2023
Priot to this change, the `fmt` command panicked when
rego files processed contained a comprehension written
on multiple lines with comments in these lines. An
example of such comprehension is presented in #5798.

After this change, comprehensions on multiple lines are
not moved in a single line, in order to correcly handle
comments, similarly to what has been already done in #3864.

Fixes: #5798

Signed-off-by: Gianluca Oldani <[email protected]>
ashutosh-narkar pushed a commit to ashutosh-narkar/opa that referenced this pull request Jun 5, 2023
Priot to this change, the `fmt` command panicked when
rego files processed contained a comprehension written
on multiple lines with comments in these lines. An
example of such comprehension is presented in open-policy-agent#5798.

After this change, comprehensions on multiple lines are
not moved in a single line, in order to correcly handle
comments, similarly to what has been already done in open-policy-agent#3864.

Fixes: open-policy-agent#5798

Signed-off-by: Gianluca Oldani <[email protected]>
(cherry picked from commit 917dfc4)
ashutosh-narkar pushed a commit that referenced this pull request Jun 6, 2023
Priot to this change, the `fmt` command panicked when
rego files processed contained a comprehension written
on multiple lines with comments in these lines. An
example of such comprehension is presented in #5798.

After this change, comprehensions on multiple lines are
not moved in a single line, in order to correcly handle
comments, similarly to what has been already done in #3864.

Fixes: #5798

Signed-off-by: Gianluca Oldani <[email protected]>
(cherry picked from commit 917dfc4)
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.

opa build panics on second end-of-line comment in function call
2 participants