How beltranaceves/uber-go-lint-style works
1. What this repository is
- This is a Go static-analysis plugin for golangci-lint that enforces Uber Go style conventions.
- The core runtime boundary is: golangci-lint loads this module as a custom linter plugin, and the plugin contributes one or more go/analysis analyzers.
2. Primary execution path
- The main entrypoint is plugin.go.
- It acts as the bridge between golangci-lint and the rule implementations in rules/, assembling the analyzers that get registered with the host linter.
3. Rule engine subsystem
- The rules/ directory is the main product surface: one file per rule, such as atomic, error_wrap, import_group, no_panic, todo, etc.
- Each rule is an independent analyzer focused on a single style concern, which keeps the architecture modular and makes rule enable/disable behavior straightforward.
4. Analysis model
- The repository is built around the standard Go analysis ecosystem (go/analysis, as described in the README).
- Rules inspect Go source code and report diagnostics; the design is intentionally heuristic in some areas, because many style rules are subjective rather than purely semantic.
5. Configuration and plugin packaging
- The repo supports golangci-lint custom plugin configuration via .custom-gcl.yml and .golangci.yml.
- A notable architectural feature is runtime rule suppression through disabled_rules_yaml, which lets the host project selectively disable analyzers without changing code.
- The setup flow is handled by cmd/setup, which generates the config files and a convenience Makefile.
6. Rule documentation layer
- RULES.md is the user-facing catalog of enforced checks.
- style_guide/rules/*.md appears to be the source/materialized documentation for each rule, tying implementation to the underlying Uber style guidance.
- This docs layer is important because the project is as much a policy bundle as it is a code analyzer.
7. Testing architecture
- plugin_test.go and the per-rule tests validate that analyzers are wired correctly and emit expected findings.
- testdata/ is the standard Go analyzer test corpus: it contains many small synthetic packages under testdata/src/... that exercise rule-specific good/bad cases.
- The tests rely on import-path-shaped fixtures and // want-style expectations, which is typical for go/analysis-based linters.
8. Test fixture organization
- The testdata/src/testlintdata/... subtree mirrors each rule name, so each analyzer has isolated fixtures.
- There are also special fixture packages under testdata/src/example.com, github.com, go.uber.org, etc., to model external-import and package-structure scenarios that matter to style rules.
9. Disabled-rule and integration coverage
- test/plugin_disabled_rules_test.go covers the config-driven rule suppression path, which is an important behavioral boundary: the same analyzer set can be pruned at runtime based on config.
- This ensures the plugin behaves correctly both as a full policy bundle and as a selectively configured linter.
10. Integration client
- test-client/ is a separate Go module used for end-to-end validation of the built plugin in a realistic consumer setup.
- It exercises the custom golangci-lint binary and serves as a smoke-test of packaging, configuration, and CLI wiring beyond unit tests.
11. Automation and delivery
- .github/workflows/go-test.yml runs the repository’s test suite in CI.
- Makefile provides local convenience targets, and the README emphasizes building a custom golangci-lint binary plus the plugin module.
- The repo is therefore optimized for distribution as a developer-tooling dependency, not as an application service.
12. Architectural summary
- The system splits cleanly into:
- a plugin wrapper (plugin.go),
- a library of analyzers (rules/),
- a fixture-driven validation layer (testdata/, plugin_test.go),
- and a consumer/setup experience (cmd/setup, test-client, config files, docs).
- For a diagram, the key flow is: Go source code → rule analyzers → diagnostics reported through golangci-lint, with docs/config/test assets surrounding that core pipeline.
Main entry points: rules Style rules · setup/main.go Setup cmd · test-client/main.go Test client · plugin_test.go Plugin tests
Components 20
Core plugin
Runtime bridge from golangci-lint into this repository's analyzers
- Plugin entry · Assembles and exposes analyzers to the host linter
plugin.go
Rule analyzers
Go/analysis checks grouped by style concern
- Style rules · Primary rule implementations covering names, declarations, flow, and formatting
rules - Imports & packages · Rules for import grouping, aliases, package naming, and init/layout conventions
rules/import_group.go - Funcs & errors · Rules for function naming, order, naked returns, and error construction/wrapping
rules/error_wrap.go - Data & types · Rules for structs, interfaces, containers, maps, slices, pointers, and zero values
rules/struct_zero.go - Control flow · Rules for panic, goroutines, exits, nesting, and time usage
rules/no_panic.go - Formatting · Rules for line length, printf usage, string conversion, and escapes
rules/line_length.go - Misc rules · Residual style checks such as TODOs, variable scope, and declarations
rules/todo.go
Validation
Unit, integration, and fixture-based analyzer tests
- Plugin tests · Direct tests for plugin wiring and rule registration
plugin_test.go - Config tests · Verifies runtime suppression of analyzers via disabled rule config
test/plugin_disabled_rules_test.go - Testdata corpus · Synthetic packages and want-expectation inputs for analyzer behavior
testdata/src/testlintdata - Import fixtures · Special package trees that model external import paths and package shapes
testdata/src/example.com/client-go/client.go
Policy docs
User-facing style guidance and rule catalog
- RULES.md · User-facing index of enabled checks
RULES.md - Style guide · Canonical policy documents backing the analyzer set
style_guide/style.md - Rule docs · Per-rule documentation mirroring the implemented checks
style_guide/rules/atomic.md
Packaging
Setup, config, and consumer integration assets
- Setup cmd · Generates custom golangci-lint config and Makefile scaffolding
cmd/setup/main.go - Plugin config · Custom golangci-lint plugin configuration and disabled rule wiring
test-client/.custom-gcl.yml - Linter config · Consumer-side golangci-lint configuration for loading the plugin
test-client/.golangci.yml - Test client · Separate Go module that exercises built plugin integration
test-client/main.go - CI workflow · Runs repository tests in continuous integration
.github/workflows/go-test.yml
Connections 20
- Plugin entry → Style rules: registers · The plugin collects analyzers from the rule package and exposes them to golangci-lint
- Style rules → Imports & packages: includes · One major slice of the analyzer set focuses on import and package conventions
- Style rules → Funcs & errors: includes · Function and error-related checks are implemented as separate analyzers
- Style rules → Data & types: includes · Type, container, and zero-value style rules are grouped together
- Style rules → Control flow: includes · Flow-sensitive checks cover panic, goroutines, exits, and nesting
- Style rules → Formatting: includes · Formatting and text-convention rules live alongside semantic checks
- Style rules → Misc rules: includes · Miscellaneous heuristics round out the rule set
- Style guide → Rule docs: documents · Per-rule markdown captures the policy behind each analyzer
- RULES.md → Style rules: catalogs · The rule catalog summarizes the analyzers that the plugin can expose
- Setup cmd → Plugin config: generates · Setup tooling emits the custom plugin configuration
- Setup cmd → Linter config: generates · Setup tooling also emits the host linter config
- Setup cmd → Test client: bootstraps · The setup flow supports a ready-to-run consumer module and Makefile
- Test client → Plugin config: loads · The consumer module uses the custom plugin configuration to enable this linter
- Test client → Linter config: runs with · The integration client validates the host linter wiring
- Plugin tests → Plugin entry: verifies · Tests ensure analyzer registration and plugin wiring are correct
- Plugin tests → Testdata corpus: exercises · Analyzer behavior is checked against fixture packages and expected diagnostics
- Config tests → Plugin config: verifies · Tests cover runtime pruning of analyzers driven by config
- Config tests → Plugin entry: prunes · The active analyzer set is reduced before registration
- Testdata corpus → Import fixtures: contains · The corpus includes special packages for external import and package-shape scenarios
- CI workflow → Plugin tests: runs · CI executes the repository test suite