Skip to content

Commit

Permalink
fix(plugin-commitlint): handling of parserPreset when it's not a st…
Browse files Browse the repository at this point in the history
…ring

fix webpro-nl#631
  • Loading branch information
RebeccaStevens committed May 12, 2024
1 parent fcee3ee commit d581ae5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
13 changes: 10 additions & 3 deletions packages/knip/src/plugins/commitlint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,23 @@ const config = [
'package.json',
];

const resolveConfig: ResolveConfig<CommitLintConfig> = config => {
const resolveConfig: ResolveConfig<CommitLintConfig> = async config => {
const extendsConfigs = config.extends
? [config.extends]
.flat()
.map(id => (id.startsWith('@') || id.startsWith('commitlint-config-') ? id : `commitlint-config-${id}`))
: [];
const plugins = config.plugins ? [config.plugins].flat().filter(s => typeof s === 'string') : [];
const formatter = config.formatter ? [config.formatter] : [];
const parserPreset = config.parserPreset ? [config.parserPreset] : [];
return [...extendsConfigs, ...plugins, ...formatter, ...parserPreset];
const parserPreset = await config.parserPreset;
const parserPresetPaths: string[] = parserPreset
? typeof parserPreset === 'string'
? [parserPreset]
: parserPreset.path
? [parserPreset.path ?? parserPreset]
: []
: [];
return [...extendsConfigs, ...plugins, ...formatter, ...parserPresetPaths];
};

export default {
Expand Down
8 changes: 7 additions & 1 deletion packages/knip/src/plugins/commitlint/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,11 @@ export type CommitLintConfig = {
extends?: string | string[];
plugins?: string[];
formatter?: string;
parserPreset?: string;
parserPreset?: string | ParserPreset | Promise<ParserPreset>;
};

type ParserPreset = {
name?: string;
path?: string;
parserOpts?: unknown;
};

0 comments on commit d581ae5

Please sign in to comment.