impi

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2022 License: MIT Imports: 15 Imported by: 0

README

Build Status Go Report Card

impi

Verify proper golang import directives, beyond the capability of gofmt and goimports. Rather than just verifying import order, it classifies imports to three types:

  1. Std: Standard go imports like fmt, os, encoding/json
  2. Local: Packages which are part of the current project
  3. Third 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.

Usage

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/...

Ignoring Generated Files

Set --ignore-generated=true to ignore files that have been generated by go generate.

Supported schemes

impi currently supports the following schemes:

  1. stdLocalThirdParty: Std -> Local -> Third party
  2. 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.

Documentation

Index

Constants

View Source
const (

	// ImportGroupVerificationSchemeSingle allows for a single, sorted group
	ImportGroupVerificationSchemeSingle = ImportGroupVerificationScheme(iota)

	// ImportGroupVerificationSchemeStdNonStd allows for up to two groups in the following order:
	// - standard imports
	// - non-standard imports
	ImportGroupVerificationSchemeStdNonStd

	// ImportGroupVerificationSchemeStdLocalThirdParty allows for up to three groups in the following order:
	// - standard imports
	// - local imports (where local prefix is specified in verification options)
	// - non-standard imports
	ImportGroupVerificationSchemeStdLocalThirdParty

	// ImportGroupVerificationSchemeStdThirdPartyLocal allows for up to three groups in the following order:
	// - standard imports
	// - non-standard imports
	// - local imports (where local prefix is specified in verification options)
	ImportGroupVerificationSchemeStdThirdPartyLocal
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorReporter

type ErrorReporter interface {
	Report(VerificationError)
}

ErrorReporter receives error reports as they are detected by the workers

type Impi

type Impi struct {
	SkipPathRegexes []*regexp.Regexp
	// contains filtered or unexported fields
}

Impi is a single instance that can perform verification on a path

func NewImpi

func NewImpi(numWorkers int) (*Impi, error)

NewImpi creates a new impi instance

func (*Impi) Verify

func (i *Impi) Verify(rootPath string, verifyOptions *VerifyOptions, errorReporter ErrorReporter) error

Verify will iterate over the path and start verifying import correctness within all .go files in the path. Path follows go tool semantics (e.g. ./...)

type ImportGroupVerificationScheme

type ImportGroupVerificationScheme int

ImportGroupVerificationScheme specifies what to check when inspecting import groups

type VerificationError

type VerificationError struct {
	FilePath string
	// contains filtered or unexported fields
}

VerificationError holds an error and a file path on which the error occurred

type VerifyOptions

type VerifyOptions struct {
	SkipTests       bool
	Scheme          ImportGroupVerificationScheme
	LocalPrefix     string
	SkipPaths       []string
	IgnoreGenerated bool
}

VerifyOptions specifies how to perform verification

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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