Verify proper golang import directives, beyond the capability of gofmt and goimports. Rather than just verifying import order, it classifies imports to three types:
Std
: Standard go imports likefmt
,os
,encoding/json
Local
: Packages which are part of the current projectThird party
: Packages which are not standard and not local
It can then verify, according to the chosen scheme, that each import resides in the proper import group. Import groups are declared in the import()
directive and are separated by an empty line:
import(
"Group #1 import #1"
"Group #1 import #2"
"Group #2 import #1"
"Group #2 import #2"
// comments are allowed within a group
"Group #2 import #3"
"Group #3 import #1"
"Group #3 import #2"
)
Note that impi does not support regenerating the files, only warns of infractions.
go get -u github.com/pavius/impi/cmd/impi
impi [--local <local import prefix>] [--ignore-generated=<bool>] --scheme <scheme> <packages>
nuclio uses impi as follows:
impi --local github.com/nuclio/nuclio/ --scheme stdLocalThirdParty ./cmd/... ./pkg/...
Set --ignore-generated=true
to ignore files that have been generated by go generate
.
impi currently supports the following schemes:
stdLocalThirdParty
:Std -> Local -> Third party
stdThirdPartyLocal
:Std -> Third party -> Local
impi will obviously not fail if a group is missing. For example, stdThirdPartyLocal
also allows Std -> Local
, Third party -> Local
, etc.