Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Analyzer = &analysis.Analyzer{ Name: "constructor", Doc: "Check developers don't create structs manually without using constructors", Requires: []*analysis.Analyzer{}, Run: run, }
Analyzer is the analyzer struct of constructor. constructor only allows constructing a struct manually in some specific functions, which is specified with tags for `constructor.Constructor` field.
It can detect the following pattern and give error (if not in constructor functions):
1. Create struct directly, like `SomeStruct{}` or `&SomeStruct{}`. 2. Create struct with `new`: `new(SomeStruct)` 3. Struct literal in slice or other struct: `[]SomeStruct{{}}` 4. Define variables through `var`: `var a SomeStruct`. 5. Implicit zero value in other struct literal: `type OtherStruct struct{SomeStruct}; other := OtherStruct{}`
TODO: verify whether this linter can work well with generics
Functions ¶
This section is empty.
Types ¶
This section is empty.