-
Notifications
You must be signed in to change notification settings - Fork 23
chore: add pre-commit hooks with Husky and lint-staged #427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
chore: add pre-commit hooks with Husky and lint-staged #427
Conversation
- Upgrade Husky from v8 to v9 - Add lint-staged for running checks only on staged files - Configure ESLint with auto-fix for .ts files - Configure Prettier for source files, JSON, Markdown, and YAML - Remove deprecated .husky/_ directory
|
|
@revaarathore11 is attempting to deploy a commit to the elixir-cloud-aai Team on Vercel. A member of the Team first needs to authorize it. |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideModernizes the Git hooks setup by upgrading Husky to v9, wiring it into npm scripts, and introducing lint-staged configuration to run ESLint --fix and Prettier only on staged files during pre-commit, while removing legacy Husky internals and updating lockfile metadata. Sequence diagram for updated Husky v9 pre-commit with lint-stagedsequenceDiagram
actor Developer
participant Git
participant Husky_v9 as Husky v9
participant lint_staged as lint-staged
participant ESLint
participant Prettier
Developer->>Git: git commit
Git->>Husky_v9: Trigger pre-commit hook
Husky_v9->>lint_staged: Run lint-staged on staged files
lint_staged->>ESLint: eslint --fix on staged *.ts
lint_staged->>Prettier: prettier --write on staged *.{ts,js,mjs,json,md,yaml,yml}
ESLint-->>lint_staged: Lint and auto-fix complete
Prettier-->>lint_staged: Formatting complete
lint_staged-->>Husky_v9: Exit code (success or failure)
Husky_v9-->>Git: Pre-commit result
Git-->>Developer: Commit succeeds or is rejected
Flow diagram for Husky v9 and lint-staged pre-commit pipelineflowchart LR
Dev["Developer runs git commit"] --> GitHook["Git pre-commit hook"]
GitHook --> Husky["Husky v9 pre-commit script"]
Husky --> LintStaged["lint-staged"]
subgraph Lint_Configs["lint-staged configuration in package.json"]
TSFiles["Pattern: *.ts"] --> ESLintFix["Command: eslint --fix"]
MultiFiles["Pattern: *.{ts,js,mjs,json,md,yaml,yml}"] --> PrettierWrite["Command: prettier --write"]
end
LintStaged --> TSFiles
LintStaged --> MultiFiles
ESLintFix --> LintStaged
PrettierWrite --> LintStaged
LintStaged -->|All checks pass| CommitOK["Commit proceeds"]
LintStaged -->|Any check fails| CommitBlocked["Commit is blocked"]
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey - I've left some high level feedback:
- The diff doesn’t show any change to
.husky/pre-commit; make sure the hook actually runslint-staged(e.g.,npx lint-staged) so the new configuration is exercised on commit. - Your
lint-stagedconfig runs on*.tsand then again on*.{ts,js,...}, so TypeScript files will be processed twice; consider consolidating to a single entry per extension (e.g.,"*.ts": ["eslint --fix", "prettier --write"]) to avoid redundant work.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The diff doesn’t show any change to `.husky/pre-commit`; make sure the hook actually runs `lint-staged` (e.g., `npx lint-staged`) so the new configuration is exercised on commit.
- Your `lint-staged` config runs on `*.ts` and then again on `*.{ts,js,...}`, so TypeScript files will be processed twice; consider consolidating to a single entry per extension (e.g., `"*.ts": ["eslint --fix", "prettier --write"]`) to avoid redundant work.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
@uniqueg please review |
Summary
This PR modernizes the Git hooks setup by upgrading Husky from v8 to v9 and introducing lint-staged to optimize pre-commit checks. The updated configuration improves performance, simplifies maintenance, and enhances the local developer experience.
Changes
• Upgrade Husky to v9
• Migrated from Husky v8 to v9 for a cleaner and more streamlined hooks setup.
• Add lint-staged
• Runs checks only on staged files, significantly reducing pre-commit execution time.
• ESLint auto-fix
• Automatically runs eslint --fix on staged .ts files.
• Prettier formatting
• Formats staged source files, JSON, Markdown, and YAML files.
• Remove legacy Husky internals
• Deleted the deprecated .husky/_ directory, which is no longer required in Husky v9.
Checklist
• My code follows the contributing guidelines of this project
• I am aware that all my commits will be squashed into a single commit using the PR title
• I have performed a self-review of my own code
• I have commented my code in hard-to-understand areas
• I have updated user-facing documentation where applicable
• My changes generate no new warnings
• I have added tests where applicable
• I have not reduced existing code coverage
Notes
This is a developer tooling–only change aimed at improving the local development workflow.
No tests were added, as the changes are configuration-based and can be verified manually by creating a commit and observing the pre-commit behavior.
Summary by Sourcery
Update Git hooks configuration to use Husky v9 with lint-staged for staged-file linting and formatting.
New Features:
Build:
Chores:
screenshot: