Skip to content

ci: add pre-commit markdownlint gate for staged .md files#232

Merged
mpaulosky merged 2 commits into
devfrom
squad/230-precommit-markdownlint-gate
May 6, 2026
Merged

ci: add pre-commit markdownlint gate for staged .md files#232
mpaulosky merged 2 commits into
devfrom
squad/230-precommit-markdownlint-gate

Conversation

@mpaulosky

Copy link
Copy Markdown
Owner

Summary

Adds a pre-commit git hook that runs markdownlint-cli2 on staged .md files before each local commit, preventing formatting violations from ever entering commits.

Changes

  • .github/hooks/pre-commit — new hook that:
    • Lints only staged .md files (fast: never scans the whole repo)
    • Uses repo .markdownlint.json config for consistent rules
    • Degrades gracefully if markdownlint-cli2 is not installed (warns, does not block)
    • Exits 1 with clear file/rule output on violations; silent on success
  • scripts/install-hooks.sh — updated to install pre-commit alongside pre-push; updated summary message
  • package.json — adds markdownlint-cli2 ^0.17.2 as dev dependency
  • package-lock.json — updated lockfile

Testing

  • Staged a known-good .md file → hook exits 0 silently ✅
  • Staged a .md file with violations → hook exits 1 with clear error output showing file and rule ✅

Context

Follows up on PR #229 which fixed 3,243+ markdownlint violations and added .markdownlint.json. This gate prevents regressions at commit time.

Working as Aragorn (Lead / Architect)

- Add .github/hooks/pre-commit: lints only staged .md files via markdownlint-cli2
- Hook degrades gracefully (warns, does not block) if binary not found
- Update scripts/install-hooks.sh to install pre-commit hook alongside pre-push
- Add markdownlint-cli2 ^0.17.2 as dev dependency in package.json
- Uses repo .markdownlint.json config for consistent rule enforcement

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 6, 2026 05:46
@github-actions github-actions Bot added the squad Squad triage inbox — Lead will assign to a member label May 6, 2026
@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor

🏗️ PR Added to Squad Triage Queue

This PR has been labeled with squad and added to the triage queue.

Next steps:

  • The squad Lead will review and assign to an appropriate team member
  • A squad:member label will be added after triage

If you know which squad member should handle this, you can add the appropriate squad:member label yourself.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@mpaulosky
mpaulosky enabled auto-merge (squash) May 6, 2026 05:48
@mpaulosky
mpaulosky merged commit 6e33b47 into dev May 6, 2026
12 checks passed
@mpaulosky
mpaulosky deleted the squad/230-precommit-markdownlint-gate branch May 6, 2026 05:49

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new local pre-commit git hook to lint staged Markdown files before commit, and wires it into the existing hook installation flow, backed by a new npm dev dependency.

Changes:

  • Added .github/hooks/pre-commit to run markdown linting against staged .md files.
  • Updated scripts/install-hooks.sh to install pre-commit alongside existing hooks and to print updated guidance.
  • Added markdownlint-cli2 to package.json and updated package-lock.json.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 7 comments.

File Description
.github/hooks/pre-commit New pre-commit gate that runs markdown linting on staged Markdown files.
scripts/install-hooks.sh Installs the new pre-commit hook and updates the post-install summary output.
package.json Adds markdownlint-cli2 as a dev dependency.
package-lock.json Lockfile update reflecting the new dev dependency tree.

Comment thread scripts/install-hooks.sh
Comment on lines 89 to 90
echo " 3. Unit/arch tests (tests/Architecture.Tests, tests/Unit.Tests)"
echo " 4. Integration tests (tests/Integration.Tests — Docker required)"
Comment thread .github/hooks/pre-commit
Comment on lines +24 to +30
if command -v markdownlint &>/dev/null; then
MARKDOWNLINT_BIN="markdownlint"
elif [[ -x "$ROOT/node_modules/.bin/markdownlint-cli2" ]]; then
MARKDOWNLINT_BIN="$ROOT/node_modules/.bin/markdownlint-cli2"
elif [[ -x "$ROOT/node_modules/.bin/markdownlint" ]]; then
MARKDOWNLINT_BIN="$ROOT/node_modules/.bin/markdownlint"
fi
Comment thread .github/hooks/pre-commit
Comment on lines +19 to +21
echo -e "${CYAN}━━━ Pre-Commit Markdownlint Gate ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${RESET}"

# ── Probe for markdownlint binary ──────────────────────────────────────────
Comment thread .github/hooks/pre-commit
Comment on lines +45 to +55
CONFIG_FLAG=""
if [[ -f "$ROOT/.markdownlint.json" ]]; then
if [[ "$(basename "$MARKDOWNLINT_BIN")" == "markdownlint-cli2" ]]; then
CONFIG_FLAG="--config $ROOT/.markdownlint.json"
else
CONFIG_FLAG="--config $ROOT/.markdownlint.json"
fi
fi

# shellcheck disable=SC2086
if "$MARKDOWNLINT_BIN" $CONFIG_FLAG "${MD_FILES[@]}" 2>&1; then
Comment thread .github/hooks/pre-commit
Comment on lines +47 to +51
if [[ "$(basename "$MARKDOWNLINT_BIN")" == "markdownlint-cli2" ]]; then
CONFIG_FLAG="--config $ROOT/.markdownlint.json"
else
CONFIG_FLAG="--config $ROOT/.markdownlint.json"
fi
Comment thread .github/hooks/pre-commit
Comment on lines +12 to +17
# ── Collect staged .md files ───────────────────────────────────────────────
STAGED_MD=$(git diff --cached --name-only --diff-filter=ACM | grep '\.md$' || true)

if [[ -z "$STAGED_MD" ]]; then
exit 0
fi
Comment thread .github/hooks/pre-commit
fi

# shellcheck disable=SC2086
if "$MARKDOWNLINT_BIN" $CONFIG_FLAG "${MD_FILES[@]}" 2>&1; then
@codecov

codecov Bot commented May 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.64%. Comparing base (4e1df52) to head (763dfad).
⚠️ Report is 2 commits behind head on dev.

Additional details and impacted files
@@           Coverage Diff           @@
##              dev     #232   +/-   ##
=======================================
  Coverage   78.64%   78.64%           
=======================================
  Files          43       43           
  Lines         721      721           
  Branches      112      112           
=======================================
  Hits          567      567           
  Misses        108      108           
  Partials       46       46           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

squad Squad triage inbox — Lead will assign to a member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants