Documentation
¶
Overview ¶
Package substitute resolves the ${...} variables in a devcontainer.json at lint time, following the reference implementation (devcontainers/cli, src/spec-common/variableSubstitution.ts) with one deliberate divergence: a variable whose value the linter cannot know resolves to the empty string instead of being deferred to container creation, so no ${...} survives substitution.
Variable values come from:
- ${localEnv:NAME} and ${env:NAME}: Context.LocalEnv only — the host environment is never read. An absent name resolves to the default argument (${localEnv:NAME:default}) or the empty string.
- ${localWorkspaceFolder} and ${localWorkspaceFolderBasename}: Context.LocalWorkspaceFolder.
- ${containerWorkspaceFolder} and ${containerWorkspaceFolderBasename}: the configuration's own "workspaceFolder", or its spec default.
- ${devcontainerId}: the fixed placeholder DevcontainerID, but only in the properties the spec allows it in (those not used to build the image, since the id is unknown at build time; see [devcontainerIDProperties]). Elsewhere it resolves to the empty string.
- Anything else (${containerEnv:...}, unrecognized or malformed variables): the empty string.
Index ¶
Constants ¶
const DevcontainerID = "1chpi9f3o037fhb9uo08e7p6i6i29ikr887u4fh4eq6a2rml99ua"
DevcontainerID is the placeholder every ${devcontainerId} resolves to. It has the format of a real id — 52 base-32 chars, as devcontainers/cli derives from a SHA-256 of the container's id labels, which only exist once a container is created — and is the real algorithm applied to the fixed input "decolint".
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
Apply resolves variables in every string value of root in place. Object member names are never substituted, and replaced text is not re-scanned, both per the reference implementation. Every node keeps its original byte offsets, so findings on substituted values still point at the source text.
${devcontainerId} is resolved only within the top-level properties that allow it (see [devcontainerIDProperties]); elsewhere it resolves to the empty string like an unknowable variable.
Types ¶
type Context ¶
type Context struct {
// LocalEnv maps names to the values ${localEnv:NAME} and ${env:NAME} resolve to. Host
// environment variables are never read, and lookups are case-sensitive on every platform.
LocalEnv map[string]string
// LocalWorkspaceFolder is the absolute host path of the directory the devcontainer
// configuration belongs to.
LocalWorkspaceFolder string
}
Context supplies the values variables resolve to.