Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions @commitlint/types/src/rules.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,31 @@ const _scopeCaseSimpleCheck: Partial<RulesConfig> = {
"scope-case": _scopeCaseSimple,
};
void _scopeCaseSimpleCheck;

// Tests for context parameter support:
// https://github.com/conventional-changelog/commitlint/issues/4357
// Rule functions should accept an optional context parameter with cwd.

// Sync function with context
const _syncWithCtx: Partial<RulesConfig> = {
"scope-enum": (ctx) => [ERROR, "always", ["foo", ctx?.cwd || "bar"]],
};
void _syncWithCtx;

// Async function with context
const _asyncWithCtx: Partial<RulesConfig> = {
"scope-enum": async (ctx) => [ERROR, "always", ["foo", ctx?.cwd || "bar"]],
};
void _asyncWithCtx;

// Function without context (backward compatibility)
const _funcNoCtx: Partial<RulesConfig> = {
"scope-enum": () => [ERROR, "always", ["foo", "bar"]],
};
void _funcNoCtx;

// Async function without context (backward compatibility)
const _asyncNoCtx: Partial<RulesConfig> = {
"scope-enum": async () => [ERROR, "always", ["foo", "bar"]],
};
void _asyncNoCtx;
8 changes: 6 additions & 2 deletions @commitlint/types/src/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,13 @@ export enum RuleConfigQuality {
Qualified,
}

export interface RuleConfigContext {
cwd?: string;
}

export type QualifiedRuleConfig<T> =
| (() => RuleConfigTuple<T>)
| (() => Promise<RuleConfigTuple<T>>)
| ((ctx?: RuleConfigContext) => RuleConfigTuple<T>)
| ((ctx?: RuleConfigContext) => Promise<RuleConfigTuple<T>>)
| RuleConfigTuple<T>;

export type RuleConfig<
Expand Down