import type { Maybe } from '@dereekb/util'; /** * Minimal JSDoc parser used by the workspace's custom ESLint rules. * * Operates on the raw `value` of an ESLint Block comment (the text between `/*` and `*\/`, * which includes the leading `*` of a JSDoc opener). Returns a structured view of the comment: * description, paragraphs, tags (with their continuation lines), and per-line metadata. */ /** * Per-line view of a comment body. */ export interface ParsedJsdocLine { /** * Raw line content with leading whitespace + `*` prefix preserved. */ readonly raw: string; /** * Text content after the leading whitespace + `*` + optional space prefix has been stripped. */ readonly text: string; /** * True when the line is blank after stripping (only `* ` with nothing else). */ readonly blank: boolean; /** * Index in the original `splitLines` array. */ readonly index: number; /** * Character offset of `raw[0]` relative to the start of `commentValue` (not the source file). */ readonly valueOffsetStart: number; /** * Character offset of `text[0]` relative to the start of `commentValue`. Equals `valueOffsetStart` plus the length of the stripped prefix. */ readonly textOffsetStart: number; } /** * Parsed view of a single `@tag` block, including any continuation lines that follow it * up to the next tag (or end of comment). */ export interface ParsedJsdocTag { /** * Tag name without the leading `@`, e.g. `param`, `returns`, `throws`, `dbxUtil`, `__NO_SIDE_EFFECTS__`. */ readonly tag: string; /** * For `@param`: the parameter name. For other tags: `undefined`. */ readonly name: Maybe; /** * For `@throws` / `@param` style: the `{Type}` annotation if present. */ readonly type: Maybe; /** * Remaining text on the tag line + continuation lines, joined with `\n`. Trimmed of trailing whitespace. */ readonly description: string; /** * All lines belonging to this tag (the tag line itself and any continuation lines). */ readonly lines: readonly ParsedJsdocLine[]; /** * Index in the comment-lines array where the tag starts. */ readonly startLineIndex: number; /** * Index (inclusive) where the tag ends. */ readonly endLineIndex: number; } /** * Parsed view of a whole JSDoc comment. */ export interface ParsedJsdoc { /** * All lines in the comment body. */ readonly lines: readonly ParsedJsdocLine[]; /** * Lines belonging to the description (before any tag). */ readonly descriptionLines: readonly ParsedJsdocLine[]; /** * Description text joined with `\n`, with leading and trailing blank lines stripped. */ readonly description: string; /** * Description split into paragraphs by blank lines, with each paragraph joined by `\n`. */ readonly descriptionParagraphs: readonly string[]; /** * All tags in source order. */ readonly tags: readonly ParsedJsdocTag[]; /** * True when the original comment is a single-line `/** ... *\/` block (no newlines). */ readonly singleLine: boolean; } /** * Parses the value of an ESLint Block comment that represents a JSDoc into a structured form. * * @param commentValue - The `value` of an ESLint Block comment (text between `/*` and `*\/`, including the leading `*`). * @returns A structured view of the JSDoc with description, paragraphs, and tags. * * @example * ```ts * const parsed = parseJsdocComment('*\n * Hello.\n *\n * @param x - The value.\n '); * // parsed.description === 'Hello.' * // parsed.tags[0].tag === 'param' * // parsed.tags[0].name === 'x' * // parsed.tags[0].description === 'The value.' * ``` */ export declare function parseJsdocComment(commentValue: string): ParsedJsdoc;