Skip to content

Commit 4ef657f

Browse files
committed
feat(plugin-eslint): update zod to v4
1 parent b1364d7 commit 4ef657f

File tree

3 files changed

+23
-26
lines changed

3 files changed

+23
-26
lines changed

packages/plugin-eslint/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"@code-pushup/utils": "0.69.5",
4242
"@code-pushup/models": "0.69.5",
4343
"yargs": "^17.7.2",
44-
"zod": "^3.22.4"
44+
"zod": "^4.0.5"
4545
},
4646
"peerDependencies": {
4747
"@nx/devkit": ">=17.0.0",

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

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { z } from 'zod';
22
import { toArray } from '@code-pushup/utils';
33

4-
const patternsSchema = z.union([z.string(), z.array(z.string()).min(1)], {
5-
description:
4+
const patternsSchema = z
5+
.union([z.string(), z.array(z.string()).min(1)])
6+
.describe(
67
'Lint target files. May contain file paths, directory paths or glob patterns',
7-
});
8+
);
89

9-
const eslintrcSchema = z.string({ description: 'Path to ESLint config file' });
10+
const eslintrcSchema = z.string().describe('Path to ESLint config file');
1011

1112
const eslintTargetObjectSchema = z.object({
1213
eslintrc: eslintrcSchema.optional(),
@@ -34,30 +35,26 @@ export type ESLintPluginRunnerConfig = {
3435
slugs: string[];
3536
};
3637

37-
const customGroupRulesSchema = z.union(
38-
[
38+
const customGroupRulesSchema = z
39+
.union([
3940
z
4041
.array(z.string())
4142
.min(1, 'Custom group rules must contain at least 1 element'),
42-
z.record(z.string(), z.number()).refine(
43-
schema => Object.keys(schema).length > 0,
44-
() => ({
45-
code: 'too_small',
46-
message: 'Custom group rules must contain at least 1 element',
43+
z
44+
.record(z.string(), z.number())
45+
.refine(schema => Object.keys(schema).length > 0, {
46+
error: 'Custom group rules must contain at least 1 element',
4747
}),
48-
),
49-
],
50-
{
51-
description:
52-
'Array of rule IDs with equal weights or object mapping rule IDs to specific weights',
53-
},
54-
);
48+
])
49+
.describe(
50+
'Array of rule IDs with equal weights or object mapping rule IDs to specific weights',
51+
);
5552

5653
const customGroupSchema = z.object({
57-
slug: z.string({ description: 'Unique group identifier' }),
58-
title: z.string({ description: 'Group display title' }),
59-
description: z.string({ description: 'Group metadata' }).optional(),
60-
docsUrl: z.string({ description: 'Group documentation site' }).optional(),
54+
slug: z.string().describe('Unique group identifier'),
55+
title: z.string().describe('Group display title'),
56+
description: z.string().describe('Group metadata').optional(),
57+
docsUrl: z.string().describe('Group documentation site').optional(),
6158
rules: customGroupRulesSchema,
6259
});
6360
export type CustomGroup = z.infer<typeof customGroupSchema>;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ describe('eslintPlugin', () => {
134134
groups: [{ slug: 'type-safety', title: 'Type safety', rules: [] }],
135135
},
136136
),
137-
).rejects.toThrow(/Custom group rules must contain at least 1 element/);
137+
).rejects.toThrow('Invalid input');
138138
await expect(
139139
eslintPlugin(
140140
{
@@ -145,14 +145,14 @@ describe('eslintPlugin', () => {
145145
groups: [{ slug: 'type-safety', title: 'Type safety', rules: {} }],
146146
},
147147
),
148-
).rejects.toThrow(/Custom group rules must contain at least 1 element/);
148+
).rejects.toThrow('Invalid input');
149149
});
150150

151151
it('should throw when invalid parameters provided', async () => {
152152
await expect(
153153
// @ts-expect-error simulating invalid non-TS config
154154
eslintPlugin({ eslintrc: '.eslintrc.json' }),
155-
).rejects.toThrow(/Invalid input/);
155+
).rejects.toThrow('Invalid input');
156156
});
157157

158158
it("should throw if eslintrc file doesn't exist", async () => {

0 commit comments

Comments
 (0)