-
-
Couldn't load subscription status.
- Fork 281
feat: add husky and lint-staged #1313
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?
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Pull Request Overview
This PR adds Husky and lint-staged to enforce code quality checks during pre-commit, ensuring consistent formatting and linting across the codebase before commits are made.
- Configures Husky pre-commit hooks to run lint-staged
- Sets up lint-staged configurations for different packages with appropriate tooling (Prettier, ESLint, TypeScript)
- Adds development dependencies and prepare script to initialize Husky
Reviewed Changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| package.json | Adds husky and lint-staged dependencies with prepare script |
| .husky/pre-commit | Defines pre-commit hook to execute lint-staged |
| .lintstagedrc.cjs | Root-level lint-staged config for general file formatting |
| website/.lintstagedrc.js | Website-specific config including CSS and React files |
| packages/to-json-schema/.lintstagedrc.js | Package config for TypeScript files |
| packages/i18n/.lintstagedrc.js | Package config with TypeScript compilation check |
| library/.lintstagedrc.js | Library package config for TypeScript files |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| @@ -0,0 +1,4 @@ | |||
| export default { | |||
| '*.{ts,js,json,md}': 'prettier --write', | |||
| 'src/**/*.ts': ['prettier --write', () => 'tsc -p tsconfig.json --noEmit'], | |||
Copilot
AI
Sep 17, 2025
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.
The arrow function returning a string will not execute the TypeScript compiler. The function should return a command that lint-staged can execute, or use a string directly like 'tsc -p tsconfig.json --noEmit'.
| 'src/**/*.ts': ['prettier --write', () => 'tsc -p tsconfig.json --noEmit'], | |
| 'src/**/*.ts': ['prettier --write', 'tsc -p tsconfig.json --noEmit'], |
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.
It seems like we should check the entire project to determine whether a file has the correct types. Therefore, we don't need to provide a path to a specific file, as lint-staged does. This is recommended by the creators of lint-staged.
| export default { | ||
| '*.{ts,js,cjs,json,md}': 'prettier --write', | ||
| 'src/**/*.css': 'prettier --write', | ||
| 'src/**/*.{ts,tsx}': ['prettier --write', 'eslint --fix'], |
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.
I think we need to add MDX here
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.
Thank you. I added mdx for prettier, eslint is not configured for mdx yet.
|
I never used Husky and lint-staged before. Does this run linting and formatting on every commit? If so, I am not sure if I want that. Mostly because it probably takes more than 30 seconds to run everything. Is it smart enough to only run it on files or folders that have changed? |
This only happens automatically for files that will be committed. The only exception is when we can't check the type validity of a single file. In this case, we run tsc on the project (this is only configured in i18n). For this package and my computer, it's almost instantaneous. I really like it when open-source projects have these hooks. Because many people use different editors, different environments, or are simply inattentive or constantly switching between projects. This helps. |
feat: add Husky and lint-staged for pre-commit checks
Instant feedback. Streamlines contributions by enforcing consistent formatting locally, reducing back-and-forth on formatting fixes