inhouse

package module
v0.0.0-...-bf75311 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2021 License: MPL-2.0 Imports: 13 Imported by: 0

README

inhouse

Test Lint Release codecov

GitHub All Releases

Go code checker for in-house code regulation.

Alternatives

Documentation

Index

Constants

View Source
const CLIENV = "INHOUSECLI"

CLIENV is a special environment variable only present during CLI run. Used internally to determine the caller is CLI/source/tests.

Variables

This section is empty.

Functions

func Log

func Log(msg ...string)

Log conditionally STDOUTs the given message, depending on DEBUG flag.

func PWD

func PWD() (string, error)

PWD returns an absolute path of caller origin.

func Sources

func Sources(dir string, recursive bool) ([]string, error)

Sources returns .go files excluding *_test.go.

func Tests

func Tests(dir string, recursive bool) ([]string, error)

Tests returns *_test.go files.

Types

type Check

type Check struct {
	Contained bool    `json:"contained"`
	Matches   []*Code `json:"matches"`
	Misses    []*Code `json:"misses"`

	// Just for testing.
	Tester interface{} `json:"tester,omitempty"`
}

Check represents a checker result.

func Contains

func Contains(dir, function string, recursive bool) (*Check, error)

Contains returns true when source files in the caller directory contains the specified Go function. The starting directory is where you call this function. This function will search for source and test files.

func ContainsPWD

func ContainsPWD(function string, recursive bool) (*Check, error)

ContainsPWD returns true when source files in the caller directory contains the specified Go function. The starting directory is where you call this function. This function will search for source and test files.

func NewCheck

func NewCheck() *Check

NewCheck with initialized slices.

func SourcesContains

func SourcesContains(dir, function string, recursive bool) (*Check, error)

SourcesContains returns true when source files in the caller directory contains the specified Go function. The starting directory is where you call this function. This function will not check for `*_test.go` files.

func SourcesContainsPWD

func SourcesContainsPWD(function string, recursive bool) (*Check, error)

SourcesContainsPWD is a wrapper of SourcesContains to resolve directory as `pwd`. Intended to be used inside test codes.

func TestsContains

func TestsContains(dir, function string, recursive bool) (*Check, error)

TestsContains returns true when test files in the caller directory contains the specified Go function. The starting directory is where you call this function. This function will check for `*_test.go` files only.

func TestsContainsPWD

func TestsContainsPWD(function string, recursive bool) (*Check, error)

TestsContainsPWD is a wrapper of TestsContains to resolve directory as `pwd`. Intended to be used inside test codes.

func (*Check) Combine

func (c *Check) Combine() []*Code

Combine all codes.

func (*Check) Sort

func (c *Check) Sort()

Sort internal codes.

func (Check) ToJSON

func (c Check) ToJSON() (string, error)

ToJSON for CLI output.

type Code

type Code struct {
	Filepath string `json:"filePath"`
	Function string `json:"function"`
	Line     int    `json:"line"`

	// Just for testing.
	Tester interface{} `json:"tester,omitempty"`
}

Code represents a Go code with some information for post processing.

func Functions

func Functions(filepath string) ([]Code, error)

Functions returns both exported and unexported function names.

func (Code) Format

func (c Code) Format(style CodeFormat) string

Format code to applicable styles. Suitable to be used together with CLI flags.

func (Code) ToCSV

func (c Code) ToCSV() string

ToCSV is a decorator to print fields in comma-separated format.

func (Code) ToColon

func (c Code) ToColon() string

ToColon is a decorator to print fields in colon-separated format.

func (Code) ToJSON

func (c Code) ToJSON() string

ToJSON is a decorator to print fields in JSON format. Note this method will exit immediately on failure.

func (Code) ToTSV

func (c Code) ToTSV() string

ToTSV is a decorator to print fields in tab-separated format.

type CodeFormat

type CodeFormat string

CodeFormat represents print styles.

const (
	CSVFormat   CodeFormat = "csv"
	ColonFormat CodeFormat = "colon"
	JSONFormat  CodeFormat = "json"
	TSVFormat   CodeFormat = "tsv"
)

List of code formats.

func (CodeFormat) String

func (c CodeFormat) String() string

String output.

type ContainsOutput

type ContainsOutput struct {
	Contained bool
	Code      *Code
}

ContainsOutput represents a matching result of code.

func (ContainsOutput) HasCode

func (c ContainsOutput) HasCode() bool

HasCode internally checks code field.

Directories

Path Synopsis
cli
examples

Jump to

Keyboard shortcuts

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