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

Function parseDescriptionContent

packages/tools/jsdocs/src/Jsdocs.ts:1120–1248  ·  view source on GitHub ↗
(lines: Array<string>)

Source from the content-addressed store, hash-verified

1118}
1119
1120function parseDescriptionContent(lines: Array<string>): ParsedContentResult {
1121 const diagnostics: Array<JSDocDiagnostic> = []
1122 const sections: Record<StandardHeading, string | null> = {
1123 "**When to use**": null,
1124 "**Details**": null,
1125 "**Gotchas**": null
1126 }
1127 const examples: Array<ParsedExample> = []
1128 const exampleTitles = new Set<string>()
1129 let index = 0
1130 let currentSectionOrder = -1
1131 let examplesStarted = false
1132
1133 while (index < lines.length && lines[index].trim() !== "" && !isHeadingLine(lines[index])) {
1134 if (isForbiddenMarkdownHeading(lines[index], false)) {
1135 diagnostics.push(diagnostic("invalid-heading", "Markdown headings are not allowed in JSDoc descriptions"))
1136 }
1137 index++
1138 }
1139
1140 const shortLines = lines.slice(0, index)
1141 if (shortLines.length === 0 || joinBody(shortLines).trim() === "") {
1142 diagnostics.push(diagnostic("missing-description", "JSDoc must include a short description"))
1143 }
1144 if (index < lines.length && lines[index].trim() === "") {
1145 const next = lines[index + 1]
1146 if (next !== undefined && !isHeadingLine(next)) {
1147 diagnostics.push(diagnostic("multiple-description-paragraphs", "JSDoc short description must be one paragraph"))
1148 }
1149 }
1150
1151 while (index < lines.length) {
1152 if (lines[index].trim() !== "") {
1153 diagnostics.push(diagnostic("invalid-spacing", "JSDoc sections must be separated by exactly one blank line"))
1154 break
1155 }
1156 if (lines[index + 1]?.trim() === "") {
1157 diagnostics.push(diagnostic("invalid-spacing", "JSDoc sections must be separated by exactly one blank line"))
1158 while (lines[index + 1]?.trim() === "") index++
1159 }
1160 index++
1161 if (index >= lines.length) {
1162 break
1163 }
1164
1165 const line = lines[index].trim()
1166 if (line.startsWith("**Example**")) {
1167 examplesStarted = true
1168 const parsed = parseExample(lines, index)
1169 diagnostics.push(...parsed.diagnostics)
1170 if (parsed.example !== undefined) {
1171 const key = parsed.example.title.trim().toLowerCase()
1172 if (exampleTitles.has(key)) {
1173 diagnostics.push(diagnostic("duplicate-example", `Duplicate example title: ${parsed.example.title.trim()}`))
1174 }
1175 exampleTitles.add(key)
1176 examples.push(parsed.example)
1177 }

Callers 1

parseCoreJSDocFunction · 0.85

Calls 15

isHeadingLineFunction · 0.85
diagnosticFunction · 0.85
joinBodyFunction · 0.85
parseExampleFunction · 0.85
parseSectionFunction · 0.85
isNearMissHeadingFunction · 0.85
isBoldOnlyLineFunction · 0.85
hasWhenToUsePrefixFunction · 0.85
trimMethod · 0.80
sliceMethod · 0.80
pushMethod · 0.65

Tested by

no test coverage detected