-
Notifications
You must be signed in to change notification settings - Fork 357
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
Errors with no range cannot be identified when emitted in recursive mode #1790
Comments
Retitled as there's no direct relationship to |
The simplest workaround for now is to always emit a range that includes the module path in a rule like In the current design, the |
Yep, thought about this. It's an improvement for end users but a hack and I worry where it might break. A range is meant to be associated with a file. Right now we print "source not available" when the file name is empty. While that could also apply when the file doesn't exist (because it's actually a dir), it's awkward to have to account for that discrepancy anywhere in the code. Seems like recursive mode would justify attaching a source module reference when emitting an issue so we can print its path for issues with no range. A variation on the dir as range filename hack that would cover all comparable rules would be to handle this at the SDK level when calling EmitIssue. If the range is a zero-value, implicitly replace it with a range that refers to the directory. |
Makes sense. I agree to add a source module reference to |
This comment was marked as off-topic.
This comment was marked as off-topic.
I currently have a slightly different position on this matter, so I'll share my thoughts. Initially I was positive about attaching the source module reference. However, considering that the issues are processed by other tools (e.g. SARIF, LSP, problem matchers, etc.), it can be difficult to deal with issues attached to module directories. Given this, it might be better to force the rules to emit issues for valid lines in some file in all cases. Regarding recursion inspection, I think it's not a bad idea to attach a module reference to improve the output with the default formatter, apart from the valid ranges used for JSON output etc. |
Summary
I was remediating the other breaking changes in tflint 0.47.0 and noticed an odd one on a large project which has a number of local submodules. After duplicating our required providers/versions config into every subdirectory, all of my modules and the top-level have a
required_version
declared but there's still a single error reported with the “source code not available” message:Warning: terraform "required_version" attribute is required (terraform_required_version) on line 0: (source code not available)
At the very least it would be useful to know the current working directory when this error was generated – I confirmed that if I remove the
required_version
from one of my submodules it will also trigger the same context-free error so I used Semgrep to confirm that everyterraform
block in the entire project has arequired_version
(this is how I found the submodule without one).Command
tflint --only=terraform_required_version --recursive
Terraform Configuration
TFLint Configuration
Output
tflint --only=terraform_required_version --recursive 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.4.0/docs/rules/terraform_required_version.md
TFLint Version
0.47.0
Terraform Version
Terraform v1.5.1 on darwin_arm64 + provider registry.terraform.io/hashicorp/archive v2.3.0 + provider registry.terraform.io/hashicorp/aws v4.67.0 + provider registry.terraform.io/hashicorp/dns v3.3.2 + provider registry.terraform.io/hashicorp/external v2.3.1 + provider registry.terraform.io/hashicorp/http v3.3.0 + provider registry.terraform.io/hashicorp/local v2.4.0 + provider registry.terraform.io/hashicorp/null v3.2.1
Operating System
The text was updated successfully, but these errors were encountered: