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

Function parseSection

packages/tools/jsdocs/src/Jsdocs.ts:1255–1299  ·  view source on GitHub ↗
(lines: Array<string>, headingIndex: number)

Source from the content-addressed store, hash-verified

1253}
1254
1255function parseSection(lines: Array<string>, headingIndex: number): {
1256 readonly body: string | null
1257 readonly nextIndex: number
1258 readonly diagnostics: ReadonlyArray<JSDocDiagnostic>
1259} {
1260 const diagnostics: Array<JSDocDiagnostic> = []
1261 if (lines[headingIndex + 1]?.trim() !== "") {
1262 diagnostics.push(
1263 diagnostic("invalid-spacing", `${lines[headingIndex].trim()} must be followed by exactly one blank line`)
1264 )
1265 }
1266 let index = headingIndex + 2
1267 const bodyStart = index
1268 let inFence = false
1269 while (index < lines.length) {
1270 const trimmed = lines[index].trim()
1271 if (trimmed.startsWith("```")) {
1272 if (isTypeScriptFence(trimmed)) {
1273 diagnostics.push(diagnostic("loose-ts-fence", "TypeScript examples must use **Example** (Title) sections"))
1274 }
1275 inFence = !inFence
1276 }
1277 if (!inFence && trimmed === "" && isHeadingLine(lines[index + 1])) {
1278 break
1279 }
1280 if (!inFence && trimmed !== "" && isForbiddenMarkdownHeading(trimmed, false)) {
1281 diagnostics.push(diagnostic("invalid-heading", "Markdown headings are not allowed in JSDoc descriptions"))
1282 }
1283 if (
1284 !inFence && isBoldOnlyLine(trimmed) && !standardHeadings.includes(trimmed as StandardHeading) &&
1285 !trimmed.startsWith("**Example**")
1286 ) {
1287 diagnostics.push(diagnostic("unknown-heading", `Unknown JSDoc section heading: ${trimmed}`))
1288 }
1289 index++
1290 }
1291 const bodyLines = lines.slice(bodyStart, index)
1292 if (joinBody(bodyLines).trim() === "") {
1293 diagnostics.push(diagnostic("empty-section", `${lines[headingIndex].trim()} must have a non-empty body`))
1294 }
1295 if (bodyLines.at(-1)?.trim() === "") {
1296 diagnostics.push(diagnostic("invalid-spacing", "Section bodies must not end with extra blank lines"))
1297 }
1298 return { body: joinBody(bodyLines), nextIndex: index, diagnostics }
1299}
1300
1301const isTypeScriptFence = (line: string): boolean => /^```ts(?:\s.*)?$/.test(line)
1302

Callers 1

parseDescriptionContentFunction · 0.85

Calls 10

diagnosticFunction · 0.85
isTypeScriptFenceFunction · 0.85
isHeadingLineFunction · 0.85
isBoldOnlyLineFunction · 0.85
joinBodyFunction · 0.85
trimMethod · 0.80
sliceMethod · 0.80
pushMethod · 0.65
atMethod · 0.65

Tested by

no test coverage detected