Skip to content

Commit aff60b3

Browse files
committed
fix(zod): lint issues
1 parent e3292ae commit aff60b3

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

packages/zod/src/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import {
44
camel,
55
type ClientBuilder,
66
type ClientGeneratorsBuilder,
7-
conventionName,
87
type ContextSpec,
8+
conventionName,
99
escape,
1010
generateMutator,
1111
type GeneratorDependency,
@@ -237,7 +237,7 @@ export const generateZodValidationSchemaDefinition = (
237237

238238
const CHAINABLE_SIBLINGS = new Set(['nullable', 'default', 'description']);
239239
const isChainable = (k: string) => CHAINABLE_SIBLINGS.has(k);
240-
const allSiblingsChainable = siblings.every(isChainable);
240+
const allSiblingsChainable = siblings.every((k) => isChainable(k));
241241

242242
if (allSiblingsChainable) {
243243
const refName = conventionName(
@@ -255,7 +255,7 @@ export const generateZodValidationSchemaDefinition = (
255255
default?: unknown;
256256
description?: string;
257257
};
258-
const refRequired = rules?.required ?? false;
258+
const refRequired = rules.required ?? false;
259259
const refHasDefault = refSchema.default !== undefined;
260260

261261
// Match the main-path modifier ordering: nullability/optional first,
@@ -275,7 +275,7 @@ export const generateZodValidationSchemaDefinition = (
275275
// constNameRegistry-based suffix that the rest of the generator uses so
276276
// multiple defaults sharing `name` don't collide on `<name>Default`.
277277
if (refHasDefault) {
278-
const registry = rules?.constNameRegistry ?? {};
278+
const registry = rules.constNameRegistry ?? {};
279279
const counter = isNumber(registry[name]) ? registry[name] + 1 : 0;
280280
registry[name] = counter;
281281
const suffix = counter ? pascal(getNumberWord(counter)) : '';
@@ -1790,7 +1790,7 @@ const generateZodRoute = async (
17901790
const isZodV4 =
17911791
!!context.output.packageJson && isZodVersionV4(context.output.packageJson);
17921792
const useReusableSchemas =
1793-
context.output.override.zod.generateReusableSchemas === true;
1793+
context.output.override.zod.generateReusableSchemas;
17941794
const spec = context.spec.paths?.[pathRoute];
17951795

17961796
if (spec == undefined) {
@@ -1928,7 +1928,7 @@ const generateZodRoute = async (
19281928
})
19291929
: undefined;
19301930

1931-
let inputResponses = parsedResponses.map((parsedResponse) =>
1931+
const inputResponses = parsedResponses.map((parsedResponse) =>
19321932
parseZodValidationSchemaDefinition(
19331933
parsedResponse.input,
19341934
context,
@@ -1941,7 +1941,7 @@ const generateZodRoute = async (
19411941

19421942
const SENTINEL_PATTERN = /__REF_([A-Za-z_$][A-Za-z0-9_$]*)__/g;
19431943
const rewriteSentinels = (s: string): string =>
1944-
s.replace(SENTINEL_PATTERN, (_m, name: string) => name);
1944+
s.replaceAll(SENTINEL_PATTERN, (_m, name: string) => name);
19451945

19461946
const allUsedRefs = new Set<string>([
19471947
...inputParams.usedRefs,
@@ -2070,7 +2070,7 @@ export const generateZod: ClientBuilder = async (verbOptions, options) => {
20702070
// Zod schemas are runtime values (not type-only), so mark with values: true
20712071
// to prevent the import writer from emitting `import type { ... }`. Sort
20722072
// by name so import order is stable across runs.
2073-
imports: [...(usedRefs ?? [])].sort().map((name) => ({
2073+
imports: [...usedRefs].toSorted().map((name) => ({
20742074
name,
20752075
schemaName: name,
20762076
values: true,

packages/zod/src/zod.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3505,7 +3505,7 @@ describe('generateZodValidationSchemaDefinition`', () => {
35053505
{ name: 'pet', sourceRef: '#/components/schemas/Pet' },
35063506
]);
35073507
expect(result.functions.at(-1)?.[0]).toBe('default');
3508-
expect(result.consts.some((c) => /Default/.test(c))).toBe(true);
3508+
expect(result.consts.some((c) => c.includes('Default'))).toBe(true);
35093509
});
35103510

35113511
it('chains .optional() when the parent does not list the ref as required', () => {

0 commit comments

Comments
 (0)