Documentation
¶
Overview ¶
Package standardgo is an unconfigurable golangci-lint configuration for amberpixels Go projects.
The ruleset lives in exactly one place — the .golangci.yml embedded below — and is delivered as a binary rather than a file to copy. Projects that adopt standardgo carry no .golangci.yml of their own, so there is nothing to drift.
golangci-lint has no config inheritance (no extends, no remote configs), so a shared ruleset cannot be referenced; it has to be distributed. That is the same design standard (JS) and standardrb (Ruby) chose deliberately, even though their engines do support inheritance.
Index ¶
Constants ¶
const OverlayFile = ".standardgo.yml"
OverlayFile is the project-local overlay read from the working directory.
const PresetFile = "standardgo-preset.yml"
PresetFile is the file a module publishes to offer a standardgo preset.
It sits at the module root and is written in the .standardgo.yml shape, so a preset is an overlay that happens to be distributed rather than typed.
Variables ¶
var Config []byte
Config is the locked golangci-lint configuration.
Functions ¶
func Merge ¶
Merge applies overlay onto the locked config and returns the result. It returns an error rather than silently dropping anything the overlay is not permitted to do, so a rejected override is visible instead of confusing.
proj says which module is being linted and how to find the presets it names; resolving one runs the go command, which is what ctx is for.
func ModuleDir ¶ added in v0.2.0
ModuleDir locates a module in the linted project's own module graph.
Going through the module graph rather than fetching a URL is what makes a preset reviewable: the version is pinned in the project's go.mod, its content is checksummed in go.sum, and it comes from the module cache, so a preset cannot change what a project enforces without a diff someone approved.
func ModulePath ¶ added in v0.2.0
ModulePath reads the module path from the go.mod in dir.
It returns "" when there is no go.mod, which is not an error here: only a preset that carries the placeholder actually needs the value, and refusing to lint a directory that has no module would be a new restriction.
Types ¶
type IgnoreRule ¶
IgnoreRule silences specific linters under a path glob.
type Overlay ¶
type Overlay struct {
// Presets are module paths, each naming a module that publishes a
// standardgo-preset.yml. A preset is an overlay a project references instead
// of pasting, so a convention shared across repos (its layering rules, say)
// has one definition, versioned where it is defined rather than here.
Presets []string `yaml:"presets"`
Linters struct {
Enable []string `yaml:"enable"`
Disable []string `yaml:"disable"`
Settings map[string]any `yaml:"settings"`
} `yaml:"linters"`
Ignore []IgnoreRule `yaml:"ignore"`
}
Overlay is the optional project-local .standardgo.yml.
It deliberately cannot change a rule the shared config already sets — in either direction. Making a locked linter stricter is refused just as firmly as making it softer, because "stricter" is not decidable in general (is a different gocritic check set stricter?) while "already configured" is. This mirrors standardrb's extend_config, which drops any cop Standard has already configured.
The one sanctioned way to get softer is Ignore, and it is path-scoped: a linter may be silenced under a glob, never globally.
type Project ¶ added in v0.2.0
type Project struct {
// Module is the linted project's own module path, substituted into presets.
// It may be empty when there is no go.mod; only a preset that carries the
// placeholder then fails, and it says so.
Module string
// Resolve locates the presets the overlay names. ModuleDir is the real one;
// tests supply their own so the merge never shells out.
Resolve Resolver
}
Project is what a merge needs to know about the module being linted.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
standardgo
command
Command standardgo lints a Go project with the locked amberpixels ruleset.
|
Command standardgo lints a Go project with the locked amberpixels ruleset. |