Skip to content

Conversation

@lonegunmanb
Copy link
Contributor

This rule will check whether variable blocks in a file are sorted by the following order:

  1. Required (without default argument) variables in alphabet order
  2. Optional (with default argument) variables in alphabet order

@lonegunmanb lonegunmanb changed the title Add terraform_variable_order rule [WIP]Add terraform_variable_order rule Sep 22, 2022
@lonegunmanb lonegunmanb changed the title [WIP]Add terraform_variable_order rule Add terraform_ordered_variables rule Sep 27, 2022
@lonegunmanb
Copy link
Contributor Author

@wata727 I think this pr is ready, appreciate if you can give it a review.

return &lastRequired
}

return nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nil causes panic. It should return an empty hcl.Range if there are no range.

Copy link
Contributor Author

@lonegunmanb lonegunmanb Sep 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I left this nil by intention, please allow me to explain. this issueRange is called when we're sure that there is at least one violation inside these blocks, otherwise the caller method checkVariableOrder should return a nil as error instead. Let's say somehow we've a bug in this issueRange method that causes we cannot find any violation, which is wrong, an empty hcl.Range will confuse our user, make them wonder what this line 0 issue stands for. In this scenario I think maybe it's better to let it crash so we can receive a bug report that this method somehow has a bug. I'll leave this decision to you, if you prefer an empty hcl.Range, I'll be happy to change it in your way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. In that case, I think calling panic explicitly is correct.
It is better to change the return type to hcl.Range instead of *hcl.Range, since it is not necessary to return nil.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Would you please give another review? Thanks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the confusion. I would like to discuss about #22 (comment) before restarting the review.

@wata727
Copy link
Member

wata727 commented Oct 17, 2022

Thank you for working on this. I'm sorry, but after consideration, this pull request will be closed for the time being. See discussion #22 (comment) for details.

@wata727 wata727 closed this Oct 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants