STG-1671: chore: add prettier pre-commit hook via husky + lint-staged#1888
STG-1671: chore: add prettier pre-commit hook via husky + lint-staged#1888
Conversation
Set up husky and lint-staged so formatting issues are caught before commit instead of failing in CI. The pre-commit hook runs prettier via lint-staged on all staged files, respecting .prettierignore. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
There was a problem hiding this comment.
1 issue found across 3 files
Confidence score: 4/5
- This PR looks safe to merge with minimal risk, but there is a moderate sequencing issue (5/10 severity, high confidence) rather than a runtime/product break.
- In
package.json, running Husky setup before the existing prepare step can skippackages/core/scripts/prepare.jsif Husky fails, which may leave core preparation incomplete in affected environments. - Pay close attention to
package.jsonandpackages/core/scripts/prepare.js- script order should ensure prepare always runs even when Husky setup errors.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="package.json">
<violation number="1" location="package.json:39">
P2: Run the existing prepare script before Husky setup. In the current order, a Husky failure skips `packages/core/scripts/prepare.js` entirely.</violation>
</file>
Architecture diagram
sequenceDiagram
participant Dev as Developer
participant PM as pnpm (Package Manager)
participant Git as Git Engine
participant Husky as Husky (Hooks)
participant LS as lint-staged
participant Prettier as Prettier (Formatter)
participant Core as Core Prepare Script
Note over Dev, Core: Initialization Flow (pnpm install)
Dev->>PM: install
PM->>PM: Run "prepare" script
PM->>Husky: NEW: husky (Initialize hooks)
PM->>Core: node packages/core/scripts/prepare.js
Husky->>Git: Write .git/hooks/pre-commit
Note over Dev, Core: Commit Flow (git commit)
Dev->>Git: git commit -m "..."
Git->>Husky: Trigger pre-commit hook
Husky->>LS: NEW: Run lint-staged
LS->>Git: Identify staged files
Git-->>LS: List of files
alt Files match glob (*)
LS->>Prettier: NEW: prettier --write --ignore-unknown [files]
Prettier->>Prettier: Format staged files
Prettier-->>LS: Success
LS->>Git: Re-stage formatted changes
end
LS-->>Husky: Exit code 0
Husky-->>Git: Allow commit
Git->>Git: Create commit object
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
… failure Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
pirate
left a comment
There was a problem hiding this comment.
Approved but I'd use oxlint and oxfmt over prettier
Summary
huskyfor git hooks andlint-stagedto scope prettier to only staged filespreparescript behavior (node packages/core/scripts/prepare.js)Changes
huskyandlint-stagedas root devDependencies.husky/pre-commithook that runspnpm exec lint-staged{ "*": "prettier --write --ignore-unknown" }(respects.prettierignore)Test plan
pnpm installsets up hooks correctly viapreparescript🤖 Generated with Claude Code