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

Commitizen with Husky #155

Closed
ozum opened this issue Jul 12, 2023 · 5 comments
Closed

Commitizen with Husky #155

ozum opened this issue Jul 12, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@ozum
Copy link
Contributor

ozum commented Jul 12, 2023

Hi,

Situation

I use Commitizen with Husky. As a result, I don't have a cz command in the scripts of package.json. Instead, I have a .husky/prepare-commit-msg file with the following contents:

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

exec < /dev/tty && npx --no-install git-cz --hook || true

This is the suggested config for Commitizen and Husky.

Problem

Knip Commitizen Plugin reports:

Unused devDependencies (1)
--------------------------
commitizen  package.json

However, Commitizen is used.

Workaround

Adding following to the package.json.

"scripts": {
  "commit": "cz"
}

Kindly Request

Is it possible to add Husky support to Commitizen Plugin? It is a popular combination.

Kind Regards,

@ozum ozum added the bug Something isn't working label Jul 12, 2023
@webpro
Copy link
Collaborator

webpro commented Jul 12, 2023

I see on https://www.npmjs.com/package/git-cz that commitizen is expected be installed globally? That's a bit odd. If it would be a regular or peer dependency Knip wouldn't report it. And now you install it as a devDependency and it gets reported.

You can also add it to ignoreDependencies: [].

Just saying, the report is not coming from any plugin, commitizen is simply not referenced anywhere.

@ozum
Copy link
Contributor Author

ozum commented Jul 13, 2023

As you said, I have commitizen as a devDependency as suggested here, because I use it in CI (GitHub workflow). Having it in devDependency triggers knip Commitizen Plugin.

However, knip Commitizen Plugin cannot see/know that I have npx --no-install git-cz in the .husky/prepare-commit-msg file.

The plugin should examine files in .husky folder and should know that I have used git-cz.

I would like to add a PR here, but this needs broad knowledge about how knip works.

@webpro
Copy link
Collaborator

webpro commented Jul 13, 2023

The .husky/prepare-commit-ms indicate the usage of husky. The husky plugin will then read the scripts in the .husky folder and find git-cz indeed.

Unfortunately prepare-commit-msg was not in that list of patterns yet, but it is now in v2.15.5.

This will probably discover git-cz, but not commitizen. So I'm afraid this still doesn't solve your issue. Knip has no way to see that it is referenced somewhere. If commitizen would be a peer dependency of git-cz, Knip would be OK with it too.

@ozum
Copy link
Contributor Author

ozum commented Jul 13, 2023

No problem. I'm using the workaround currently. It would be nice if it could be solved in the future.

@webpro
Copy link
Collaborator

webpro commented Jul 17, 2023

The issue is that Knip can't really solve it without reporting false positives for correct situations. There needs to be a (proper) reference somehow. Going to close this now, but not without telling you I really appreciate the discussions :)

@webpro webpro closed this as completed Jul 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants