Questions tagged [husky]

Tool that provides git hooks to prevent bad commits

Husky is a tool to make modern native Git hooks easy. Husky supports all Git hooks. It can be used to improve your commits by linting your commit messages, running tests, linting code, etc...

268 questions
8
votes
3 answers

Pre-commit hook (husky + pretty-quick) doesn't work

I've configured prettier and pre-commit hook like before but in my new project husky doesn't run before any commit! Below is part of the project package.json file: { ..., "devDependencies": { "husky": "^4.3.6", "prettier": "2.2.1", …
8
votes
2 answers

How to bypass pre-commit hooks after fixing merge conflicts?

TLDR: git rev-parse -q --verify MERGE_HEAD errors out when NOT in a merge state. How can I get a similar command that would error out when we're IN a merge state? Problem: when I merge master into my branch and it has conflicts, I have to manually…
Flavio Wuensche
  • 9,460
  • 1
  • 57
  • 54
7
votes
3 answers

What is the correct way to add commitlint to the commit-msg hook in husky?

I have an angular project where I want to enforce conventional commits. I have not been able to successfully had the right hook to prevent incorrect hooks. I started with this tutorial, where it said to add the following to package.json: { …
PMO1948
  • 2,210
  • 11
  • 34
7
votes
1 answer

Using Husky with Docker when no Node.js is available in local

Working with Docker, I'm trying to make Husky work when there is Node.js in the container but no on the local machine. As it will be triggered with git commands, with the info from here: "if you're running git commands in the terminal, husky will…
lewislbr
  • 1,012
  • 14
  • 23
6
votes
0 answers

Pending git changes are lost when commit fails due to linting error (husky + lint-staged)

I have an Angular app using git and Visual Studio Code. I set up ESLint and am using husky to run lint-staged in a pre-commit hook, so that changes with linting errors cannot be committed. When I first set it up, the pending changes in failed…
Roobot
  • 860
  • 1
  • 10
  • 20
5
votes
3 answers

How to configure husky when .git is in a different folder?

I'm trying to set up automatic linting on commit for my company's project, and the best way I've seen to do so has been the husky NPM package. I'm following instructions on setting up Husky with eslint , prettier , and lint-staged but I keep hitting…
movac
  • 1,576
  • 3
  • 21
  • 45
5
votes
1 answer

Visual studio cannot run pre/post commit hooks: /usr/bin/env 'bash': No such file or directory

We have an existing git repository with a .Net solution. We are adding a web application to the mix. The web application(angular) is in a specific subfolder. We did install some pre-post commit hooks, to ensure the file is properly linted.…
J4N
  • 19,480
  • 39
  • 187
  • 340
5
votes
2 answers

How to prevent files with "console.log" to be committed?

I'm currently trying to enforce that me or my colleague cannot commit files that contains console.log in my angular application. I currently already have husky on pre-commit, that execute a ng lint --fix. Is there a way to either add something to my…
J4N
  • 19,480
  • 39
  • 187
  • 340
5
votes
1 answer

Error [ERR_REQUIRE_ESM] - Husky, lint-staged, eslint - nodeJS:

although there were other questions about this, most were left without a response or the response given did not work for me. For what it gives apparently eslint is looking within node_modules, here is the given error: Error [ERR_REQUIRE_ESM]:…
kamoraes
  • 51
  • 3
5
votes
4 answers

Unable to git commit

When I commit, I get the following husky error. I ran npx --version to see if npx was installed. It showed 8.0.0. After running rm -rf .husky, I did another git commit, but it didn't solve the problem. error .husky/pre-commit: line 4: npx: command…
yuturo
  • 171
  • 1
  • 3
  • 11
5
votes
1 answer

Run Husky hooks only for specific folder changes

Is it possible to run only git hooks for when only files in certain folder are changed?? I have monorepo with backend and frontend. I would like to run husky hook only when the files in frontend got changed. Otherwise it should not be triggered and…
Mugetsu
  • 1,739
  • 2
  • 20
  • 41
5
votes
0 answers

How to harmonize husky pre-commit hook when working with pretty-quick in my node.js project?

I have a husky pre-commit hook in my package.json file: "husky": { "hooks": { "pre-commit": "npx pretty-quick --staged" } } I also have a .prettierrc file in my project: { "printWidth": 100, "singleQuote": false, "trailingComma":…
Adam Arold
  • 29,285
  • 22
  • 112
  • 207
5
votes
0 answers

lint-staged not adding files modified by prettier

I'm running lint-staged (v11.0.0) as part of my pre-commit hook through Husky (v4.3.8). My lint-staged performs eslint (v7.27.0) and Prettier (v2.3.0). However, after Prettier runs, the "prettified" files aren't added to the commit. How can files…
Luke
  • 20,878
  • 35
  • 119
  • 178
5
votes
2 answers

Install husky git hooks in Jenkins pipeline job by overriding "CI detected, skipping Git hooks installation"

I am trying to use husky to install git hooks as part of a Jenkins pipeline job. I've added this to the Jenkins job: npm install husky --save-dev But when the job runs I see this in the Jenkins output: > node-sass@4.14.1 install…
Employee
  • 2,231
  • 3
  • 33
  • 60
5
votes
0 answers

How to run "stylelint --fix" with husky and lint-staged without blocking the commit

I'm using husky and lint-staged to run "stylelint --fix" on my sass files with this configuration "husky": { "hooks": { "pre-commit": "lint-staged", "post-commit": "git update-index --again" } }, "lint-staged": { …
1 2
3
17 18