lint

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2021 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package lint provides a simple linter for conventional commits

Index

Constants

View Source
const (
	SeverityWarn  = "warn"
	SeverityError = "error"
)

Rule Severity Constants

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Formatter string                `yaml:"formatter"`
	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 ruleName

type Formatter

type Formatter interface {
	// Name is a unique identifier for formatter
	Name() string
	Format(res *Result) (string, error)
}

Formatter represent a lint result formatter

type Linter

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

Linter is a simple linter for conventional commits

func NewLinter

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

NewLinter returns a new Linter object with given conf

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 *message.Commit) (*Result, error)

LintCommit checks the given parser.Commit for 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
	// SetAndCheckArgument sets the argument to the rule from config file
	// if args are invalid or not expected return an error
	// SetAndCheckArgument is called before Validate
	SetAndCheckArgument(arg interface{}) error
	// Validate validates the rule for given message
	Validate(msg *message.Commit) (result string, isValid bool)
}

Rule represent a linter rule

type RuleConfig

type RuleConfig struct {
	Enabled  bool        `yaml:"enabled"`
	Severity string      `yaml:"severity"`
	Argument interface{} `yaml:"argument"`
}

RuleConfig represent config for a rule

type RuleResult

type RuleResult struct {
	Name     string
	Severity string
	Message  string
}

RuleResult holds result of a linter rule

Jump to

Keyboard shortcuts

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