Skip to content

FT-1859: Add pre-commit formatting hook and CI format check#60

Merged
calthejuggler merged 4 commits intomainfrom
bugfix/ft-1859/add-precommit-format-hook
Apr 16, 2026
Merged

FT-1859: Add pre-commit formatting hook and CI format check#60
calthejuggler merged 4 commits intomainfrom
bugfix/ft-1859/add-precommit-format-hook

Conversation

@calthejuggler
Copy link
Copy Markdown
Contributor

@calthejuggler calthejuggler commented Apr 16, 2026

Description

The javascript-sdk repo has Prettier configured but no enforcement mechanism — unformatted code can be committed and merged without any check.

Jira Issue FT-1859

Solution

  • Pre-commit hook: Install husky + lint-staged to auto-format staged files on commit. Only changed files are formatted (fast), and the formatted result is included in the commit.
  • CI format check: Add a dedicated format job to the Build workflow that runs prettier --check against the full codebase. This catches any formatting issues that slip through.
  • Build script: Replace format --write with format:check in the build script — CI should detect violations, not silently fix them.

Other Changes

  • Added actions/setup-node@v4 with npm caching to both CI jobs
  • Switched CI from npm install to npm ci (faster, deterministic)
  • Added package-lock.json to .prettierignore
  • Added format:check npm script (prettier --check)

How to Test

1. Make a formatting change (e.g., add extra spaces in a .ts file)
2. Stage and commit the file — lint-staged should auto-format it
3. Verify the committed file is properly formatted
4. Run `npm run format:check` — should pass
5. Run `npm run build` — should pass (includes format:check)

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Summary by CodeRabbit

  • Chores
    • CI adds a separate formatting check job and uses the repo Node version, installing dependencies with npm ci for reproducibility.
    • Build now runs a formatting check (no automatic rewrites) before lint/build/test.
    • Pre-commit hooks run staged lint/format via lint-staged; Husky is enabled in the package lifecycle.
    • Prettier set to ignore package-lock.json.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 16, 2026

Walkthrough

This pull request adds a format GitHub Actions job that checks out the repo, sets up Node.js from .nvmrc with npm caching, runs npm ci --ignore-scripts, and executes npm run format:check. The build job was updated to use the same checkout and Node setup and to install deps with npm ci --ignore-scripts before npm run build. A trailing newline was added to the workflow file. A .husky/pre-commit hook invoking npx lint-staged was added. package-lock.json was added to .prettierignore. package.json gained format:check and prepare scripts, Husky and lint-staged devDependencies and a top-level lint-staged config. A .nvmrc file with 24 was added.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 I nibble at whitespace, tidy and light,
I guard each newline through the night,
Husky taps, lint-staged does its part,
Prettier checks, neat code from the start,
A happy hop — CI spring in sight ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarises the primary changes: adding both a pre-commit formatting hook and a CI format check, matching the core objectives of the pull request.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bugfix/ft-1859/add-precommit-format-hook

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

@calthejuggler calthejuggler force-pushed the bugfix/ft-1859/add-precommit-format-hook branch from 7324468 to 4357787 Compare April 16, 2026 10:53
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
.github/workflows/build.yml (1)

10-26: Format check runs twice—consider adding a dependency or removing redundancy.

The format job runs npm run format:check, and the build job also runs format:check as part of npm run build. This means formatting is checked twice per workflow run.

If this is intentional for fast-fail feedback (format job finishes quickly while build continues), consider making build depend on format to avoid redundant checks:

Option: Add dependency to avoid redundant checks
   build:
+    needs: format
     runs-on: ubuntu-latest

Then update the build script in package.json to remove format:check from the chain.

Alternatively, keeping them separate is acceptable if the intent is parallel execution with independent failure signals.

Also applies to: 28-44

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/build.yml around lines 10 - 26, The workflow currently
runs the format job and also runs npm run format:check again inside the build
job, causing duplicate checks; either make the build job depend on the format
job or remove the redundant check from the build pipeline: update the workflow
by adding needs: format to the build job (referencing the job name "format") so
build waits for the format job, and then remove the format:check invocation from
your "build" npm script in package.json (referencing the "build" script) so
formatting is only verified by the separate "format" job; alternatively, if you
prefer a single job, remove the standalone "format" job and keep format:check
inside the "build" job.
.husky/pre-commit (1)

1-1: Consider adding a shebang line for portability.

While Husky v9 can execute hooks without a shebang on most systems, adding #!/bin/sh at the top ensures consistent behaviour across different environments and shell configurations.

Proposed fix
+#!/bin/sh
 npx lint-staged
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.husky/pre-commit at line 1, Add a POSIX shebang to the Husky pre-commit
hook so it runs reliably across environments: update the .husky/pre-commit file
(the pre-commit hook that currently calls npx lint-staged) to prepend a single
line with the shebang (e.g. #!/bin/sh) followed by the existing command,
ensuring the file remains executable.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.github/workflows/build.yml:
- Around line 35-38: The "Setup Node.js" step in the build job currently only
sets cache and must explicitly set the Node.js version like the format job does;
update the "Setup Node.js" step (uses: actions/setup-node@v4) to include a
node-version entry under with (matching the version used in the format job) so
the workflow consistently pins the Node.js runtime.
- Around line 17-20: The workflow uses actions/setup-node@v4 with caching but no
explicit Node version; update the setup step (actions/setup-node@v4) to set
node-version (or node-version-file) so builds are reproducible—either add a
specific "node-version" value (e.g., from your .nvmrc or package.json engines)
or enable "node-version-file" to point to a version file while keeping cache:
"npm".

---

Nitpick comments:
In @.github/workflows/build.yml:
- Around line 10-26: The workflow currently runs the format job and also runs
npm run format:check again inside the build job, causing duplicate checks;
either make the build job depend on the format job or remove the redundant check
from the build pipeline: update the workflow by adding needs: format to the
build job (referencing the job name "format") so build waits for the format job,
and then remove the format:check invocation from your "build" npm script in
package.json (referencing the "build" script) so formatting is only verified by
the separate "format" job; alternatively, if you prefer a single job, remove the
standalone "format" job and keep format:check inside the "build" job.

In @.husky/pre-commit:
- Line 1: Add a POSIX shebang to the Husky pre-commit hook so it runs reliably
across environments: update the .husky/pre-commit file (the pre-commit hook that
currently calls npx lint-staged) to prepend a single line with the shebang (e.g.
#!/bin/sh) followed by the existing command, ensuring the file remains
executable.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0cd9f751-3ff0-44ba-aa24-9c2a61275c22

📥 Commits

Reviewing files that changed from the base of the PR and between c80055d and 7324468.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • .github/workflows/build.yml
  • .husky/pre-commit
  • .prettierignore
  • package.json

Comment thread .github/workflows/build.yml
Comment thread .github/workflows/build.yml
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@package.json`:
- Line 39: Update the package.json engines declaration to accurately reflect the
minimum Node.js required by our tooling: change the engines.node field from its
current "node >=6" to ">=20.17" (or alternatively downgrade/pin devDependencies
such as lint-staged to versions that support the older engine), and ensure the
prepare script ("prepare": "husky") and devDependency lint-staged (v16.4.0) are
compatible with the new engines.node value; update package.json's engines.node
accordingly and run npm install / CI to validate.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4d40dcc5-7f17-4c2b-aed4-0892da1e1fe3

📥 Commits

Reviewing files that changed from the base of the PR and between 7324468 and 4357787.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • .github/workflows/build.yml
  • .husky/pre-commit
  • .prettierignore
  • package.json
✅ Files skipped from review due to trivial changes (2)
  • .husky/pre-commit
  • .prettierignore
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/build.yml

Comment thread package.json
@calthejuggler calthejuggler force-pushed the bugfix/ft-1859/add-precommit-format-hook branch from f082a08 to 144f4fd Compare April 16, 2026 11:04
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
package.json (1)

72-74: ⚠️ Potential issue | 🟠 Major

Align engines.node with the newly added tooling requirements.

With lint-staged added at Line 74, the current engine declaration at Line 25 (>=6) is no longer accurate and will mislead consumers and contributors. Please raise engines.node to match the minimum supported Node version for this tooling (or pin tooling versions compatible with your declared engines).

🔧 Proposed patch
 "engines": {
   "npm": ">=3",
-  "node": ">=6"
+  "node": ">=20.17"
 },
#!/bin/bash
set -euo pipefail

# Verify current engines declaration in this repo
cat -n package.json | sed -n '22,27p'

# Verify published engine requirements for added tooling
npm view lint-staged@16.4.0 engines --json
npm view husky@9.1.7 engines --json || true
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@package.json` around lines 72 - 74, The package.json currently declares
"engines.node" too low for the newly added tools; inspect the published engine
requirements for lint-staged@16.4.0, husky@9.1.7 and jest@29.3.1 and update the
engines.node field in package.json to the highest minimum Node version required
by those packages (or pin the added tooling to versions compatible with the
existing engines.node); locate the engines.node property in package.json and
change its value to that minimum (e.g., ">=X") so it aligns with
lint-staged/husky/jest requirements.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@package.json`:
- Around line 72-74: The package.json currently declares "engines.node" too low
for the newly added tools; inspect the published engine requirements for
lint-staged@16.4.0, husky@9.1.7 and jest@29.3.1 and update the engines.node
field in package.json to the highest minimum Node version required by those
packages (or pin the added tooling to versions compatible with the existing
engines.node); locate the engines.node property in package.json and change its
value to that minimum (e.g., ">=X") so it aligns with lint-staged/husky/jest
requirements.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9659a39b-086c-4051-8313-3a8c6f3b55da

📥 Commits

Reviewing files that changed from the base of the PR and between 8a0321d and 144f4fd.

📒 Files selected for processing (3)
  • .github/workflows/build.yml
  • .nvmrc
  • package.json
✅ Files skipped from review due to trivial changes (1)
  • .nvmrc
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/build.yml

@calthejuggler calthejuggler marked this pull request as ready for review April 16, 2026 11:09
@calthejuggler calthejuggler merged commit 29fb24a into main Apr 16, 2026
3 checks passed
@calthejuggler calthejuggler deleted the bugfix/ft-1859/add-precommit-format-hook branch April 16, 2026 11:16
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.

2 participants