constructor

package
v1.1.0-beta.0...-cea46f1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const ConstructorUtilPath = "github.com/pingcap/tidb/pkg/util/linter/constructor"

ConstructorUtilPath defines the path of the constructor utility package.

Variables

View Source
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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL