Skip to content

Commit 725afc4

Browse files
committed
feat(core): enhance config validation
1 parent 5efe94a commit 725afc4

File tree

7 files changed

+8
-8
lines changed

7 files changed

+8
-8
lines changed

packages/core/src/lib/implementation/read-rc-file.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import {
88
coreConfigSchema,
99
} from '@code-pushup/models';
1010
import {
11-
coreConfigMessageBuilder,
1211
fileExists,
1312
importModule,
13+
zodErrorMessageBuilder,
1414
} from '@code-pushup/utils';
1515

1616
export class ConfigPathError extends Error {
@@ -44,7 +44,7 @@ export async function readRcByPath(
4444
return coreConfigSchema.parse(cfg);
4545
} catch (error) {
4646
const validationError = fromError(error, {
47-
messageBuilder: coreConfigMessageBuilder,
47+
messageBuilder: zodErrorMessageBuilder,
4848
});
4949
throw isZodErrorLike(error)
5050
? new ConfigValidationError(filepath, validationError.message)

packages/models/src/lib/category-config.unit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ describe('categoryConfigSchema', () => {
176176
],
177177
} satisfies CategoryConfig),
178178
).toThrow(
179-
/In a category, there has to be at least one ref with weight > 0. Affected refs: \\"functional\/immutable-data\\", \\"lighthouse-experimental\\"/,
179+
'In a category, there has to be at least one ref with weight > 0. Affected refs: functional/immutable-data, lighthouse-experimental',
180180
);
181181
});
182182
});

packages/models/src/lib/implementation/schemas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ export function scorableSchema<T extends ReturnType<typeof weightedRefSchema>>(
182182
)
183183
// category weights are correct
184184
.refine(hasNonZeroWeightedRef, refs => {
185-
const affectedRefs = refs.map(ref => `"${ref.slug}"`).join(', ');
185+
const affectedRefs = refs.map(ref => ref.slug).join(', ');
186186
return {
187187
message: `In a category, there has to be at least one ref with weight > 0. Affected refs: ${affectedRefs}`,
188188
};

packages/plugin-lighthouse/src/lib/lighthouse-plugin.unit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe('lighthousePlugin-config-object', () => {
5757
});
5858

5959
expect(() => pluginConfigSchema.parse(pluginConfig)).toThrow(
60-
/In a category, there has to be at least one ref with weight > 0. Affected refs: \\"csp-xss\\"/,
60+
'In a category, there has to be at least one ref with weight > 0. Affected refs: csp-xss',
6161
);
6262
});
6363
});

packages/utils/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,4 @@ export type {
122122
WithRequired,
123123
} from './lib/types.js';
124124
export { verboseUtils } from './lib/verbose-utils.js';
125-
export { coreConfigMessageBuilder } from './lib/zod-validation.js';
125+
export { zodErrorMessageBuilder } from './lib/zod-validation.js';

packages/utils/src/lib/zod-validation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function formatErrorPath(errorPath: (string | number)[]): string {
1212
.join('');
1313
}
1414

15-
export const coreConfigMessageBuilder: MessageBuilder = issues =>
15+
export const zodErrorMessageBuilder: MessageBuilder = issues =>
1616
issues
1717
.map(issue => {
1818
const formattedMessage = red(`${bold(issue.code)}: ${issue.message}`);

packages/utils/src/lib/zod-validation.unit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe('formatErrorPath', () => {
88
[['categories'], 'categories'],
99
[[], ''],
1010
[['path', 5], 'path[5]'],
11-
])('formats error path correctly for $input', (input, expected) => {
11+
])('should format error path %j as %j', (input, expected) => {
1212
expect(formatErrorPath(input)).toBe(expected);
1313
});
1414
});

0 commit comments

Comments
 (0)