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

opo fmt incorrectly formats commented code #1060

Closed
marco-styra opened this issue Nov 8, 2018 · 0 comments
Closed

opo fmt incorrectly formats commented code #1060

marco-styra opened this issue Nov 8, 2018 · 0 comments
Labels

Comments

@marco-styra
Copy link
Contributor

marco-styra commented Nov 8, 2018

First issue: commented line is not ignored, rendering the code unparsable

 package format_bug

 example[[a]] {
-
-	commits = [[
-         {"test": "test"},
-#       {"pods": "pod"},
-    ]]
+	commits = [[{"test": "test"}#       {"pods": "pod"},]
+	]
 }
 }

Second issue: one of the brackets of the reformatted ]], is moved to a commented line, rendering the code unparsable

 package format_bug

 example[[a]] {
-
 	commits = [[
-         {"test": "test"},
-         {"test1": "test2"},
-#       {"pods": "pod"},
-    ]]
+		{"test": "test"},
+		{"test1": "test2"},
+	#       {"pods": "pod"},]
+	]
 }
@tsandall tsandall added the bug label Nov 8, 2018
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants