Go docs drift
Rimfe parses changed .go files without building them and records the exported surface: upper-case functions, methods, types and fields, Gin and Echo routes with group prefixes, Cobra commands and flags, config struct tags and os.Getenv reads. When one changes, the docs sections that name it are checked, and a stale line gets a finding.
What Rimfe reads
An upper-case name is exported, so that is the surface Rimfe compares between the base and head of a pull request. Lower-case helpers are internal.
| Surface | What is read |
|---|---|
| Exports | Functions, methods with their receiver type, structs and their fields, interfaces with their methods, type aliases, constants and variables. The package doc comment. |
| Routes | Gin and Echo calls such as r.GET("/users/:id", h), from GET to OPTIONS plus Any and Match, with Group prefixes joined, nested groups included. |
| CLI | Cobra &cobra.Command{} values: Use, Short, Long and Deprecated. Flags() and PersistentFlags() calls such as StringP or IntVar with name, default and usage, and MarkDeprecated. The standard flag package too. |
| Config | Struct fields tagged yaml, toml, mapstructure, env, envconfig or koanf become config keys. json is a wire format and is not read as config. |
| Env vars | os.Getenv and os.LookupEnv. |
| Modules | go.mod requirements and vendor/modules.txt. |
| Deprecations | A // Deprecated: paragraph in a doc comment. |
Example: a flag default changes
docs/cli/serve.md says --port defaults to 8080. Rimfe posts a Docs conflict on that line, quoting it beside the flag call, with an edit that sets the value to 3000.
- cmd.Flags().IntP("port", "p", 8080, "port to listen on")+ cmd.Flags().IntP("port", "p", 3000, "port to listen on")Example: a route group moves
Rimfe joins the group prefix to each route, so every route in the group changes path. The curl sample in docs/api.md that calls /v1/orders is reported as an Outdated code sample. Routes match snippets in any language, shell included.
- v1 := r.Group("/v1")+ v1 := r.Group("/v2") v1.GET("/orders", listOrders)Example: a config key is renamed
docs/configuration.md still lists timeout under the server block. The yaml tag is the key readers write, so the page now names a config key the code does not have, and Rimfe reports a Broken reference. A YAML sample with the old key is an Outdated code sample.
type Server struct {- Timeout time.Duration `yaml:"timeout"`+ Timeout time.Duration `yaml:"request_timeout"` }Docs tools beside Go
Go reference lives on pkg.go.dev, built from doc comments, so the docs that drift are the written guides: a README, a docs/ folder, or a Hugo site. Rimfe reads those Markdown pages. Doc comments are code to Rimfe, and a changed one counts as a docstring change on the function it belongs to.
Set up a Go repository
Map cmd/ and the config package to their pages, so those pages are read first. surface adds env vars and flags to docs coverage. The file applies when Documentation scope is set to .rimfe.json at the PR base.
{ "$schema": "https://rimfe.com/schema/rimfe.json", "docsGlobs": ["README.md", "docs/**/*.md"], "codeMappings": [ { "source": "cmd/acme/**", "target": "docs/cli/" }, { "source": "internal/config/**", "target": "docs/configuration.md" } ], "surface": ["ACME_DATA_DIR", "--port"]}Limits
- Only Gin and Echo produce route facts. chi, gorilla/mux and
net/httphandlers are read as ordinary functions. - Viper keys read by name, such as
viper.GetString("server.port"), are not config facts. Tag the struct withmapstructureand they are. - Code is parsed, never built. Flags registered in a loop or named at runtime are not listed.
_test.gofiles,testdata/,vendor/and files headed// Code generated ... DO NOT EDIT.are skipped.
Try it on your next pull request.
Free for public repositories, with unlimited members.
Start free with GitHub