Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Placing hooks configuration in .huskyrc, .huskyrc.json or .huskyrc.js file not working #413

Closed
nidkil opened this issue Dec 5, 2018 · 7 comments

Comments

@nidkil
Copy link

nidkil commented Dec 5, 2018

I have put the following husky configuration in a separate config file, but it is not picked up when I commit. I tried both .huskyrc and .huskyrc.json without luck.

{
  "husky": {
    "hooks": {
      "pre-commit": "npm test && npm run lint:fix",
      "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
    }
  }
}

This is the output when I set HUSKY_DEBUG=true:

@ C:\dev\myrepos\vue-build-helper
$ set HUSKY_DEBUG=true

@ C:\dev\myrepos\vue-build-helper
$ echo %HUSKY_DEBUG%
true

@ C:\dev\myrepos\vue-build-helper
$ git commit -m "DELETE ME"
husky:debug pre-commit hook started...
husky:debug prepare-commit-msg hook started...
husky:debug commit-msg hook started...
husky:debug post-commit hook started...
[update_readme c357fcd] DELETE ME
 3 files changed, 1 insertion(+), 1 deletion(-)
 rename .huskyrc.json => .huskyrc (59%)
 create mode 100644 commitlint.config.js
 create mode 100644 test-file

@ C:\dev\myrepos\vue-build-helper

When I put the configuration in the package.json file it works. This is the output:

$ git commit -m "DELETE ME"
husky:debug pre-commit hook started...
husky > pre-commit (node v10.9.0)

> vue-build-helper@0.0.5 test C:\dev\myrepos\vue-build-helper
> jest

PASS test/common/fs-helpers.spec.js
PASS test/commands/add-eslint-disable.cmd.spec.js
PASS test/commands/create-exports.cmd.spec.js

Test Suites: 3 passed, 3 total
Tests:       25 passed, 25 total
Snapshots:   0 total
Time:        2.541s
Ran all test suites.

> vue-build-helper@0.0.5 lint:fix C:\dev\myrepos\vue-build-helper
> eslint -c .eslintrc.json --format codeframe --fix src test bin

husky:debug prepare-commit-msg hook started...
husky:debug commit-msg hook started...
husky > commit-msg (node v10.9.0)

⧗   input:
DELETE ME

✖   message may not be empty [subject-empty]
✖   type may not be empty [type-empty]
✖   found 2 problems, 0 warningshusky > commit-msg hook failed (add --no-verify to bypass)

I'm using husky version 1.2.0. It seems that it only checks the package.json file for the husky config and ignores .huskyrc and .huskyrc.json.

Any ideas what I am doing wrong?

@mwmcode
Copy link

mwmcode commented Dec 5, 2018

Hi @nidkil did you try.huskyrc without the husky: {}?

{
  "hooks": {
    "pre-commit": "npm test"
  }
}

@nidkil
Copy link
Author

nidkil commented Dec 6, 2018

O well, don't I feel stupid :-(

Yep, now it works. Thx for the quick respons!

@typicode
Copy link
Owner

typicode commented Dec 6, 2018

Thanks @mustafawm, closing :)

@typicode typicode closed this as completed Dec 6, 2018
@rkt2spc
Copy link

rkt2spc commented Dec 3, 2019

You're not alone @nidkil 🤣

@mwmcode
Copy link

mwmcode commented Dec 3, 2019

It seems that defining husky in package.json is the convention now

{
  "husky": {
    "hooks": {
      "pre-commit": "npm test",
      "pre-push": "npm test",
      "...": "..."
    }
  }
}

@shelbykauth
Copy link

shelbykauth commented Dec 20, 2020

I had the same error, super hard to debug. Finally figured it out:
I was trying to use huskyrc.json instead of .huskyrc

@MohammedALREAI
Copy link

inside the file .huskyrc
add this section put what you want
{ "hooks": { "pre-commit": "lint-staged " } }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants