lint

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2021 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package lint provides a simple linter for conventional commits

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Commit added in v0.5.0

type Commit = parser.Commit

Commit represent a commit message for now it is an alias of parser.Commit

func Parse added in v0.5.0

func Parse(msg string) (*Commit, error)

Parse parses given commit message

type Config

type Config struct {
	// Formatter of the lint result
	Formatter string `yaml:"formatter"`

	// Rules is rule name to rule config map
	Rules map[string]RuleConfig `yaml:"rules"`
}

Config represent linter config

func (*Config) GetRule

func (c *Config) GetRule(ruleName string) RuleConfig

GetRule returns RuleConfig for given rule name

type Formatter

type Formatter interface {
	// Name is a unique identifier for formatter
	Name() string

	// Format formats the linter result
	Format(result *Result) (string, error)
}

Formatter represent a lint result formatter

type Linter

type Linter struct {
	// contains filtered or unexported fields
}

Linter is linter for commit message

func New added in v0.5.0

func New(conf *Config, rules []Rule) (*Linter, error)

New returns a new Linter instance with given config and rules

func (*Linter) Lint

func (l *Linter) Lint(commitMsg string) (*Result, error)

Lint checks the given commitMsg string against rules

func (*Linter) LintCommit

func (l *Linter) LintCommit(msg *Commit) (*Result, error)

LintCommit checks the given Commit against rules

type Result

type Result struct {
	// contains filtered or unexported fields
}

Result holds result of linter

func (*Result) Errors

func (res *Result) Errors() []RuleResult

Errors returns all error messages

func (*Result) HasErrors

func (res *Result) HasErrors() bool

HasErrors returns true if errors found by linter

func (*Result) HasWarns

func (res *Result) HasWarns() bool

HasWarns returns true if warnings found by linter

func (*Result) Input

func (res *Result) Input() string

Input returns input commit message

func (*Result) IsOK

func (res *Result) IsOK() bool

IsOK returns true if commit message passed all the rules

func (*Result) Warns

func (res *Result) Warns() []RuleResult

Warns returns all warning messages

type Rule

type Rule interface {
	// Name returns name of the rule, it should be a unique identifier
	Name() string

	// Apply calls with arguments and flags for the rule from config file
	// if flags or arguments are invalid or not expected return an error
	// Apply is called before Validate
	Apply(arg interface{}, flags map[string]interface{}) error

	// Validate validates the rule for given message
	// if given message is valid, return true and result string is ignored
	// if invalid, return a error result with false
	Validate(msg *Commit) (result string, isValid bool)
}

Rule represent a linter rule

type RuleConfig

type RuleConfig struct {
	Enabled bool `yaml:"enabled"`

	Severity Severity `yaml:"severity"`

	Argument interface{} `yaml:"argument"`

	// Flags are optional key value pairs
	Flags map[string]interface{} `yaml:"flags"`
}

RuleConfig represent config for a rule

type RuleResult

type RuleResult struct {
	Name     string
	Severity Severity
	Message  string
}

RuleResult holds result of a linter rule

type Severity added in v0.5.0

type Severity string

Severity represent the severity level of a rule

const (
	SeverityWarn  Severity = "warn"
	SeverityError Severity = "error"
)

Rule Severity Constants

func (Severity) String added in v0.5.0

func (s Severity) String() string

Jump to

Keyboard shortcuts

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