FT-1859: Add pre-commit formatting hook and CI format check#60
FT-1859: Add pre-commit formatting hook and CI format check#60calthejuggler merged 4 commits intomainfrom
Conversation
WalkthroughThis pull request adds a Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
7324468 to
4357787
Compare
There was a problem hiding this comment.
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
formatjob runsnpm run format:check, and thebuildjob also runsformat:checkas part ofnpm 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
builddepend onformatto avoid redundant checks:Option: Add dependency to avoid redundant checks
build: + needs: format runs-on: ubuntu-latestThen update the
buildscript inpackage.jsonto removeformat:checkfrom 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/shat 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
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (4)
.github/workflows/build.yml.husky/pre-commit.prettierignorepackage.json
There was a problem hiding this comment.
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
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (4)
.github/workflows/build.yml.husky/pre-commit.prettierignorepackage.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
f082a08 to
144f4fd
Compare
There was a problem hiding this comment.
♻️ Duplicate comments (1)
package.json (1)
72-74:⚠️ Potential issue | 🟠 MajorAlign
engines.nodewith the newly added tooling requirements.With
lint-stagedadded at Line 74, the current engine declaration at Line 25 (>=6) is no longer accurate and will mislead consumers and contributors. Please raiseengines.nodeto 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
📒 Files selected for processing (3)
.github/workflows/build.yml.nvmrcpackage.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
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
formatjob to the Build workflow that runsprettier --checkagainst the full codebase. This catches any formatting issues that slip through.format --writewithformat:checkin the build script — CI should detect violations, not silently fix them.Other Changes
actions/setup-node@v4with npm caching to both CI jobsnpm installtonpm ci(faster, deterministic)package-lock.jsonto.prettierignoreformat:checknpm script (prettier --check)How to Test
Type of change
Checklist
Summary by CodeRabbit