uninitialized

package module
v0.0.0-...-b88b656 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2025 License: MIT Imports: 3 Imported by: 0

README

Uninitialized

Uninitialized: check for uninitialized but required struct fields within composite literals.

Why?

I've found myself wanting required fields within structs as sometimes a zero value is either unworkable or impractical. While constructors can help to mitigate this need, constructors can suffer from the same issue--a new field is added to the type being constructed, but one has forgotten to update the constructor too.

Caveats
Install
go get -u github.com/danielmmetz/uninitialized
Use

Annotate struct fields with a tag: required:"true".

Example:

type Foo struct {
    Member Bar `required:"true"`
}

Composite literals of Foo that do not explicitly set the member field Member will then be flagged.

Example:

func main() {
    _ = Foo{}  // `Foo missing required keys: [Member]`
    _ = Foo{Member: Bar{}}  // OK
}
Run
uninitialized: check for uninitialized but required struct fields within composite literals

Usage: uninitialized [-flag] [package]

Example:

uninitialized ./...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(settings any) (register.LinterPlugin, error)

Types

type Plugin

type Plugin struct{}

func (*Plugin) BuildAnalyzers

func (p *Plugin) BuildAnalyzers() ([]*analysis.Analyzer, error)

func (*Plugin) GetLoadMode

func (p *Plugin) GetLoadMode() string

Directories

Path Synopsis
cmd
uninitialized command
internal

Jump to

Keyboard shortcuts

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