nit is an opinionated Code Organization linter for Go.
It defines a collection of rules to determine how each Go file should be organized internally.
-
importsis the first section- Requires parenthesized declaration,
- One maximum, and
- Separated in 3 blocks: standard, external and same package (local).
-
typeis the second section- Requires parenthesized declaration,
- Section must be sorted: exported first, then unexported; and
- Supports
//-comment for separating groups
-
constis the third section- Requires parenthesized declaration,
- Multiple allowed, and
- Section must be sorted: exported first, then unexported.
-
varis the fourth section- Requires parenthesized declaration, and
- Section must be sorted: exported first, then unexported.
-
funcis the fifth section- Must be sorted, exported first, then unexported, and
- Supports
//-comment for separating groups.
-
funcmethod, is the sixth section- Must be sorted by type, exported first, then unexported; and
- Supports
//-comment for separating groups.
Fancy State Machine explaining the rules above:
- Using
go(>= 1.13):go get github.com/MarioCarrion/nit/cmd/nit@v0.6.0, for installing v0.6.0 for example; see the releases for other versions. - Using it as a dependency with the
tools.goparadigm:
// +build tools
package tools
import (
_ "github.com/MarioCarrion/nit/cmd/nit"
)After installing you can use:
nit -pkg <base local package> $(go list ./...)
Please use nit -h for other available arguments.
Go >= 1.14.0
