Documentation
¶
Overview ¶
Package doclint is a documentation drift guard.
It scans tracked Markdown files for repository-relative paths used as inputs to commands in fenced code blocks and reports any that no longer resolve on disk. It exists to prevent the specific class of staleness that broke the front-door quickstart: an example was relocated from examples/01-counter to examples/public/counter, but every copy-paste `gwc` command in the README, the getting-started chapter, and AGENTS.md kept pointing at the dead path, so a fresh evaluator's first command failed on a clean checkout.
The guard is deliberately high precision rather than exhaustive. It only inspects tokens inside fenced code blocks, only treats a token as a repo-relative path when its first segment is an existing top-level repo entry, and skips command outputs and obvious user-project placeholders. The goal is zero false positives so the lane can fail a build without becoming noise that gets disabled.
Index ¶
- func ExecCommandRunner(parseCtx context.Context, parseDir string, parseEnv []string, parseName string, ...) (string, error)
- func ExtractKnownGwcFlags(parseGwcDir string) (map[string]bool, error)
- func FindRepoRoot(start string) (root string, ok bool)
- type CommandRunner
- type FlagRef
- type GoBlock
- type GoBlockCompileError
- type GoBlockError
- type GwcCommandPlan
- type GwcCommandRef
- type GwcCommandResult
- type GwcCommandRunOptions
- type GwcCommandRunSummary
- type PathRef
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExecCommandRunner ¶
func ExecCommandRunner(parseCtx context.Context, parseDir string, parseEnv []string, parseName string, parseArgs []string) (string, error)
ExecCommandRunner runs one command and returns combined stdout/stderr.
func ExtractKnownGwcFlags ¶
ExtractKnownGwcFlags returns the set of flag names defined anywhere in the gwc launcher source under gwcDir (handling both name-first definitions and flag.Var definitions where the name is the second argument).
func FindRepoRoot ¶
FindRepoRoot walks up from start until it finds the directory containing go.mod, returning the module root. It returns ok=false if none is found.
Types ¶
type CommandRunner ¶
CommandRunner executes one command from one working directory with extra environment variables.
type FlagRef ¶
FlagRef is one `-flag` token found on a gwc command line in a doc, which does not correspond to any flag defined in the gwc launcher source.
func ScanDocGwcFlags ¶
ScanDocGwcFlags returns every `-flag` used on a gwc command line in a tracked Markdown shell block whose flag name is not in parseKnown. It is the flag-existence half (part c) of the doc-drift guard: a renamed or removed launcher flag still referenced in docs is reported.
type GoBlock ¶
type GoBlock struct {
DocPath string // repo-relative path of the Markdown file
Line int // 1-based line of the block's opening fence
Source string // the block's Go source
// Compile is true when the opening fence is marked `gwc:build` — an opt-in that the sample
// is a complete, runnable program to be type-checked (compiled), not just parsed. Native is
// true for the `gwc:build:native` variant (a server/native sample); otherwise the sample is
// compiled for the browser (js/wasm) target.
Compile bool
Native bool
}
GoBlock is one fenced ```go code block in the docs that is a COMPLETE Go file (it declares a package). Fragments — snippets without a package clause — are intentionally not validated here, keeping the guard high-precision (zero false positives) like the path-reference scanner: only copy-paste-runnable samples are checked, which is exactly the rot that breaks a fresh reader.
func ScanGoBlocks ¶
ScanGoBlocks walks every tracked Markdown file under root and returns the complete-file ```go blocks (those containing a top-level `package ` declaration).
type GoBlockCompileError ¶
GoBlockCompileError is a `gwc:build`-marked sample that failed to compile (type-check) against the real module — the type-level "docs can't silently lie" guard (a renamed/removed API used by a runnable sample fails here even though it still parses).
func CompileMarkedGoBlocks ¶
func CompileMarkedGoBlocks(repoRoot string) ([]GoBlockCompileError, error)
CompileMarkedGoBlocks compiles every `gwc:build`-marked complete-file sample against the real module: each is written to a throwaway module with a `replace` to repoRoot and built with `go build` (js/wasm by default, native for `gwc:build:native`). This is the opt-in type-level gate — only samples explicitly marked as runnable programs are compiled, so illustrative fragments never produce false failures. repoRoot is the module root (contains go.mod).
type GoBlockError ¶
GoBlockError is a complete-file ```go sample that no longer parses, so the docs would silently hand a reader broken Go.
func ValidateGoBlocks ¶
func ValidateGoBlocks(root string) ([]GoBlockError, error)
ValidateGoBlocks parses every complete-file ```go sample under root and returns the ones that no longer parse — the documentation-can't-silently-lie guard for code samples. It uses go/parser (offline, deterministic, no module resolution) so the lane stays fast and dependency-free, matching the path-reference guard's design.
type GwcCommandPlan ¶
type GwcCommandPlan struct {
Ref GwcCommandRef
Args []string
SkipReason string
}
GwcCommandPlan is the executable or explicitly skipped plan for one documented command.
func PlanDocGwcCommands ¶
func PlanDocGwcCommands(parseRefs []GwcCommandRef, parseOutputRoot string) []GwcCommandPlan
PlanDocGwcCommands classifies documented commands into finite executable commands and explicit skips.
type GwcCommandRef ¶
GwcCommandRef is one documented gwc command line found in a Markdown shell block.
func ScanDocGwcCommands ¶
func ScanDocGwcCommands(parseRoot string) ([]GwcCommandRef, error)
ScanDocGwcCommands returns gwc command lines from Markdown shell blocks.
type GwcCommandResult ¶
type GwcCommandResult struct {
Plan GwcCommandPlan
Output string
Err error
}
GwcCommandResult records one attempted or skipped documented command.
type GwcCommandRunOptions ¶
type GwcCommandRunOptions struct {
OutputRoot string
Timeout time.Duration
MaxCommands int
Runner CommandRunner
}
GwcCommandRunOptions configures the documented-command execution lane.
type GwcCommandRunSummary ¶
type GwcCommandRunSummary struct {
Executed []GwcCommandResult
Skipped []GwcCommandResult
}
GwcCommandRunSummary is the result of the command-execution doclint lane.
func RunDocGwcCommands ¶
func RunDocGwcCommands(parseRoot string, parseOptions GwcCommandRunOptions) (GwcCommandRunSummary, error)
RunDocGwcCommands executes the finite planned commands with a network-off Go environment.
type PathRef ¶
type PathRef struct {
// DocPath is the repo-relative path of the Markdown file that contains it.
DocPath string
// Line is the 1-based line number of the reference within that file.
Line int
// Raw is the token exactly as written in the doc (Windows or POSIX style).
Raw string
// Rel is the normalized, forward-slash, repo-relative path to resolve.
Rel string
}
PathRef is one repo-relative path reference found inside a doc command block.
func Resolve ¶
Resolve reports the references whose target does not exist under root. A reference is considered live if it resolves EITHER repo-root-relative (the front-door case: README/getting- started commands run from the repo root) OR relative to its own doc file's directory (a subdir README whose command runs from that subdir, e.g. tools/devtools-extension/README.md running `node --test test/bridge.test.mjs` from the extension dir). Accepting the doc-dir-relative resolution removes a false-positive class without weakening the front-door drift guard.