Skip to content

Commit 719320f

Browse files
renovate[bot]github-actions[bot]
authored andcommitted
Apply auto lint-fix changes
1 parent cba3f09 commit 719320f

File tree

6 files changed

+128
-108
lines changed

6 files changed

+128
-108
lines changed

src/directive.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ export function buildApiForValibot(config: FormattedDirectiveConfig, directives:
150150
const argsConfig = config[directiveName];
151151
const apis = _buildApiFromDirectiveArguments(argsConfig, directive.arguments ?? []);
152152
return apis.map(api => `v${api}`);
153-
}).flat()
153+
})
154+
.flat()
154155
}
155156

156157
function buildApiSchema(validationSchema: string[] | undefined, argValue: ConstValueNode): string {

src/graphql.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,7 @@ export function topsort(g: Graph): string[] {
181181
}
182182

183183
export function isGeneratedByIntrospection(schema: GraphQLSchema): boolean {
184-
return Object.entries(schema.getTypeMap())
185-
.filter(([name, type]) => !name.startsWith('__') && !isSpecifiedScalarType(type))
186-
.every(([, type]) => type.astNode === undefined)
184+
return Object.entries(schema.getTypeMap()).filter(([name, type]) => !name.startsWith('__') && !isSpecifiedScalarType(type)).every(([, type]) => type.astNode === undefined)
187185
}
188186

189187
// https://spec.graphql.org/October2021/#EscapedCharacter

src/myzod/index.ts

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ export class MyZodSchemaVisitor extends BaseSchemaVisitor {
4545
return (
4646
`\n${
4747
[
48-
new DeclarationBlock({}).export().asKind('const').withName(`${anySchema}`).withContent(`myzod.object({})`)
49-
.string,
48+
new DeclarationBlock({}).export().asKind('const').withName(`${anySchema}`).withContent(`myzod.object({})`).string,
5049
...this.enumDeclarations,
5150
].join('\n')}`
5251
);
@@ -84,7 +83,8 @@ export class MyZodSchemaVisitor extends BaseSchemaVisitor {
8483
.export()
8584
.asKind('const')
8685
.withName(`${name}Schema: myzod.Type<${name}>`)
87-
.withContent([`myzod.object({`, shape, '})'].join('\n')).string + appendArguments
86+
.withContent([`myzod.object({`, shape, '})'].join('\n'))
87+
.string + appendArguments
8888
);
8989

9090
case 'function':
@@ -94,7 +94,8 @@ export class MyZodSchemaVisitor extends BaseSchemaVisitor {
9494
.export()
9595
.asKind('function')
9696
.withName(`${name}Schema(): myzod.Type<${name}>`)
97-
.withBlock([indent(`return myzod.object({`), shape, indent('})')].join('\n')).string + appendArguments
97+
.withBlock([indent(`return myzod.object({`), shape, indent('})')].join('\n'))
98+
.string + appendArguments
9899
);
99100
}
100101
}),
@@ -129,7 +130,8 @@ export class MyZodSchemaVisitor extends BaseSchemaVisitor {
129130
shape,
130131
'})',
131132
].join('\n'),
132-
).string + appendArguments
133+
)
134+
.string + appendArguments
133135
);
134136

135137
case 'function':
@@ -146,7 +148,8 @@ export class MyZodSchemaVisitor extends BaseSchemaVisitor {
146148
shape,
147149
indent('})'),
148150
].join('\n'),
149-
).string + appendArguments
151+
)
152+
.string + appendArguments
150153
);
151154
}
152155
}),
@@ -169,12 +172,14 @@ export class MyZodSchemaVisitor extends BaseSchemaVisitor {
169172
.withName(`${enumname}Schema`)
170173
.withContent(
171174
`myzod.literals(${node.values?.map(enumOption => `'${enumOption.name.value}'`).join(', ')})`,
172-
).string
175+
)
176+
.string
173177
: new DeclarationBlock({})
174178
.export()
175179
.asKind('const')
176180
.withName(`${enumname}Schema`)
177-
.withContent(`myzod.enum(${enumname})`).string,
181+
.withContent(`myzod.enum(${enumname})`)
182+
.string,
178183
);
179184
},
180185
};
@@ -189,37 +194,35 @@ export class MyZodSchemaVisitor extends BaseSchemaVisitor {
189194
const visitor = this.createVisitor('output');
190195

191196
const unionName = visitor.convertName(node.name.value);
192-
const unionElements = node.types
193-
?.map((t) => {
194-
const element = visitor.convertName(t.name.value);
195-
const typ = visitor.getType(t.name.value);
196-
if (typ?.astNode?.kind === 'EnumTypeDefinition')
197+
const unionElements = node.types?.map((t) => {
198+
const element = visitor.convertName(t.name.value);
199+
const typ = visitor.getType(t.name.value);
200+
if (typ?.astNode?.kind === 'EnumTypeDefinition')
201+
return `${element}Schema`;
202+
203+
switch (this.config.validationSchemaExportType) {
204+
case 'const':
197205
return `${element}Schema`;
198-
199-
switch (this.config.validationSchemaExportType) {
200-
case 'const':
201-
return `${element}Schema`;
202-
case 'function':
203-
default:
204-
return `${element}Schema()`;
205-
}
206-
})
207-
.join(', ');
206+
case 'function':
207+
default:
208+
return `${element}Schema()`;
209+
}
210+
}).join(', ');
208211
const unionElementsCount = node.types?.length ?? 0;
209212

210213
const union = unionElementsCount > 1 ? `myzod.union([${unionElements}])` : unionElements;
211214

212215
switch (this.config.validationSchemaExportType) {
213216
case 'const':
214-
return new DeclarationBlock({}).export().asKind('const').withName(`${unionName}Schema`).withContent(union)
215-
.string;
217+
return new DeclarationBlock({}).export().asKind('const').withName(`${unionName}Schema`).withContent(union).string;
216218
case 'function':
217219
default:
218220
return new DeclarationBlock({})
219221
.export()
220222
.asKind('function')
221223
.withName(`${unionName}Schema()`)
222-
.withBlock(indent(`return ${union}`)).string;
224+
.withBlock(indent(`return ${union}`))
225+
.string;
223226
}
224227
},
225228
};
@@ -238,15 +241,17 @@ export class MyZodSchemaVisitor extends BaseSchemaVisitor {
238241
.export()
239242
.asKind('const')
240243
.withName(`${name}Schema: myzod.Type<${name}>`)
241-
.withContent(['myzod.object({', shape, '})'].join('\n')).string;
244+
.withContent(['myzod.object({', shape, '})'].join('\n'))
245+
.string;
242246

243247
case 'function':
244248
default:
245249
return new DeclarationBlock({})
246250
.export()
247251
.asKind('function')
248252
.withName(`${name}Schema(): myzod.Type<${name}>`)
249-
.withBlock([indent(`return myzod.object({`), shape, indent('})')].join('\n')).string;
253+
.withBlock([indent(`return myzod.object({`), shape, indent('})')].join('\n'))
254+
.string;
250255
}
251256
}
252257
}

src/valibot/index.ts

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ export class ValibotSchemaVisitor extends BaseSchemaVisitor {
7474
.export()
7575
.asKind('function')
7676
.withName(`${name}Schema(): v.GenericSchema<${name}>`)
77-
.withBlock([indent(`return v.object({`), shape, indent('})')].join('\n')).string + appendArguments
77+
.withBlock([indent(`return v.object({`), shape, indent('})')].join('\n'))
78+
.string + appendArguments
7879
);
7980
}
8081
}),
@@ -109,7 +110,8 @@ export class ValibotSchemaVisitor extends BaseSchemaVisitor {
109110
shape,
110111
indent('})'),
111112
].join('\n'),
112-
).string + appendArguments
113+
)
114+
.string + appendArguments
113115
);
114116
}
115117
}),
@@ -136,7 +138,8 @@ export class ValibotSchemaVisitor extends BaseSchemaVisitor {
136138
.export()
137139
.asKind('const')
138140
.withName(`${enumname}Schema`)
139-
.withContent(`v.enum_(${enumname})`).string,
141+
.withContent(`v.enum_(${enumname})`)
142+
.string,
140143
);
141144
},
142145
};
@@ -149,19 +152,17 @@ export class ValibotSchemaVisitor extends BaseSchemaVisitor {
149152
return;
150153
const visitor = this.createVisitor('output');
151154
const unionName = visitor.convertName(node.name.value);
152-
const unionElements = node.types
153-
.map((t) => {
154-
const element = visitor.convertName(t.name.value);
155-
const typ = visitor.getType(t.name.value);
156-
if (typ?.astNode?.kind === 'EnumTypeDefinition')
157-
return `${element}Schema`;
158-
159-
switch (this.config.validationSchemaExportType) {
160-
default:
161-
return `${element}Schema()`;
162-
}
163-
})
164-
.join(', ');
155+
const unionElements = node.types.map((t) => {
156+
const element = visitor.convertName(t.name.value);
157+
const typ = visitor.getType(t.name.value);
158+
if (typ?.astNode?.kind === 'EnumTypeDefinition')
159+
return `${element}Schema`;
160+
161+
switch (this.config.validationSchemaExportType) {
162+
default:
163+
return `${element}Schema()`;
164+
}
165+
}).join(', ');
165166
const unionElementsCount = node.types.length ?? 0;
166167

167168
const union = unionElementsCount > 1 ? `v.union([${unionElements}])` : unionElements;
@@ -172,7 +173,8 @@ export class ValibotSchemaVisitor extends BaseSchemaVisitor {
172173
.export()
173174
.asKind('function')
174175
.withName(`${unionName}Schema()`)
175-
.withBlock(indent(`return ${union}`)).string;
176+
.withBlock(indent(`return ${union}`))
177+
.string;
176178
}
177179
},
178180
};
@@ -191,7 +193,8 @@ export class ValibotSchemaVisitor extends BaseSchemaVisitor {
191193
.export()
192194
.asKind('function')
193195
.withName(`${name}Schema(): v.GenericSchema<${name}>`)
194-
.withBlock([indent(`return v.object({`), shape, indent('})')].join('\n')).string;
196+
.withBlock([indent(`return v.object({`), shape, indent('})')].join('\n'))
197+
.string;
195198
}
196199
}
197200
}

src/yup/index.ts

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
5555
indent('test: (value) => schemas.some((schema) => schema.isValidSync(value))', 2),
5656
indent('}).defined()'),
5757
].join('\n'),
58-
).string}`
58+
)
59+
.string}`
5960
);
6061
}
6162

@@ -82,12 +83,10 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
8283
const appendArguments = argumentBlocks ? `\n${argumentBlocks}` : '';
8384

8485
// Building schema for fields.
85-
const shape = node.fields
86-
?.map((field) => {
87-
const fieldSchema = generateFieldYupSchema(this.config, visitor, field, 2);
88-
return isNonNullType(field.type) ? fieldSchema : `${fieldSchema}.optional()`;
89-
})
90-
.join(',\n');
86+
const shape = node.fields?.map((field) => {
87+
const fieldSchema = generateFieldYupSchema(this.config, visitor, field, 2);
88+
return isNonNullType(field.type) ? fieldSchema : `${fieldSchema}.optional()`;
89+
}).join(',\n');
9190

9291
switch (this.config.validationSchemaExportType) {
9392
case 'const':
@@ -96,7 +95,8 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
9695
.export()
9796
.asKind('const')
9897
.withName(`${name}Schema: yup.ObjectSchema<${name}>`)
99-
.withContent([`yup.object({`, shape, '})'].join('\n')).string + appendArguments
98+
.withContent([`yup.object({`, shape, '})'].join('\n'))
99+
.string + appendArguments
100100
);
101101

102102
case 'function':
@@ -106,7 +106,8 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
106106
.export()
107107
.asKind('function')
108108
.withName(`${name}Schema(): yup.ObjectSchema<${name}>`)
109-
.withBlock([indent(`return yup.object({`), shape, indent('})')].join('\n')).string + appendArguments
109+
.withBlock([indent(`return yup.object({`), shape, indent('})')].join('\n'))
110+
.string + appendArguments
110111
);
111112
}
112113
}),
@@ -141,7 +142,8 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
141142
shape,
142143
'})',
143144
].join('\n'),
144-
).string + appendArguments
145+
)
146+
.string + appendArguments
145147
);
146148

147149
case 'function':
@@ -158,7 +160,8 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
158160
shape,
159161
indent('})'),
160162
].join('\n'),
161-
).string + appendArguments
163+
)
164+
.string + appendArguments
162165
);
163166
}
164167
}),
@@ -207,37 +210,37 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
207210
const unionName = visitor.convertName(node.name.value);
208211
this.importTypes.push(unionName);
209212

210-
const unionElements = node.types
211-
?.map((t) => {
212-
const element = visitor.convertName(t.name.value);
213-
const typ = visitor.getType(t.name.value);
214-
if (typ?.astNode?.kind === 'EnumTypeDefinition')
215-
return `${element}Schema`;
213+
const unionElements = node.types?.map((t) => {
214+
const element = visitor.convertName(t.name.value);
215+
const typ = visitor.getType(t.name.value);
216+
if (typ?.astNode?.kind === 'EnumTypeDefinition')
217+
return `${element}Schema`;
216218

217-
switch (this.config.validationSchemaExportType) {
218-
case 'const':
219-
return `${element}Schema`;
220-
case 'function':
221-
default:
222-
return `${element}Schema()`;
223-
}
224-
})
225-
.join(', ');
219+
switch (this.config.validationSchemaExportType) {
220+
case 'const':
221+
return `${element}Schema`;
222+
case 'function':
223+
default:
224+
return `${element}Schema()`;
225+
}
226+
}).join(', ');
226227

227228
switch (this.config.validationSchemaExportType) {
228229
case 'const':
229230
return new DeclarationBlock({})
230231
.export()
231232
.asKind('const')
232233
.withName(`${unionName}Schema: yup.MixedSchema<${unionName}>`)
233-
.withContent(`union<${unionName}>(${unionElements})`).string;
234+
.withContent(`union<${unionName}>(${unionElements})`)
235+
.string;
234236
case 'function':
235237
default:
236238
return new DeclarationBlock({})
237239
.export()
238240
.asKind('function')
239241
.withName(`${unionName}Schema(): yup.MixedSchema<${unionName}>`)
240-
.withBlock(indent(`return union<${unionName}>(${unionElements})`)).string;
242+
.withBlock(indent(`return union<${unionName}>(${unionElements})`))
243+
.string;
241244
}
242245
},
243246
};
@@ -256,15 +259,17 @@ export class YupSchemaVisitor extends BaseSchemaVisitor {
256259
.export()
257260
.asKind('const')
258261
.withName(`${name}Schema: yup.ObjectSchema<${name}>`)
259-
.withContent(['yup.object({', shape, '})'].join('\n')).string;
262+
.withContent(['yup.object({', shape, '})'].join('\n'))
263+
.string;
260264

261265
case 'function':
262266
default:
263267
return new DeclarationBlock({})
264268
.export()
265269
.asKind('function')
266270
.withName(`${name}Schema(): yup.ObjectSchema<${name}>`)
267-
.withBlock([indent(`return yup.object({`), shape, indent('})')].join('\n')).string;
271+
.withBlock([indent(`return yup.object({`), shape, indent('})')].join('\n'))
272+
.string;
268273
}
269274
}
270275
}

0 commit comments

Comments
 (0)