Skip to content

Commit c7b18dc

Browse files
committed
Add linting with goimports to the pre-commit configuration
This will run the Go tool `goimports` against the repository if it contains any Go files. This tool bundles the functionality of `go fmt` with the additional benefit of sorting Go imports much like the isort tool we use for Python code.
1 parent c0eed09 commit c7b18dc

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ jobs:
109109
PACKAGE_URL: github.com/go-critic/go-critic/cmd/gocritic
110110
PACKAGE_VERSION: ${{ steps.setup-env.outputs.go-critic-version }}
111111
run: go install ${PACKAGE_URL}@${PACKAGE_VERSION}
112+
- name: Install goimports
113+
env:
114+
PACKAGE_URL: golang.org/x/tools/cmd/goimports
115+
PACKAGE_VERSION: ${{ steps.setup-env.outputs.goimports-version }}
116+
run: go install ${PACKAGE_URL}@${PACKAGE_VERSION}
112117
- name: Install gosec
113118
env:
114119
PACKAGE_URL: github.com/securego/gosec/v2/cmd/gosec

.pre-commit-config.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ repos:
7878
- id: go-vet-repo-mod
7979
# GoSec
8080
- id: go-sec-repo-mod
81-
81+
# goimports
82+
- id: go-imports-repo
83+
args:
84+
# Write changes to files
85+
- -w
8286
# Nix hooks
8387
- repo: https://github.com/nix-community/nixpkgs-fmt
8488
rev: v1.3.0

0 commit comments

Comments
 (0)