Open voxmachinaio opened 2 years ago
Some things I've tried:
extends: ['@commitlint/config-conventional']
to the plugin module's exported configuration: the result is the same, parserPreset
is overwrittencommitlint
cli (i.e. commitlint -x @acse/commitlint-config @commitlint/config-conventional
): the result is the same, parserPreset
is overwrittenThanks for the issue and the research! I doubt we habe time to look into this but if you are motivated to dig into this we could try to support.
I was able to find a solution! I'm not sure what the technical mechanism was that was producing the issue but the fix was to factor out the parserPreset
object into a separate file, i.e.:
module.exports = {
parserPreset: {
parserOpts: {
headerPattern: /^(?:([A-Z]{2,}-\d+(?:, [A-Z]{2,}-\d+)*) \| ){1}(\w*)(?:\((\w*)\))?!?: (.+)$/,
headerCorrespondence: [`jiraIds`, `type`, `scope`, `subject`],
},
},
rules: {
'header-max-length': [2, `always`, 110],
'jira-empty': [2, `always`],
},
plugins: [
{
rules: {
'jira-empty': ({ jiraIds }) => {
const test = jiraIds ? true : false;
return [
test,
`jira id(s) may not be empty`,
]
},
}
}
]
};
module.exports = {
parserPreset: './parser-preset',
rules: {
'header-max-length': [2, `always`, 110],
'jira-empty': [2, `always`],
},
plugins: [
{
rules: {
'jira-empty': ({ jiraIds }) => {
const test = jiraIds ? true : false;
return [
test,
`jira id(s) may not be empty`,
]
},
}
}
]
};
module.exports = {
parserOpts: {
headerPattern: /^(?:([A-Z]{2,}-\d+(?:, [A-Z]{2,}-\d+)*) \| ){1}(\w*)(?:\((\w*)\))?!?: (.+)$/,
headerCorrespondence: [`jiraIds`, `type`, `scope`, `subject`],
},
};
@commitlint/cli
and @commitlint/load
leads me to believe that the issue lies somewhere in the interaction of these two components, but I was unable to track down exactly what was happening before finding the fixAwesome! Good to know, thanks! At least we have a workaround :)
I am finding this impossible. With the comment above the parseOpts ends up ignored as it's not within a parserPreset.
It seems the @commitlint/resolve-extends
is unable to merge parserOpts because when you are referencing @commitlint/config-conventional it's now a function that is returned for parserOpts, which of course can't merge so it just overwrites.
I am attempting to replace the default headerPattern and headerCorrespondence values of @commitlint/config-conventional by using a plugin module.
My plugin module looks like this:
index.js
package.json
Expected Behavior
From a test git repository with
@commitlint/cli
,@commitlint/config-conventional
, and@acse/commitlint-config
(the plugin module) installed locally, run:My expectation would be that this command exits in success (since that header line passes the headerPattern regex set in the plugin module's config.
Current Behavior
Instead that command exits in failure because the
parserPreset
in the resolved config has been overwritten by the parserPreset that@commitlint/config-conventional
sets (note the addition of--print-config
):You can see that it does correctly merge the local plugin definition and additional rule from the plugin module, but it overwrites the
parserPreset
value entirely.If I don't additionally extend the configuration with with
@commitlint/config-conventional
I do get the correct headerPattern and headerCorrespondence values, but then I lose everything else extending@commitlint/config-conventional
gives me (all the default rules, prompt definitions, etc):Affected packages
Possible Solution
Not sure, but my expectation based on reading the documentation and gut instinct would be that the
parserPreset
options are merged into the ones provided by packages extended "before" my plugin package (when defining the extensions via the-x
option on thecommitlint
cli, i.e.:Steps to Reproduce (for bugs)
@commitlint/cli
,@commitlint/config-conventional
, and<plugin_module>
locallyparserPreset
gets overwrittenContext
Essentially I am attempting to "extend" the default rules and configuration of the
@commitlint/config-conventional
module withheaderPattern
andheaderCorrespondence
values that should inform the parser to parse out a superset of values that are expected from the header (jiraIds, type, scope, subject).Your Environment
commitlint --version
git --version
node --version