-
Notifications
You must be signed in to change notification settings - Fork 279
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: Allow "fmt" subcommand to indicate whether any formatting changes are necessary #363
Comments
Original reply by @seh in cuelang/cue#363 (comment) I see that the aging #247 addresses some of these ideas. |
I'd like to work on this issue as it would make my life simpler :) Can we talk about how we should approach this ? Ie: what UX interface to implement ? |
For modules we are just about to land Not least because Go is moving in that direction too: golang/go#46289 (comment) We have missed the boat for v0.8.0, but would be happy to see something land in the first alpha of v0.9.0. I will create a project for that release series now. |
Done: https://github.com/orgs/cue-lang/projects/21/views/1 If anyone would like to work on this, please shout! |
Adds a --check flag that will cause cue to fail with exit code 1 in case any files require formatting. A list of non formatted files will be displayed, line by line, to stdout. resolves #363. Change-Id: I27c8e9b18bb01f981cd061a23ee3323bc403c9a9 Signed-off-by: Noam Dolovich <noam.tzvi.dolovich@gmail.com>
Adds a --check flag that will cause cue to fail with exit code 1 in case any files require formatting. A list of non formatted files will be displayed, line by line, to stdout. Also, a typo is fixed in cue/ast/ast.go. resolves #363. Change-Id: I27c8e9b18bb01f981cd061a23ee3323bc403c9a9 Signed-off-by: Noam Dolovich <noam.tzvi.dolovich@gmail.com>
Adds a --check flag that will cause cue to fail with exit code 1 in case any files require formatting. A list of non formatted files will be displayed, line by line, to stdout. Also, a typo is fixed in cue/ast/ast.go. resolves #363. Change-Id: I27c8e9b18bb01f981cd061a23ee3323bc403c9a9 Signed-off-by: Noam Dolovich <noam.tzvi.dolovich@gmail.com>
Adds a --check flag that will cause cue to fail with exit code 1 in case any files require formatting. A list of non formatted files will be displayed, line by line, to stdout. Also, a typo is fixed in cue/ast/ast.go. resolves #363. Change-Id: I27c8e9b18bb01f981cd061a23ee3323bc403c9a9 Signed-off-by: Noam Dolovich <noam.tzvi.dolovich@gmail.com>
Adds a --check flag that will cause cue to fail with exit code 1 in case any files require formatting. A list of non formatted files will be displayed, line by line, to stdout. Also, a typo is fixed in cue/ast/ast.go. resolves #363. Change-Id: I27c8e9b18bb01f981cd061a23ee3323bc403c9a9 Signed-off-by: Noam Dolovich <noam.tzvi.dolovich@gmail.com>
Adds a --check flag that will cause cue to fail with exit code 1 in case any files require formatting. A list of non formatted files will be displayed, line by line, to stdout. Also, a typo is fixed in cue/ast/ast.go. resolves #363. Change-Id: I27c8e9b18bb01f981cd061a23ee3323bc403c9a9 Signed-off-by: Noam Dolovich <noam.tzvi.dolovich@gmail.com>
Adds a --check flag that will cause cue to fail with exit code 1 in case any files require formatting. A list of non formatted files will be displayed, line by line, to stdout. Also, a typo is fixed in cue/ast/ast.go. fixes #363. Change-Id: I27c8e9b18bb01f981cd061a23ee3323bc403c9a9 Signed-off-by: Noam Dolovich <noam.tzvi.dolovich@gmail.com>
Adds a --check flag that will cause cue to fail with exit code 1 in case any files require formatting. A list of non formatted files will be displayed, line by line, to stdout. Also, a typo is fixed in cue/ast/ast.go. fixes #363. Change-Id: I27c8e9b18bb01f981cd061a23ee3323bc403c9a9 Signed-off-by: Noam Dolovich <noam.tzvi.dolovich@gmail.com>
Adds a --check flag that will cause cue to fail with exit code 1 in case any files require formatting. A list of non formatted files will be displayed, line by line, to stdout. Also, a typo is fixed in cue/ast/ast.go. fixes #363. Change-Id: I27c8e9b18bb01f981cd061a23ee3323bc403c9a9 Signed-off-by: Noam Dolovich <noam.tzvi.dolovich@gmail.com>
Adds a --check flag that will cause cue to fail with exit code 1 in case any files require formatting. A list of non formatted files will be displayed, line by line, to stdout. Also, a typo is fixed in cue/ast/ast.go. fixes #363. Change-Id: I27c8e9b18bb01f981cd061a23ee3323bc403c9a9 Signed-off-by: Noam Dolovich <noam.tzvi.dolovich@gmail.com>
Currently, `cue fmt` will always write to cue files, regardless of whether they are formatted or not. In the case of formatted files, there contents will remain exactly the same, but their modification time will change. This is problematic for tools that rely on the mod time. Fixes #1731, #363 Signed-off-by: Noam Dolovich <noam.tzvi.dolovich@gmail.com> Change-Id: Iea55c1eb9e99c1dcba301194857a92dad1faa9ad
Currently, `cue fmt` will always write to cue files, regardless of whether they are formatted or not. In the case of formatted files, there contents will remain exactly the same, but their modification time will change. This is problematic for tools that rely on the mod time. Fixes #1731, #363 Signed-off-by: Noam Dolovich <noam.tzvi.dolovich@gmail.com> Change-Id: Iea55c1eb9e99c1dcba301194857a92dad1faa9ad
Currently, `cue fmt` will always write to cue files, regardless of whether they are formatted or not. In the case of formatted files, their contents will remain exactly the same, but their modification time will change. This is problematic for tools that rely on the mod time. To fix this, we buffer the original/formatted bytes. If the result is exactly the same, the file is not written to. Fixes #1731, #363 Signed-off-by: Noam Dolovich <noam.tzvi.dolovich@gmail.com> Change-Id: Iea55c1eb9e99c1dcba301194857a92dad1faa9ad
Currently, `cue fmt` will always write to cue files, regardless of whether they are formatted or not. In the case of formatted files, their contents will remain exactly the same, but their modification time will change. This is problematic for tools that rely on the mod time. To fix this, we buffer the original/formatted bytes. If the result is exactly the same, the file is not written to. Fixes #1731, #363 Signed-off-by: Noam Dolovich <noam.tzvi.dolovich@gmail.com> Change-Id: Iea55c1eb9e99c1dcba301194857a92dad1faa9ad
Currently, `cue fmt` will always write to cue files, regardless of whether they are formatted or not. In the case of formatted files, their contents will remain exactly the same, but their modification time will change. This is problematic for tools that rely on the mod time. To fix this, we buffer the original/formatted bytes. If the result is exactly the same, the file is not written to. Fixes #1731, #363 Signed-off-by: Noam Dolovich <noam.tzvi.dolovich@gmail.com> Change-Id: Iea55c1eb9e99c1dcba301194857a92dad1faa9ad
Currently, `cue fmt` will always write to cue files, regardless of whether they are formatted or not. In the case of formatted files, their contents will remain exactly the same, but their modification time will change. This is problematic for tools that rely on the mod time. To fix this, we buffer the original/formatted bytes. If the result is exactly the same, the file is not written to. Fixes #1731, #363 Signed-off-by: Noam Dolovich <noam.tzvi.dolovich@gmail.com> Change-Id: Iea55c1eb9e99c1dcba301194857a92dad1faa9ad
Originally opened by @seh in cuelang/cue#363
At present, cue fmt unconditionally overwrites a target file, whether or not any changes in formatting were required. It doesn't offer any indication to a calling process whether the input required rewriting. In other words, repeated invocations of cue fmt reaches a fixed point, but a caller can only tell that by comparing the input and output afterward.
Describe the solution you'd like
Introduce three additions to cue fmt:
Since the existing tool exits with code zero whether or not it had to change the file content, in the interest of backward compatibility, we could introduce a command-line flag like
--detailed-code
to enable this distinction. Exit with zero if the content changed, and something like two if the content didn't need to change.If we're already able to tell whether a change is necessary, we can skip overwriting the target file when there's no need to do so. cue fmt already claims that it operates in place, so there's no need to emit unchanged content to handle creating new files unconditionally. This is also convenient when integrating with tools like Make, which might be fooled by the file's mtime changing even if its content did not. (Bazel is more clever than that.)
Allow using cue fmt to detect whether changes are necessary without actually writing those changes to the target file. This is useful in pre-commit hooks and CI jobs to enforce proper formatting of CUE files.
Describe alternatives you've considered
It's possible to wrap cue fmt in a helper tool that copies the original content, runs cue fmt, compares the original content to the resulting content, and exits with a distinguished code indicating its findings. In other words, the predicate is whether the original content matches the resulting content. Could we track whether we've performed any mutations in the call to
cmd.fix
, and handle this inside of cue fmt?Additional context
The jsonnetfmt command is the basis of inspiration here.
The text was updated successfully, but these errors were encountered: