-
Notifications
You must be signed in to change notification settings - Fork 14
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
how to retrieve or iterate all files #119
Comments
Feels like a |
Currently, there is no API provided to access the low-level HCL body, but I think it is possible to provide such an API. |
thank you for the reply! |
Sure! This issue will be resolved someday, but if you need features sooner, please open a PR and I'll be happy to review it. |
I've just opened this PR terraform-linters/tflint#1132 which I imagine is the first step to have Files() available to the sdk. If the implementation is correct and approved, then I will add this to the client side. |
Nice! It's a good idea to merge the sdk changes first and then update the TFLint side PR. |
Hi, func (rule *TerraformPortefaixStandardStructureRule) checkDirectories(runner tflint.Runner) error {
files, _ := runner.Files()
log.Printf("[INFO] Files: %d", len(files))
allowedFiles := map[string]bool{"providers.tf": true, "main.tf": true}
for name := range files {
_, filename := path.Split(name)
log.Printf("[INFO] OK: %s %s", name, filename)
if _, exists := allowedFiles[filename]; !exists {
message := fmt.Sprintf("File %s is not allowed here.", filename)
return runner.EmitIssue(rule, message, hcl.Range{Start: hcl.InitialPos})
}
}
} But i've got no files. Any idea ?
|
Hi @nlamirault could you please provide which version of tflint and tflint-plugin-sdk you currently have installed? according to the docs, tflint does not recursively find files, but it should list files from the root/current working dir:
|
and :
|
missing a |
@jonathansp i've got it :) juste copy paste missing on github. |
do you think it could be caused for any other reason, like relative paths or anything else I can do to reproduce the problem? |
I push my code here : https://github.com/nlamirault/tflint-ruleset-portefaix |
$ git clone https://github.com/nlamirault/tflint-ruleset-portefaix.git
Cloning into 'tflint-ruleset-portefaix'...
remote: Enumerating objects: 38, done.
remote: Counting objects: 100% (38/38), done.
remote: Compressing objects: 100% (30/30), done.
remote: Total 38 (delta 9), reused 25 (delta 7), pack-reused 0
Unpacking objects: 100% (38/38), done.
$ cd tflint-ruleset-portefaix
$ make install
go build
mkdir -p ~/.tflint.d/plugins
mv ./tflint-ruleset-portefaix ~/.tflint.d/plugins
$ tflint-ruleset-portefaix git:(main) tflint --enable-plugin=portefaix ../tf-files --only=terraform_portefaix_standard_structure
1 issue(s) found:
Error: File dns.tf is not allowed here. (terraform_portefaix_standard_structure)
on line 1:
(source code not available)
Reference: https://github.com/nlamirault/tflint-ruleset-portefaix/blob/master/README.md $ cat go.mod
module github.com/nlamirault/tflint-ruleset-portefaix
go 1.16
require (
github.com/agext/levenshtein v1.2.3 // indirect
github.com/fatih/color v1.12.0 // indirect
github.com/google/go-cmp v0.5.6 // indirect
github.com/hashicorp/go-hclog v0.16.1 // indirect
github.com/hashicorp/go-plugin v1.4.2 // indirect
github.com/hashicorp/go-version v1.3.0 // indirect
github.com/hashicorp/hcl/v2 v2.10.0
github.com/hashicorp/yamux v0.0.0-20210316155119-a95892c5f864 // indirect
github.com/mattn/go-isatty v0.0.13 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/terraform-linters/tflint-plugin-sdk v0.8.3-0.20210614125323-8364139f3745
github.com/vmihailenco/tagparser v0.1.2 // indirect
github.com/zclconf/go-cty v1.8.4 // indirect
golang.org/x/net v0.0.0-20210614182718-04defd469f4e // indirect
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20210701191553-46259e63a0a9 // indirect
google.golang.org/grpc v1.39.0 // indirect
) $ tflint --version
TFLint version 0.29.0 I noticed you're using tflint 0.28, which doesn't expose |
I have no idea why it does not work :( |
I think I may have been using tflint from master branch, which would explain that. @wata727 can you please confirm if this feature was release already or will be? |
It works with master branch !
|
TFLint v0.30 / Plugin SDK v0.9 has been released. |
I need to low-level iterate all files for style checking, but I can't see the list being accessible.
I read the intention of
File(string)
is such a use case, also there is an unexported list underrunner.data.Files
available, but I'm struggling to grasp their access.Use case is to determine if a heredoc syntax has been used.
Thank you for help @wata727
The text was updated successfully, but these errors were encountered: