linter

package
v0.0.0-...-4604cca Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: EUPL-1.2 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRepositoryRequired = errors.New("repository is required")
	ErrNoLinter           = errors.New("no linter")
)

Functions

func NoReporting

func NoReporting(_ context.Context, _ error)

NoReporting will cause the linter to not report any of the lint errors, but the linter will still return an error if any commit doesn't adhere to the linter's expectations.

Types

type CommitLinter

type CommitLinter interface {
	Lint(*object.Commit) error
}

type Error

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

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() []error

type LintError

type LintError struct {
	Err  error
	Hash plumbing.Hash
	Pos  int
}

func (LintError) Error

func (err LintError) Error() string

func (LintError) Unwrap

func (err LintError) Unwrap() error

type Linter

type Linter struct {
	// Repo is the repository whose commits should be traversed.
	Repo *git.Repository
	// Rev is the revision of where to start the traversal at. Defaults to HEAD.
	Rev plumbing.Revision
	// OtherRev is the revision of a commit whose common ancestor the traversal should stop at.
	OtherRev plumbing.Revision
	// ReportFunc is called after each call to CommitLinter if it returned an error.
	ReportFunc ReportFunc
	// CommitLinter is called for each commit.
	CommitLinter CommitLinter
	// StopFunc is called before CommitLinter is called. Determines if the traversal should stop.
	StopFunc StopFunc

	Logger *slog.Logger
}

func (*Linter) Run

func (l *Linter) Run(ctx context.Context) error

Run will traverse the commit tree, calls [Linter.CommitLinter.Lint] for each commit message.

func (*Linter) Validate

func (l *Linter) Validate() error

Validate will verify that required values are set and sets default values.

type ReportFunc

type ReportFunc func(ctx context.Context, err error)

func SlogReporter

func SlogReporter(logger *slog.Logger) ReportFunc

SlogReporter will log linter errors using log/slog.

type StopFunc

type StopFunc func(commit *object.Commit) bool

func NoStop

func NoStop() StopFunc

NoStop will cause the linter to never stop. Allows the linter to run until the last commit.

func StopAfterN

func StopAfterN(n uint) StopFunc

StopAfterN will cause the linter to stop after N commits.

func StopAtMergeBases

func StopAtMergeBases(mergeBases []*object.Commit) StopFunc

StopAtMergeBases will cause the linter to stop at any of the merge bases.

Jump to

Keyboard shortcuts

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