Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Merge passed config with file based options
const preliminaryConfig = valid(
merge({}, loaded ? loaded.config : null, seed)
);
const config = {
...preliminaryConfig,
parserPreset: await loadParserPreset(base, preliminaryConfig)
};
const opts = merge(
{extends: [], rules: {}, formatter: '@commitlint/format'},
pick(config, 'extends', 'plugins', 'ignores', 'defaultIgnores')
);
// Resolve extends key
const extended = resolveExtends(opts, {
prefix: 'commitlint-config',
cwd: base,
parserPreset: config.parserPreset
});
const preliminaryPreset = valid(mergeWith(extended, config, w));
const preset = {
...preliminaryPreset,
parserPreset: await loadParserPreset(base, preliminaryPreset)
};
config.extends = Array.isArray(config.extends) ? config.extends : [];
// Resolve config-relative formatter module
if (typeof config.formatter === 'string') {
preset.formatter =
pick(config, 'extends', 'plugins', 'ignores', 'defaultIgnores')
);
// Resolve parserPreset key when overwritten by main config
if (typeof config.parserPreset === 'string') {
const resolvedParserPreset = resolveFrom(base, config.parserPreset);
config.parserPreset = {
name: config.parserPreset,
path: resolvedParserPreset,
parserOpts: require(resolvedParserPreset)
};
}
// Resolve extends key
const extended = resolveExtends(opts, {
prefix: 'commitlint-config',
cwd: base,
parserPreset: config.parserPreset
});
const preset = valid(mergeWith(extended, config, w));
// Resolve parser-opts from preset
if (typeof preset.parserPreset === 'object') {
preset.parserPreset.parserOpts = await loadParserOpts(
preset.parserPreset.name,
preset.parserPreset
);
}
// Resolve config-relative formatter module
let resolvedParserConfig = await require(resolvedParserPreset);
// Resolve loaded parser preset factory
if (typeof resolvedParserConfig === 'function') {
resolvedParserConfig = await resolvedParserConfig();
}
config.parserPreset = {
name: config.parserPreset,
path: resolvedParserPreset,
parserOpts: resolvedParserConfig.parserOpts
};
}
// Resolve extends key
const extended = resolveExtends(opts, {
prefix: 'commitlint-config',
cwd: base,
parserPreset: config.parserPreset
});
const preset = valid(mergeWith(extended, config, w));
// Await parser-preset if applicable
if (
typeof preset.parserPreset === 'object' &&
typeof preset.parserPreset.parserOpts === 'object' &&
typeof preset.parserPreset.parserOpts.then === 'function'
) {
let parserPreset = await preset.parserPreset.parserOpts;
// Resolve loaded parser preset factory from extended config
if (typeof parserPreset === 'function') {