Skip to content

Commit

Permalink
Lint all Go modules
Browse files Browse the repository at this point in the history
In projects with multiple modules, Shipyard's linting rule ends up
ignoring all but the main module. To find all modules which need to be
analysed, this looks for directories containing a file named go.mod
and *.go files declaring functions. Running golangci-lint on multiple
modules now requires a workspace covering the modules, so this is set
up before the linter invocation.

Signed-off-by: Stephen Kitt <[email protected]>
  • Loading branch information
skitt committed Feb 15, 2024
1 parent 7dc13d5 commit 5d4565c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Makefile.linting
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ golangci-lint:
ifneq (,$(shell find . -name '*.go'))
golangci-lint version
golangci-lint linters
golangci-lint run --timeout 10m
# Set up a workspace to include all modules
go work init
find . -name go.mod -execdir git grep -qFl 'func ' -- '*.go' \; -printf '%h ' | xargs go work use
# Analyse all the modules containing function declarations
golangci-lint run --timeout 10m $$(find . -name go.mod -execdir git grep -qFl 'func ' -- '*.go' \; -printf '%h/...\n')
else
@echo 'There are no Go files to lint.'
endif
Expand Down

0 comments on commit 5d4565c

Please sign in to comment.