gruntwork-io / gruntwork-io/pre-commit

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

Open
#90 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Shell
Stars
547
Forks
168
PR merge metrics
No merged PRs in 30d

Description

**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

```hcl
// 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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.