将预提交挂钩链接到 VSC 源代码控制

Posted

技术标签:

【中文标题】将预提交挂钩链接到 VSC 源代码控制【英文标题】:linking pre-commit hook to VSC source control 【发布时间】:2021-11-09 11:06:40 【问题描述】:

我的目标是每次我 git commit 时,eslint 应该首先运行。目前,我正在使用哈士奇钩子。

当我使用git commit -m "some message" 通过终端提交时,它按预期工作。

问题是当我在 Visual Studio Code(或 webStorm)中使用源代码控制时。

source control commit

当我这样提交时,eslint 不会运行。

这是 husky 预提交文件:husky pre-commit file。 这是 package.json 脚本部分:package.json script section

【问题讨论】:

嘿,欢迎来到 ***。最好以文本而不是代码图像的形式发布代码。 Why we do not upload images of code/errors when asking a question. 【参考方案1】:

用recommended steps 安装哈士奇似乎对我有用:

 From github.com:rachOS/BonApp-FRONT
 * branch            feature/create-user-account -> FETCH_HEAD
> git status -z -u
> git symbolic-ref --short HEAD
> git for-each-ref --format=%(refname)%00%(upstream:short)%00%(objectname)%00%(upstream:track) refs/heads/feature/create-user-account refs/remotes/feature/create-user-account
> git for-each-ref --sort -committerdate --format %(refname) %(objectname) %(*objectname)
> git remote --verbose
> git config --get commit.template
> git ls-files --stage -- /home/rach/Documents/Code/BonApp/front-bon_app.ts/src/entities/Recipe.ts
> git cat-file -s 96fa250abd168e2175cffe887b14db1f5787e7dc
> git show --textconv :src/entities/Recipe.ts
> git -c user.useConfigOnly=true commit --quiet --allow-empty-message --file -
> git ls-files --stage -- /home/rach/Documents/Code/BonApp/front-bon_app.ts/src/entities/Recipe.ts
> git cat-file -s 96fa250abd168e2175cffe887b14db1f5787e7dc
> git show --textconv :src/entities/Recipe.ts

> front-bon_app.ts@0.1.0 validate
> npm-run-all --parallel  check-format lint build


> front-bon_app.ts@0.1.0 lint
> eslint --ignore-path .gitignore -c .eslintrc --ext .ts --fix .


> front-bon_app.ts@0.1.0 build
> react-scripts build


> front-bon_app.ts@0.1.0 check-format
> npm run format -- --list-different


> front-bon_app.ts@0.1.0 format
> npm run prettier -- --write  "--list-different"


> front-bon_app.ts@0.1.0 prettier
> prettier --ignore-path .gitignore "**/*.+(js|ts|json|jsx|tsx|css|html)" "--write" "--list-different"

Creating an optimized production build...
Compiled with warnings.

src/adapters/primary/components/Form/Form.jsx
  Line 103:3:   'readOnly' is defined but never used  no-unused-vars
  Line 137:45:  'type' is defined but never used      no-unused-vars

src/adapters/primary/components/Signup/manager/SignupManager.jsx
  Line 4:10:  'signup' is defined but never used  no-unused-vars

Search for the keywords to learn more about each warning.
To ignore, add // eslint-disable-next-line to the line before.

File sizes after gzip:

  59.19 KB  build/static/js/2.58d43881.chunk.js
  1.63 KB   build/static/js/3.90fad592.chunk.js
  1.55 KB   build/static/js/main.5cbbd48f.chunk.js
  1.17 KB   build/static/js/runtime-main.63262bbd.js
  1.14 KB   build/static/css/main.8636b64b.chunk.css

The project was built assuming it is hosted at /.
You can control this with the homepage field in your package.json.

The build folder is ready to be deployed.
You may serve it with a static server:

  npm install -g serve
  serve -s build

Find out more about deployment here:

  https://cra.link/deployment
> git status -z -u
> git symbolic-ref --short HEAD
> git for-each-ref --format=%(refname)%00%(upstream:short)%00%(objectname)%00%(upstream:track) refs/heads/feature/create-user-account refs/remotes/feature/create-user-account
> git for-each-ref --sort -committerdate --format %(refname) %(objectname) %(*objectname)
> git remote --verbose
> git config --get commit.template
> git config --get commit.template
> git ls-files --stage -- /home/rach/Documents/Code/BonApp/front-bon_app.ts/src/entities/Recipe.ts
> git cat-file -s 96fa250abd168e2175cffe887b14db1f5787e7dc
> git show --textconv :src/entities/Recipe.ts

【讨论】:

以上是关于将预提交挂钩链接到 VSC 源代码控制的主要内容,如果未能解决你的问题,请参考以下文章

Perforce客户端预提交挂钩

颠覆:在预提交挂钩中获取用户的 IP 地址?

VSCode 集成源代码控制和预提交

如何在预提交挂钩中使用 git diff 的退出代码

SVN 的 CPP 检查预提交挂钩

IntelliJ IDEA 中的预提交挂钩