golangci-lint
The golangci-lint module runs Go linters as a Dagger check, using the same
configuration locally and in CI. It discovers go.mod files and runs
golangci-lint separately in each selected Go module.
Add it to your workspace
dagger module install dagger.io/go/golangci-lint
dagger module recommend suggests this module when it finds .golangci.yml,
.golangci.yaml, .golangci.toml, or .golangci.json in the workspace.
Run the check
dagger check # run every check in the workspace
dagger check golangci-lint:lint-all # lint the selected Go modules
lint-all discovers Go modules at or below the working directory, including
the enclosing module when run from a subdirectory. Run it from the workspace
root to check every module. Each check runs golangci-lint run with the
workspace's .golangci.* configuration files and reports diagnostics with
workspace-relative paths.
Go and C/C++ sources, embedded assets, and local go.mod replacement
dependencies within the workspace are included automatically. Go module,
build, and golangci-lint caches are shared between runs.
Module discovery
lint-all finds Go modules by looking for go.mod files:
- Every directory at or below the directory
daggerruns from that holds ago.modis a Go module. Rundaggerfrom the workspace root to cover the whole repository. - When
daggerruns from a directory inside a Go module, that enclosing module is included as well. - Every
go.modcounts, including those undervendor/,testdata/,examples/, hidden directories, and directories listed in.gitignore. - A directory is a module when its
go.modparses and it holds at least one Go file, so an empty module or a placeholdergo.modis left out.
Exclude a module with the lint setting, which selects module roots by path
from the workspace root. "!vendor" excludes the module at vendor and any
module below it, and exclusions always win. The pattern rules are the same as
the Go module's test setting, listed under
Module discovery.
Configure it
List the current settings with dagger module settings golangci-lint, then
change one with dagger module settings golangci-lint <key> <value>. Settings
live in dagger.toml under [modules.golangci-lint.settings]:
version(default2.11.4) selects the golangci-lint release every module is linted with, without thevprefix. The default is pinned by digest. It is installed into the lint container unless that container already carries golangci-lint.goVersionsets one Go toolchain for every module, overriding thegodirective in each module'sgo.mod. Without it, each module is linted with the toolchain its owngo.modasks for. It is separate from the Go module'sversion, which applies to tests and generators.baseis an optional container to run golangci-lint in. It must carry a Go toolchain and any C/C++ dependencies the modules need, and golangci-lint is installed into it unless it already has one. It supplies its own toolchain, sogoVersionis ignored alongside it.includeExtraFiles(default empty) adds workspace-root path patterns for files that automatic source discovery misses.lint(default["**"]) selects module roots to lint. A bare path orpath/**includes that module and its descendants;!pathexcludes them. Exclusions always win."**"and"*"match every module. With no positive pattern, every module is included unless excluded;["!**"]skips all modules. Other glob forms are not supported by this setting.
Edit list-valued settings directly in dagger.toml:
[modules.golangci-lint.settings]
version = "2.11.4"
goVersion = "1.26"
lint = ["**", "!legacy-service"]
includeExtraFiles = ["shared/config/**"]
Working with other modules
Use this module alongside Go for tests and code generation.