我们有一个带有文件夹结构的企业应用程序,如下所示:
/项目
.git
/ sub1
... Java项目
/ sub2
package.json
... Javascript Backbone专案
/ sub3
... Java项目
/ sub4
... Java项目
/ sub5
package.json
... JavaScript React项目
目前,我在sub2和sub5项目中都设置了Husky,这会引起冲突(每次切换项目时都需要安装npm)。另外,Java开发人员报告说,当他们在项目sub1,sub3和sub4中提交代码时,正在执行Husky git钩子。
如果您在提交时位于某个文件夹中,是否只能运行挂钩?
例如,我在 .rb 和 .js 文件上匹配了它。
例如**/*.{js,rb}
例如,还想匹配Gemfile。Rakefile
我有一个问题husky。我希望 huskyeslint在 git commit 即将完成时运行并且更漂亮,以便它可以强制执行干净的编码检查。我已经设置eslint并prettier集成了两者。手动使用时它们工作正常。eslint然而,如果违反其中一条规则,哈士奇允许提交。
我还将pre-commit.sample本地项目.git/hooks目录中的文件重命名为pre-commit.
这是我的package.json文件:
"scripts": {
"prettier-format": "prettier --config .prettierrc 'src/**/*.ts' 'test/**/*.ts' --write",
"lint": "eslint . --ext .ts"
},
"husky": {
"hooks": {
"pre-commit": "npm run prettier-format && npm run lint"
}
},
"devDependencies": {
"husky": "^7.0.1"
}
Run Code Online (Sandbox Code Playgroud)
请问这里可能是什么问题?非常感谢。
我正在尝试配置 husky 预推送挂钩以在推送之前运行测试。一切看起来都很好。运行git push origin钩子被触发并且测试正在运行后。问题是,当测试完成后,即使操作成功,推送也会被冻结,并且没有其他事情发生。
包.json
"scripts": {
...
"pre-commit": "npm run lint",
"pre-push": "npm run test"
}
Run Code Online (Sandbox Code Playgroud)
.husky/预推
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npm run pre-push
Run Code Online (Sandbox Code Playgroud)
我们有一个带有 .Net 解决方案的现有 git 存储库。我们正在添加一个网络应用程序。Web 应用程序(角度)位于特定的子文件夹中。
我们确实安装了一些 pre-post commit hook,以确保文件正确检查。使用 VS Code 或源代码树提交时一切正常。但是当我尝试直接从 Visual Studio 提交某些内容时,我收到此错误:
/usr/bin/env: 'bash': No such file or directory
Run Code Online (Sandbox Code Playgroud)
有办法让它发挥作用吗?
作为参考,这是我的钩子:
结帐后
#!/bin/sh
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting '.git/hooks/post-checkout'.\n"; exit 2; }
git lfs post-checkout "$@"
Run Code Online (Sandbox Code Playgroud)
提交后
#!/bin/sh
command -v git-lfs >/dev/null 2>&1 …Run Code Online (Sandbox Code Playgroud) 我已经husky在我的 npm 项目中安装了prepare如下脚本
{
"name": "functions",
"scripts": {
"build": "tsc",
"start": "npm run serve",
"deploy": "firebase deploy --only functions",
"prepare": "husky install functions/.husky"
}
"dependencies": {
"firebase-admin": "^11.4.1",
"firebase-functions": "^4.1.1",
},
"devDependencies": {
"husky": "^8.0.2",
"typescript": "^4.9.4"
}
}
Run Code Online (Sandbox Code Playgroud)
husky声明为devDependencies这个 npm 模块仅在本地开发时需要,在运行时应用程序中不需要。
所以当我运行时npm run deploy,我收到以下错误
i functions: updating Node.js 16 function funName(us-central1)...
Build failed:
> prepare
> husky install functions/.husky
sh: 1: husky: not found
npm ERR! code 127
npm ERR! …Run Code Online (Sandbox Code Playgroud) 我正在通过 Husky (v4.3.8) 运行 lint-staged (v11.0.0) 作为预提交挂钩的一部分。我的 lint-staged 执行 eslint (v7.27.0) 和 Prettier (v2.3.0)。但是,在 Prettier 运行后,“美化”文件不会添加到提交中。
作为 lint 暂存过程的一部分,Prettier 修改的文件如何自动添加到提交中?
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"{src,test}/**/*.ts": {
"eslint ./src --ext .ts",
"prettier ./src --write"
}
}
Run Code Online (Sandbox Code Playgroud) 当我提交时,我收到以下哈士奇错误。
我跑去npx --version看npx是否安装了。
这显示了8.0.0。
运行后rm -rf .husky,我又做了一次git commit,但没有解决问题。
错误
.husky/pre-commit: line 4: npx: command not found
husky - pre-commit hook exited with code 127 (error)
Run Code Online (Sandbox Code Playgroud) 尽管还有其他问题,但大多数都没有得到答复,或者给出的答复对我不起作用。
对于它给出的显然 eslint 正在 node_modules 中查找的内容,这里是给定的错误:
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/kamoraes/Workspace/node_adc/node_modules/supports-color/index.js from /home/kamoraes/Workspace/node_adc/.git/hooks/commit-msg not supported.
Instead change the require of index.js in /home/kamoraes/Workspace/node_adc/.git/hooks/commit-msg to a dynamic import() which is available in all CommonJS modules.
at Object.<anonymous> (/home/kamoraes/Workspace/node_adc/.git/hooks/commit-msg:8:23) {
code: 'ERR_REQUIRE_ESM'
}
Node v16.13.0
Run Code Online (Sandbox Code Playgroud)
问题是,该项目正处于第一步,快速在同一节点和纱线、版本上的另一台机器上重做该项目,不会给出相同的错误。还请我的一个朋友尝试一下。没有给出错误。
另外,这个项目是一门课程,执行相同的步骤,这是我现在的完整代码:
此给定错误的最后一次提交是杂务:eslintignore 6250e5bdea05cc2eb413c8a57a97e4bbe4bd5bb9
我添加了哈士奇,lint-staged
yarn add -D husky lint-staged
Run Code Online (Sandbox Code Playgroud)
然后添加它们各自的配置文件
.huskyrc.json:
{
"hooks": {
"pre-commit": "lint-staged"
}
}
Run Code Online (Sandbox Code Playgroud)
.lintstagedrd.json:
{
"*.ts": [
"eslint 'src/**' --fix",
"git add"
]
}
Run Code Online (Sandbox Code Playgroud)
供参考:tsconfig:
{
"compilerOptions": …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试强制我或我的同事无法在我的角度应用程序中提交包含 console.log 的文件。
我目前已经进行了husky预提交,执行ng lint --fix.
有没有办法在我的 linting 中添加一些内容以防止控制台日志,或者在 husky 脚本中添加一些内容?
人们仍然应该能够使用 console.log,只是不提交它。
谢谢