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

Feature: Allow linting on stdin #858

Open
gdavison opened this issue Jul 30, 2020 · 3 comments
Open

Feature: Allow linting on stdin #858

gdavison opened this issue Jul 30, 2020 · 3 comments
Labels
pending Wondering if it should be implemented

Comments

@gdavison
Copy link

In some CI validation usecases, such as blocks in documentation, it could be useful to pipe a configuration to tflint on stdin.

For example:

terrafmt blocks --zero-terminated my_docs.md | xargs -0 -n1 tflint --format=json

(Null-terminated blocks in terrafmt are suggested in katbyte/terrafmt#24)

@bendrucker
Copy link
Member

Interesting. The provided directory gets two passes: Terraform loads the configuration, and tflint separately scans for annotations. The raw HCL bodies are also re-parsed from the source cache so rules can do low level inspection if desired.

https://github.com/terraform-linters/tflint/blob/master/cmd/inspect.go#L95

I think the most straightforward change here is to load stdin and put it in an in-memory afero.Fs as stdin.tf. That should minimize the amount of code changing.

@wata727
Copy link
Member

wata727 commented Feb 7, 2023

I'm thinking about this now, but given that TFLint is moving towards a directory-oriented interface, I'm wondering if we should implement this feature.

Once this issue is marked as pending. Discussions are welcome.

@wata727 wata727 added pending Wondering if it should be implemented and removed enhancement labels Feb 7, 2023
@bendrucker
Copy link
Member

In the original example of terrafmt, it seems like there'd need be substantial value in a more advanced wrapper than just gluing together with xargs, especially in GitHub Actions.

If TFLint supported stdin, it would have to use a generated filename like input.tf and would report ranges relative to that filename and its lines.

This is not especially helpful for users, who would instead want a GitHub error annotation that is reported on the actual source, e.g., in a Terraform code block in a Markdown file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending Wondering if it should be implemented
Development

No branches or pull requests

3 participants