(lines: Array<string>, headingIndex: number)
| 1253 | } |
| 1254 | |
| 1255 | function 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 | |
| 1301 | const isTypeScriptFence = (line: string): boolean => /^```ts(?:\s.*)?$/.test(line) |
| 1302 |
no test coverage detected