refactor: Add pre-commit hook for running prettier on affected files#784
Conversation
|
📝 WalkthroughWalkthroughThe changes configure lint-staged to handle different file types separately, using a SKIP_ESLINT environment variable for TypeScript/JSX files while running Prettier on other files. The format-and-lint script is updated to respect this flag, and cross-env is added as a dependency. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
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 53: The lint-staged command for "*.{ts,tsx,js,jsx}" runs TypeScript via
"node scripts/format-and-lint.ts" but omits the Node 22 TypeScript runtime flag;
update the command to invoke node with --experimental-strip-types (i.e., "node
--experimental-strip-types scripts/format-and-lint.ts") so the TypeScript file
executes correctly—modify the package.json entry that currently maps
"*.{ts,tsx,js,jsx}" to add this flag.
ℹ️ Review info
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled
You can enable these sources in your CodeRabbit configuration.
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (2)
package.jsonscripts/format-and-lint.ts
| }, | ||
| "lint-staged": { | ||
| "*.(js|ts|tsx|jsx|json|md|mdx|css|scss|yaml|yml|html|yml|yaml|json)": "prettier --write" | ||
| "*.{ts,tsx,js,jsx}": "cross-env SKIP_ESLINT=1 node scripts/format-and-lint.ts", |
There was a problem hiding this comment.
Missing --experimental-strip-types flag for TypeScript execution.
The command invokes node scripts/format-and-lint.ts directly, but other scripts in this file (e.g., line 11) use node --experimental-strip-types to run TypeScript files. Without this flag, Node 22 won't execute the TypeScript file correctly.
🐛 Proposed fix
- "*.{ts,tsx,js,jsx}": "cross-env SKIP_ESLINT=1 node scripts/format-and-lint.ts",
+ "*.{ts,tsx,js,jsx}": "cross-env SKIP_ESLINT=1 node --experimental-strip-types scripts/format-and-lint.ts",📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| "*.{ts,tsx,js,jsx}": "cross-env SKIP_ESLINT=1 node scripts/format-and-lint.ts", | |
| "*.{ts,tsx,js,jsx}": "cross-env SKIP_ESLINT=1 node --experimental-strip-types scripts/format-and-lint.ts", |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@package.json` at line 53, The lint-staged command for "*.{ts,tsx,js,jsx}"
runs TypeScript via "node scripts/format-and-lint.ts" but omits the Node 22
TypeScript runtime flag; update the command to invoke node with
--experimental-strip-types (i.e., "node --experimental-strip-types
scripts/format-and-lint.ts") so the TypeScript file executes correctly—modify
the package.json entry that currently maps "*.{ts,tsx,js,jsx}" to add this flag.
Summary by CodeRabbit
Chores
Style