-
Notifications
You must be signed in to change notification settings - Fork 354
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
add terraform_comment_syntax rule #762
add terraform_comment_syntax rule #762
Conversation
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.
Looks good!
@@ -237,6 +238,17 @@ func (r *Runner) File(path string) *hcl.File { | |||
return r.files[path] | |||
} | |||
|
|||
// Files returns the raw *hcl.File representation of all Terraform configuration in the module directory. | |||
func (r *Runner) Files() map[string]*hcl.File { |
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.
👍
According to Terraform documentation:
After reading this, I wondered if |
Agreed, I think anything detectable by I suspect that in the real world a lot of users (if not most) have a a mix of comment styles. Double slash is pretty much everywhere except for shells. If your editor has a syntax definition for Terraform/HCL, the keyboard shortcut for opening a comment should use Enforcing one comment style would be breaking for The language about auto-formatting in the docs is definitely interesting, and comes from here: Seems like Terraform 0.12 would have been the best time to introduce this, given that users were already significantly rewriting their configs. Very possible that was being considered at the time and it was cut from the release. |
This PR adds a
terraform_comment_syntax
rule that enforces the canonical#
comment style as described in the Terraform syntax guide:https://www.terraform.io/docs/configuration/syntax.html#comments
This was requested by a colleague who noticed that @TakeScoop's Terraform configuration contains a mix of
#
and//
comments but that Terraform clearly recommends#
.Since this is an aesthetic preference, the rule is disabled by default.
In order to accomplish this, I've added a
Files
method to the runner which returns all files in the current module. I'm interested in some other syntax-oriented rules that would depend on that method, e.g. enforcing canonical block padding: