Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add possibility to extend from string #865

Merged
merged 1 commit into from
Feb 3, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions @commitlint/resolve-extends/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ test('fails for missing extends', async () => {
);
});

test('resolves extends for single config', () => {
const input = {extends: 'extender-name'};
const ctx = {
resolve: id,
require: jest.fn(() => ({}))
} as ResolveExtendsContext;
resolveExtends(input, ctx);

expect(ctx.require).toHaveBeenCalledWith('extender-name');
});

test('uses empty prefix by default', () => {
const input = {extends: ['extender-name']};
const ctx = {
Expand Down
7 changes: 5 additions & 2 deletions @commitlint/resolve-extends/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface ResolvedConfig {

export interface ResolveExtendsConfig {
parserPreset?: unknown;
extends?: string[];
extends?: string | string[];
[key: string]: unknown;
}

Expand Down Expand Up @@ -48,7 +48,10 @@ function loadExtends(
config: ResolveExtendsConfig = {},
context: ResolveExtendsContext = {}
): ResolvedConfig[] {
return (config.extends || []).reduce<ResolvedConfig[]>((configs, raw) => {
const {extends: e} = config;
const ext = e ? (Array.isArray(e) ? e : [e]) : [];

return ext.reduce<ResolvedConfig[]>((configs, raw) => {
const load = context.require || require;
const resolved = resolveConfig(raw, context);
const c = load(resolved);
Expand Down