Skip to content

Commit 23bb64b

Browse files
committed
Fix running golangci-lint in different packages
The built-in typecheck cannot run on single files and will cause a compilation error as soon as we attempt to lint a file that requires a file from the same package. As a best-effort workaround now linting the entire package a file has been changed in in the pre-commit hook. golangci/golangci-lint#1574 (comment) golangci/golangci-lint#2912
1 parent 11dcce3 commit 23bb64b

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

go.yaml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@ pre-commit:
77
golangci-lint:
88
tags: lint go
99
glob: "*.go"
10-
# `golangci-lint run` requires all files to be in the same package
11-
# when passing it named files, thus in order to only lint staged files
12-
# in the pre-commit hook linting them one by one...
13-
run: for file in {staged_files}; do golangci-lint run $file; done
10+
# Cannot easily run `golangci-lint run` on single files as imported types from the
11+
# same package will appear as undefined and cause a typecheck compilation error.
12+
# https://github.com/golangci/golangci-lint/issues/1574#issuecomment-804500358
13+
# https://github.com/golangci/golangci-lint/issues/2912
14+
#
15+
# Thus linting the entire package of a staged files..
16+
run: |
17+
packages=$(echo {staged_files} | xargs dirname | uniq)
18+
for package in $packages; do golangci-lint run "$package"; done
1419
pre-push:
1520
parallel: true
1621
gotest:

0 commit comments

Comments
 (0)