Skip to content
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

Disable linting rule for whole file or block. #1641

Closed
michael-delarue-axomic opened this issue Jan 9, 2023 · 1 comment · Fixed by #1909
Closed

Disable linting rule for whole file or block. #1641

michael-delarue-axomic opened this issue Jan 9, 2023 · 1 comment · Fixed by #1909

Comments

@michael-delarue-axomic
Copy link

Introduction

In order to be able to use certain rules it would be good to be able to disable them through an entire file. Specifically terraform_unused_declarations in my case.

Proposal

Currently, according to the documentation, # tflint-ignore: works only on the current or next line. I'd propose two changes.

a) tflint-ignore should work for a block if declared on the line directly before it

# the following awful variable names are required by our sandwich machine vendor so don't 
# try to fix them or we will all go hungry. 
# tflint-ignore: terraform_naming_convention
locals {
     BadLENAMEDvariABle_That_HAS_2_maTCH = 42
     BadLENAMEDvariABle_for_e_That_HAS_2_maTCH_2 = 3.14159265359
}

b) tflint-ignore-file should work for an entire file.

Valuable Use Case Description

The specific valuable use case I have is a single global definitions file which is included into multiple / many terraform directories as a symbolic link. In this case not all of the definitions are used in each module. I would like to disable the terraform_unused_declarations` rule in this particular file so that I can use and benefit from it in my other files.

References

@wata727
Copy link
Member

wata727 commented Jan 10, 2023

Block-based ignoring is a bit more complicated, but file-based ignoring is relatively easy to implement.
You can make tflint.Annotation an interface that implements IsAffected(), and adds tflint.FileAnnotation.
https://github.com/terraform-linters/tflint/blob/v0.44.1/tflint/annotation.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

3 participants