Skip to main content
Version: 1.0-beta

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 dagger runs from that holds a go.mod is a Go module. Run dagger from the workspace root to cover the whole repository.
  • When dagger runs from a directory inside a Go module, that enclosing module is included as well.
  • Every go.mod counts, including those under vendor/, testdata/, examples/, hidden directories, and directories listed in .gitignore.
  • A directory is a module when its go.mod parses and it holds at least one Go file, so an empty module or a placeholder go.mod is 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 (default 2.11.4) selects the golangci-lint release every module is linted with, without the v prefix. The default is pinned by digest. It is installed into the lint container unless that container already carries golangci-lint.
  • goVersion sets one Go toolchain for every module, overriding the go directive in each module's go.mod. Without it, each module is linted with the toolchain its own go.mod asks for. It is separate from the Go module's version, which applies to tests and generators.
  • base is 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, so goVersion is 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 or path/** includes that module and its descendants; !path excludes 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.

source code