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

Error when used with Husky: "Please add rules to your commitlint.config.js" #583

Closed
1 of 4 tasks
nareshbhatia opened this issue Feb 15, 2019 · 11 comments
Closed
1 of 4 tasks

Comments

@nareshbhatia
Copy link

Expected Behavior

The following Husky hook used to work perfectly with "@commitlint/cli": "^7.2.1" and "husky": "^1.2.1"

  "husky": {
    "hooks": {
      "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
    }
  },

Current Behavior

Today I started getting the following error:

Please add rules to your commitlint.config.js

I have never needed this file before!

image

Affected packages

  • cli
  • core
  • prompt
  • config-angular

Possible Solution

I added the commitlint.config.js file to fix the problem, but it seems mysterious how this started appearing suddenly.

Note: I do not understand how HUSKY_GIT_PARAMS works. The husky documents do not quite explain it.

Steps to Reproduce (for bugs)

You can see my fixed project here: https://github.com/archfirst/joinjs. The previous commit did not work.

@nareshbhatia
Copy link
Author

Looks like this change in behavior has been introduced after version 7.2.1. When I use version 7.5.2, I start getting the error message mentioned earlier: "Please add rules to your commitlint.config.js".

I looked through the change log, but there is no mention of it,

@marionebl
Copy link
Contributor

The warning about a missing commitlint.config.js was introduced exactly for this kind of scenario.

commitlint versions 7.2.1 and older essentially allowed any commit message to go through when no config was provided.

To avoid the confusion around this and make sure users actually get what they want from commitlint we introduced the warning.

Feel free to reopen if you think there is a problem not covered by my explanation.

@nareshbhatia
Copy link
Author

Thanks for clarifying @marionebl. It makes total sense 👍

@sc250024
Copy link

Not to re-open this issue, but I'm receiving the same error, but I actually use a global commitlint file located at ~/commitlint.config.js. This issue added support for a global configuration:

#127

For some reason though, the interaction between Husky and Commitlint fails to read this global file.

@ghost
Copy link

ghost commented Nov 23, 2020

In my case, I was following guidelines from https://commitlint.js.org/#/
There is a step asking as: echo "module.exports = {extends: ['@commitlint/config-conventional']}" > commitlint.config.js
This step is indeed creating this required file names as commitline.config.js. but the contents of this file are getting wrapped in double quotes.

So, fix for me was to remove these not needed double quotes and make the file contents syntactically correct as per JavaScript.
Hope this helps, Thanks...

@AndresdoSantos
Copy link

For those who try to use the file as TS, it won't work, after switching to JS it ran normally for me.

So use this... commitlint.config.js

@escapedcat
Copy link
Member

For those who try to use the file as TS, it won't work, after switching to JS it ran normally for me.

So use this... commitlint.config.js

Which version did you use. TS configs should work at leats for the current version:
https://commitlint.js.org/#/reference-configuration?id=typescript

It migh t be a new bug if these don't work.

@AndresdoSantos
Copy link

Hi @escapedcat, were these versions...

{
    "@commitlint/cli": "^17.0.2",
    "@commitlint/config-conventional": "^17.0.2",
    "typescript": "^4.7.3",
}

@escapedcat
Copy link
Member

Hi @escapedcat, were these versions...

Alright, thanks. Would you mind opening a new issue for that?

@AndresdoSantos
Copy link

Dude, I'm pretty wrapped up with a new project, if you want to do it, feel free

@gvozdenkov
Copy link

For those who try to use the file as TS, it won't work, after switching to JS it ran normally for me.
So use this... commitlint.config.js

Which version did you use. TS configs should work at leats for the current version: https://commitlint.js.org/#/reference-configuration?id=typescript

It migh t be a new bug if these don't work.

Works for me on TS 5.3

commit-msg

#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx --no -- commitlint --edit ${1}

commitlint.config.ts

import type { UserConfig } from '@commitlint/types';

const Configuration: UserConfig = {
  extends: ['@commitlint/config-conventional'],
  // yand add -D @commitlint/format
  formatter: '@commitlint/format',
  helpUrl: 'https://github.com/conventional-changelog/commitlint/#what-is-commitlint',
};

module.exports = Configuration;

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

No branches or pull requests

6 participants