Skip to content

Commit a76e70e

Browse files
committed
fix: rollback config validation
1 parent f6aab6b commit a76e70e

File tree

3 files changed

+30
-93
lines changed

3 files changed

+30
-93
lines changed

@commitlint/load/src/load.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ import {
1616

1717
import loadPlugin from './utils/load-plugin';
1818
import {loadConfig} from './utils/load-config';
19-
import {loadParser} from './utils/load-parser-opts';
19+
import {loadParserOpts} from './utils/load-parser-opts';
2020
import {pickConfig} from './utils/pick-config';
21-
import {validateConfig} from './utils/validators';
2221

2322
export default async function load(
2423
seed: UserConfig = {},
@@ -56,13 +55,11 @@ export default async function load(
5655
}
5756

5857
// Resolve extends key
59-
const extended = resolveExtends(config, {
58+
const extended = (resolveExtends(config, {
6059
prefix: 'commitlint-config',
6160
cwd: base,
6261
parserPreset: config.parserPreset,
63-
});
64-
65-
validateConfig(extended);
62+
}) as unknown) as UserConfig;
6663

6764
let plugins: PluginRecords = {};
6865
uniq(extended.plugins || []).forEach((plugin) => {
@@ -105,7 +102,7 @@ export default async function load(
105102
formatter:
106103
resolveFrom.silent(base, extended.formatter) || extended.formatter,
107104
// Resolve parser-opts from preset
108-
parserPreset: await loadParser(extended.parserPreset),
105+
parserPreset: await loadParserOpts(extended.parserPreset),
109106
ignores: extended.ignores,
110107
defaultIgnores: extended.defaultIgnores,
111108
plugins: plugins,

@commitlint/load/src/utils/load-parser-opts.ts

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,35 @@
11
import {ParserPreset} from '@commitlint/types';
2-
import {
3-
isObjectLike,
4-
isParserOptsFunction,
5-
isPromiseLike,
6-
validateParser,
7-
} from './validators';
8-
9-
export async function loadParser(
10-
pendingParser: unknown
2+
3+
function isObjectLike(obj: unknown): obj is Record<string, unknown> {
4+
return Boolean(obj) && typeof obj === 'object'; // typeof null === 'object'
5+
}
6+
7+
function isPromiseLike(obj: unknown): obj is Promise<unknown> {
8+
return (
9+
(typeof obj === 'object' || typeof obj === 'function') &&
10+
typeof (obj as any).then === 'function'
11+
);
12+
}
13+
14+
function isParserOptsFunction<T extends ParserPreset>(
15+
obj: T
16+
): obj is T & {
17+
parserOpts: (
18+
cb: (_: never, parserOpts: Record<string, unknown>) => unknown
19+
) => Record<string, unknown> | undefined;
20+
} {
21+
return typeof obj.parserOpts === 'function';
22+
}
23+
24+
export async function loadParserOpts(
25+
pendingParser: string | ParserPreset | Promise<ParserPreset> | undefined
1126
): Promise<ParserPreset | undefined> {
12-
if (!pendingParser) {
27+
if (!pendingParser || typeof pendingParser === 'string') {
1328
return undefined;
1429
}
1530
// Await for the module, loaded with require
1631
const parser = await pendingParser;
1732

18-
validateParser(parser);
19-
2033
// Await parser opts if applicable
2134
if (isPromiseLike(parser.parserOpts)) {
2235
parser.parserOpts = ((await parser.parserOpts) as any).parserOpts;
@@ -26,7 +39,7 @@ export async function loadParser(
2639
// Create parser opts from factory
2740
if (
2841
isParserOptsFunction(parser) &&
29-
parser.name &&
42+
typeof parser.name === 'string' &&
3043
parser.name.startsWith('conventional-changelog-')
3144
) {
3245
return new Promise((resolve) => {

@commitlint/load/src/utils/validators.ts

Lines changed: 0 additions & 73 deletions
This file was deleted.

0 commit comments

Comments
 (0)