-
Notifications
You must be signed in to change notification settings - Fork 3
implement an opinionated format command #31
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
Conversation
add a new fmt command that allows for formatting and checking the format of .hcl files. In the process convert any key value pairs inside object literals to always consistently use = instead of :. It uses the std hclformat package for formatting. A flag is present to turn off the key value normalizer. It may be removed once we have enough experience with the formatter in the wild. Signed-off-by: gotwarlost <krishnan.anantheswaran@elastic.co>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements an opinionated format command for HCL files that standardizes object literal syntax from key: value to key = value while preserving the correct usage of colons in ternary expressions and for-expressions.
Key Changes
- Added a new
fmtcommand with check mode and recursive directory processing capabilities - Implemented token-based parsing to distinguish between object literal colons and expression colons
- Created comprehensive test coverage for various HCL syntax patterns including nested objects, ternaries, and for-expressions
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/format/format.go | Core formatting logic with stack-based token processing to normalize object literal syntax |
| internal/format/format_test.go | Comprehensive test suite covering object literals, ternaries, for-expressions, and edge cases |
| internal/format/cmd.go | CLI implementation with file collection, stdin support, and check mode |
| cmd/fn-hcl-tools/tools.go | Command registration with flags for normalization, checking, and recursion |
| cmd/fn-hcl-tools/main.go | Integration of format command into main CLI |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: gotwarlost <krishnan.anantheswaran@elastic.co>
Signed-off-by: gotwarlost <krishnan.anantheswaran@elastic.co>
ydubreuil
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, very well done. I added a few nit comments for the tests.
Co-authored-by: Yoann Dubreuil <yoann.dubreuil@gmail.com> Signed-off-by: gotwarlost <krishnan.anantheswaran@elastic.co>
|
OK, I committed your suggestions but realized they were incorrect because the variables in the |
add a new fmt command that allows for formatting and checking the format of .hcl files. In the process convert any key value pairs inside object literals to always consistently use
=instead of:.It uses the std hclformat package for formatting.
A flag is present to turn off the key value normalizer. It may be removed once we have enough experience with the formatter in the wild.