gruntwork-io / pre-commit

A collection of pre-commit hooks used by Gruntwork tools
https://gruntwork.io/
Apache License 2.0
484 stars 155 forks source link

tflint hook filters out too many issues #112

Open michasng opened 5 months ago

michasng commented 5 months ago

Describe the bug The --filter argument to tflint is too restrictive.

This is the relevant code:

for file in "${FILES[@]}"
do
  tflint "${ARGS[@]}" --chdir "$(dirname "$file")" --filter "$(basename "$file")"
done

tflint runs for each file and then shows only the issues in that file. However some issues don't reference specific files, namely those issues where something is missing, like a missing required_version or provider declaration.

To Reproduce Run the hook with a terraform file like this:

terraform {
  # required_version = "~>1.6.6"
}

which should find this issue

1 issue(s) found:

Warning: terraform "required_version" attribute is required (terraform_required_version)

  on  line 0:
   (source code not available)

Reference: https://github.com/terraform-linters/tflint-ruleset-terraform/blob/v0.5.0/docs/rules/terraform_required_version.md

but this is filtered out, because it does not reference a specific source code file.

Expected behavior The issue should be found and the hook should fail.

Additional context Finding issues like this requires that tflint no longer runs for each changed file, but for all files at once. I think this trade-off should be taken in order to find all issues.