GitHub Packages · MIT · Node ≥ 18

commit-gauge

A lightweight Conventional Commits linter for git hooks and CI, with clear fix-up suggestions.

Lightweight Conventional Commits linter for git hooks and CI: lints a message, a file, stdin or a commit range, explains every problem and suggests a corrected header. Configurable types/scopes, sign-off and issue rules, hook installer. Text/JSON/SARIF/Markdown, allowlist with expiry, GitHub Action. Zero deps.

  1. 1 Point the @mrlouiswright scope at GitHub Packages in .npmrc

    @mrlouiswright:registry=https://npm.pkg.github.com
  2. 2 Install

    npm i -D @mrlouiswright/commit-gauge
Installing from GitHub Packages needs a token

Published to GitHub Packages, not npmjs.com. GitHub Packages needs a GitHub token with read:packages to install, even for public packages: add //npm.pkg.github.com/:_authToken=${GITHUB_TOKEN} to .npmrc or run npm login --registry=https://npm.pkg.github.com.

~/project — zsh
$ npx commit-gauge -m "feature(API): Added new endpoint."commit-gauge — commit message1 commit(s) linted, 1 with problems HIGH     type "feature" is not one of: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert [type-unknown]         ↳ fix: Use "feat". Suggested header: "feat(api): add new endpoint"LOW      scope "API" should be lowercase [scope-case]         ↳ fix: Use "api".LOW      subject ends with a full stop [subject-full-stop]         ↳ fix: Remove the trailing ".".LOW      subject starts with an uppercase letter ("Added") [subject-case]         ↳ fix: Use "added". 1 high, 3 low, 1 info✖ Failing (fail-on: high).
Sample output from the commit-gauge README.

Why it exists

commit-gauge checks commit messages against Conventional Commits. It tells you what's wrong and also what to write instead. “Fixed the Login bug.” gets the suggestion “fix: fix the Login bug”, and “feature(API): Added new endpoint.” gets “feat(api): add new endpoint”. Use it as a commit-msg hook, on a single message, or on every commit in a pull request.

CLI, library and GitHub Action. Node.js 18+, zero runtime dependencies (commitlint needs dozens). By Louis Wright.

Features

Inputs

--message, --edit (the commit-msg hook file), --file, --stdin, or a git range --from/--to. Merge, revert and release commits are skipped. An all-zero --from (a new branch push) lints just the head commit.

Header rules

format, allowed types (with the closest match: feature → feat, bugfix → fix), lowercase type and scope, empty and allowed scopes, empty subject, trailing full stop, sentence case, imperative mood (added → add), and max length.

Body/footer rules

blank lines before body and footer, BREAKING CHANGE: spelling, line length (URLs exempt), optional Signed-off-by and issue-reference requirements.

History hygiene

fixup!/squash!/amend! and WIP commits are caught before merge.

Hook installer

commit-gauge --install-hook writes .husky/commit-msg if Husky is set up, otherwise .git/hooks/commit-msg.

Output

text, JSON, SARIF 2.1.0 and Markdown; --fail-on; exit codes 0/1/2; allowlist entries with expiry dates.

Usage

# lint every commit message locally

 npx commit-gauge --install-hook

# Example

 npx commit-gauge -m "feature(API): Added new endpoint."

# every commit on this branch

 npx commit-gauge --from origin/main --to HEAD

# Example

 git log -1 --format=%B | npx commit-gauge --stdin

CI / GitHub Action

permissions:
  contents: read
  security-events: write   # only needed for the SARIF upload
jobs:
  commit-gauge:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
        with: { persist-credentials: false, fetch-depth: 0 }
      - uses: MrLouisWright/commit-gauge@v1
        with:
          fail-on: high
          sarif: commit-gauge.sarif
      - uses: github/codeql-action/upload-sarif@v3
        if: always()
        with: { sarif_file: commit-gauge.sarif }

Options & flags

FlagDescription
-m, --message <msg>Lint this message
-e, --edit [file]Lint the commit-msg hook file (default: .git/COMMIT_EDITMSG)
--file <file>Lint a message stored in a file
--stdinRead the message from stdin
--from <ref>Lint every commit in <from>..<to> (all-zero SHA = only <to>)
--to <ref>End of the range (default: HEAD)
Rules
--types <list>Allowed types (default: feat,fix,docs,style,refactor,perf,test,build,ci,chore,revert)
--scopes <list>Allowed scopes (default: any)
--require-scopeA scope is mandatory
--max-length <n>Header max length (default: 100)
--require-signoffRequire a Signed-off-by trailer
--issue-pattern <re>Require an issue reference matching this regex
--no-merges-ignoredAlso lint merge commits
Hooks
--install-hookWrite a commit-msg hook (.husky/commit-msg if husky is set up, else .git/hooks)
Common
-c, --config <file>JSON config (default: .commit-gauge.json or "commitGauge" in package.json)
-f, --format <fmt>text (default) | json | sarif | markdown
--json <file>Also write a JSON report
--sarif <file>Also write SARIF 2.1.0
--markdown <file>Also write Markdown (e.g. for a job summary)
--fail-on <sev>critical | high | medium | low | info | none (default: high)
--list-rulesPrint rules and default severities
--no-fixesHide fix suggestions in text output
--no-colorDisable colours

Full reference, config file format and API in the README.

Support this project

Support open-source security tools

I build free, open-source tools that help developers ship safer websites. Every coffee helps keep them maintained, documented and free for everyone.

Buy me a coffee (opens Stripe in a new tab)

Secure checkout by Stripe

Portrait of Louis Wright

About the author

Louis Wright

Cyber security researcher and software engineer based in the UK.

More tools by Louis Wright

58 tools

Sentinels security scanners & CI gates · 20