Skip to content

Conversation

@yslpn
Copy link
Contributor

@yslpn yslpn commented Sep 17, 2025

feat: add Husky and lint-staged for pre-commit checks

  • Add Husky pre-commit hook
  • Configure lint-staged to run prettier, eslint and tsc on staged files.
  • Dev tooling only; no runtime code changes

Instant feedback. Streamlines contributions by enforcing consistent formatting locally, reducing back-and-forth on formatting fixes

Copilot AI review requested due to automatic review settings September 17, 2025 09:17
@vercel
Copy link

vercel bot commented Sep 17, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
valibot Ready Ready Preview Comment Sep 19, 2025 0:08am

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. tooling Tooling for devs labels Sep 17, 2025
Copy link

Copilot AI left a 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'],
Copy link

Copilot AI Sep 17, 2025

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'.

Suggested change
'src/**/*.ts': ['prettier --write', () => 'tsc -p tsconfig.json --noEmit'],
'src/**/*.ts': ['prettier --write', 'tsc -p tsconfig.json --noEmit'],

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

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.

https://github.com/lint-staged/lint-staged?tab=readme-ov-file#example-run-tsc-on-changes-to-typescript-files-but-do-not-pass-any-filename-arguments

export default {
'*.{ts,js,cjs,json,md}': 'prettier --write',
'src/**/*.css': 'prettier --write',
'src/**/*.{ts,tsx}': ['prettier --write', 'eslint --fix'],
Copy link
Owner

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

Copy link
Contributor Author

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.

@fabian-hiller
Copy link
Owner

fabian-hiller commented Sep 19, 2025

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?

@yslpn
Copy link
Contributor Author

yslpn commented Sep 19, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S This PR changes 10-29 lines, ignoring generated files. tooling Tooling for devs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants