No module is replaced by a directory
golang/no-local-replacements@v1
No replace directive redirects a module to a filesystem path, so the build reads only source the checkout carries.
| Id | golang/no-local-replacements |
| Version | v1 |
| Category | golang |
| Default severity | error |
| Interpreter | python3 |
| Timeout | 30 seconds |
| Violations tolerated | 0 |
| Collects | golang |
Collectors
This guardrail gathers nothing itself. It depends on the collectors below, which the CLI runs once per build before any check, and reads what they found out of GUARDRAIL_FACTS. A collector that collects nothing skips this guardrail rather than failing it.
| Collector | Gathers | Inputs it is given |
|---|---|---|
golang | The Go build in the project directory: the module it declares, the Go version it asks for, every module of a workspace, the modules it requires directly and indirectly, and the replacements and lock file beside them. | projectDir |
The inputs above are this guardrail's own, passed straight through. Configuring one in buildnote.json changes what is collected, and two guardrails configured the same way share the one collection.
Configuration
{
"guardrails": {
"failOn": "error",
"comment": true,
"checks": [
{
"use": "golang/no-local-replacements@v1",
"severity": "error",
"with": {
"projectDir": "."
},
"exemptions": []
}
]
}
}Inputs
| Input | Description | Default | Environment variable |
|---|---|---|---|
projectDir | Directory holding the project, relative to the directory the CLI runs in. | . | GUARDRAIL_INPUT_PROJECTDIR |
How to fix
Drop the directive and require the module by its own path, or replace it with a module path and version rather than a directory:
replace github.com/acme/queue => github.com/acme/queue/v2 v2.1.0For local development across modules, list the directories in a go.work file's use block rather than reaching for a second replace:
go 1.22
use (
./widget
./queue
)A replace pointing at a directory builds from something the checkout does not carry, so it compiles on the author's laptop and nowhere else.
More in golang
golang/checksums-committed. The module commitsgo.sum, so every module a build downloads is checked against the checksum the commit recorded.golang/toolchain-pinned. The module names the toolchain that compiles it, rather than leaving thegodirective as a floor.golang/version-declared. The module declares the Go version it is built against, and that version is no older than the configured floor.