linter

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommitCorrection added in v0.3.0

type CommitCorrection struct {
	Type    string
	Scope   string
	Message string
	Score   float64
}

func SuggestCorrection added in v0.3.0

func SuggestCorrection(message string, config *KeywordsConfig) (*CommitCorrection, error)

SuggestCorrection analyzes an invalid commit message and suggests corrections

type KeywordType added in v0.3.0

type KeywordType struct {
	Name        string   `yaml:"name"`
	Description string   `yaml:"description"`
	Keywords    []string `yaml:"keywords"`
}

type KeywordsConfig added in v0.3.0

type KeywordsConfig struct {
	CommitTypes  []KeywordType `yaml:"commit_types"`
	CommitScopes []KeywordType `yaml:"commit_scopes"`
}

func LoadKeywords added in v0.3.0

func LoadKeywords() (*KeywordsConfig, error)

type LintError

type LintError struct {
	CommitHash string
	Message    string
	FixSteps   string
}

type Linter

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

func New

func New(cfg *config.Config) *Linter

func (*Linter) LintCommitMessage

func (l *Linter) LintCommitMessage(message string) error

LintCommitMessage lints a single commit message from a string

func (*Linter) LintCommitMessageFile

func (l *Linter) LintCommitMessageFile(filepath string) error

LintCommitMessageFile lints a commit message from a file path

func (*Linter) LintCommits

func (l *Linter) LintCommits(commitRange string) error

LintCommits lints the commit messages in the given range and returns an error if any commit fails the linting rules.

The function accepts a Git commit range (e.g., "HEAD~5..HEAD") and validates each commit message against the configured linting rules. It performs the following checks:

  • Commit message format validation
  • Commit type verification
  • Scope requirement check (if enabled)
  • Message length validation

For any commits that fail validation, it generates detailed error messages including:

  • The commit hash
  • The specific validation failure
  • Step-by-step instructions for fixing the commit

Example usage:

git-commit-linter --config=config.yaml --check="HEAD~5..HEAD"

Returns nil if all commits pass validation, or error details if any commits fail.

func (*Linter) SuggestMessageCorrection added in v0.3.0

func (l *Linter) SuggestMessageCorrection(message string) (string, error)

type ValidationError added in v0.3.0

type ValidationError struct {
	Message string
}

func (*ValidationError) Error added in v0.3.0

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

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