Skip to content

Commit 27884eb

Browse files
committed
chore: lint
1 parent ae536fc commit 27884eb

5 files changed

Lines changed: 49 additions & 42 deletions

File tree

src/context-file.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ export class ContextFile extends ModuleBuilder {
4848
yield ` return <${contextName}.Provider value={value}>{children}</${contextName}.Provider>;`;
4949
yield `};`;
5050

51-
const sortedInterfaces = [...this.service.interfaces].sort((a, b) => a.name.value.localeCompare(b.name.value))
51+
const sortedInterfaces = [...this.service.interfaces].sort((a, b) =>
52+
a.name.value.localeCompare(b.name.value),
53+
);
5254
for (const int of sortedInterfaces) {
5355
const hookName = buildServiceHookName(int);
5456
const getterName = buildServiceGetterName(int);
@@ -75,7 +77,9 @@ export class ContextFile extends ModuleBuilder {
7577
yield ` if (!context) { throw new Error('${hookName} must be used within a ${providerName}'); }`;
7678
yield ` const ${localName}: ${this.types.type(
7779
interfaceName,
78-
)} = new ${this.client.fn(className)}(context.fetch ?? window.fetch.bind(window), context);`;
80+
)} = new ${this.client.fn(
81+
className,
82+
)}(context.fetch ?? window.fetch.bind(window), context);`;
7983
yield ` return ${localName};`;
8084
yield `}`;
8185
}

src/hook-file.ts

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
getTypeByName,
66
getUnionByName,
77
HttpMethod,
8-
HttpParameter,
98
HttpRoute,
109
Interface,
1110
isRequired,
@@ -96,8 +95,9 @@ export class HookFile extends ModuleBuilder {
9695
const serviceHookName = buildServiceHookName(this.int);
9796

9897
for (const method of [...this.int.methods].sort((a, b) =>
99-
buildHookName(a, this.service)
100-
.localeCompare(buildHookName(b, this.service)),
98+
buildHookName(a, this.service).localeCompare(
99+
buildHookName(b, this.service),
100+
),
101101
)) {
102102
const name = buildHookName(method, this.service);
103103
const suspenseName = buildHookName(method, this.service, {
@@ -160,7 +160,9 @@ export class HookFile extends ModuleBuilder {
160160
const optionsExpression = `options?: Omit<${mutationOptions()}, 'mutationFn'>`;
161161

162162
yield* buildDescription(method.description, true); // Mark as deprecated
163-
yield `/** @deprecated Use ${buildMutationOptionsName(method)} with useMutation instead */`;
163+
yield `/** @deprecated Use ${buildMutationOptionsName(
164+
method,
165+
)} with useMutation instead */`;
164166
yield `export function ${name}(${optionsExpression}) {`;
165167
yield ` const queryClient = ${useQueryClient()}();`;
166168
yield ` const ${serviceName} = ${this.context.fn(serviceHookName)}()`;
@@ -220,15 +222,18 @@ export class HookFile extends ModuleBuilder {
220222
yield ` return res;`;
221223
yield ` },`;
222224
yield* this.buildInfiniteSelectFn(method);
223-
yield ` initialPageParam: ${getInitialPageParam()}(params${q ? '?? {}' : ''
224-
}),`;
225+
yield ` initialPageParam: ${getInitialPageParam()}(params${
226+
q ? '?? {}' : ''
227+
}),`;
225228
yield ` ${getNextPageParam()},`;
226229
yield ` ${getPreviousPageParam()},`;
227230
yield ` };`;
228231
yield `}`;
229232

230233
yield* buildDescription(method.description, true); // Mark as deprecated
231-
yield `/** @deprecated Use ${buildInfiniteQueryOptionsName(method)} with useInfiniteQuery instead */`;
234+
yield `/** @deprecated Use ${buildInfiniteQueryOptionsName(
235+
method,
236+
)} with useInfiniteQuery instead */`;
232237
yield `export const ${buildHookName(method, this.service, {
233238
suspense: false,
234239
infinite: true,
@@ -238,7 +243,9 @@ export class HookFile extends ModuleBuilder {
238243
yield `}`;
239244

240245
yield* buildDescription(method.description, true); // Mark as deprecated
241-
yield `/** @deprecated Use ${buildInfiniteQueryOptionsName(method)} with useSuspenseInfiniteQuery instead */`;
246+
yield `/** @deprecated Use ${buildInfiniteQueryOptionsName(
247+
method,
248+
)} with useSuspenseInfiniteQuery instead */`;
242249
yield `export const ${buildHookName(method, this.service, {
243250
suspense: true,
244251
infinite: true,
@@ -339,8 +346,9 @@ export class HookFile extends ModuleBuilder {
339346

340347
yield ` select: (data: ${InfiniteData()}<${type(
341348
returnTypeName,
342-
)}, string | undefined>) => data.pages.flatMap((page) => page.data${optional ? ' ?? []' : ''
343-
}),`;
349+
)}, string | undefined>) => data.pages.flatMap((page) => page.data${
350+
optional ? ' ?? []' : ''
351+
}),`;
344352
}
345353

346354
private buildQueryOptions(method: Method): () => string {
@@ -459,21 +467,21 @@ export class HookFile extends ModuleBuilder {
459467
const dataProp =
460468
returnType.kind === 'Type'
461469
? returnType.properties.find(
462-
(p) =>
463-
p.name.value.toLocaleLowerCase() === 'data' ||
464-
p.name.value.toLocaleLowerCase() === 'value' ||
465-
p.name.value.toLocaleLowerCase() === 'values',
466-
)
470+
(p) =>
471+
p.name.value.toLocaleLowerCase() === 'data' ||
472+
p.name.value.toLocaleLowerCase() === 'value' ||
473+
p.name.value.toLocaleLowerCase() === 'values',
474+
)
467475
: undefined;
468476
if (!dataProp) return { envelope: undefined, returnType };
469477

470478
const errorProp =
471479
returnType.kind === 'Type'
472480
? returnType.properties.find(
473-
(p) =>
474-
p.name.value.toLocaleLowerCase() === 'error' ||
475-
p.name.value.toLocaleLowerCase() === 'errors',
476-
)
481+
(p) =>
482+
p.name.value.toLocaleLowerCase() === 'error' ||
483+
p.name.value.toLocaleLowerCase() === 'errors',
484+
)
477485
: undefined;
478486
if (!errorProp) return { envelope: undefined, returnType };
479487

@@ -541,10 +549,7 @@ export class HookFile extends ModuleBuilder {
541549
const { skipSelect, dataProp } = this.xxxx(method);
542550

543551
yield '';
544-
yield* buildDescription(
545-
method.description,
546-
method.deprecated?.value,
547-
);
552+
yield* buildDescription(method.description, method.deprecated?.value);
548553
yield `export const ${exportedName} = (${paramsExpression}) => {`;
549554
yield ` const ${serviceName} = ${this.context.fn(serviceGetterName)}()`;
550555
yield ` return ${queryOptions()}({`;
@@ -593,10 +598,7 @@ export class HookFile extends ModuleBuilder {
593598
const dataProp = envelope?.dataProp;
594599

595600
yield '';
596-
yield* buildDescription(
597-
method.description,
598-
method.deprecated?.value,
599-
);
601+
yield* buildDescription(method.description, method.deprecated?.value);
600602
yield `export const ${mutationOptionsName} = () => {`;
601603
yield ` const ${serviceName} = ${this.context.fn(serviceGetterName)}()`;
602604
yield ` return ${mutationOptions()}({`;
@@ -651,10 +653,7 @@ export class HookFile extends ModuleBuilder {
651653
: '';
652654

653655
yield '';
654-
yield* buildDescription(
655-
method.description,
656-
method.deprecated?.value,
657-
);
656+
yield* buildDescription(method.description, method.deprecated?.value);
658657
yield `export const ${infiniteOptionsName} = (${paramsExpression}) => {`;
659658
yield ` const ${serviceName} = ${this.context.fn(serviceGetterName)}();`;
660659
yield ` return ${infiniteQueryOptions()}({`;
@@ -672,8 +671,9 @@ export class HookFile extends ModuleBuilder {
672671
yield ` return res;`;
673672
yield ` },`;
674673
yield* this.buildInfiniteSelectFn(method);
675-
yield ` initialPageParam: ${getInitialPageParam()}(params${q ? '?? {}' : ''
676-
}),`;
674+
yield ` initialPageParam: ${getInitialPageParam()}(params${
675+
q ? '?? {}' : ''
676+
}),`;
677677
yield ` ${getNextPageParam()},`;
678678
yield ` ${getPreviousPageParam()},`;
679679
yield ` });`;
@@ -702,4 +702,3 @@ export class HookFile extends ModuleBuilder {
702702
return `[${queryKey.join(', ')}]`;
703703
}
704704
}
705-

src/hook-generator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class HookGenerator {
1818
constructor(
1919
private readonly service: Service,
2020
private readonly options: NamespacedReactQueryOptions,
21-
) { }
21+
) {}
2222

2323
async generate(): Promise<File[]> {
2424
const files: File[] = [];
@@ -55,8 +55,8 @@ class HookGenerator {
5555
path: buildFilePath(['hooks', 'README.md'], this.service, this.options),
5656
contents: await formatMarkdown(
5757
from(new ReadmeFile(this.service, this.options).build()),
58-
this.options
59-
)
58+
this.options,
59+
),
6060
});
6161

6262
for (const int of this.service.interfaces) {

src/readme-file.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ import { plural } from 'pluralize';
99
import { format, Options } from 'prettier';
1010

1111
import { NamespacedReactQueryOptions } from './types';
12-
import { buildHookName, buildProviderName, buildServiceName, buildServiceHookName } from './name-helpers';
12+
import {
13+
buildHookName,
14+
buildProviderName,
15+
buildServiceName,
16+
buildServiceHookName,
17+
} from './name-helpers';
1318
import { isRelayPaginaged } from './utils';
1419

1520
type MethodInfo = {
@@ -27,7 +32,6 @@ export class ReadmeFile {
2732
private readonly options: NamespacedReactQueryOptions,
2833
) {}
2934

30-
3135
private import(...path: string[]) {
3236
return `./${buildFilePath(path, this.service, this.options).join('/')}`;
3337
}

src/snapshot/test-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export async function* generateFiles(): AsyncIterable<File> {
1212
const options: NamespacedReactQueryOptions = {};
1313

1414
const parser = require('@basketry/ir');
15-
15+
1616
const { engines } = await NodeEngine.load({
1717
sourcePath: 'source/path.ext',
1818
sourceContent: JSON.stringify(service),

0 commit comments

Comments
 (0)