Skip to content

Feature/563 Add pre-commit hook to auto fix lint issues before committing - #782

Merged
junaidiqbalmoj merged 9 commits into
masterfrom
feature/563-add-pre-commit-hook
Jul 3, 2026
Merged

Feature/563 Add pre-commit hook to auto fix lint issues before committing#782
junaidiqbalmoj merged 9 commits into
masterfrom
feature/563-add-pre-commit-hook

Conversation

@KianKwa

@KianKwa KianKwa commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Jira link

#563

Change description

Add pre-commit hook to auto fix lint issues before committing

Testing done

Security Vulnerability Assessment

CVE Suppression: Are there any CVEs present in the codebase (either newly introduced or pre-existing) that are being intentionally suppressed or ignored by this commit?

  • Yes
  • No

Checklist

  • commit messages are meaningful and follow good commit message guidelines
  • README and other documentation has been updated / added (if needed)
  • tests have been updated / new tests has been added (if needed)
  • Does this PR introduce a breaking change

Summary by CodeRabbit

  • New Features
    • Added an automatic pre-commit hook that runs Biome on staged files, applies auto-fixes, and re-stages changes.
    • Hook installation runs after setup, with a CI bypass and a single-commit opt-out option.
  • Documentation
    • Updated commit workflow guidance and ticket documentation for the new pre-commit behaviour and scenarios.
  • Chores / Configuration
    • Added Lefthook configuration and improved local override ignores.
    • Added a .dockerignore to reduce build context bloat.

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f7743a5f-6a99-4e9f-9a16-1f8f2b2e70b9

📥 Commits

Reviewing files that changed from the base of the PR and between 67ff591 and f710058.

📒 Files selected for processing (3)
  • .dockerignore
  • .gitignore
  • lefthook.yml
✅ Files skipped from review due to trivial changes (2)
  • lefthook.yml
  • .gitignore

📝 Walkthrough

Walkthrough

Adds lefthook as a dev dependency, wires it into postinstall, configures a serial pre-commit Biome hook, updates git ignore rules, and adds ticket documentation for #563. A new .dockerignore also excludes local, cache, build, and docs artefacts from Docker builds.

Changes

Lefthook Pre-commit Hook Implementation

Layer / File(s) Summary
Dependency, postinstall, and hook config
package.json, lefthook.yml, .gitignore
lefthook 2.1.9 is added to devDependencies; postinstall now runs lefthook install unless CI is set; lefthook.yml defines a serial pre-commit Biome command with auto-staging of fixes; .lefthook-local.yml is ignored.
Developer docs and ticket documentation
CLAUDE.md, docs/tickets/563/*
CLAUDE.md adds a Git Hooks note and LEFTHOOK=0 bypass; the ticket, plan, tasks, and review documents describe the hook workflow, edge cases, acceptance criteria, and review outcome.

Docker Context Ignore List

Layer / File(s) Summary
.dockerignore contents
.dockerignore
Adds Docker ignore patterns for Git history, environment files, certificates, editor artefacts, test outputs, cache, and build/docs directories.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding a pre-commit hook to auto-fix lint issues before commits.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/563-add-pre-commit-hook

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Nitpick comments (1)
docs/tickets/563/review.md (1)

32-34: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Add language specifiers to fenced code blocks.

Lines 32 and 72 show quoted file content in fenced code blocks without language tags. Add text or markdown specifiers for consistent rendering.

Also applies to: 72-74


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f8d07295-8ec9-4591-9f10-64692f5a5ee2

📥 Commits

Reviewing files that changed from the base of the PR and between 4e271dd and 67ff591.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (8)
  • .gitignore
  • CLAUDE.md
  • docs/tickets/563/plan.md
  • docs/tickets/563/review.md
  • docs/tickets/563/tasks.md
  • docs/tickets/563/ticket.md
  • lefthook.yml
  • package.json

Comment thread CLAUDE.md
Comment on lines +18 to +21
# Git Hooks (installed automatically via postinstall)
# Pre-commit hook runs Biome --write on all staged files and re-stages fixes.
# To skip the hook for a single commit: LEFTHOOK=0 git commit ...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Update documentation to match actual hook scope.

Line 19 states "all staged files", but the hook targets only TypeScript files (**/*.{ts,tsx} per review.md). Update to "TypeScript/TSX files" for accuracy. Also consider clarifying that Biome handles lint/format only, not type errors.

Comment thread docs/tickets/563/plan.md
Add to root `package.json` devDependencies:

```json
"lefthook": "1.11.14"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Plan specifies incorrect lefthook version.

The plan documents version 1.11.14, but package.json installs 2.1.9. Update the plan to match the actual dependency version to avoid confusion.

Comment thread docs/tickets/563/plan.md
Comment thread docs/tickets/563/tasks.md
## Implementation Tasks

- [x] Add `lefthook` dev dependency to root `package.json` (pinned version)
- [x] Update `postinstall` script in root `package.json` to run `lefthook install` (CI-guarded) after `yarn db:generate`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Remove stale --reset-hooks-path reference.

The implementation removed this flag (per review.md), but tasks.md still records it. Update to match the actual node -e "process.env.CI || ..." guard.

Comment thread lefthook.yml
Comment on lines +1 to +6
pre-commit:
parallel: false
commands:
biome-check:
run: yarn biome check --write {staged_files}
stage_fixed: true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check if glob is present in lefthook.yml
cat -n lefthook.yml

Repository: hmcts/cath-service

Length of output: 332


🌐 Web query:

Lefthook command glob staged_files default behaviour no glob file filtering documentation

💡 Result:

In Lefthook, the default behavior for file filtering when no glob is explicitly defined is to process all relevant files based on the hook type (e.g., all staged files for pre-commit hooks) [1][2][3]. When you define a glob or exclude filter, Lefthook applies it to the file list before executing your command [3][4]. The specific mechanics are as follows: 1. Automatic Filtering: If you use a file template in your run command (such as {staged_files}) or provide a custom files command, Lefthook uses your specified glob and exclude patterns to filter that list [1][5]. 2. Implicit Filtering without Templates: If you specify a glob or exclude filter but do not include a file template (like {staged_files}) in your run command, Lefthook will still automatically check the relevant file set—{staged_files} for pre-commit or {push_files} for pre-push [1][4]. 3. Command Skipping: In this scenario, if the filtering process results in no files remaining (e.g., no staged files match your glob pattern), Lefthook will automatically skip the execution of that command entirely [1][6][4]. By default, Lefthook uses the gobwas/glob library for pattern matching [1][7]. A key detail to note is that the `` pattern in this library matches one or more directories deep by default; to match files at the top level and nested directories simultaneously, you must either provide separate patterns or enable glob_matcher: doublestar in your configuration [1][7].

Citations:


Add the glob filter back — without it, this hook will run biome check --write against every staged file, not just TS/TSX files.

@github-actions

github-actions Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

🎭 Playwright E2E Test Results

84 tests   52 ✅  6m 25s ⏱️
33 suites  32 💤
 1 files     0 ❌

Results for commit f710058.

♻️ This comment has been updated with latest results.

KianKwa and others added 4 commits June 29, 2026 16:07
The postinstall references `node scripts/install-hooks.js` but the file
was never committed because `*.js` in .gitignore was catching it.

Added `!scripts/install-hooks.js` exception to .gitignore alongside the
existing `!e2e-tests/run-with-credentials.js` exception for hand-written
CommonJS utility scripts.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

Preview Deployment Successful 🚀

Your preview environment is ready:

The environment will be automatically cleaned up when this PR is closed.

@KianKwa KianKwa linked an issue Jun 29, 2026 that may be closed by this pull request
Comment thread lefthook.yml
commands:
biome-check:
run: yarn biome check --write --no-errors-on-unmatched {staged_files}
stage_fixed: true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you ask AI to compare this hook with existing CaTH? https://github.com/hmcts/pip-frontend/blob/master/lefthook.yml.

@sonarqubecloud

sonarqubecloud Bot commented Jul 3, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Preview Deployment Successful 🚀

Your preview environment is ready:

The environment will be automatically cleaned up when this PR is closed.

@junaidiqbalmoj
junaidiqbalmoj merged commit d3f0540 into master Jul 3, 2026
26 checks passed
hmctsclaudecode Bot pushed a commit that referenced this pull request Jul 9, 2026
10 STATUS + IMPL changes (closed issue + merged closing PR → verified):
  REQ-0078 (#301): implemented → verified (PR #458)
  REQ-0105 (#428): in_progress  → verified (PR #749)
  REQ-0106 (#429): approved     → verified (PR #761)
  REQ-0107 (#431): implemented → verified (PR #701)
  REQ-0108 (#434): approved     → verified (PR #772)
  REQ-0109 (#436): implemented → verified (PR #727)
  REQ-0112 (#467): implemented → verified (PR #670)
  REQ-0124 (#563): approved     → verified (PR #782)
  REQ-0135 (#569): in_progress  → verified (PR #748)
  REQ-0137 (#729): approved     → verified (PR #766)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix any typescript and lint issue when commit code into branch

2 participants