style

package
v2.2.6 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 5 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 style shapes and checks commit messages.

The rules are the ones people actually argue about in review: banned punctuation, subject length, whether a subject ends in a period. preen applies them to the messages it generates and verifies the result, so a configured style is enforced rather than merely requested.

Index

Constants

View Source
const DefaultMaxSubject = 72

DefaultMaxSubject is the subject cap when a style does not set one. It is the width git's own tooling assumes.

Variables

View Source
var ErrStyle = errors.New("message does not match the configured style")

ErrStyle reports a commit message that breaks the configured convention.

Functions

This section is empty.

Types

type BodyMode

type BodyMode string

BodyMode controls when a commit gets a message body.

const (
	// BodyAuto keeps a body only when one was written.
	BodyAuto BodyMode = "auto"
	// BodyAlways keeps a body and falls back to naming the files touched.
	BodyAlways BodyMode = "always"
	// BodyNever drops the body, leaving a subject-only message.
	BodyNever BodyMode = "never"
)

The body modes.

type Punctuation

type Punctuation string

Punctuation controls terminal punctuation on a subject.

const (
	// PunctAuto leaves terminal punctuation as written.
	PunctAuto Punctuation = "auto"
	// PunctAlways ends the subject with a period.
	PunctAlways Punctuation = "always"
	// PunctNever strips terminal punctuation from the subject.
	PunctNever Punctuation = "never"
)

The punctuation modes.

type Style

type Style struct {
	// NoEmDash forbids em and en dashes anywhere in a message.
	NoEmDash bool
	// NoSemicolon forbids semicolons.
	NoSemicolon bool
	// NoHyphen forbids hyphens, for repositories that spell compounds out.
	NoHyphen bool
	// MaxSubject caps the subject length. Zero means the default of 72.
	MaxSubject int
	// Punctuation controls the terminal punctuation on a subject.
	Punctuation Punctuation
	// LowerSubject lowercases the first letter of the subject.
	LowerSubject bool
	// Conventional shapes subjects as Conventional Commits, "type: subject".
	Conventional bool
	// Prefix is prepended to every subject, such as a ticket identifier.
	Prefix string
	// Body controls whether a message keeps a body.
	Body BodyMode
	// SignOff adds a Signed-off-by trailer built from Signer.
	SignOff bool
	// Signer is the identity used for the sign-off trailer.
	Signer string
}

Style is a commit message convention.

func (Style) Apply

func (s Style) Apply(commit plan.Commit) plan.Commit

Apply returns the commit with its message shaped to the style.

func (Style) Verify

func (s Style) Verify(commit plan.Commit) error

Verify reports the ways a message breaks the style, so a message can be checked before it is recorded rather than discovered in review.

Jump to

Keyboard shortcuts

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