Skip to content

feat(commits): add commit message normalizer and validator#185

Open
iamlasse wants to merge 1 commit into
marcus:mainfrom
iamlasse:chore/commit-normalize-20260714
Open

feat(commits): add commit message normalizer and validator#185
iamlasse wants to merge 1 commit into
marcus:mainfrom
iamlasse:chore/commit-normalize-20260714

Conversation

@iamlasse

@iamlasse iamlasse commented Jul 14, 2026

Copy link
Copy Markdown

Summary

Adds a Conventional Commits message normalizer/validator to the project, with an installable enforcement hook and documentation.

  • internal/commits: a parser/normalizer/validator package
    • Normalize(raw) (string, error) rewrites a raw message into canonical form: lowercase type and scope, imperative subject clamped to 72 chars, hard-wrapped body (≤72 cols), preserved trailers with stable ordering. Idempotent on already-conforming input.
    • Validate(raw) []Violation reports structured violations: missing/unknown type, oversize subject, non-imperative verb, trailing period, unwrapped body, malformed trailer.
    • Conforms(raw) bool convenience predicate.
  • cmd/commit-lint: standalone validator that reads the commit message file (Git commit-msg hook contract) and exits non-zero on violations.
  • scripts/install-commit-msg.sh: installs a .git/hooks/commit-msg hook that runs cmd/commit-lint on every commit.
  • docs/commit-messages.md: the convention, allowed types/scopes, examples, and hook install instructions.

Test plan

  • go build ./...
  • go vet ./...
  • gofmt -l clean
  • go test ./internal/commits/... — 22 unit tests covering idempotency, normalization, malformed input, trailer preservation, subject clamping, body wrapping, and validator codes.
  • Smoke-tested cmd/commit-lint: well-formed message exits 0; malformed message exits 1 and prints violations.

Closes the commit-normalize task.

Nightshift-Task: commit-normalize
Nightshift-Ref: https://github.com/marcus/nightshift


Automated by nightshift

Implement a Conventional Commits parser, normalizer, and validator in
internal/commits. The normalizer rewrites a raw message into the canonical
format (lowercase type and scope, imperative subject clamped to 72 chars,
hard-wrapped body, preserved trailers with stable ordering) and is
idempotent on already-conforming input. The validator reports structured
violations for missing/unknown type, oversize subject, non-imperative
verb, trailing period, and unwrapped body.

Also adds cmd/commit-lint (powers the hook), an installable commit-msg
hook (scripts/install-commit-msg.sh), and docs/commit-messages.md listing
allowed types and scopes. Unit tests cover idempotency, normalization,
malformed input, trailer preservation, subject clamping, and wrapping.

Nightshift-Task: commit-normalize
Nightshift-Ref: https://github.com/marcus/nightshift
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant