MCPcopy Create free account
hub / github.com/Effect-TS/effect / parseModuleExamples

Function parseModuleExamples

packages/tools/jsdocs/src/Jsdocs.ts:1381–1419  ·  view source on GitHub ↗
(block: JSDocBlock)

Source from the content-addressed store, hash-verified

1379}
1380
1381function parseModuleExamples(block: JSDocBlock): {
1382 readonly examples: ReadonlyArray<ParsedExample>
1383 readonly diagnostics: ReadonlyArray<JSDocDiagnostic>
1384} {
1385 const diagnostics: Array<JSDocDiagnostic> = []
1386 const examples: Array<ParsedExample> = []
1387 const exampleTitles = new Set<string>()
1388 const firstTagLine = block.tags[0]?.line ?? block.lines.length
1389 const lines = block.lines.slice(0, firstTagLine)
1390 let index = 0
1391 while (index < lines.length) {
1392 const trimmed = lines[index].trim()
1393 if (trimmed.startsWith("**Example**")) {
1394 const parsed = parseExample(lines, index)
1395 diagnostics.push(...parsed.diagnostics)
1396 if (parsed.example !== undefined) {
1397 const key = parsed.example.title.trim().toLowerCase()
1398 if (exampleTitles.has(key)) {
1399 diagnostics.push(diagnostic("duplicate-example", `Duplicate example title: ${parsed.example.title.trim()}`))
1400 }
1401 exampleTitles.add(key)
1402 examples.push(parsed.example)
1403 }
1404 index = Math.max(parsed.nextIndex, index + 1)
1405 continue
1406 }
1407 if (trimmed.startsWith("```")) {
1408 diagnostics.push(
1409 diagnostic("loose-ts-fence", "Code fences in module JSDoc must use **Example** (Title) sections")
1410 )
1411 index++
1412 while (index < lines.length && !lines[index].trim().startsWith("```")) index++
1413 if (index < lines.length) index++
1414 continue
1415 }
1416 index++
1417 }
1418 return { examples, diagnostics }
1419}
1420
1421function joinBody(lines: ReadonlyArray<string>): string {
1422 let start = 0

Callers 2

checkModuleExamplesFunction · 0.85
parseModuleJSDocTsFunction · 0.85

Calls 7

parseExampleFunction · 0.85
diagnosticFunction · 0.85
sliceMethod · 0.80
trimMethod · 0.80
pushMethod · 0.65
hasMethod · 0.65
addMethod · 0.65

Tested by

no test coverage detected