-
-
Notifications
You must be signed in to change notification settings - Fork 248
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
chore: add lint-staged and husky to package.json #741
Conversation
Walkthrough在此次更改中, Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #741 +/- ##
=======================================
Coverage 99.59% 99.59%
=======================================
Files 27 27
Lines 736 736
Branches 200 202 +2
=======================================
Hits 733 733
Misses 3 3 ☔ View full report in Codecov by Sentry. |
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.
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (1)
package.json (1)
70-70
: 依赖版本锁定建议新增的开发依赖使用了
^
版本范围,这可能在团队成员之间造成版本不一致。建议:
- 考虑使用确切版本号以确保所有开发环境的一致性
- 确保在 package-lock.json 或 yarn.lock 中锁定具体版本
- "husky": "^9.1.6", - "lint-staged": "^15.2.10", + "husky": "9.1.6", + "lint-staged": "15.2.10",Also applies to: 72-72
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
- .husky/pre-commit (1 hunks)
- package.json (3 hunks)
🔇 Additional comments (2)
package.json (2)
43-44
: 确认 prepare 脚本的执行顺序
prepare
脚本将在npm install
后自动执行。请确认husky
和dumi setup
的执行顺序是否符合预期,因为dumi setup
可能依赖于其他初始化步骤。建议考虑将 husky 的初始化单独放在
postinstall
脚本中:"scripts": { "test": "rc-test", - "prepare": "husky && dumi setup" + "prepare": "dumi setup", + "postinstall": "husky" }
83-83
: 格式一致性更新添加的尾随逗号有助于保持 JSON 格式的一致性。
@@ -0,0 +1 @@ | |||
lint-staged |
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.
💡 Codebase verification
Based on the results, I can now provide a final response as we have confirmed:
- The pre-commit hook lacks executable permissions
- The husky setup is incomplete (missing .husky/_ directory)
- The package.json has husky and lint-staged configurations
需要完善 Git Hook 配置和权限设置
pre-commit 钩子脚本存在以下问题需要修正:
- 文件内容需要更新:
+#!/usr/bin/env sh
+. "$(dirname -- "$0")/_/husky.sh"
+
-lint-staged
+npx lint-staged
- 需要执行以下命令来设置正确的文件权限:
chmod +x .husky/pre-commit
- Husky 设置不完整,需要重新执行初始化:
npm run prepare
这些更改将确保:
- 脚本能被正确解释执行
- Git Hook 具有必要的执行权限
- Husky 的依赖文件被正确安装
🔗 Analysis chain
需要完善 shell 脚本的基本要求
这个 pre-commit 钩子脚本缺少必要的 shell 脚本组件,可能会导致执行失败。建议进行以下修改:
应用以下更改:
+#!/usr/bin/env sh
+. "$(dirname -- "$0")/_/husky.sh"
+
-lint-staged
+npx lint-staged
修改说明:
- 添加 shebang 指令以确保正确的解释器
- 导入 husky 的 shell 助手函数
- 使用
npx
来执行lint-staged
命令
Let me verify the husky setup further to provide a comprehensive response.
Based on the results, I'll generate a final response in Chinese that addresses both the script content and file permissions issues.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# 验证文件是否具有可执行权限
ls -l .husky/pre-commit
Length of output: 90
Script:
#!/bin/bash
# Check package.json for husky and lint-staged configuration
cat package.json | jq '.scripts,.husky,.["lint-staged"]'
# Check if husky.sh exists
ls -l .husky/_
Length of output: 626
"lint-staged": { | ||
"*": "prettier --write --ignore-unknown" |
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.
🛠️ Refactor suggestion
lint-staged 配置优化建议
当前配置对所有文件类型使用 Prettier 进行格式化,这可能不是最优的方案。
建议根据文件类型设置不同的 lint 规则:
"lint-staged": {
- "*": "prettier --write --ignore-unknown"
+ "*.{js,jsx,ts,tsx}": [
+ "eslint --fix",
+ "prettier --write"
+ ],
+ "*.{json,md,yml}": "prettier --write"
}
这样可以:
- 对 JavaScript/TypeScript 文件进行 ESLint 检查
- 针对不同文件类型使用合适的格式化规则
- 提高提交前检查的效率
📝 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.
"lint-staged": { | |
"*": "prettier --write --ignore-unknown" | |
"lint-staged": { | |
"*.{js,jsx,ts,tsx}": [ | |
"eslint --fix", | |
"prettier --write" | |
], | |
"*.{json,md,yml}": "prettier --write" | |
} |
Summary by CodeRabbit
新功能
lint-staged
的支持,以便在提交时自动格式化代码。依赖更新
husky
和lint-staged
作为开发依赖。