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

cue fix tries to align comments inside braces with those outside, causing weird field indentation #1006

Open
cueckoo opened this issue Jul 3, 2021 · 2 comments
Labels
fmt Related to formatting functionality. NeedsFix

Comments

@cueckoo
Copy link
Collaborator

cueckoo commented Jul 3, 2021

Originally opened by @zellyn in cuelang/cue#1006

What version of CUE are you using (cue version)?

$ cue version
cue version 0.4.0 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

indent-bug-repro.cue:

x: {
	y: string

	// Comment
	z: string
} | "long_string_to_push_out_the_comment_on_this_line" // Comment

cue fix indent-bug-repro.cue

What did you expect to see?

The same output as input

What did you see instead?

x: {
	y: string

							// Comment
							z: string
} | "long_string_to_push_out_the_comment_on_this_line" // Comment
@myitcv
Copy link
Member

myitcv commented Jul 29, 2021

Thanks for raising this @zellyn, and apologies for the radio silence as we completed our migration (#1078).

Confirmed with ecb17c9:

cp x.cue x.cue.golden
exec cue fmt x.cue
cmp x.cue x.cue.golden

-- x.cue --
x: {
	y: string

	// Comment
	z: string
} | "long_string_to_push_out_the_comment_on_this_line" // Comment

@myitcv myitcv added NeedsFix S and removed NeedsInvestigation Triage Requires triage/attention labels Jul 29, 2021
@myitcv myitcv removed the S label Oct 26, 2021
@myitcv myitcv added this to the fmt-redesign milestone Apr 27, 2023
@myitcv myitcv added the zGarden label Jun 13, 2023
@rudifa
Copy link
Contributor

rudifa commented Nov 19, 2023

This script compares different test inputs

# issue #1006: run with `testscript -continue 1006.txtar
env CUEDO_FMT_DEBUGSTR=1

# x -----------------------------------
cp x.cue x.cue.golden
exec cue fmt x.cue
cmp x.cue x.cue.golden

# y -----------------------------------
cp y.cue y.cue.golden
exec cue fmt y.cue
cmp y.cue y.cue.golden

# z -----------------------------------
cp z.cue z.cue.golden
exec cue fmt z.cue
cmp z.cue z.cue.golden

-- x.cue --
x: {
	y: string

	// Comment 4
	z: string
} | "long_string_to_push_out_the_comment_on_this_line" // Comment 5
-- y.cue --
x: {
	y: string

	z: string
} | "long_string_to_push_out_the_comment_on_this_line" // Comment 5
-- z.cue --
x: {
	y: string
	z: string
} | "long_string_to_push_out_the_comment_on_this_line" // Comment 5

The tidied up output is

# x -----------------------------------
x: {
        y: string

                                                        // Comment 4
                                                        z: string
} | "long_string_to_push_out_the_comment_on_this_line" // Comment 5
# y -----------------------------------
x: {
        y: string

                                                       z: string
        z: string
} | "long_string_to_push_out_the_comment_on_this_line" // Comment 5
# z -----------------------------------
x: {
                                                       y: string
                                                       z: string
} | "long_string_to_push_out_the_comment_on_this_line" // Comment 5

and the corresponding DebugStr are

file: x.cue decoded ast DebugStr:<[5// Comment 5] x: {y: string, <[d0// Comment 4] z: string>}|"long_string_to_push_out_the_comment_on_this_line">
file: y.cue decoded ast DebugStr:<[5// Comment 5] x: {y: string, z: string}|"long_string_to_push_out_the_comment_on_this_line">
file: z.cue decoded ast DebugStr:<[5// Comment 5] x: {y: string, z: string}|"long_string_to_push_out_the_comment_on_this_line">

@mvdan mvdan removed the zGarden label Feb 8, 2024
@mvdan mvdan removed this from the fmt-redesign milestone Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fmt Related to formatting functionality. NeedsFix
Projects
None yet
Development

No branches or pull requests

4 participants