{"id":13602834,"url":"https://github.com/gruntwork-io/pre-commit","last_synced_at":"2025-06-10T15:31:06.493Z","repository":{"id":35189231,"uuid":"133653910","full_name":"gruntwork-io/pre-commit","owner":"gruntwork-io","description":"A collection of pre-commit hooks used by Gruntwork tools","archived":false,"fork":false,"pushed_at":"2025-06-05T23:42:54.000Z","size":100,"stargazers_count":517,"open_issues_count":41,"forks_count":167,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-06-06T00:30:49.962Z","etag":null,"topics":["bash","devops","git","precommit-hooks"],"latest_commit_sha":null,"homepage":"https://gruntwork.io/","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gruntwork-io.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-05-16T11:13:23.000Z","updated_at":"2025-05-25T06:04:42.000Z","dependencies_parsed_at":"2024-12-16T12:18:37.137Z","dependency_job_id":"1533121b-82f1-48c8-a14f-9127fcf893e2","html_url":"https://github.com/gruntwork-io/pre-commit","commit_stats":null,"previous_names":[],"tags_count":39,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gruntwork-io%2Fpre-commit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gruntwork-io%2Fpre-commit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gruntwork-io%2Fpre-commit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gruntwork-io%2Fpre-commit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gruntwork-io","download_url":"https://codeload.github.com/gruntwork-io/pre-commit/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gruntwork-io%2Fpre-commit/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259101072,"owners_count":22805198,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","devops","git","precommit-hooks"],"created_at":"2024-08-01T18:01:39.416Z","updated_at":"2025-06-10T15:31:06.482Z","avatar_url":"https://github.com/gruntwork-io.png","language":"Shell","readme":"[![Maintained by Gruntwork.io](https://img.shields.io/badge/maintained%20by-gruntwork.io-%235849a6.svg)](https://gruntwork.io/?ref=repo_pre-commit)\n\n# Pre-commit hooks\n\nThis repo defines Git pre-commit hooks intended for use with [pre-commit](http://pre-commit.com/). The currently\nsupported hooks are:\n\n* **tofu-fmt**: Automatically run `tofu fmt` on all OpenTofu code (`*.tf`, `*.tofu` files).\n* **tofu-validate**: Automatically run `tofu validate` on all OpenTofu code (`*.tf`, `*.tofu` files).\n* **terraform-fmt**: Automatically run `terraform fmt` on all Terraform code (`*.tf` files).\n* **terraform-validate**: Automatically run `terraform validate` on all Terraform code (`*.tf` files).\n* **packer-validate**: Automatically run `packer validate` on all Packer code (`*.pkr.*` files).\n* **terragrunt-hclfmt**: Automatically run `terragrunt hclfmt` on all Terragrunt configurations.\n* **tflint**: Automatically run [`tflint`](https://github.com/terraform-linters/tflint) on all OpenTofu/Terraform code (`*.tf`, `*.tofu` files).\n* **shellcheck**: Run [`shellcheck`](https://www.shellcheck.net/) to lint files that contain a bash [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)).\n* **gofmt**: Automatically run `gofmt` on all Golang code (`*.go` files).\n* **goimports**: Automatically run `goimports` on all Golang code (`*.go` files).\n* **golint**: Automatically run `golint` on all Golang code (`*.go` files). [**DEPRECATED**]: Please use `golangci-lint` below.\n* **golangci-lint**: Automatically run `golangci-lint` on all Golang code (`*.go` files).\n* **yapf**: Automatically run [`yapf`](https://github.com/google/yapf) on all python code (`*.py` files).\n* **helmlint** Automatically run [`helm lint`](https://helm.sh/docs/helm/helm_lint/) on your Helm chart files. [See caveats here](#helm-lint-caveats).\n* **markdown-link-check** Automatically run [markdown-link-check](https://github.com/tcort/markdown-link-check) on\n  markdown doc files.\n* **sentinel-fmt**: Automatically run `sentinel fmt` on all Sentinel code (`*.sentinel.*` files).\n\n\n\n\n\n## General Usage\n\nIn each of your repos, add a file called `.pre-commit-config.yaml` with the following contents:\n\n```yaml\nrepos:\n  - repo: https://github.com/gruntwork-io/pre-commit\n    rev: \u003cVERSION\u003e # Get the latest from: https://github.com/gruntwork-io/pre-commit/releases\n    hooks:\n      - id: tofu-fmt\n      - id: tofu-validate\n      - id: tflint\n      - id: shellcheck\n      - id: gofmt\n      - id: golint\n```\n\nNext, have every developer: \n\n1. Install [pre-commit](http://pre-commit.com/). E.g. `brew install pre-commit`.\n1. Run `pre-commit install` in the repo.\n\nThat’s it! Now every time you commit a code change (`.tf` file), the hooks in the `hooks:` config will execute.\n\n\n\n\n## Running Against All Files At Once\n\n\n### Example: Formatting all files\n\nIf you'd like to format all of your code at once (rather than one file at a time), you can run:\n\n```bash\npre-commit run tofu-fmt --all-files\n```\n\n\n\n### Example: Enforcing in CI\n\nIf you'd like to enforce all your hooks, you can configure your CI build to fail if the code doesn't pass checks by\nadding the following to your build scripts:\n\n```bash\npip install pre-commit\npre-commit install\npre-commit run --all-files\n```\n\nIf all the hooks pass, the last command will exit with an exit code of 0. If any of the hooks make changes (e.g.,\nbecause files are not formatted), the last command will exit with a code of 1, causing the build to fail.\n\n\n\n\n## Helm Lint Caveats\n\n### Detecting charts\n\nThe `helmlint` pre-commit hook runs `helm lint` on the charts that have been changed by the commit. It will run once per\nchanged chart that it detects.\n\nNote that charts are detected by walking up the directory tree of the changed file and looking for a `Chart.yaml` file\nthat exists on the path.\n\n### linter_values.yaml\n\n`helm lint` requires input values to look for configuration errors in your helm chart. However, this means that the\nlinter needs a complete values file. Because we want to develop charts that define required values that the operator\nshould provide, we don't want to specify defaults for all the values the chart expects in the default `values.yaml`\nfile.\n\nTherefore, to support this, this pre-commit hook looks for a special `linter_values.yaml` file defined in the chart\npath. This will be combined with the `values.yaml` file before running `helm lint`. In your charts, you should define\nthe required values in `linter_values.yaml`.\n\nFor example, suppose you had a helm chart that defined two input values: `containerImage` and `containerTag`. Suppose\nthat your chart required `containerImage` to be defined, but not `containerTag`. To enforce this, you created the\nfollowing `values.yaml` file for your chart:\n\n```yaml\n# values.yaml\n\n# containerImage is required and defines which image to use\n\n# containerTag specifies the image tag to use. Defaults to latest.\ncontainerTag: latest\n```\n\nIf you run `helm lint` on this chart, it will fail because somewhere in your chart you will reference\n`.Values.containerImage` which will be undefined with this `values.yaml` file. To handle this, you can define a\n`linter_values.yaml` file that defines `containerImage`:\n\n```yaml\n# linter_values.yaml\ncontainerImage: nginx\n```\n\nNow when the pre-commit hook runs, it will call `helm lint` with both `linter_values.yaml` and `values.yaml`:\n\n```\nhelm lint -f values.yaml -f linter_values.yaml .\n```\n\n## Shellcheck Arguments\n\nTo enable optional shellcheck features you can use the `--enable` flag.\nOther shellcheck flags can not be passed through.\n\n```yaml\nrepos:\n  - repo: https://github.com/gruntwork-io/pre-commit\n    rev: \u003cVERSION\u003e\n    hooks:\n      - id: shellcheck\n        args: [\"--enable require-variable-braces,deprecate-which\"]\n```\n\n## tflint Caveats\n\n### Using the `--config` argument\n\nWith the introduction of `--chdir` into tflint, the `--config` argument is now bound to whatever subdirectory you are\nrunning the check against.  For mono-repos this isn't ideal as you may have a central configuration file you'd like to\nuse.  If this matches your use-case, you can specify the placeholder `__GIT_ROOT__` value in the `--config` argument \nthat will evaluate to the root of the repository you are in.\n\n```yaml\nrepos:\n  - repo: https://github.com/gruntwork-io/pre-commit\n    rev: \u003cVERSION\u003e\n    hooks:\n    - id: tflint\n      args:\n        - \"--config=__GIT_ROOT__/.tflint.hcl\"\n```\n\n#### Changing the placeholder value\n\nYou can change the value of the placeholder by populating the `PRECOMMIT_TFLINT_REPO_ROOT_KEYWORD` environment variable.\n\n```bash\nexport PRECOMMIT_TFLINT_REPO_ROOT_KEYWORD=__foo__\n\ncat \u003c\u003cEOF \u003e .pre-commit-config.yaml\n---\nrepos:\n  - repo: https://github.com/gruntwork-io/pre-commit\n    rev: v0.1.22\n    hooks:\n    - id: terragrunt-hclfmt\n    - id: tflint\n      args:\n        - \"--config=__foo__/.tflint.hcl\"\nEOF\n\npre-commit run\n```\n\n## License\n\nThis code is released under the Apache 2.0 License. Please see [LICENSE](LICENSE) and [NOTICE](NOTICE) for more details.\n\nCopyright \u0026copy; 2019 Gruntwork, Inc.\n","funding_links":[],"categories":["Shell","bash"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgruntwork-io%2Fpre-commit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgruntwork-io%2Fpre-commit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgruntwork-io%2Fpre-commit/lists"}