Skip to content

Commit d3bfaeb

Browse files
committed
refactor(models,utils): move schema validation helper to models
1 parent d610049 commit d3bfaeb

File tree

7 files changed

+14
-11
lines changed

7 files changed

+14
-11
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import {
44
type CoreConfig,
55
SUPPORTED_CONFIG_FILE_FORMATS,
66
coreConfigSchema,
7+
validate,
78
} from '@code-pushup/models';
8-
import { fileExists, importModule, parseSchema } from '@code-pushup/utils';
9+
import { fileExists, importModule } from '@code-pushup/utils';
910

1011
export class ConfigPathError extends Error {
1112
constructor(configPath: string) {
@@ -31,7 +32,7 @@ export async function readRcByPath(
3132
format: 'esm',
3233
});
3334

34-
return parseSchema(coreConfigSchema, cfg, {
35+
return validate(coreConfigSchema, cfg, {
3536
schemaType: 'core config',
3637
sourcePath: filepath,
3738
});

packages/models/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727
},
2828
"type": "module",
2929
"dependencies": {
30-
"zod": "^4.0.5",
31-
"vscode-material-icons": "^0.1.0"
30+
"ansis": "^3.3.2",
31+
"vscode-material-icons": "^0.1.0",
32+
"zod": "^4.0.5"
3233
},
3334
"files": [
3435
"src",

packages/models/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ export {
7171
type MaterialIcon,
7272
} from './lib/implementation/schemas.js';
7373
export { exists } from './lib/implementation/utils.js';
74+
export {
75+
SchemaValidationError,
76+
validate,
77+
} from './lib/implementation/validate.js';
7478
export {
7579
issueSchema,
7680
issueSeveritySchema,

packages/utils/src/lib/zod-validation.ts renamed to packages/models/src/lib/implementation/validate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class SchemaValidationError extends Error {
2020
}
2121
}
2222

23-
export function parseSchema<T extends z.ZodTypeAny>(
23+
export function validate<T extends z.ZodTypeAny>(
2424
schema: T,
2525
data: z.input<T>,
2626
{ schemaType, sourcePath }: SchemaValidationContext,

packages/plugin-eslint/src/lib/eslint-plugin.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { createRequire } from 'node:module';
2-
import type { PluginConfig } from '@code-pushup/models';
3-
import { parseSchema } from '@code-pushup/utils';
2+
import { type PluginConfig, validate } from '@code-pushup/models';
43
import {
54
type ESLintPluginConfig,
65
type ESLintPluginOptions,
@@ -36,7 +35,7 @@ export async function eslintPlugin(
3635
config: ESLintPluginConfig,
3736
options?: ESLintPluginOptions,
3837
): Promise<PluginConfig> {
39-
const targets = parseSchema(eslintPluginConfigSchema, config, {
38+
const targets = validate(eslintPluginConfigSchema, config, {
4039
schemaType: 'ESLint plugin config',
4140
});
4241

@@ -45,7 +44,7 @@ export async function eslintPlugin(
4544
artifacts,
4645
scoreTargets,
4746
} = options
48-
? parseSchema(eslintPluginOptionsSchema, options, {
47+
? validate(eslintPluginOptionsSchema, options, {
4948
schemaType: 'ESLint plugin options',
5049
})
5150
: {};

packages/utils/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
"multi-progress-bars": "^5.0.3",
3838
"semver": "^7.6.0",
3939
"simple-git": "^3.20.0",
40-
"zod": "^4.0.5",
4140
"ora": "^9.0.0"
4241
},
4342
"files": [

packages/utils/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,3 @@ export type {
155155
Prettify,
156156
WithRequired,
157157
} from './lib/types.js';
158-
export { parseSchema, SchemaValidationError } from './lib/zod-validation.js';

0 commit comments

Comments
 (0)