typescript - länka pre-commit hook till VSC källkontroll
Mitt mål är att varje gång jag gör en git commit, ska eslint köras först. För närvarande använder jag husky hooks.
När jag committar genom terminalen med git commit -m "något meddelande", fungerar det som förväntat.
Problemet är när jag använder källkontrollen i Visual Studio Code (eller WebStorm).
källkontroll-commit
När jag gör en commit som denna kommer eslint inte att köras.
Detta är husky pre-commit-filen: husky pre-commit-filen.
Detta är package.json-skriptsektionen: package.json-skriptsektion
Svar #1
att installera husky med rekommenderade steg verkar fungera för mig:
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
> [email validate
> npm-run-all --parallel check-format lint build
> [email lint
> eslint --ignore-path .gitignore -c .eslintrc --ext .ts --fix .
> [email build
> react-scripts build
> [email check-format
> npm run format -- --list-different
> [email format
> npm run prettier -- --write "--list-different"
> [email 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
Svar #2
Jag installerade nyligen husky för min React-app. Jag följde helt enkelt instruktionerna från den officiella guiden Kom igång | 🐶 husky. Eftersom jag använder yarn följde jag specifikt stegen från yarn-sektionen Yarn 2-installation
- Installera
husky
yarn add husky --dev
- Aktivera git-hookar
yarn husky install
- Installera den hook du vill ha - i mitt fall ville jag att husky skulle köra
npx pretty-quick --staged
yarn husky set .husky/pre-commit \"npx pretty-quick --staged\"
- För att ha Git-hook aktiverad efter installation, redigera
package.json. Du kommer att behöva detta om du planerar att klona repo och körayarn install.
{
"scripts": {
"postinstall": "husky install"
}
}
Efter detta begick jag mina ändringar med hjälp av VS Code källkontroll. För att verifiera om husky-pre-hook fungerade kontrollerade jag Git-loggarna. Du kan hitta dem i Debug Console (öppna den med Shift+Escape), gå till fliken OUTPUT och välj Git-alternativet från rullgardinsmenyn.



