(block: JSDocBlock)
| 1357 | } |
| 1358 | |
| 1359 | function parseModuleExamples(block: JSDocBlock): { |
| 1360 | readonly examples: ReadonlyArray<ParsedExample> |
| 1361 | readonly diagnostics: ReadonlyArray<JSDocDiagnostic> |
| 1362 | } { |
| 1363 | const diagnostics: Array<JSDocDiagnostic> = [] |
| 1364 | const examples: Array<ParsedExample> = [] |
| 1365 | const exampleTitles = new Set<string>() |
| 1366 | const firstTagLine = block.tags[0]?.line ?? block.lines.length |
| 1367 | const lines = block.lines.slice(0, firstTagLine) |
| 1368 | let index = 0 |
| 1369 | while (index < lines.length) { |
| 1370 | const trimmed = lines[index].trim() |
| 1371 | if (trimmed.startsWith("**Example**")) { |
| 1372 | const parsed = parseExample(lines, index) |
| 1373 | diagnostics.push(...parsed.diagnostics) |
| 1374 | if (parsed.example !== undefined) { |
| 1375 | const key = parsed.example.title.trim().toLowerCase() |
| 1376 | if (exampleTitles.has(key)) { |
| 1377 | diagnostics.push(diagnostic("duplicate-example", `Duplicate example title: ${parsed.example.title.trim()}`)) |
| 1378 | } |
| 1379 | exampleTitles.add(key) |
| 1380 | examples.push(parsed.example) |
| 1381 | } |
| 1382 | index = Math.max(parsed.nextIndex, index + 1) |
| 1383 | continue |
| 1384 | } |
| 1385 | if (trimmed.startsWith("```")) { |
| 1386 | diagnostics.push( |
| 1387 | diagnostic("loose-ts-fence", "Code fences in module JSDoc must use **Example** (Title) sections") |
| 1388 | ) |
| 1389 | index++ |
| 1390 | while (index < lines.length && !lines[index].trim().startsWith("```")) index++ |
| 1391 | if (index < lines.length) index++ |
| 1392 | continue |
| 1393 | } |
| 1394 | index++ |
| 1395 | } |
| 1396 | return { examples, diagnostics } |
| 1397 | } |
| 1398 | |
| 1399 | function joinBody(lines: ReadonlyArray<string>): string { |
| 1400 | let start = 0 |
no test coverage detected