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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add new rule to check comparisons with empty list #1359
feat: add new rule to check comparisons with empty list #1359
Conversation
a8128ac
to
2b18257
Compare
2b18257
to
d6f34fd
Compare
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.
Nice, few minor comments
Co-authored-by: Ben Drucker <bvdrucker@gmail.com>
@bendrucker thank you for reviewing it so quickly! 馃檱 Just fixed all the issues reported. Have a great day! |
Will get back on this tomorrow |
Thank you! |
5d11bca
to
70f7f98
Compare
70f7f98
to
0fb3337
Compare
sorry to bother you @bendrucker, but please let me know if there's still something missing on the PR 馃槂 thank you! and have an awesome week! |
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.
It looks good to me. If @bendrucker approves, merge this pull request.
Thanks for adding this rule, but unfortunately it only picks up the most trivial cases. For example, it picks up this: resource "aws_security_group_rule" "outbound_proxy" {
count =var.proxy_subnets != [] ? 1 : 0 but not this: resource "aws_security_group_rule" "outbound_proxy" {
count = var.enabled && var.proxy_subnets != [] ? 1 : 0 nor this: templatefile("${path.module}/jenkins.yaml.tmpl", {
JENKINS_INGRESS_ENABLED = var.jenkins_controller_alb_allow_list != []
}) I guess it needs to implement more recursion for parsing into more complex expressions. |
Thanks for the feedback @sergei-ivanov! Can you report this as an issue so I can tackle it when I have some time please? 馃檱 |
@bmbferreira I have created #1424 -- thank you very much for your contribution! |
As explained by @jbardin on this issue "...the preferred way to check for an empty set or series of any type would be to check its length, rather than compare it against a literal value".
I've had a bug on my terraform code that took me almost 2 days to find out the root cause, just to find out that we had a check for
[]
in our code that was returning always false. 馃槗Since we are already using tflint, having a check for it would be a really good way to avoid doing the same stupid mistake again! 馃槂 Hopefully, you will also find this new rule useful and everyone can save a lot of headaches with it as well.
More info about why this rule is "needed":
https://discuss.hashicorp.com/t/conditional-for-empty-list/26958/2
hashicorp/terraform#25798 (comment)