Closed ghost closed 1 year ago
Hey @rundas912, the type is not set by default as it's materialized by the emoji.
To add the type explicitly you can add the conventional: true
option to your cz-emoji
configuration:
{
"config": {
"cz-emoji": {
"conventional": true,
}
}
}
Also, are you using this commitlint
configuration?
Hey @ngryman 😄
Ahhh that's what I missed then. Yes now it seems like type is correctly added to the commit message. Yes I am using that exact same configuration for commitlint but it keeps failing because the commitlint-config package expect an order like so
:gitmoji: type(scope?): subject
while I am getting this in a different order now
type(scope) :gitmoji: subject
I guess #53 could solve this maybe?
Thanks for your work
@rundas912 Got it, thanks for the details.
Hey @arvinxx, sorry to pull you here but I'd like to use your 🧠 to make cz-emoji
work with commitlint-config-gitmoji
by default.
cz-emoji
comes with 2 predefined commit formats:
emoji (scope?)
as the default.type(scope?): emoji
to support conventional commits.The comminlint
configuration we provide in the README is:
module.exports = {
extends: ['gitmoji'],
parserPreset: {
parserOpts: {
headerPattern: /^(:\w*:)(?:\s)(?:\((.*?)\))?\s((?:.*(?=\())|.*)(?:\(#(\d*)\))?/,
headerCorrespondence: ['type', 'scope', 'subject', 'ticket']
}
}
}
It looks wrong 🤔 But I'm not sure how to properly configure it.
In a perfect world, we would provide configuration(s) to support the 2 default format of cz-emoji
.
Do you think you could help us here?
@ngryman sorry, I just see it by now. I will try to help.
Hello, thank you for your great tool! Any news about the compatibility with commitlint-config-gitmoji
?
Same as you @rundas912 ! I think also that this is not related to #53 because it represents a new feature in configuration while this one is for running the adapter 🤔
Better late than never ;) I just published a new version, could you check that it fixed the issue? You can install it with npm install -g cz-emoji@canary
. Thanks!
@ngryman for me it fails with:
require() of ES Module /home/michael/Code/cognivore-bootcamps/cognivore-gateway/node_modules/cz-emoji/node_modules/wrap-ansi/index.js from /home/michael/Code/cognivore-bootcamps/cognivore-gateway/node_modules/cz-emoji/index.js not supported.
Instead change the require of /home/michael/Code/cognivore-bootcamps/cognivore-gateway/node_modules/cz-emoji/node_modules/wrap-ansi/index.js in /home/michael/Code/cognivore-bootcamps/cognivore-gateway/node_modules/cz-emoji/index.js to a dynamic import() which is available in all CommonJS modules.
@myknbani Could you retry with the latest canary? (npm i -g cz-emoji@canary-2
) Thanks.
Hi there! Thank you for this awesome tool which I use for most of my projects for couple years now. Sadly, I can't still make it work since last upgrades. I also use this package with husky pre-commit hooks and commitlint-config-gitmoji. I get the same error as @rundas912.
Here's my package versions:
"@commitlint/cli": "^17.3.0",
"commitizen": "^4.2.2",
"commitlint": "^17.3.0",
"commitlint-config-gitmoji": "^2.2.8",
"cz-emoji": "^1.3.2-canary.2",
And my commitlint.config.js
file:
module.exports = {
extends: ['gitmoji'],
parserPreset: {
parserOpts: {
headerPattern: /^(:\w*:)(?:\s*)(?:\((.*?)\))?(?:\s*)((?:.*(?=\())|.*)(?:\(#(\d*)\))?/,
headerCorrespondence: ['type', 'scope', 'subject', 'ticket'],
},
},
};
I also tried to add the conventional: true
option to my cz-emoji configuration as mentioned earlier which gives me that error:
husky > commit-msg (node v16.19.0)
⧗ input: lint(config): :rotating_light: Update eslint rules
✖ Your commit should start with gitmoji code,please check the emoji code on https://gitmoji.dev/. [start-with-gitmoji]
✖ subject may not be empty [subject-empty]
✖ type may not be empty [type-empty]
and #66 doesn't seems to fix it.
I'm out of ideas of what to do now and hope for a workaround to make it work again.
There is an option to disable the commitlint type-enum
too, that way the lint stops breaking
module.exports = {
extends: ['gitmoji'],
rules: {
'type-enum': [1, 'never'],
},
parserPreset: {
parserOpts: {
headerPattern: /^(:\w*:)(?:\s)(?:\((.*?)\))?\s((?:.*(?=\())|.*)(?:\(#(\d*)\))?/,
headerCorrespondence: ['type', 'scope', 'subject', 'ticket']
}
}
};
Hi, sorry for the very late reply.
So I've been digging into this issue this morning and my conclusion is that it'd be pretty hard to ensure compatibility with commitlint-config-gitmoji
. Our formats diverge.
Instead, I came up with an ad-hoc rule that you can put in your commitlint.config.js
file:
const pkg = require("./package.json");
// Check if the user has configured the package to use conventional commits.
const isConventional = pkg.config ? pkg.config["cz-emoji"]?.conventional : false;
// Regex for default and conventional commits.
const RE_DEFAULT_COMMIT = /^(?::.*:|(?:\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]))\s(?<emoji>\((?<scope>.*)\)\s)?.*$/gm;
const RE_CONVENTIONAL_COMMIT = /^^(?<type>\w+)(?:\((?<scope>\w+)\))?\s(?<emoji>:.*:|(?:\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]))\s.*$/gm;
module.exports = {
rules: {
"cz-emoji": [2, "always"],
},
plugins: [
{
rules: {
"cz-emoji": ({ raw }) => {
const isValid = isConventional
? RE_CONVENTIONAL_COMMIT.test(raw)
: RE_DEFAULT_COMMIT.test(raw);
const message = isConventional
? `Your commit message should follow conventional commit format.`
: `Your commit message should be: <emoji> (<scope>)?: <subject>`;
return [isValid, message];
},
},
},
],
};
I know it's not perfect but it works around the issue.
I'll update the docs and I might eventually release this as a commitlint
plugin in the future if people have enough interest in it.
Also, closing the issue as the above should resolve it.
Thanks for you patience with this 🙏
Sorry if I'm doing something wrong but when I try to commit something on a repo using this package and husky pre-commit hooks, type doesn't get added to the commit message.
Therefore, the commitlint-config-emoji returns an error telling me that type is empty (see image below)
Am I the only one having this problem?
Packages versions if relevant.