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

opa fmt vs git -- trailing newline issue #1032

Closed
srenatus opened this issue Oct 24, 2018 · 3 comments
Closed

opa fmt vs git -- trailing newline issue #1032

srenatus opened this issue Oct 24, 2018 · 3 comments

Comments

@srenatus
Copy link
Contributor

When committing opa fmt'ed files to git, it'll complain about the trailing newline:

screen shot 2018-10-24 at 11 07 07

It's by no means a big deal, just a minor annoyance. Anyhow, I think it would be preferable if it wasn't so. 😃 What do you think?

@tsandall
Copy link
Member

I agree this is annoying. What's the desired behaviour we want? opa fmt should only add a newline at the end of the file if one is not present?

@srenatus
Copy link
Contributor Author

only add a newline at the end of the file if one is not present

Yeah, I suppose that would be it! 👍

kichristensen added a commit to kichristensen/opa that referenced this issue Oct 24, 2018
opa fmt should only add one newline at the end of the file

Fixes open-policy-agent#1032

Signed-off-by: Kim Christensen <kimworking@gmail.com>
@srenatus
Copy link
Contributor Author

@kichristensen thank you! 🎈

tsandall added a commit to tsandall/opa that referenced this issue Nov 19, 2018
Previously trailing comments inside arrays, objects, and sets were not
being formatted correctly. For example:

[
    1,
    2,
    # foo
]

Would result in:

[
    1,
    2,
 # foo ]

The problem was that when the sequence was ended, the comments were not
being emitted. As a result when the comments were finally emitted, the
indenting was wrong and the state of the formatter was not consistent
(and so the closing bracket appeared on the same line the comment.)

These changes modify the formatter to emit the comments when ending the
sequence, as that's the point where the indenting state is known.

Also, as part of these changes, the fix for extra newlines (open-policy-agent#1032) has
been modified. Instead of changing the startLine and endLine behaviours
(which are a bit sensitive) we just squash trailing newlines at the end
of the formatting process.

Fixes open-policy-agent#1060

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
tsandall added a commit that referenced this issue Nov 19, 2018
Previously trailing comments inside arrays, objects, and sets were not
being formatted correctly. For example:

[
    1,
    2,
    # foo
]

Would result in:

[
    1,
    2,
 # foo ]

The problem was that when the sequence was ended, the comments were not
being emitted. As a result when the comments were finally emitted, the
indenting was wrong and the state of the formatter was not consistent
(and so the closing bracket appeared on the same line the comment.)

These changes modify the formatter to emit the comments when ending the
sequence, as that's the point where the indenting state is known.

Also, as part of these changes, the fix for extra newlines (#1032) has
been modified. Instead of changing the startLine and endLine behaviours
(which are a bit sensitive) we just squash trailing newlines at the end
of the formatting process.

Fixes #1060

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants