lint

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2023 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 interface {
	Message() string
	Header() string
	Body() string
	Footer() string
	Type() string
	Scope() string
	Description() string
	Notes() []Note
	IsBreakingChange() bool
}

Commit represent a commit message

type Config

type Config struct {
	// MinVersion is the minimum version of commitlint required
	// should be in semver format
	MinVersion string `yaml:"version"`

	// Formatter of the lint result
	Formatter string `yaml:"formatter"`

	// Enabled Rules
	Rules []string `yaml:"rules"`

	// Severity
	Severity SeverityConfig `yaml:"severity"`

	// Settings is rule name to rule settings
	Settings map[string]RuleSetting `yaml:"settings"`
}

Config represent linter config

func (*Config) GetRule

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

GetRule returns RuleConfig for given rule name

func (*Config) GetSeverity added in v0.8.0

func (c *Config) GetSeverity(ruleName string) Severity

GetSeverity returns Severity for given ruleName

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 Issue added in v0.8.0

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

Issue holds a rule result

func NewIssue added in v0.8.0

func NewIssue(desc string, infos ...string) *Issue

NewIssue returns a new issue

func (*Issue) Description added in v0.8.0

func (r *Issue) Description() string

Description returns description of the issue

func (*Issue) Infos added in v0.8.0

func (r *Issue) Infos() []string

Infos returns additional infos about the issue

func (*Issue) RuleName added in v0.8.0

func (r *Issue) RuleName() string

RuleName returns rule name

func (*Issue) Severity added in v0.8.0

func (r *Issue) Severity() Severity

Severity returns severity of the Rule Failure

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

Lint checks the given Commit against rules

func (*Linter) ParseAndLint added in v0.8.0

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

ParseAndLint checks the given commitMsg string against rules

type Note added in v0.8.0

type Note interface {
	Token() string
	Value() string
}

Note represent a footer note

type Parser added in v0.8.0

type Parser interface {
	Parse(msg string) (Commit, error)
}

Parser parses given commit message

type Result

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

Result holds a linter result

func (*Result) Input

func (r *Result) Input() string

Input returns the input commit message

func (*Result) Issues added in v0.8.0

func (r *Result) Issues() []*Issue

Issues returns linter issues

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(setting RuleSetting) error

	// Validate validates the rule for given commit message
	// if given commit is valid, return true and messages slice are ignored
	// if invalid, return a error messages with false
	Validate(msg Commit) (issue *Issue, isValid bool)
}

Rule represent a linter rule

type RuleSetting added in v0.8.0

type RuleSetting struct {
	Argument interface{}            `yaml:"argument"`
	Flags    map[string]interface{} `yaml:"flags,omitempty"`
}

RuleSetting represent config for a 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

type SeverityConfig added in v0.8.0

type SeverityConfig struct {
	Default Severity            `yaml:"default"`
	Rules   map[string]Severity `yaml:"rules,omitempty"`
}

SeverityConfig represent severity levels for rules

Jump to

Keyboard shortcuts

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