{"id":28270119,"url":"https://github.com/tekwizely/pre-commit-golang","last_synced_at":"2025-09-22T19:10:12.890Z","repository":{"id":36348510,"uuid":"193633912","full_name":"TekWizely/pre-commit-golang","owner":"TekWizely","description":"Pre-commit hooks for Golang with support for monorepos, the ability to pass arguments and environment variables to all hooks, and the ability to invoke custom go tools.","archived":false,"fork":false,"pushed_at":"2025-07-29T17:00:55.000Z","size":114,"stargazers_count":314,"open_issues_count":11,"forks_count":38,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-07-29T19:34:17.134Z","etag":null,"topics":["golang","mit-license","precommit-hooks"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TekWizely.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["TekWizely"]}},"created_at":"2019-06-25T04:22:00.000Z","updated_at":"2025-07-23T20:24:09.000Z","dependencies_parsed_at":"2024-06-20T00:25:48.780Z","dependency_job_id":"1cbce45a-0f4e-4195-ad6e-cc7b6da8b35d","html_url":"https://github.com/TekWizely/pre-commit-golang","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/TekWizely/pre-commit-golang","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TekWizely%2Fpre-commit-golang","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TekWizely%2Fpre-commit-golang/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TekWizely%2Fpre-commit-golang/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TekWizely%2Fpre-commit-golang/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TekWizely","download_url":"https://codeload.github.com/TekWizely/pre-commit-golang/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TekWizely%2Fpre-commit-golang/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276458380,"owners_count":25646129,"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","status":"online","status_checked_at":"2025-09-22T02:00:08.972Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["golang","mit-license","precommit-hooks"],"created_at":"2025-05-20T16:17:25.703Z","updated_at":"2025-09-22T19:10:12.883Z","avatar_url":"https://github.com/TekWizely.png","language":"Shell","funding_links":["https://github.com/sponsors/TekWizely"],"categories":[],"sub_categories":[],"readme":"# Pre-Commit-GoLang [![MIT license](https://img.shields.io/badge/License-MIT-green.svg)](https://github.com/tekwizely/pre-commit-golang/blob/master/LICENSE)\n\nA set of git pre-commit hooks for Golang with support for multi-module monorepos, the ability to pass arguments and environment variables to all hooks, and the ability to invoke custom go tools.\n\nRequires the [Pre-Commit.com](https://pre-commit.com) Hook Management Framework.\n\n---------------\n## Installation\n\nYou can copy/paste the following snippet into your `.pre-commit-config.yaml` file.\n\n**NOTE** A more fleshed-out version can be found in [`sample-config.yaml`](https://github.com/TekWizely/pre-commit-golang/blob/master/sample-config.yaml)\n\n```yaml\n    # ==========================================================================\n    # Golang Pre-Commit Hooks | https://github.com/tekwizely/pre-commit-golang\n    #\n    # !! ALL Hooks enabled by default - Comment out hooks you are not using\n    #\n    # Visit the project home page to learn more about the available Hooks,\n    # including useful arguments you might want to pass into them.\n    #\n    # NOTE: When passing options to hooks, if your options contain a reference\n    #       to an existing file, then you will need to use a trailing '--'\n    #       argument to separate the hook options from the modified-file list\n    #       that Pre-Commit passes into the hook.\n    #       For repo-based hooks, '--' is not needed.\n    #\n    # NOTE: You can pass environment variables to hooks using args with the\n    #       following format:\n    #\n    #           --hook:env:NAME=VALUE\n    #\n    # Consider adding aliases to longer-named hooks for easier CLI usage.\n    # ==========================================================================\n-   repo: https://github.com/tekwizely/pre-commit-golang\n    # See 'pre-commit help autoupdate'\n    rev: v1.0.0-rc.2\n    hooks:\n    #\n    # Go Build\n    #\n    -   id: go-build-mod\n    -   id: go-build-pkg\n    -   id: go-build-repo-mod\n    -   id: go-build-repo-pkg\n    #\n    # Go Mod Tidy\n    #\n    -   id: go-mod-tidy\n    -   id: go-mod-tidy-repo\n    #\n    # Go Test\n    #\n    -   id: go-test-mod\n    -   id: go-test-pkg\n    -   id: go-test-repo-mod\n    -   id: go-test-repo-pkg\n    #\n    # Go Vet\n    #\n    -   id: go-vet\n    -   id: go-vet-mod\n    -   id: go-vet-pkg\n    -   id: go-vet-repo-mod\n    -   id: go-vet-repo-pkg\n    #\n    # Revive\n    #\n    -   id: go-revive\n    -   id: go-revive-mod\n    -   id: go-revive-repo-mod\n    #\n    # GoSec\n    #\n    -   id: go-sec-mod\n    -   id: go-sec-pkg\n    -   id: go-sec-repo-mod\n    -   id: go-sec-repo-pkg\n    #\n    # StaticCheck\n    #\n    -   id: go-staticcheck-mod\n    -   id: go-staticcheck-pkg\n    -   id: go-staticcheck-repo-mod\n    -   id: go-staticcheck-repo-pkg\n    #\n    # StructSlop\n    #\n    -   id: go-structslop-mod\n    -   id: go-structslop-pkg\n    -   id: go-structslop-repo-mod\n    -   id: go-structslop-repo-pkg\n    #\n    # Formatters\n    #\n    -   id: go-fmt\n    -   id: go-fmt-repo\n    -   id: go-fumpt        # replaces go-fmt\n    -   id: go-fumpt-repo   # replaces go-fmt-repo\n    -   id: go-imports      # replaces go-fmt\n    -   id: go-imports-repo # replaces go-fmt-repo\n    -   id: go-returns      # replaces go-imports \u0026 go-fmt\n    -   id: go-returns-repo # replaces go-imports-repo \u0026 go-fmt-repo\n    #\n    # Style Checkers\n    #\n    -   id: go-lint\n    -   id: go-critic\n    #\n    # GolangCI-Lint\n    # - Fast Multi-Linter\n    # - Can be configured to replace MOST other hooks\n    # - Supports repo config file for configuration\n    # - https://github.com/golangci/golangci-lint\n    #\n    -   id: golangci-lint\n    -   id: golangci-lint-mod\n    -   id: golangci-lint-pkg\n    -   id: golangci-lint-repo-mod\n    -   id: golangci-lint-repo-pkg\n    #\n    # Invoking Custom Go Tools\n    # - Configured *entirely* through the `args` attribute, ie:\n    #   args: [ go, test, ./... ]\n    # - Use arg `--hook:error-on-output` to indicate that any output from the tool\n    #   should be treated as an error.\n    # - Use the `name` attribute to provide better messaging when the hook runs\n    # - Use the `alias` attribute to be able to invoke your hook via `pre-commit run`\n    #\n    -   id: my-cmd\n    -   id: my-cmd-mod\n    -   id: my-cmd-pkg\n    -   id: my-cmd-repo\n    -   id: my-cmd-repo-mod\n    -   id: my-cmd-repo-pkg\n```\n\n-----------\n## Overview\n\n### Hook Targets\n\n#### File-Based Hooks\nSome hooks run against matching staged files individually.\n\n##### Module-Based Hooks\nSome hooks work on a per-module basis.  The hooks run against module root folders containing one or more matching staged files.\n\n_Module Root Folder:_ A folder containing a `go.mod` file.  Discovered by walking up the folder path from the staged file.\n\n###### Module Mode\nModule-based hooks enable module mode (`GO111MODULE=on`) before invoking their respective tools.\n\n##### Package-Based Hooks\nSome hooks work on a per-package basis.  The hooks run against folders containing one or more staged files.\n\n_Package Folder:_ A folder containing one or more `.go` files.\n\n###### Package Mode\nPackage-based hooks disable module mode (`GO111MODULE=off`) before invoking their respective tools.\n\n##### Repo-Based Hooks\nSome hooks run against the entire repo.  The hooks only run once (if any matching files are staged), and are NOT provided the list of staged files,\n\n-----------------\n### Hook Suffixes\nHooks have suffixes in their name that indicate their targets:\n\n| Suffix      | Target       | Description                                       |\n|-------------|--------------|---------------------------------------------------|\n| \\\u003cnone\u003e     | Files        | Targets staged files directly                     |\n| `-mod`      | Module       | Targets module root folders of staged `.go` files |\n| `-pkg`      | Package      | Targets folders containing staged `.go` files     |\n| `-repo`     | Repo Root    | Targets the repo root folder                      |\n| `-repo-mod` | All Modules  | Targets all module root folders in the repo       |\n| `-repo-pkg` | All Packages | Targets all package folders in the repo           |\n\n-----------------------------\n### Multiple Hook Invocations\nDue to OS command-line-length limits, Pre-Commit can invoke a hook multiple times if a large number of files are staged.\n\nFor file and repo-based hooks, this isn't an issue, but for module and package-based hooks, there is a potential for the hook to run against the same module or package multiple times, duplicating any errors or warnings.\n\n-------------------------\n### Invoking Custom Tools\nWhile this project includes builtin hooks for many popular go tools, it's not possible to include builtin hooks for every tool that users might want to use.\n\nTo help accommodate those users, this project includes the ability to invoke custom go tools.\n\nSee the [my-cmd](#my-cmd) hooks for more information.\n\n--------------------------\n### Useful Hook Parameters\n```\n-   id: hook-id\n    args: [arg1, arg2, ..., '--'] # Pass options ('--' is optional)\n    always_run: true              # Run even if no matching files staged\n    alias: hook-alias             # Create an alias\n    verbose: true                 # Display output, even if no errors\n```\n\n#### Passing Options To Hooks\nYou can pass options into individual hooks to customize tool behavior.\n\nIf your options contain a reference to an existing file, then you\nwill need to use a trailing `'--'` argument to separate the hook options from\nthe modified-file list that Pre-Commit passes into the hook.\n\n**NOTE:** For repo-based hooks, `'--'` is not needed.\n\nSee each hook's description below for some popular options that you might want to use.\n\nAdditionally, you can view each tool's individual home page or help settings to learn about all the available options.\n\n#### Passing Environment Variables To Hooks\nYou can pass environment variables to hooks to customize tool behavior.\n\n**NOTE:** The Pre-Commit framework does not directly support the ability to pass environment variables to hooks.\n\nThis feature is enabled via support for a specially-formatted argument:\n\n* `--hook:env:NAME=VALUE`\n\nThe hook script will detect this argument and set the variable `NAME` to the value `VALUE` before invoking the configured tool.\n\nYou can pass multiple  `--hook:env:` arguments.\n\nThe arguments can appear anywhere in the `args:` list.\n\n#### Passing Ignore Patterns To Hooks\n\nYou can pass arguments to hooks to specify files / directories to ignore.\n\n##### Ignoring Directories\n\nTo specify a directory to ignore, use:\n\n* `--hook:ignore-dir=PATTERN`\n\n**Pattern Syntax**\n\nHere's a table with examples of how the directory ignore patterns work:\n\n| \u003csub\u003e(see legend below)\u003c/sub\u003e | `/foo` | `/foo/bar` | `/foo/*/bar` | `bar` | `bing/bar` | `bing/*/bar` | `foo/*/bang/*/bar` |\n|:------------------------------|:------:|:----------:|:------------:|:-----:|:----------:|:------------:|:------------------:|\n| `file`                        |        |            |              |       |            |              |                    |\n| `foo/file`                    |   ✔    |            |              |       |            |              |                    |\n| `foo/bar/file`                |   ✔    |     ✔      |              |   ✔   |            |              |                    |\n| `foo/bing/bar/file`           |   ✔    |            |      ✔       |   ✔   |     ✔      |              |                    |\n| `foo/bing/bang/bar/file`      |   ✔    |            |      ✔       |   ✔   |            |      ✔       |                    |\n| `foo/bing/bang/baz/bar/file`  |   ✔    |            |      ✔       |   ✔   |            |      ✔       |         ✔          |\n| `bar/file`                    |        |            |              |   ✔   |            |              |                    |\n| `bing/bar/file`               |        |            |              |   ✔   |     ✔      |              |                    |\n| `bing/bang/bar/file`          |        |            |              |   ✔   |            |      ✔       |                    |\n\n\u003csub\u003erows = filenames. columns = ignore patterns. ✔ = directory ignored (matched).\u003c/sub\u003e\n\nNOTES:\n* Only the directory portion of the filename is considered for matching\n  * File `foo/bar/file` would attempt to match patterns against the directory `foo/bar`\n* Patterns with leading slash (`/`) indicate that the pattern is _anchored_ and must match the **beginning** of the directory path\n  * Pattern `/bar` would match filenames `bar/file` and `bar/bang/file`, but **not** `foo/bar/file`\n* Patterns without leading slash (`/`) indicate that the pattern is _floating_ and can match **anywhere** in the directory path\n  * Pattern `bar` would match **all** filenames `bar/file`, `bar/bang/file` and `foo/bar/file`\n* Trailing slashes (`foo/`) are not supported and are ignored\n* Explicit Leading and trailing wildcards (`*/foo`, `foo/*`, `*/foo/*`) are not supported\n* Recursive directory patterns (`**`) are not supported\n\n##### Ignoring Files\n\nTo specify files to ignore, use:\n\n* `--hook:ignore-file=PATTERN`\n\n**Pattern Syntax**\n\nHere's a table with examples of how the file ignore patterns work:\n\n| \u003csub\u003e(see legend below)\u003c/sub\u003e | `file1.txt` | `file?.txt` | `file2.*` | `*.md` | `bar/*.md` | `/bar/*.txt` |\n|:------------------------------|:-----------:|:-----------:|:---------:|:------:|:----------:|:------------:|\n| `file1.txt`                   |      ✔      |      ✔      |           |        |            |              |\n| `file2.txt`                   |             |      ✔      |     ✔     |        |            |              |\n| `file3.md`                    |             |             |           |   ✔    |            |              |\n| `foo/file1.txt`               |      ✔      |      ✔      |           |        |            |              |\n| `bar/file1.txt`               |      ✔      |      ✔      |           |        |            |      ✔       |\n| `bar/file2.md`                |             |             |     ✔     |   ✔    |     ✔      |              |\n| `foo/bar/file4.txt`           |             |      ✔      |           |        |            |              |\n| `foo/bar/file5.md`            |             |             |           |   ✔    |     ✔      |              |\n\n\u003csub\u003erows = filenames. columns = ignore patterns. ✔ = file ignored (matched).\u003c/sub\u003e\n\nNOTES:\n* Patterns with no slashes (`/`) are only matched against the filename portion of the file path\n    * Pattern `file.txt` would match filenames `file.txt`, `foo/file.txt`, and `bar/file.txt`\n* Patterns with leading slash (`/`) indicate that the pattern is _anchored_ and must match the **full** file path\n    * Pattern `/bar/file` would match filename `bar/file`, but **not** `foo/bar/file`\n* Patterns without leading slash (`/`) indicate that the pattern is _trailing_ and just needs to match the **end** of the file path\n    * Pattern `bar/file` would match filenames `bar/file` and `foo/bar/file`\n* Explicit Leading  (`*/foo/file`) are not supported\n* Recursive directory patterns (`**`) are not supported\n\n\n##### Ignore By Pattern\n\nIf the directory and file-based convenience options are not enough, you can specify a more complicated (bash-specific) pattern.\n\nTo specify these types of patterns to ignore, use:\n\n* `--hook:ignore-pattern=PATTERN`\n\n**Pattern Syntax**\n\nHere's a table with examples of how the general ignore patterns work:\n\n| \u003csub\u003e(see legend below)\u003c/sub\u003e | `file` | `foo/bar/*` | `foo/*/bar/*` | `*/file` | `*/bar/file` | `*/bar/*` | `*/bing/*/bar/*` | `*/b?ng/*/file` |\n|:------------------------------|:------:|:-----------:|:-------------:|:--------:|:------------:|:---------:|:----------------:|:---------------:|\n| `file`                        |   ✔    |             |               |          |              |           |                  |                 |\n| `foo/file`                    |        |             |               |    ✔     |              |           |                  |                 |\n| `foo/bar/file`                |        |      ✔      |               |    ✔     |      ✔       |     ✔     |                  |                 |\n| `foo/bing/bar/file`           |        |             |       ✔       |    ✔     |      ✔       |     ✔     |                  |        ✔        |\n| `foo/bang/bar/file`           |        |             |       ✔       |    ✔     |      ✔       |     ✔     |                  |        ✔        |\n| `foo/bing/bang/bar/file`      |        |             |       ✔       |    ✔     |      ✔       |     ✔     |        ✔         |        ✔        |\n| `foo/bing/bang/baz/bar/file`  |        |             |       ✔       |    ✔     |      ✔       |     ✔     |        ✔         |        ✔        |\n| `bar/file`                    |        |             |               |    ✔     |              |           |                  |                 |\n| `bing/bar/file`               |        |             |               |    ✔     |      ✔       |     ✔     |                  |                 |\n| `bing/bang/bar/file`          |        |             |               |    ✔     |      ✔       |     ✔     |                  |        ✔        |\n| `.file`                       |        |             |               |          |              |           |                  |                 |\n| `.bar/file`                   |        |             |               |    ✔     |              |           |                  |                 |\n| `foo/.bang/bar/file`          |        |             |       ✔       |    ✔     |      ✔       |     ✔     |                  |                 |\n\n\u003csub\u003erows = filenames. columns = ignore patterns. ✔ = file ignored (matched).\u003c/sub\u003e\n\nNOTES:\n* Patterns are matched against the **full** (relative) file path\n* Patterns are Bash-specific (although _possibly_ POSIX compliant) and are **not** regular expressions (regex)\n* See the Official Bash documentation for [Pattern Matching](https://www.gnu.org/software/bash/manual/bash.html#Pattern-Matching)\n* Patterns based on `extglob` setting/syntax are **not** supported\n\n#### Always Run\nBy default, hooks ONLY run when matching file types (usually `*.go`) are staged.\n\nWhen configured to `\"always_run\"`, a hook is executed as if EVERY matching file were staged.\n\n#### Aliases / Names\n\npre-commit supports the ability to assign both an `alias` and a `name` to a configured hook:\n\n| config | description                                                                                             |\n|--------|---------------------------------------------------------------------------------------------------------|\n| alias  | (optional) allows the hook to be referenced using an additional id when using `pre-commit run \u003chookid\u003e` |\n| name   | (optional) override the name of the hook - shown during hook execution                                  |\n\nThese are beneficial for a couple of reasons:\n\n* Creating short names for long-named hooks for easier CLI usage:\n```\n# ...\n      hooks:\n        -   id: go-build-repo-mod\n            alias: build\n```\n_usage_\n```\n$ pre-commit run build\n```\n\n* Having variations of a given hook with different configurations:\n```\n# ...\n    hooks:\n      -   id: go-fmt\n\n          # Add a second go-fmt hook with -w enabled\n          # Configure so it only runs when manually invoked\n      -   id: go-fmt\n          args: [ -w ]\n          alias: go-fmtw-alias\n          name: go-fmtw-name\n          stages: [manual]\n```\n **NOTE:** When creating variations, take note that the `alias` is used to execute the hook, but the the `name` is used in the hook report.\n\n _usage: alias vs name_\n```\n $ pre-commit run --hook-stage manual go-fmtw-alias\n\n go-fmtw-name................................Passed\n```\n\n#### Verbose Hook Output\nWhen the `\"verbose\"` flag is enabled, all output generated by the hook will be displayed, even if there were no errors.\n\nThis can be useful, for example, for hooks that display warnings, but don't generate error codes for them.\n\n--------\n## Hooks\n\n - Build Tools\n   - [go-build](#go-build)\n   - [go-mod-tidy](#go-mod-tidy)\n - Correctness Checkers\n   - [go-test](#go-test)\n   - [go-vet](#go-vet)\n   - [go-sec](#go-sec)\n   - [go-staticcheck](#go-staticcheck)\n   - [go-structslop](#go-structslop)\n - Formatters\n   - [go-fmt](#go-fmt)\n   - [go-fumpt](#go-fumpt)\n   - [go-imports](#go-imports)\n   - [go-returns](#go-returns)\n - Style Checkers\n   - [go-lint](#go-lint)\n   - [go-critic](#go-critic)\n   - [go-revive](#go-revive)\n - GolangCI-Lint\n   - [golangci-lint](#golangci-lint)\n - Invoking Custom Tools\n   - [my-cmd](#my-cmd)\n\n------------\n### go-build\nCompiles packages, along with their dependencies, but does not install the results.\n\n| Hook ID             | Description                                                                                |\n|---------------------|--------------------------------------------------------------------------------------------|\n| `go-build-mod`      | Run `'cd $(mod_root $FILE); go build -o /dev/null [$ARGS] ./...'` for each staged .go file |\n| `go-build-pkg`      | Run `'go build -o /dev/null [$ARGS] ./$(dirname $FILE)'` for each staged .go file          |\n| `go-build-repo-mod` | Run `'cd $(mod_root); go build -o /dev/null [$ARGS] ./...'` for each module in the repo    |\n| `go-build-repo-pkg` | Run `'go build -o /dev/null [$ARGS] ./...'` in repo root folder                            |\n\n##### Install\nComes with Golang ( [golang.org](https://golang.org/) )\n\n##### Help\n - https://golang.org/cmd/go/#hdr-Compile_packages_and_dependencies\n - `go help build`\n\n---------------\n### go-mod-tidy\nMakes sure `go.mod` matches the source code in the module.\n\n| Hook ID            | Description                                                                      |\n|--------------------|----------------------------------------------------------------------------------|\n| `go-mod-tidy`      | Run `'cd $(mod_root $FILE); go mod tidy [$ARGS] ./...'` for each staged .go file |\n| `go-mod-tidy-repo` | Run `'cd $(mod_root); go mod tidy [$ARGS] ./...'` for each module in the repo    |\n\n##### Install\nComes with Golang ( [golang.org](https://golang.org/) )\n\n##### Help\n - https://golang.org/ref/mod#go-mod-tidy\n - `go mod help tidy`\n\n-----------\n### go-test\nAutomates testing, printing a summary of test results.\n\n| Hook ID            | Description                                                                  |\n|--------------------|------------------------------------------------------------------------------|\n| `go-test-mod`      | Run `'cd $(mod_root $FILE); go test [$ARGS] ./...'` for each staged .go file |\n| `go-test-pkg`      | Run `'go test [$ARGS] ./$(dirname $FILE)'` for each staged .go file          |\n| `go-test-repo-mod` | Run `'cd $(mod_root); go test [$ARGS] ./...'` for each module in the repo    |\n| `go-test-repo-pkg` | Run `'go test [$ARGS] ./...'` in repo root folder                            |\n\n##### Install\nComes with Golang ( [golang.org](https://golang.org/) )\n\n##### Help\n - https://golang.org/cmd/go/#hdr-Test_packages\n - `go help test`\n\n----------\n### go-sec\nInspects source code for security problems by scanning the Go AST.\n\n| Hook ID           | Description                                                                |\n|-------------------|----------------------------------------------------------------------------|\n| `go-sec-mod`      | Run `'cd $(mod_root $FILE); gosec [$ARGS] ./...'` for each staged .go file |\n| `go-sec-pkg`      | Run `'gosec [$ARGS] ./$(dirname $FILE)'` for each staged .go file          |\n| `go-sec-repo-mod` | Run `'cd $(mod_root); gosec [$ARGS] ./...'` for each module in the repo    |\n| `go-sec-repo-pkg` | Run `'gosec [$ARGS] ./...'` in repo root folder                            |\n\n##### Install (via [bingo](https://github.com/TekWizely/bingo))\n```\nbingo install github.com/securego/gosec/v2/cmd/gosec\n```\n\n##### Help\n - https://github.com/securego/gosec#usage\n - `gosec (no args)`\n\n------------------\n### go-staticcheck\nA state of the art linter for the Go programming language. Using static analysis, it finds bugs and performance issues, offers simplifications, and enforces style rules.\n\n| Hook ID                   | Description                                                                      |\n|---------------------------|----------------------------------------------------------------------------------|\n| `go-staticcheck-mod`      | Run `'cd $(mod_root $FILE); staticcheck [$ARGS] ./...'` for each staged .go file |\n| `go-staticcheck-pkg`      | Run `'staticcheck [$ARGS] ./$(dirname $FILE)'` for each staged .go file          |\n| `go-staticcheck-repo-mod` | Run `'cd $(mod_root); staticcheck [$ARGS] ./...'` for each module in the repo    |\n| `go-staticcheck-repo-pkg` | Run `'staticcheck [$ARGS] ./...'` in repo root folder                            |\n\n##### Install (via [bingo](https://github.com/TekWizely/bingo))\n```\nbingo install honnef.co/go/tools/cmd/staticcheck\n```\n\n##### Help\n - https://staticcheck.io/\n - `staticcheck -h`\n\n-----------------\n### go-structslop\nRecommends struct field rearrangements to provide for maximum space/allocation efficiency.\n\n - Can modify files (see `-apply`)\n\n| Hook ID                  | Description                                                                     |\n|--------------------------|---------------------------------------------------------------------------------|\n| `go-structslop-mod`      | Run `'cd $(mod_root $FILE); structslop [$ARGS] ./...'` for each staged .go file |\n| `go-structslop-pkg`      | Run `'structslop [$ARGS] ./$(dirname $FILE)'` for each staged .go file          |\n| `go-structslop-repo-mod` | Run `'cd $(mod_root); structslop [$ARGS] ./...'` for each module in the repo    |\n| `go-structslop-repo-pkg` | Run `'structslop [$ARGS] ./...'` in repo root folder                            |\n\n##### Install (via [bingo](https://github.com/TekWizely/bingo))\n```\nbingo install github.com/orijtech/structslop/cmd/structslop\n```\n\n##### Useful Args\n```\n-apply : apply suggested fixes\n```\n\n##### Help\n - https://github.com/orijtech/structslop#usage\n - `structslop -h`\n\n----------\n### go-vet\nExamines Go source code and reports suspicious constructs, such as\nPrintf calls whose arguments do not align with the format string. Vet uses\nheuristics that do not guarantee all reports are genuine problems, but it\ncan find errors not caught by the compilers.\n\n| Hook ID           | Description                                                                 |\n|-------------------|-----------------------------------------------------------------------------|\n| `go-vet`          | Run `'go vet [$ARGS] $FILE'` for each staged .go file                       |\n| `go-vet-mod`      | Run `'cd $(mod_root $FILE); go vet [$ARGS] ./...'` for each staged .go file |\n| `go-vet-pkg`      | Run `'go vet [$ARGS] ./$(dirname $FILE)'` for each staged .go file          |\n| `go-vet-repo-mod` | Run `'cd $(mod_root); go vet [$ARGS] ./...'` for each module in the repo    |\n| `go-vet-repo-pkg` | Run `'go vet [$ARGS] ./...'` in repo root folder                            |\n\n##### Install\nComes with Golang ( [golang.org](https://golang.org/) )\n\n##### Help\n - https://golang.org/cmd/go/#hdr-Report_likely_mistakes_in_packages\n - `go doc cmd/vet`\n\n----------\n### go-fmt\nFormats Go programs. It uses tabs for indentation and blanks for alignment. Alignment assumes that an editor is using a fixed-width font.\n\n - Can modify files (see `-w`)\n\n| Hook ID       | Description                                                |\n|---------------|------------------------------------------------------------|\n| `go-fmt`      | Run `'gofmt -l -d [$ARGS] $FILE'` for each staged .go file |\n| `go-fmt-repo` | Run `'gofmt -l -d [$ARGS] .'` in repo root folder          |\n\n##### Install\nComes with Golang ( [golang.org](https://golang.org/) )\n\n##### Useful Args\n```\n-d=false : Hide diffs\n-s       : Try to simplify code\n-w       : Update source file directly\n```\n\n##### Help\n - https://godoc.org/github.com/golang/go/src/cmd/gofmt\n - `gofmt -h`\n\n------------\n### go-fumpt\nEnforce a stricter format than `gofmt`, while being backwards compatible.\n\n - Replaces `go-fmt`\n - Can modify files (see `-w`)\n\n| Hook ID         | Description                                                  |\n|-----------------|--------------------------------------------------------------|\n| `go-fumpt`      | Run `'gofumpt -l -d [$ARGS] $FILE'` for each staged .go file |\n| `go-fumpt-repo` | Run `'gofumpt -l -d [$ARGS] .'` in repo root folder          |\n\n##### Install (via [bingo](https://github.com/TekWizely/bingo))\n```\nbingo install mvdan.cc/gofumpt\n```\n\n##### Useful Args\n```\n-d=false : Hide diffs\n-extra   : Enable extra rules which should be vetted by a human\n-s       : Try to simplify code\n-w       : Update source file directly\n```\n\n##### Help\n - https://pkg.go.dev/mvdan.cc/gofumpt\n - `gofumpt -h`\n\n--------------\n### go-imports\nUpdates your Go import lines, adding missing ones and removing unreferenced ones.\n\n - Replaces `go-fmt`\n - Can modify files (see `-w`)\n\n| Hook ID           | Description                                                    |\n|-------------------|----------------------------------------------------------------|\n| `go-imports`      | Run `'goimports -l -d [$ARGS] $FILE'` for each staged .go file |\n| `go-imports-repo` | Run `'goimports -l -d [$ARGS] .'` in repo root folder          |\n\n##### Install (via [bingo](https://github.com/TekWizely/bingo))\n```\nbingo install golang.org/x/tools/cmd/goimports\n```\n\n##### Useful Args\n```\n-d=false        : Hide diffs\n-format-only    : Do not fix imports, act ONLY as go-fmt\n-local prefixes : Add imports matching prefix AFTER 3rd party packages\n                  (prefixes = comma-separated list)\n-v              : Verbose logging\n-w              : Update source file directly\n```\n\n##### Help\n - https://godoc.org/golang.org/x/tools/cmd/goimports\n - `goimports -h`\n\n--------------\n### go-returns\nImplements a Go pretty-printer (like `go-fmt`) that also adds zero-value return values as necessary to incomplete return statements.\n\n - Replaces `go-fmt` and `go-imports`\n - Can modify files (see `-w`)\n\n| Hook ID           | Description                                                    |\n|-------------------|----------------------------------------------------------------|\n| `go-returns`      | Run `'goreturns -l -d [$ARGS] $FILE'` for each staged .go file |\n| `go-returns-repo` | Run `'goreturns -l -d [$ARGS] .'` in repo root folder          |\n\n##### Install (via [bingo](https://github.com/TekWizely/bingo))\n```\nbingo install github.com/sqs/goreturns\n```\n\n##### Useful Args\n```\n-b              : Remove bare returns\n-d=false        : Hide diffs\n-i=false        : Disable go-imports\n-local prefixes : Add imports matching prefix AFTER 3rd party packages\n                  (prefixes = comma-separated list)\n-p              : Print non-fatal type-checking errors to STDERR\n-s              : Try to simplify code\n-w              : Update source file directly\n```\n\n##### Help\n - https://godoc.org/github.com/sqs/goreturns\n - `goreturns -h`\n\n-----------\n### go-lint\nA linter for Go source code, meant to carry out the stylistic conventions put forth in [Effective Go](https://golang.org/doc/effective_go.html) and [CodeReviewComments](https://golang.org/wiki/CodeReviewComments).\n\n| Hook ID   | Description                                                            |\n|-----------|------------------------------------------------------------------------|\n| `go-lint` | Run `'golint -set_exit_status [$ARGS] $FILE'` for each staged .go file |\n\n##### Install (via [bingo](https://github.com/TekWizely/bingo))\n```\nbingo install golang.org/x/lint/golint\n```\n\n##### Help\n - https://godoc.org/golang.org/x/lint\n - `golint -h`\n - https://golang.org/doc/effective_go.html\n - https://golang.org/wiki/CodeReviewComments\n\n-------------\n### go-revive\n\\~6x faster, stricter, configurable, extensible, and beautiful drop-in replacement for golint.\n\n| Hook ID              | Description                                                                 |\n|----------------------|-----------------------------------------------------------------------------|\n| `go-revive`          | Run `'revive [$ARGS] $FILE'` for each staged .go file                       |\n| `go-revive-mod`      | Run `'cd $(mod_root $FILE); revive [$ARGS] ./...'` for each staged .go file |\n| `go-revive-repo-mod` | Run `'cd $(mod_root); revive [$ARGS] ./...'` for each module in the repo    |\n\n##### Support for Repository-Level Config\nAs of time of writing, revive only auto-checks for configs in `${HOME}/revive.toml`, and doesn't check the local folder (ie. `${REPO_ROOT}/revive.toml`).\n\nTo make revive more useful, these hooks add built-in support for a repository-level config file.\n\n###### Auto-Configured\nThese hooks are configured to auto-add `-config=revive.toml` when the file is present in the repository root.\n\n###### Triggerred When Modified\nThese hooks are configured to run when the repo-level `revive.toml` file is modified (and staged).\n\n**NOTE:** Although configured to run, the file-based `go-revive` hook will, by default, effectively _do nothing_ if there are no staged `.go` files to run against.\n\n##### Install (via [bingo](https://github.com/TekWizely/bingo))\n```\nbingo install github.com/mgechev/revive\n```\n\n##### Useful Args\n```\n-config [PATH]     : Path to config file (TOML)\n-exclude [PATTERN] : Pattern for files/directories/packages to be excluded from linting\n-formatter [NAME]  : formatter to be used for the output\n```\n\n##### Displaying Warnings\nBy default, `revive` doesn't generate errors on warnings, so warning messages may not be displayed if there are no accompanying error messages.\n\nYou can use the `\"verbose: true\"` hook configuration to always show hook output.\n\n##### Help\n - https://github.com/mgechev/revive#usage\n - `revive -h`\n\n-------------\n### go-critic\nThe most opinionated Go source code linter for code audit.\n\n| Hook ID     | Description                                                   |\n|-------------|---------------------------------------------------------------|\n| `go-critic` | Run `'gocritic check [$ARGS] $FILE'` for each staged .go file |\n\n##### Install\n   https://github.com/go-critic/go-critic#installation\n\n##### Useful Args\n```\n-enableAll        : Enable ALL checkers\n-enable checkers  : comma-separated list of checkers to be enabled\n                    (can include #tags)\n-disable checkers : comma-separated list of checkers to be disabled\n                    (can include #tags)\n```\n**Tags**\n - `#diagnostic`\n - `#style`\n - `#opinionated`\n - `#performance`\n - `#experimental`\n\n#### Help\n - https://go-critic.github.io/overview\n - `gocritic check -help`\n\n-----------------\n### golangci-lint\nA FAST linter aggregator, with colored output, fewer false-positives, and support for yaml/toml configuration.\n\n - Manages multiple linters\n - Can replace many/most other hooks\n - Can report only new issues (see `--new`)\n - Can modify files (see `--fix`)\n\n| Hook ID                  | Description                                                                            |\n|--------------------------|----------------------------------------------------------------------------------------|\n| `golangci-lint`          | Run `'golangci-lint run [$ARGS] $FILE'` for each staged .go file                       |\n| `golangci-lint-mod`      | Run `'cd $(mod_root $FILE); golangci-lint run [$ARGS] ./...'` for each staged .go file |\n| `golangci-lint-pkg`      | Run `'golangci-lint run [$ARGS] ./$(dirname $FILE)'` for each staged .go file          |\n| `golangci-lint-repo-mod` | Run `'cd $(mod_root); golangci-lint run [$ARGS] ./...'` for each module in the repo    |\n| `golangci-lint-repo-pkg` | Run `'golangci-lint run [$ARGS] ./...'` in repo root folder                            |\n\n##### Install (via [bingo](https://github.com/TekWizely/bingo))\n```\nbingo install github.com/golangci/golangci-lint/cmd/golangci-lint\n```\n##### Useful Args\n```\n   --config PATH     : Specify config file\n   --disable linters : Disable specific linter(s)\n   --enable-all      : Enable ALL linters\n   --enable linters  : Enable specific linter(s)\n   --fast            : Run only fast linters (from enabled linters sets)\n   --fix             : Fix found issues (if supported by linter)\n   --new             : Show only new issues (see help for further details)\n   --no-config       : don't read config file\n   --presets presets : Enable presets of linters\n```\n**Presets**\n - `bugs`\n - `complexity`\n - `format`\n - `performance`\n - `style`\n - `unused`\n\n##### Help\n - https://github.com/golangci/golangci-lint#quick-start\n - `golangci-lint run -h`\n\n##### Config File Help:\n - https://github.com/golangci/golangci-lint#config-file\n - `golangci-lint config -h`\n\n----------\n### my-cmd\n\nUsing the `my-cmd-*` hooks, you can invoke custom go tools in various contexts.\n\n| Hook ID           | Description                                                                                |\n|-------------------|--------------------------------------------------------------------------------------------|\n| `my-cmd`          | Run `'$ARGS[0] [$ARGS[1:]] $FILE'` for each staged .go file                                |\n| `my-cmd-mod`      | Run `'cd $(mod_root $FILE); GO111MODULE=on $ARGS[0] [$ARGS[1:]]'` for each staged .go file |\n| `my-cmd-pkg`      | Run `'GO111MODULE=off $ARGS[0] [$ARGS[1:]] ./$(dirname $FILE)'` for each staged .go file   |\n| `my-cmd-repo`     | Run `'$ARGS[0] [$ARGS[1:]]'` in the repo root folder                                       |\n| `my-cmd-repo-mod` | Run `'cd $(mod_root); GO111MODULE=on $ARGS[0] [$ARGS[1:]]'` for each module in the repo    |\n| `my-cmd-repo-pkg` | Run `'GO111MODULE=off $ARGS[0] [$ARGS[1:]]` in repo root folder                            |\n\n#### Configuring the hooks\n\nThe my-cmd hooks are configured **entirely** through the pre-commit `args` attribute, including specifying which tool to run (ie `$ARGS[0]` above).\n\nThis includes the need to manually add the `./...` target for module-based tools that require it.\n\n#### Examples\n\nHere's an example of what it would look like to use the my-cmd hooks to invoke `go test` if it wasn't already included:\n\n_.pre-commit-config.yaml_\n```\n# ...\n      hooks:\n            # Run 'cd $(mod_root $FILE); go test ./...' for each staged .go file\n        -   id: my-cmd-mod\n            name: go-test-mod\n            alias: go-test-mod\n            args: [ go, test, ./... ]\n```\n\n##### Names \u0026amp; Aliases\n\nIt is recommended that you use both `name` and `alias` attributes when defining my-cmd hooks.\n\nThe name will provide better messaging when the hook runs.\n\nThe alias will enable you to invoke the hook manually from the command-line when needed (see `pre-commit help run`)\n\n##### error-on-output\n\nSome tools, like `gofmt`, `goimports`, and `goreturns`, don't generate error codes, but instead expect the presence of any output to indicate warning/error conditions.\n\nThe my-cmd hooks accept a `--hook:error-on-output` argument to indicate this behavior.\n\nHere's an example of what it would look like to use the my-cmd hooks to invoke `gofmt` if it wasn't already included:\n\n_.pre-commit-config.yaml_\n```\n# ...\n      hooks:\n            # Run 'gofmt -l -d $FILE' for each staged .go file\n            # Treat any output as indication of failure\n        -   id: my-cmd\n            name: go-fmt\n            alias: go-fmt\n            args: [ gofmt, -l, -d, --hook:error-on-output]\n```\n\n**NOTE:** The plain `--error-on-output` option is now deprecated, but still supported, as long as it's the **very first** entry in the `args:` list.\n\n----------\n## License\n\nThe `tekwizely/pre-commit-golang` project is released under the [MIT](https://opensource.org/licenses/MIT) License.  See `LICENSE` file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftekwizely%2Fpre-commit-golang","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftekwizely%2Fpre-commit-golang","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftekwizely%2Fpre-commit-golang/lists"}