commitlint

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2021 License: MIT Imports: 8 Imported by: 0

README

commitlint

commitlint checks if your commit messages meets the conventional commit format

PkgGoDev

Table of Contents
Installation
# Install commitlint
go install github.com/conventionalcommit/commitlint/cmd/commitlint@latest

# test commitlint - error case
echo "fear: do not fear for commit message" | commitlint lint
# will show error message like
# ❌ type: 'fear' is not allowed, you can use one of [feat fix docs style refactor perf test build ci chore revert merge]

# test commitlint - valid case
echo "feat: good commit message" | commitlint lint
#  ✓ commit message
Enable in Git Repo
# enable for single repo
commitlint create hook # from repo directory

# enable for globally for all repos
commitlint create hook --global
Benefits using commitlint
Commit Types

​ Commonly used commit types from Conventional Commit Types

Type Description
feat A new feature
fix A bug fix
docs Documentation only changes
style Changes that do not affect the meaning of the code (white-space, formatting etc)
refactor A code change that neither fixes a bug nor adds a feature
perf A code change that improves performance
test Adding missing tests or correcting existing tests
build Changes that affect the build system or external dependencies
ci Changes to our CI configuration files and scripts
chore Other changes that don't modify src or test files
revert Reverts a previous commit
merge Merges a branch
Library
Config Precedence
  • commitlint.yaml config file in current directory
  • config file passed with --config command-line argument
  • default config
Message Precedence
  • stdin stream
  • commit message file passed with --message command-line argument
  • .git/COMMIT_EDITMSG in current directory
Default Config
header:
    min-length:
        enabled: true
        type: error
        value: 10
    max-length:
        enabled: true
        type: error
        value: 50
    types:
        enabled: true
        type: error
        value:
            - feat
            - fix
            - docs
            - style
            - refactor
            - perf
            - test
            - build
            - ci
            - chore
            - revert
            - merge
    scopes:
        enabled: false
        type: error
        value: []
body:
    can-be-empty: true
    max-line-length:
        enabled: true
        type: error
        value: 72
footer:
    can-be-empty: true
    max-line-length:
        enabled: true
        type: error
        value: 72
License

All packages are licensed under MIT License

Documentation

Overview

Package commitlint provides a simple linter for conventional commits

Index

Constants

View Source
const (
	WarnType  = "warn"
	ErrorType = "error"
)

Rule Type Constants

Variables

This section is empty.

Functions

func CommitMsgHook

func CommitMsgHook() string

func DefaultConfToFile

func DefaultConfToFile(confPath string) error

DefaultConfToFile writes default config to given file

func StreamCommitMsgHook

func StreamCommitMsgHook(qw422016 *qt422016.Writer)

func WriteCommitMsgHook

func WriteCommitMsgHook(qq422016 qtio422016.Writer)

func WriteConfToFile

func WriteConfToFile(confPath string, conf *Config) (retErr error)

WriteConfToFile util func to write config object to given file

Types

type Body

type Body struct {
	CanBeEmpty    bool    `yaml:"can-be-empty"`
	MaxLineLength IntConf `yaml:"max-line-length"`
}

Body contains rules for Body in commit message

type Config

type Config struct {
	Header Header `yaml:"header"`
	Body   Body   `yaml:"body"`
	Footer Footer `yaml:"footer"`
}

Config represent the rules for commit message

type EnumConf

type EnumConf struct {
	Enabled bool     `yaml:"enabled"`
	Type    string   `yaml:"type"`
	Value   []string `yaml:"value"`
}

EnumConf represent enums config

type Footer struct {
	CanBeEmpty    bool    `yaml:"can-be-empty"`
	MaxLineLength IntConf `yaml:"max-line-length"`
}

Footer contains rules for Footer in commit message

type Header struct {
	MinLength IntConf  `yaml:"min-length"`
	MaxLength IntConf  `yaml:"max-length"`
	Types     EnumConf `yaml:"types"`
	Scopes    EnumConf `yaml:"scopes"`
}

Header contains rules for Header in commit message

type IntConf

type IntConf struct {
	Enabled bool   `yaml:"enabled"`
	Type    string `yaml:"type"`
	Value   int    `yaml:"value"`
}

IntConf represent int config

type Linter

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

Linter is a simple linter for conventional commits

func NewDefaultLinter

func NewDefaultLinter() *Linter

NewDefaultLinter returns Linter with default config

func NewLinter

func NewLinter(conf *Config) *Linter

NewLinter returns a new Linter object with given conf

func (*Linter) Lint

func (l *Linter) Lint(commitMsg string) (lintReport string, hasError bool, err error)

Lint checks the given commitMsg string against rules

func (*Linter) LintCommit

func (l *Linter) LintCommit(msg *parser.Commit) (lintReport string, hasError bool)

LintCommit checks the given parser.Commit for rules

type Result

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

Result holds the linter error and warning messages for each rule checked

func NewResult

func NewResult() *Result

NewResult returns new Result Object

func (*Result) Errors

func (res *Result) Errors() []string

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) IsOK

func (res *Result) IsOK() bool

IsOK returns true if commit message passed all the rules

func (*Result) Warns

func (res *Result) Warns() []string

Warns returns all warning messages

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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