golangci-lint
The golangci-lint module runs Go linters as a Dagger check, using the same configuration locally and in CI. Each golangci-lint configuration file roots a project, and the module lints each project with its own configuration.
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 --golangci-lint # lint every project
dagger check --golangci-lint-project=services/api # lint one project
The check is golangci-lint/projects/lint. It runs golangci-lint run once for
each Go module a project covers, on the toolchain that module's go.mod asks
for, and reports diagnostics with workspace-relative paths. golangci-lint finds
the project's configuration with its own lookup.
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.
Projects
| Flag | Collection | Key |
|---|---|---|
--golangci-lint-project | projects | Directory holding the configuration file, relative to the workspace root. The root is . |
List the keys with dagger list golangci-lint-projects -a. Select collection items describes how to select items.
A project is a directory holding .golangci.yml, .golangci.yaml,
.golangci.toml, or .golangci.json. It covers everything below it that a
nested configuration does not claim: each Go module below it, and the part
below it of a Go module that encloses it. A repository without a configuration
file has no projects, so nothing is linted.
Projects are found at or below the directory dagger runs from, plus the
nearest project that encloses it. Run dagger from the workspace root to
cover the whole repository.
Exclude a project with the lint setting, which selects project roots by path
from the workspace root. "!vendor" excludes the project at vendor and any
project below it, and exclusions always win. The pattern rules are the same as
the Go module's test setting, listed under
Module discovery. An excluded project is still
listed, and its check passes without running.
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 project 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 Go 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 project roots to lint. A bare path orpath/**includes that project and the projects below it;!pathexcludes them. Exclusions always win."**"and"*"match every project. With no positive pattern, every project is included unless excluded;["!**"]skips all projects. 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.