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

allow formating of multiple files #19442

Closed
fawaf opened this issue Nov 22, 2018 · 7 comments
Closed

allow formating of multiple files #19442

fawaf opened this issue Nov 22, 2018 · 7 comments

Comments

@fawaf
Copy link

fawaf commented Nov 22, 2018

Current Terraform Version

Terraform v0.11.8

Use-cases

format more than one file at a time, but not an directory. especially since fmt tries to format every file in the .terraform directory as well.

Attempted Solutions

in order to format more than one file, one has to use a loop or specifiy terraform fmt on each file separately since the fmt command only supports format of an entire directory or a single file.

Proposal

support terraform fmt file [file ..] so one can format more that one file at once, but not an entire directory.

References

@gmunguia
Copy link

gmunguia commented Jul 1, 2019

This would make using tools like https://github.com/okonet/lint-staged much easier.

@eryon
Copy link

eryon commented Jan 24, 2020

Looks like we have a potential fix in #19528. Can this be looked at by a contributor? @teamterraform

@dphang
Copy link

dphang commented Nov 5, 2020

Just came across this and I am also using lint-staged. If anyone is looking for a workaround while the PR is pending, and you have node available (assuming you probably do if you are using lint-staged), I just created a simple JS script to wrap terraform fmt in a loop:

Create a script, I called it terraform-multi-fmt.js:

const execSync = require("child_process").execSync;
const paths = process.argv.slice(2); // the command to be run is "node terraform-multi-fmt.js <path1> <path2> ...", so slice(2) creates an array of ["path1", "path2", ...]

for (const path of paths) {
  execSync(`terraform fmt ${path}`, { stdio: "inherit" });
}

Then you can add it to lint-staged in package.json:

  "lint-staged": {
    "**/*.tf": [
      "node terraform-multi-fmt.js"
    ]
  }

@1mamute
Copy link

1mamute commented Jul 25, 2021

Up, I'm using lint-staged too and needed to use @dphang workaround. The #19528 could solve the problem but has been neglected for a long time.

@mfellner
Copy link

For lint-staged users, there is an option to run a lint-staged command once per file using this configuration: https://github.com/okonet/lint-staged#example-wrap-filenames-in-single-quotes-and-run-once-per-file

@sbevels
Copy link

sbevels commented Jul 13, 2023

This appears to be resolved in v1.4.4.

@fawaf fawaf closed this as completed Nov 28, 2023
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants