Skip to content

feat: add commit message normalizer (library + commit-normalize subcommand)#177

Open
iamlasse wants to merge 1 commit into
marcus:mainfrom
iamlasse:feat/commit-normalize-20260623
Open

feat: add commit message normalizer (library + commit-normalize subcommand)#177
iamlasse wants to merge 1 commit into
marcus:mainfrom
iamlasse:feat/commit-normalize-20260623

Conversation

@iamlasse

Copy link
Copy Markdown

Summary

Adds a Conventional Commits commit-message normalizer, exposed both as a reusable Go library (internal/normalizer) and as a nightshift commit-normalize subcommand.

Normalization rules

  • Lowercase the subject line.
  • Strip trailing periods from the subject.
  • Trim leading/trailing whitespace (overall and per line).
  • Separate subject and body with exactly one blank line (inserted if missing).
  • Enforce the type(scope)!?: subject shape — lowercases the type/scope, normalizes the colon-space and ! breaking marker.
  • Wrap body paragraphs to <=100 columns (greedy word wrap); footer lines (Token: value / Token #123) are left verbatim.
  • Warn when the subject exceeds 72 characters or lacks a type prefix.

CLI

nightshift commit-normalize reads a message from a positional file path, --file, or stdin, prints the normalized message to stdout, emits any warnings to stderr, and exits non-zero on empty/invalid input.

$ echo 'Fix: Add OAuth.' | nightshift commit-normalize
fix: add oauth

Tests

Table-driven tests in internal/normalizer/normalizer_test.go cover: clean input, lowercase + period stripping, scope/breaking-marker normalization, missing type prefix, oversized subject, trailing-whitespace trimming, blank-line insertion, subject/body/footer structure, and empty-input errors. Additional tests assert body wrapping stays <=100 columns and that footers are not wrapped. go build ./..., go vet, and go test ./... all pass.

Assumptions / notes

  • The plan assumed the repo was empty and would be bootstrapped from scratch. In practice marcus/nightshift already contains a Go module, so this integrates into the existing module (github.com/marcus/nightshift) and follows the established cobra command pattern rather than running go mod init or rewriting main.go.
  • "Lowercase the subject" is implemented literally: the entire subject line (type, scope, and description) is lowercased. If the project prefers to lowercase only the type(scope) prefix and preserve the description's casing, that is a one-line change.
  • The 72-char subject limit and 100-col body wrap are exposed as SubjectLimit / WrapLimit constants.

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

Add a Conventional Commits normalizer exposed as a reusable library
(internal/normalizer) and a `commit-normalize` subcommand.

Normalization rules:
- lowercase the subject line
- strip trailing periods
- trim leading/trailing whitespace
- separate subject and body with a single blank line
- enforce the type(scope)!?: subject shape
- wrap body paragraphs to <=100 columns (footers kept verbatim)
- warn when the subject exceeds 72 characters or lacks a type prefix

The subcommand reads a message from a positional file path, --file, or
stdin and prints the normalized message, exiting non-zero on empty/invalid
input. Logic is covered by table-driven tests.

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