使用 Husky/lint-staged 挂钩时是否可以排除/忽略文件?
查看文档 atm 但没有任何运气找到任何关于此的内容。
希望有类似的东西
/*ignore*/
Run Code Online (Sandbox Code Playgroud)
我可以添加的标签。
使 lint-staged 忽略导致格式问题的某些文件。
对此的任何想法都非常感谢:)
我的哈士奇脚本:
"husky": {
"hooks": {
"pre-commit": "sh ./tools/githooks/pre-commit.sh"
}
}
Run Code Online (Sandbox Code Playgroud)
假设我正在做一个git commit -m "I want that text". 如何在 shell 脚本中访问我的提交消息?我试图在 shell 脚本中回显 $HUSKY_GIT_PARAMS 和 $HUSKY_GIT_STDIN 但没有成功
如标题所示,目前我已将我的应用程序配置为每次执行 git Push 时运行测试,
"husky": {
"hooks": {
"pre-push": "npm run test:unit"
}
}
Run Code Online (Sandbox Code Playgroud)
但显然它的扩展性不好,测试越多,推送所需的时间就越长,那么有没有一种方法可以仅在文件发生更改时才触发测试?
最终我发现 Jest 有一个很好的标志叫做--changedSince
,所以你可以在你的 package.json 文件中包含类似这样的东西:
"test:unit": "test:unit --changedSince=@{push}"
只会执行自上次推送以来已更改的文件的测试,与远程 HEAD 进行比较
我使用 husky 和 lint-staged 在具有此配置的 sass 文件上运行“stylelint --fix”
\n"husky": {\n "hooks": {\n "pre-commit": "lint-staged",\n "post-commit": "git update-index --again"\n }\n},\n"lint-staged": {\n "resources/sass/*.scss": [\n "stylelint --fix",\n "git add"\n ]\n}\nRun Code Online (Sandbox Code Playgroud)\nPhpStorm 阻止了我的提交并告诉我:
\nCommit failed with error, 0 file committed, 4 files failed to commit: test lintstaged husky > pre-commit (node v12.18.4) \xe2\x9a\xa0 Some of your tasks use `git add` command. Please remove it from the config since all modifications made by tasks will be automatically added to the git commit …
我正在尝试使用husky安装 git hooks 作为 Jenkins 管道作业的一部分。
我已将其添加到 Jenkins 作业中:
npm install husky --save-dev
Run Code Online (Sandbox Code Playgroud)
但是当作业运行时,我在 Jenkins 输出中看到了这一点:
> node-sass@4.14.1 install /home/jenkins/agent/workspace/<branch_name>/node_modules/node-sass
> node scripts/install.js
Downloading binary from https://github.com/sass/node-sass/releases/download/v4.14.1/linux_musl-x64-72_binding.node
Download complete
Binary saved to /home/jenkins/agent/workspace/<branch_name>/node_modules/node-sass/vendor/linux_musl-x64-72/binding.node
Caching binary to /root/.npm/node-sass/4.14.1/linux_musl-x64-72_binding.node
> husky@4.3.0 install /home/jenkins/agent/workspace/<branch_name>/node_modules/husky
> node husky install
husky > Setting up git hooks
CI detected, skipping Git hooks installation.
husky > Done
Run Code Online (Sandbox Code Playgroud)
...并且.git/hooks/precommit钩子文件永远不会创建。
故障排除研究笔记:
在husky v4 文档中,它说“默认情况下,Husky 不会安装在 CI 服务器上”。我找不到任何有关如何覆盖该默认行为的文档。
在搜索 repo 代码时,我什至无法在代码中 …
假设我正在使用多个遥控器:
$ git remote -v
origin https://github.com/ettie62/Quicke(fetch)
origin https://github.com/ettie62/Quicke(push)
public https://github.com/roslyn80/Quicke(fetch)
public https://github.com/roslyn80/Quicke(push)
Run Code Online (Sandbox Code Playgroud)
每个遥控器都有多个分支:
$ git branch -a
* master
refactor
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/refactor
remotes/public/dev
remotes/public/master
Run Code Online (Sandbox Code Playgroud)
如何仅在尝试推送到某个远程的某个分支时运行以下预推送挂钩,例如public/master,但在推送时不运行它origin/master:
"husky": {
"hooks": {
"pre-push": "CI=true npm test"
}
},
Run Code Online (Sandbox Code Playgroud) 我在 CLI 中输入这个
git commit -m "Hello World!"
Run Code Online (Sandbox Code Playgroud)
这是我收到的错误消息
husky > commit-msg (node v14.15.3)
? input: Hello World!
? subject may not be empty [subject-empty]
? type may not be empty [type-empty]
? found 2 problems, 0 warnings
? Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint
husky > commit-msg hook failed (add --no-verify to bypass)
Run Code Online (Sandbox Code Playgroud)
这是什么意思?
当仅更改特定文件夹中的文件时,是否可以仅运行 git hooks?
我有带有后端和前端的 monorepo。我想仅当前端的文件发生更改时才运行 husky hook。否则它不应该被触发并且不运行 linting 测试等......这会激怒后端开发人员
我正在关注从其github README打包的 lint-staged 自定义配置文件 (lint-staged.config.js) 的第一个示例(复制/粘贴) ,但没有成功。我error Command failed with exit code 1.总是得到。
我尝试了三件事,对于每种情况,我都将其lint-staged.config.js放在根目录中。
error Command failed with exit code 1."lint-staged": {
"packages/**/*.{ts,tsx}": [
"yarn lint-staged --config ./lint-staged.config.js"
]
},
Run Code Online (Sandbox Code Playgroud)
error Command failed with exit code 1.npx lint-staged --config ../lint-staged.config.js
Run Code Online (Sandbox Code Playgroud)
error Command failed with exit code 1.yarn lint-staged --config lint-staged.config.js
Run Code Online (Sandbox Code Playgroud)
我只是在寻找运行自定义配置文件。
问题是执行失败,错误消息与命令相关,但命令本身正确为lint-staged [options](yarn/npx lint-staged -h),然后提供一个自定义配置文件,但它lint-staged [--config [path]]失败了(我什至提供路径的各种引号)。
我有一个涡轮 monorepo,带有packages/...和apps/app-a, apps/app-b。我已经设置了哈士奇pre-commit钩子,它将运行pnpm dlx lint-staged
我想lint-staged从最接近暂存文件的位置运行 lint 脚本package.json。例如:
foo.js自apps/app-a- 它将运行lint中描述的脚本apps/app-a/package.jsonbar.js从apps/app-b将运行lint从apps/app-b/package.jsonETC。
那可能吗?
我尝试lintsatgedrc.json在apps/app-a和apps/app-b文件夹中进行设置
{
"*.{ts,tsx}": ["pnpm run lint", "pnpm run check-types"]
}
Run Code Online (Sandbox Code Playgroud)
但它总是尝试从 monorepo 的 root运行lint和脚本。chack-typespackage.json