Closed midhundeltaco closed 2 years ago
Hey, sorry for the late reply; been busy lately, are you still having this issue? Also if you could paste some error logs from the console (if any) that would be awesome
@alessandrojcm Just ran into this issue in trying out this plugin as well. As of the writing of this I have done limited testing... One thing I'm curious about is does this plugin assume you have node installed with the @commitlint/config-conventional
package available?
hey all, you need to include it as an additional dependency:
repos:
- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
rev: v8.0.0
hooks:
- id: commitlint
stages: [ commit-msg ]
additional_dependencies: ["@commitlint/config-conventional"]
Hey, folks sorry for the late reply (again). Re your comments:
@picarro-dbatz Node is already provided by pre-commit
, since this is a node-based hook pre-commit
installs it under the hood.
Regarding @commitlint/config-conventional
, @smparekh is right; you need to provide at least one configuration in order for the hook to work (this is not an assumption made by this hook is just how commitlint
works). Like it states on the commitlint
docs.
This package's README uses the Angular configuration as an example but I guess I can reword the README to make it more explicit that you need to provide one configuration package via additional_dependencies
. Will do that shortly, apologies @midhundeltaco.
Done in #88 :smile:
Update:
I see the error in my ways.
The readme snippet suggests using @commitlint/convention-angular
.
However https://commitlint.js.org/#/?id=configure uses @commitlint/conventional-config
I didn't catch the miss-match until the bug report 🦆
Hi, I'm wondering what I'm doing wrong here. This is contained in my yaml file
❯ tail .pre-commit-config.yaml
- id: requirements-txt-fixer
- id: sort-simple-yaml
- id: trailing-whitespace
- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
rev: v9.10.0
hooks:
- id: commitlint
stages: [commit-msg]
additional_dependencies: ['@commitlint/config-angular']
I've installed the hook
❯ cat ./.git/hooks/commit-msg
#!/usr/bin/env bash
# File generated by pre-commit: https://pre-commit.com
# ID: 138fd403232d2ddd5efb44317e38bf03
# start templated
INSTALL_PYTHON=/usr/local/opt/python@3.11/bin/python3.11
ARGS=(hook-impl --config=.pre-commit-config.yaml --hook-type=commit-msg)
# end templated
HERE="$(cd "$(dirname "$0")" && pwd)"
ARGS+=(--hook-dir "$HERE" -- "$@")
if [ -x "$INSTALL_PYTHON" ]; then
exec "$INSTALL_PYTHON" -mpre_commit "${ARGS[@]}"
elif command -v pre-commit > /dev/null; then
exec pre-commit "${ARGS[@]}"
else
echo '`pre-commit` not found. Did you forget to activate your virtualenv?' 1>&2
exit 1
fi
Config
❯ cat commitlint.config.js
// https://commitlint.js.org/#/?id=configure
module.exports = {extends: ['@commitlint/config-conventional']}
Run the hook
❯ git commit -am "foobar"
[INFO] Initializing environment for https://github.com/psf/black-pre-commit-mirror.
[INFO] Initializing environment for https://github.com/psf/black-pre-commit-mirror:.[jupyter].
[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Initializing environment for https://github.com/alessandrojcm/commitlint-pre-commit-hook.
[INFO] Initializing environment for https://github.com/alessandrojcm/commitlint-pre-commit-hook:@commitlint/config-angular.
..snip..
commitlint...............................................................Failed
- hook id: commitlint
- exit code: 1
~/.cache/pre-commit/repo4d6gkdh1/node_env-default/lib/node_modules/commitlint-pre-commit-hook/node_modules/@commitlint/cli/lib/cli.js:123
throw err;
^
Error: Cannot find module "@commitlint/config-conventional" from "<REDACTED>"
at resolveId (~/.cache/pre-commit/repo4d6gkdh1/node_env-default/lib/node_modules/commitlint-pre-commit-hook/node_modules/@commitlint/resolve-extends/lib/index.js:104:17)
at resolveConfig (~/.cache/pre-commit/repo4d6gkdh1/node_env-default/lib/node_modules/commitlint-pre-commit-hook/node_modules/@commitlint/resolve-extends/lib/index.js:88:26)
at ~/.cache/pre-commit/repo4d6gkdh1/node_env-default/lib/node_modules/commitlint-pre-commit-hook/node_modules/@commitlint/resolve-extends/lib/index.js:47:26
at Array.reduce (<anonymous>)
at loadExtends (~/.cache/pre-commit/repo4d6gkdh1/node_env-default/lib/node_modules/commitlint-pre-commit-hook/node_modules/@commitlint/resolve-extends/lib/index.js:45:16)
at resolveExtends (~/.cache/pre-commit/repo4d6gkdh1/node_env-default/lib/node_modules/commitlint-pre-commit-hook/node_modules/@commitlint/resolve-extends/lib/index.js:25:22)
at load (~/.cache/pre-commit/repo4d6gkdh1/node_env-default/lib/node_modules/commitlint-pre-commit-hook/node_modules/@commitlint/load/lib/load.js:42:52)
at async main (~/.cache/pre-commit/repo4d6gkdh1/node_env-default/lib/node_modules/commitlint-pre-commit-hook/node_modules/@commitlint/cli/lib/cli.js:189:20) {
code: 'MODULE_NOT_FOUND'
}
Node.js v21.5.0
Im getting this error, i have commitlint.config.js added on root folder, will this be picked without any reference