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

cmd/cue: fmt -s does not preserve the scope of comments which is important for tool files #2672

Open
gotwarlost opened this issue Nov 2, 2023 · 1 comment
Labels
fmt Related to formatting functionality. NeedsFix

Comments

@gotwarlost
Copy link

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

$ cue version
cue version v0.6.0

go version go1.20.7
      -buildmode exe
       -compiler gc
       -trimpath true
     CGO_ENABLED 1
          GOARCH arm64
            GOOS darwin

Does this issue reproduce with the latest stable release?

Yes.

What did you do?

Wrote a tool file and ran cue fmt -s on it. While the output of the formatting is correct, it changes the behavior of the tool file by changing the scope of the comment attached to the command.

$ cat make_tool.cue
package make_tool

import (
	"tool/exec"
)

// displays help for available commands
command: help: {
	show: exec.Run & {cmd: [ "sh", "-c", "cue help cmd | grep -A2 'Available Commands:'"]}
}

$ cue cmd help
Available Commands:
  help        displays help for available commands

$ cue fmt -s make_tool.cue

# note that the help text is gone
$ cue cmd help
Available Commands:
  help

# that's because the comment is now scoped to command: help: show instead of command: help
$ cat make_tool.cue
package make_tool

import (
	"tool/exec"
)

// displays help for available commands
command: help: show: exec.Run & {cmd: [ "sh", "-c", "cue help cmd | grep -A2 'Available Commands:'"]}

What did you expect to see?

No change to the behavior of the cue cmd help output after simplification

What did you see instead?

The help text disappears because of the scope change of the comment

@gotwarlost gotwarlost added NeedsInvestigation Triage Requires triage/attention labels Nov 2, 2023
@gotwarlost gotwarlost changed the title cue fmt -s simplifies too much for tool files cue fmt -s does not preserve the scope of comments which is important for tool files Nov 2, 2023
@gotwarlost gotwarlost changed the title cue fmt -s does not preserve the scope of comments which is important for tool files cmd/cue: fmt -s does not preserve the scope of comments which is important for tool files Nov 21, 2023
@mvdan
Copy link
Member

mvdan commented Dec 13, 2023

Thanks for the report - agreed that cue fmt, even with the -s flag, should not lead to changes in the output of cue cmd help.

@mvdan mvdan added NeedsFix fmt Related to formatting functionality. and removed NeedsInvestigation Triage Requires triage/attention labels Dec 13, 2023
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

2 participants