Documentation ¶
Overview ¶
Package requiredfield implements a linter that checks for required fields during struct initialization.
Fields can be marked as required by adding a comment in the form "// required" next to the field, optionally followed by a description. For example:
type T struct { A string // required B int // required: must be positive C bool // required because reasons }
The analyzer will report an error when an instance of the struct is initialized without setting one or more of the required fields explicitly. For example:
T{A: "foo"} // error: missing required fields: B, C
The explicit value can be the zero value of the field type, but it must be set explicitly.
T{A: "foo", B: 0, C: false}
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Analyzer = &analysis.Analyzer{ Name: "requiredfield", Doc: "check for required fields during struct initialization", Run: run, Requires: []*analysis.Analyzer{ inspect.Analyzer, }, FactTypes: []analysis.Fact{ new(isRequiredField), new(hasRequiredFields), }, }
Analyzer implements the requiredfield linter.
See package documentation for details.
Functions ¶
This section is empty.
Types ¶
This section is empty.
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
requiredfield
requiredfield is a linter for Go code that checks for missing required fields in struct literals.
|
requiredfield is a linter for Go code that checks for missing required fields in struct literals. |
Click to show internal directories.
Click to hide internal directories.