pre-commit icon indicating copy to clipboard operation
pre-commit copied to clipboard

Trying to set chdir so only scans certain folders is not working

Open balq60 opened this issue 1 year ago • 0 comments

Describe the bug I want to be able to scan folders. I have tried these settings. All of these settings fail to scan JUST the folder I set:

#EXAMPLE 1

  • repo: https://github.com/gruntwork-io/pre-commit rev: v0.1.18 hooks:
    • id: tflint args: ["--chdir=IaC/environments/2-staging/"]

#EXAMPLE 2

  • repo: https://github.com/gruntwork-io/pre-commit rev: v0.1.18 hooks:
    • id: tflint args:
      • --chdir=IaC/environments/2-staging/

#EXAMPLE 3

  • repo: https://github.com/gruntwork-io/pre-commit rev: v0.1.18 hooks:
    • id: tflint args:
      • --chdir=IaC/environments/2-staging/

#EXAMPLE 4 #This fails as well

  • repo: https://github.com/gruntwork-io/pre-commit rev: v0.1.18 hooks:
    • id: tflint args:
      • --filter=IaC/environments/2-staging/*.tf

To Reproduce Terraform version 1.3.9

// paste code snippets here
To Trip the linter I added this in my IaC/environments/1-test folder

variable "not_used" {
  description = "To trip linters"
  type        = string
  default     = null
}

tflint...................................................................Failed
- hook id: tflint
- exit code: 2

1 issue(s) found:

Warning: variable "not_used" is declared but not used (terraform_unused_declarations)

  on IaC/environments/1-test/compute-priv-variables.tf line 183:
 183: variable "not_used" {

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

**Expected behavior**
Since I am setting a chdir argument to scan the IaC/environments/2-staging/ folder (I tried without the trailing slash, fails as well)

I would NOT expect the linter to find the issue in the IaC/environments/1-test folder.

I would expect no errors reported

**Nice to have**
- [ ] Terminal output
- [ ] Screenshots

**Additional context**
I want to be able to set different exclusion per environment.  I want production to have all rules applied with lower environments I want the ability to exclude rules.  I cannot do that, since chdir is not being honored.  I submitted this bug in the tflint repo, they it was not their issue.

balq60 avatar Mar 06 '23 17:03 balq60