Skip to content

Commit e4ad36a

Browse files
committed
refactor: fix lint
1 parent 02a462f commit e4ad36a

File tree

2 files changed

+160
-21
lines changed

2 files changed

+160
-21
lines changed

tools/zod2md-jsdocs/src/lib/generators/sync-zod2md-setup/sync-zod2md-setup.ts

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -209,23 +209,9 @@ function applyFixes(
209209
});
210210
}
211211
}
212-
function formatIssues(issues: readonly SyncIssue[]): string | undefined {
213-
if (issues.length === 0) {
214-
return undefined;
215-
}
216-
const grouped: Record<SyncIssue['type'], readonly SyncIssue[]> =
217-
issues.reduce<Record<SyncIssue['type'], readonly SyncIssue[]>>(
218-
(acc, issue) => ({
219-
...acc,
220-
[issue.type]: [...(acc[issue.type] ?? []), issue],
221-
}),
222-
{
223-
[missingTsconfig]: [],
224-
[missingTarget]: [],
225-
[missingBuildDeps]: [],
226-
[missingTsPlugin]: [],
227-
},
228-
);
212+
function formatIssueGroups(
213+
grouped: Record<SyncIssue['type'], readonly SyncIssue[]>,
214+
): readonly (string | null)[] {
229215
return [
230216
grouped[missingTsconfig]?.length
231217
? `Missing tsconfig in:\n${grouped[missingTsconfig]
@@ -258,9 +244,27 @@ function formatIssues(issues: readonly SyncIssue[]): string | undefined {
258244
.map(i => ` - ${i.projectRoot}`)
259245
.join('\n')}`
260246
: null,
261-
]
262-
.filter(Boolean)
263-
.join('\n\n');
247+
];
248+
}
249+
250+
export function formatIssues(issues: readonly SyncIssue[]): string | undefined {
251+
if (issues.length === 0) {
252+
return undefined;
253+
}
254+
const grouped: Record<SyncIssue['type'], readonly SyncIssue[]> =
255+
issues.reduce<Record<SyncIssue['type'], readonly SyncIssue[]>>(
256+
(acc, issue) => ({
257+
...acc,
258+
[issue.type]: [...(acc[issue.type] ?? []), issue],
259+
}),
260+
{
261+
[missingTsconfig]: [],
262+
[missingTarget]: [],
263+
[missingBuildDeps]: [],
264+
[missingTsPlugin]: [],
265+
},
266+
);
267+
return formatIssueGroups(grouped).filter(Boolean).join('\n\n');
264268
}
265269
export async function syncZod2mdSetupGenerator(tree: Tree, _?: unknown) {
266270
const graph = await createProjectGraphAsync();

tools/zod2md-jsdocs/src/lib/generators/sync-zod2md-setup/sync-zod2md-setup.unit.test.ts

Lines changed: 136 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from '../../plugin/constants.js';
99
import { addZod2MdTransformToTsConfig } from '../configuration/tsconfig.js';
1010
import { generateZod2MdConfig } from '../configuration/zod2md-config.js';
11-
import { syncZod2mdSetupGenerator } from './sync-zod2md-setup.js';
11+
import { formatIssues, syncZod2mdSetupGenerator } from './sync-zod2md-setup.js';
1212

1313
describe('sync-zod2md-setup generator', () => {
1414
const createProjectGraphAsyncSpy = vi.spyOn(
@@ -248,4 +248,139 @@ describe('sync-zod2md-setup generator', () => {
248248
).length;
249249
expect(generateDocsCount).toBe(1);
250250
});
251+
252+
describe('formatIssues', () => {
253+
it('should return undefined for empty issues array', () => {
254+
expect(formatIssues([])).toBeUndefined();
255+
});
256+
257+
it('should format missing tsconfig issues', () => {
258+
const issues = [
259+
{
260+
type: 'missing-tsconfig' as const,
261+
projectRoot: 'libs/project1',
262+
data: undefined,
263+
},
264+
{
265+
type: 'missing-tsconfig' as const,
266+
projectRoot: 'libs/project2',
267+
data: undefined,
268+
},
269+
];
270+
271+
expect(formatIssues(issues)).toBe(`Missing tsconfig in:
272+
- libs/project1
273+
- libs/project2`);
274+
});
275+
276+
it('should format missing target issues', () => {
277+
const issues = [
278+
{
279+
type: 'missing-target' as const,
280+
projectRoot: 'libs/project1',
281+
data: { target: 'generate-docs' },
282+
},
283+
];
284+
285+
expect(formatIssues(issues)).toBe(`Missing "generate-docs" target in:
286+
- libs/project1`);
287+
});
288+
289+
it('should format missing build dependencies issues', () => {
290+
const issues = [
291+
{
292+
type: 'missing-build-depends-on' as const,
293+
projectRoot: 'libs/project1',
294+
data: { missing: ['generate-docs', 'ts-patch'] },
295+
},
296+
{
297+
type: 'missing-build-depends-on' as const,
298+
projectRoot: 'libs/project2',
299+
data: { missing: ['generate-docs'] },
300+
},
301+
];
302+
303+
expect(formatIssues(issues)).toBe(`Missing build.dependsOn entries:
304+
- libs/project1: generate-docs, ts-patch
305+
- libs/project2: generate-docs`);
306+
});
307+
308+
it('should format missing ts plugin issues', () => {
309+
const issues = [
310+
{
311+
type: 'missing-ts-plugin' as const,
312+
projectRoot: 'libs/project1',
313+
data: undefined,
314+
},
315+
];
316+
317+
expect(formatIssues(issues))
318+
.toBe(`Missing Zod2Md TypeScript plugin configuration in:
319+
- libs/project1`);
320+
});
321+
322+
it('should format multiple issue types', () => {
323+
const issues = [
324+
{
325+
type: 'missing-tsconfig' as const,
326+
projectRoot: 'libs/project1',
327+
data: undefined,
328+
},
329+
{
330+
type: 'missing-target' as const,
331+
projectRoot: 'libs/project2',
332+
data: { target: 'generate-docs' },
333+
},
334+
{
335+
type: 'missing-build-depends-on' as const,
336+
projectRoot: 'libs/project3',
337+
data: { missing: ['generate-docs'] },
338+
},
339+
{
340+
type: 'missing-ts-plugin' as const,
341+
projectRoot: 'libs/project4',
342+
data: undefined,
343+
},
344+
];
345+
346+
const expected = `Missing tsconfig in:
347+
- libs/project1
348+
349+
Missing "generate-docs" target in:
350+
- libs/project2
351+
352+
Missing build.dependsOn entries:
353+
- libs/project3: generate-docs
354+
355+
Missing Zod2Md TypeScript plugin configuration in:
356+
- libs/project4`;
357+
358+
expect(formatIssues(issues)).toBe(expected);
359+
});
360+
361+
it('should filter out null formatted sections', () => {
362+
const issues = [
363+
{
364+
type: 'missing-tsconfig' as const,
365+
projectRoot: 'libs/project1',
366+
data: undefined,
367+
},
368+
// No missing-target issues
369+
// No missing-build-deps issues
370+
{
371+
type: 'missing-ts-plugin' as const,
372+
projectRoot: 'libs/project2',
373+
data: undefined,
374+
},
375+
];
376+
377+
const expected = `Missing tsconfig in:
378+
- libs/project1
379+
380+
Missing Zod2Md TypeScript plugin configuration in:
381+
- libs/project2`;
382+
383+
expect(formatIssues(issues)).toBe(expected);
384+
});
385+
});
251386
});

0 commit comments

Comments
 (0)