lint

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 4 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 = commit.Commit

Type aliases for backward compatibility. External packages that depend on lint.Commit, lint.Note, or lint.Parser continue to work without changes.

type Config

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

	// DeprecatedVersion is the old "version" key, kept for backward compatibility.
	// Use MinVersion ("min-version") in new config files.
	DeprecatedVersion string `yaml:"version,omitempty"`

	// 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"`

	// DisableDefaultIgnores disables the built-in ignore patterns
	// (merge, revert, fixup, squash, etc.) when set to true.
	DisableDefaultIgnores bool `yaml:"disable-default-ignores"`

	// IgnorePatterns is a list of user-defined regex patterns.
	// If the first line of the commit message matches any pattern,
	// linting is skipped. These are added on top of the default
	// patterns (unless DisableDefaultIgnores is true).
	IgnorePatterns []string `yaml:"ignores"`

	// DefaultIgnorePatterns holds the built-in patterns (set by config package).
	// Not serialized to YAML - users never set this directly.
	DefaultIgnorePatterns []string `yaml:"-"`
}

Config represent linter config

func (*Config) EffectiveIgnorePatterns added in v0.11.0

func (c *Config) EffectiveIgnorePatterns() []string

EffectiveIgnorePatterns returns the combined list of patterns the linter should use. If DisableDefaultIgnores is true, only user-defined patterns are returned.

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 using the default inspection parser.

func NewWithParser added in v0.13.0

func NewWithParser(conf *Config, rules []Rule, parser commit.Parser) (*Linter, error)

NewWithParser returns a new Linter instance using parser for ParseAndLint.

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 = commit.Note

Type aliases for backward compatibility. External packages that depend on lint.Commit, lint.Note, or lint.Parser continue to work without changes.

type Parser added in v0.8.0

type Parser = commit.Parser

Type aliases for backward compatibility. External packages that depend on lint.Commit, lint.Note, or lint.Parser continue to work without changes.

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"`
}

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"`
}

SeverityConfig represent severity levels for rules

Directories

Path Synopsis
Package formatter contains lint result formatters
Package formatter contains lint result formatters
Package rule contains lint rules
Package rule contains lint rules

Jump to

Keyboard shortcuts

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