Categorygithub.com/patrickchense/initcheck
module
1.0.2
Repository: https://github.com/patrickchense/initcheck.git
Documentation: pkg.go.dev

# README

initcheck

Go linter to check initialization of various Go types, such as slice, map, struct etc,.

Code Style

initchecker aims to detect "smelly" Go code in initialization. To follow the guidelines from Uber style guide, initchecker detects below code as "bad".

nil is a valid slice

// "bad" code
a := []int{}
// "good" code
var a []int

Local Variable Declaration

// "bad" code
var c = "foo"
// "good" code
c := "foo"

Omit Zero Value Fields in Structs

// "bad" code
Order struct {
    id int
    name string
    num int
    price double 
}
o1 := new Order{
    id: 111111,
    name: "",
    num: 0,
    price: 0.0,
}

// "good" code
o1 := new Order{
    id: 111111,
}

Use var for Zero Value Structs

// "bad" code
o2 := Order{}
// "good" code
var o2 Order

Initializing Maps with make

// "bad" code
m1 = map[T1]T2{}
// "good" code
m1 = make(map[T1]T2)

Run initchecker

  1. Download the package
go install github.com/patrickchense/initcheck/cmd@latest
  1. Run the checker

Run from source

  1. Build the project
go build -o ./bin/initchecker ./cmd
  1. Run against a file or package
./bin/initchecker ./test

Run with Golangci-lint

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author