/** * Shared helpers for the `@dbx` companion-tag ESLint rules. Mirrors the * scanner schemas in `packages/dbx-cli/src/lib/mcp-scan/scan/*-extract.ts` so * violations surface at lint time instead of at manifest-regeneration time. * * Each per-family rule supplies a {@link DbxTagFamilySpec} describing which * companions are required/optional, what value format each accepts, and which * messageId to emit when a check fails. The rule body itself only wires the * visitors and message map; all value-format validation lives here. */ import type { Maybe } from '@dereekb/util'; import { type ParsedJsdoc, type ParsedJsdocTag } from './jsdoc-parser'; interface AstNode { readonly type: string; [key: string]: any; } /** * Kebab-case slug pattern: lowercase letters/digits, words separated by single hyphens, * starts with a letter. Used to validate slug/related/skill-ref values. */ export declare const KEBAB_SLUG_PATTERN: RegExp; /** * Pascal-case TypeScript identifier pattern (starts uppercase). Used for model * identifiers and other `` style tag values. */ export declare const PASCAL_IDENTIFIER_PATTERN: RegExp; /** * Discriminated description of how a companion tag's value should be parsed * and validated. The shared checker dispatches on `kind`. */ export type DbxTagFormat = { readonly kind: 'marker'; } | { readonly kind: 'kebab-slug'; } | { readonly kind: 'enum'; readonly values: readonly string[]; } | { readonly kind: 'pascal-identifier'; } | { readonly kind: 'comma-list-kebab-slug'; } | { readonly kind: 'comma-list-lowercase'; } | { readonly kind: 'comma-list-free-text'; } | { readonly kind: 'free-text'; } | { readonly kind: 'boolean'; }; /** * One companion-tag spec entry. `suffix` is appended to the family marker name * to form the full tag (e.g. `dbxPipe` + `Slug` → `@dbxPipeSlug`). */ export interface DbxCompanionTagSpec { readonly suffix: string; readonly required?: boolean; readonly multiple?: boolean; readonly format: DbxTagFormat; } /** * The full set of companions plus the marker that triggers a family rule. */ export interface DbxTagFamilySpec { readonly marker: string; readonly companions: readonly DbxCompanionTagSpec[]; } /** * One violation emitted by {@link checkDbxTagFamily}. Each rule's `meta.messages` * map provides the message text for each `kind`. */ export type DbxTagViolation = { readonly kind: 'missing'; readonly suffix: string; readonly lineIndex: number; } | { readonly kind: 'empty'; readonly suffix: string; readonly lineIndex: number; } | { readonly kind: 'invalid-kebab'; readonly suffix: string; readonly value: string; readonly lineIndex: number; } | { readonly kind: 'invalid-enum'; readonly suffix: string; readonly value: string; readonly allowed: readonly string[]; readonly lineIndex: number; } | { readonly kind: 'invalid-pascal'; readonly suffix: string; readonly value: string; readonly lineIndex: number; } | { readonly kind: 'invalid-boolean'; readonly suffix: string; readonly value: string; readonly lineIndex: number; } | { readonly kind: 'comma-item-not-kebab'; readonly suffix: string; readonly value: string; readonly lineIndex: number; } | { readonly kind: 'tags-not-lowercase'; readonly suffix: string; readonly value: string; readonly lineIndex: number; readonly raw: ParsedJsdocTag; } | { readonly kind: 'unknown'; readonly suffix: string; readonly lineIndex: number; } | { readonly kind: 'duplicate'; readonly suffix: string; readonly lineIndex: number; }; /** * Splits a comma-separated tag-value string into trimmed items, preserving order. * * @param value - Raw text following the tag name on a single line. * @returns Non-empty trimmed segments in declaration order. */ export declare function splitCommaSeparated(value: string): string[]; /** * Parses a boolean tag value using the workspace vocabulary * (`''`/`true`/`yes` → true; `false`/`no` → false). Other inputs return `undefined`. * * @param text - The trimmed tag value text. * @returns The parsed boolean, or `undefined` when the text is not in the vocabulary. */ export declare function parseBooleanTagValue(text: string): Maybe; /** * Returns the source-text offset of an offset-within-comment-value, given a Block comment node. * * @param commentNode - The ESLint Block comment AST node. * @param valueOffset - The character offset within `comment.value`. * @returns The character offset in the source file. */ export declare function commentValueToSourceOffset(commentNode: AstNode, valueOffset: number): number; /** * Returns the family marker + companion tag list for the given parsed JSDoc. * Family membership is determined by tag-name prefix. * * @param parsed - The parsed JSDoc. * @param marker - The bare family marker (e.g. `'dbxPipe'`). * @returns The marker tag (if present), and all companion tags in source order. */ export declare function findFamilyTags(parsed: ParsedJsdoc, marker: string): { readonly markerTag: Maybe; readonly familyTags: readonly ParsedJsdocTag[]; }; /** * Groups companion tags (those after the marker) by suffix. Marker entries are excluded. * * @param familyTags - The family tag list from {@link findFamilyTags}. * @param marker - The bare family marker. * @returns Lookup keyed by companion-suffix listing matching tags in declaration order. */ export declare function groupCompanionsBySuffix(familyTags: readonly ParsedJsdocTag[], marker: string): Map; /** * Runs the canonical companion-tag validation pass for a `@dbx`-tagged * JSDoc against the supplied {@link DbxTagFamilySpec}. Emits one * {@link DbxTagViolation} per finding via `emit`; the calling rule maps each * violation to its own messageId. * * Validation pass order: * * 1. Unknown companions (typo detection — companions not in the spec). * 2. Required companions present (one violation per missing required tag). * 3. Duplicates (companion appears more than once, when `multiple` is not set). * 4. Per-companion value-format validation. * * Marker presence is the caller's responsibility — pass `markerPresent=true` * (i.e. `requireBareMarker` already satisfied) before invoking this. */ export interface CheckDbxTagFamilyInput { readonly parsed: ParsedJsdoc; readonly spec: DbxTagFamilySpec; readonly markerTag: ParsedJsdocTag; readonly familyTags: readonly ParsedJsdocTag[]; readonly emit: (violation: DbxTagViolation) => void; } /** * Validates a `@dbx` marker plus its companion tags against the supplied spec. * Reports unknown companions, missing required companions, duplicates, and per-companion * value violations through `input.emit`. * * @param input - Parsed JSDoc, family spec, resolved marker/companion tags, and emit sink. * * @example * ```ts * checkDbxTagFamily({ parsed, spec, markerTag, familyTags, emit }); * ``` */ export declare function checkDbxTagFamily(input: CheckDbxTagFamilyInput): void; /** * Wraps `context.report` with the family rule's common "report on a tag line" * helper. The shared rule body uses this to translate {@link DbxTagViolation} * locations into ESLint source ranges. */ export interface ReportOnLineInput { readonly commentNode: AstNode; readonly parsed: ParsedJsdoc; readonly sourceCode: AstNode; readonly lineIndex: number; readonly messageId: string; readonly data?: Record | undefined; readonly report: (descriptor: { loc: AstNode; messageId: string; data?: Record; fix?: (fixer: AstNode) => Maybe; }) => void; readonly fix?: ((fixer: AstNode) => Maybe) | undefined; } /** * Translates a JSDoc-line violation into an ESLint `context.report()` call by computing the * source range of the offending line and attaching the supplied message + optional fixer. * * @param input - Reporting context (comment node, parsed JSDoc, source code, line index, message id, optional data + fixer, report sink). * * @example * ```ts * reportOnJsdocLine({ commentNode, parsed, sourceCode, lineIndex: tag.startLineIndex, messageId: 'unknown', report: context.report }); * ``` */ export declare function reportOnJsdocLine(input: ReportOnLineInput): void; /** * The visitor scopes used by `@dbx` companion-tag rules. Each rule * supplies a subset and the shared visitor wires them with the canonical * `getStatementAnchor` / `leadingJsdocFor` logic. */ export type DbxFamilyVisitorKind = 'FunctionDeclaration' | 'VariableDeclaration' | 'ClassDeclaration' | 'TSInterfaceDeclaration' | 'TSTypeAliasDeclaration' | 'TSEnumDeclaration' | 'TSPropertySignature' | 'PropertyDefinition' | 'TSEnumMember'; /** * Callback that maps a {@link DbxTagViolation} to its rule-specific * messageId + data, or `null` when the violation should be silently dropped * (e.g. when the rule does not require the missing companion). */ export type DbxFamilyViolationMapper = (violation: DbxTagViolation) => Maybe<{ readonly messageId: string; readonly data?: Record; readonly fixable?: boolean; }>; /** * Produces an auto-fix for a `@dbxTags ...` line that lowercases every * token after the tag name. Returns the replacement source range + text, or * `undefined` when the line is already canonical. * * @param input - The fix context (comment node, parsed JSDoc, source code, tag). * @returns The replacement range/text, or `undefined` when no fix is needed. */ export interface BuildLowercaseTagsFixInput { readonly commentNode: AstNode; readonly parsed: ParsedJsdoc; readonly sourceCode: AstNode; readonly tag: ParsedJsdocTag; } export interface LowercaseTagsFixResult { readonly startOffset: number; readonly endOffset: number; readonly replacement: string; } /** * Computes an auto-fix descriptor that lowercases every token after a `@dbxTags` tag * name. Returns `undefined` when the line is already canonical so the caller can short-circuit. * * @param input - Fix context (comment node, parsed JSDoc, source code, target tag). * @returns Replacement range + text when a rewrite is needed; otherwise `undefined`. * * @example * ```ts * const fix = buildLowercaseTagsFix({ commentNode, parsed, sourceCode, tag }); * ``` */ export declare function buildLowercaseTagsFix(input: BuildLowercaseTagsFixInput): Maybe; export {};