Skip to main content
Version: 1.0-beta

Staticcheck

The Staticcheck module analyzes Go source as a Dagger check, using the same configuration locally and in CI. Each staticcheck.conf roots a project, and the module analyzes each project with its configuration.

Add it to your workspace​

dagger module install dagger.io/go/staticcheck

dagger module recommend suggests this module when it finds staticcheck.conf in the workspace.

Run the check​

dagger check --staticcheck                              # analyze every project
dagger check --staticcheck-project=services/api # analyze one project

The check is staticcheck/projects/lint. It runs staticcheck on the packages of each Go module a project covers, on the toolchain that module's go.mod asks for. Test files are analyzed too; tests and generators are not executed.

The module includes staticcheck.conf files with their directory structure intact. Staticcheck merges a package's staticcheck.conf files itself, so a nested project inherits its parent's configuration. Go and native sources, embedded assets, and local go.mod replacement dependencies within the workspace are included automatically. Go module, build, and Staticcheck caches are shared between runs.

Projects​

FlagCollectionKey
--staticcheck-projectprojectsDirectory holding the staticcheck.conf, relative to the workspace root. The root is .

List the keys with dagger list staticcheck-projects -a. Select collection items describes how to select items.

A project is a directory holding a staticcheck.conf. It covers everything below it that a nested staticcheck.conf does not claim: each Go module below it, and the part below it of a Go module that encloses it. A repository without a staticcheck.conf has no projects, so nothing is analyzed.

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. 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 staticcheck, then change one with dagger module settings staticcheck <key> <value>. Settings live in dagger.toml under [modules.staticcheck.settings]:

  • version (default v0.8.1) selects the Staticcheck release every project is checked with. It is installed into the lint container unless that container already carries Staticcheck.
  • goVersion sets one Go toolchain for every Go module, overriding the go directive in each module's go.mod. Without it, each module is checked in golang:<version>-alpine for the version 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 Staticcheck in. It must carry a Go toolchain and any C/C++ dependencies the modules need, and Staticcheck 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 project roots to analyze. A bare path or path/** includes that project and the projects below it; !path excludes 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.staticcheck.settings]
version = "v0.8.1"
goVersion = "1.26"
lint = ["**", "!legacy-service"]
includeExtraFiles = ["shared-assets/**"]

Working with other modules​

Use this module alongside Go for tests and code generation.

source code