-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathconfig.ts
More file actions
67 lines (58 loc) · 2.19 KB
/
config.ts
File metadata and controls
67 lines (58 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { z } from 'zod';
import { pluginArtifactOptionsSchema } from '@code-pushup/models';
import { toArray } from '@code-pushup/utils';
const patternsSchema = z
.union([z.string(), z.array(z.string()).min(1)])
.describe(
'Lint target files. May contain file paths, directory paths or glob patterns',
);
const eslintrcSchema = z.string().describe('Path to ESLint config file');
const eslintTargetObjectSchema = z.object({
eslintrc: eslintrcSchema.optional(),
patterns: patternsSchema,
});
type ESLintTargetObject = z.infer<typeof eslintTargetObjectSchema>;
export const eslintTargetSchema = z
.union([patternsSchema, eslintTargetObjectSchema])
.transform(
(target): ESLintTargetObject =>
typeof target === 'string' || Array.isArray(target)
? { patterns: target }
: target,
);
export type ESLintTarget = z.infer<typeof eslintTargetSchema>;
export const eslintPluginConfigSchema = z
.union([eslintTargetSchema, z.array(eslintTargetSchema).min(1)])
.transform(toArray);
export type ESLintPluginConfig = z.input<typeof eslintPluginConfigSchema>;
export type ESLintPluginRunnerConfig = {
targets: ESLintTarget[];
slugs: string[];
};
const customGroupRulesSchema = z
.union([
z
.array(z.string())
.min(1, 'Custom group rules must contain at least 1 element'),
z
.record(z.string(), z.number())
.refine(schema => Object.keys(schema).length > 0, {
error: 'Custom group rules must contain at least 1 element',
}),
])
.describe(
'Array of rule IDs with equal weights or object mapping rule IDs to specific weights',
);
const customGroupSchema = z.object({
slug: z.string().describe('Unique group identifier'),
title: z.string().describe('Group display title'),
description: z.string().describe('Group metadata').optional(),
docsUrl: z.string().describe('Group documentation site').optional(),
rules: customGroupRulesSchema,
});
export type CustomGroup = z.infer<typeof customGroupSchema>;
export const eslintPluginOptionsSchema = z.object({
groups: z.array(customGroupSchema).optional(),
artifacts: pluginArtifactOptionsSchema.optional(),
});
export type ESLintPluginOptions = z.infer<typeof eslintPluginOptionsSchema>;