checkers

package
v0.0.0-...-f90256a Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2017 License: Apache-2.0 Imports: 9 Imported by: 13

Documentation

Overview

Package checkers provides utilities for implementing lint checkers.

Index

Constants

This section is empty.

Variables

SkipDirFunc determines if a directory must be skipped when listing packages. It takes two arguments, the full path and name of the directory and returns true if the directory should be skipped.

Functions

func Error

func Error(errs ...string) error

Error returns an error containing errs.

If errs is empty, nil is returned. If not the returned error will implement the following interface

type errors interface {
	Errors() []string
}

and return errs unmodified.

func FindBin

func FindBin(bin string) (string, error)

FindBin returns bin if it exists in the path. If not it checks go bin directories ($GOROOT/bin and $GOPATH/bin) and returns that if it exists. If neither exist it returns an error.

func GoFiles

func GoFiles(pkgs ...string) ([]string, error)

GoFiles lists all .go files in pkgs.

func InstallMissing

func InstallMissing(bin, getPath, importPath string) (string, error)

InstallMissing runs go get getPath and then go get importPath if bin cannot be found in the directories contained in the PATH environment variable. It returns the path to the installed binary on success.

func Lint

func Lint(bin, getPath, installPath string, pkgs []string, args ...string) error

Lint runs the linter specified by bin for each package in pkgs. The linter is installed if necessary using

go get getPath
go install installPath

If getPath is empty, installPath is used for go get.

func SkipDirs

func SkipDirs(fns ...func(path, name string) bool) func(string, string) bool

SkipDirs returns a function that will return true if any of fns returns true.

func SkipTestdata

func SkipTestdata(path, name string) bool

SkipTestdata skips all testdata directories

func SkipUnderscoreDirs

func SkipUnderscoreDirs(path, name string) bool

SkipUnderscoreDirs skips all directories with the _ prefix

func SkipVendor

func SkipVendor(path, name string) bool

SkipVendor skips all vendor directories

func Unload

func Unload(pkg string)

Unload removes any information about pkg from the cache.

Types

type ExecErrors

type ExecErrors []string

ExecErrors holds errors collected from executing a linter

func (*ExecErrors) Add

func (e *ExecErrors) Add(r ExecResult)

Add appends any output from stdout or stderr as an error. The exit code is ignored. Empty lines are also ignored

type ExecResult

type ExecResult struct {
	Code   int
	Stdout string
	Stderr string
}

ExecResult holds a status code, stdout and stderr for a single command execution.

func Exec

func Exec(cmd *exec.Cmd) (ExecResult, error)

Exec executes cmd and results exit code, stdout and stderr of the result. It additionally returns and error if the status code is not 0.

type Package

type Package struct {
	// The path of the package. Can be a wildcard path such as ...
	Path string
	// Files holds all files in the package. If the Path is a wildcard path
	// (...) files in sub packages are also returned.
	Files []string
	// All files in Files with a .go extension
	GoFiles []string
	// All sub packages if Path is a wildcard, or just Path if not.
	Pkgs []string
	// build.Package instance for this package
	Build *build.Package
}

Package holds file and sub directory information about a single package.

func Load

func Load(pkg string) (*Package, error)

Load returns a cached Package instance if one exists or creates a new instance if not. It returns an error if there was an error reading package information.

Jump to

Keyboard shortcuts

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