@orkestrel/guide 0.0.21 → 0.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -102,12 +102,14 @@ export declare function buildTable(table: TableNode, row: number, column: number
102
102
  * optional heritage clause between the identifier and the opening `{`; the identifier is the head's
103
103
  * own run up to that list or clause, so it enters the key as literal text and no name reaches a
104
104
  * `RegExp`. Body lines are the raw source between the head and the first projected column-zero `}`,
105
- * keeping JSDoc evidence intact. Every balanced `<...>` span is removed from the head before its
105
+ * keeping JSDoc evidence intact; a head whose last line closes its own body with `{}` or `{ }`
106
+ * records an empty body. Every balanced `<...>` span is removed from the head before its
106
107
  * `extends` clause is read, so a `T extends Base` type parameter is never a base and `Base<T>`
107
108
  * reads as `Base`; a class's `implements` clause and everything after it is excluded, and a
108
109
  * qualified base such as `namespace.Base` is returned verbatim. The first head of a key that opens
109
110
  * a column-zero close answers for that key: a head that opens none records nothing, and a later
110
- * head of a key already collected adds nothing.
111
+ * head of a key already collected adds nothing unless the earlier head recorded neither a body
112
+ * nor bases, which declares nothing as {@link Source} reads it, so the later head replaces it.
111
113
  *
112
114
  * @param source - The file's source text to read
113
115
  * @returns One entry per collected declaration, keyed `${keyword} ${name}`
@@ -490,7 +492,7 @@ export declare function createSurfaceSymbolContract(): ContractInterface<Surface
490
492
  * {@link collectDeclarations}).
491
493
  */
492
494
  export declare interface Declaration {
493
- /** Holds the declaration's raw body lines, between the head and the column-zero closing `}`. */
495
+ /** Holds the declaration's raw body lines, between the head and the column-zero closing `}`; empty when the head's last line closes its own body. */
494
496
  readonly body: readonly string[];
495
497
  /** Lists the base identifiers its head extends, in head order. */
496
498
  readonly bases: readonly string[];
@@ -504,7 +506,7 @@ export declare interface Declaration {
504
506
  export declare interface DeclarationHead {
505
507
  /** Holds the joined, space-separated head text. */
506
508
  readonly text: string;
507
- /** Holds the index (within the source `lines`) of the line ending in `{`. */
509
+ /** Holds the index (within the source `lines`) of the line that carries the opening `{`. */
508
510
  readonly end: number;
509
511
  }
510
512
 
@@ -1389,6 +1391,22 @@ export declare interface GuideInterface {
1389
1391
  */
1390
1392
  export declare type GuideModule = string | readonly string[];
1391
1393
 
1394
+ /**
1395
+ * Checks whether a source declares at least one behavioural member — a `class` or `interface`
1396
+ * in its surface that carries a call-signature member — so a guide owes a `## Methods` group only
1397
+ * where the source has one to document.
1398
+ *
1399
+ * @param source - The reflected source under parity
1400
+ * @returns True if a surface `class` or `interface` declares a member; false otherwise
1401
+ *
1402
+ * @example
1403
+ * ```ts
1404
+ * hasBehaviouralSurface(createSource({ files: { 'src/types.ts': 'export interface Widget { render(): void }' }, module: 'src' })) // true
1405
+ * hasBehaviouralSurface(createSource({ files: { 'src/constants.ts': 'export const NAMES = Object.freeze({})' }, module: 'src' })) // false
1406
+ * ```
1407
+ */
1408
+ export declare function hasBehaviouralSurface(source: SourceInterface): boolean;
1409
+
1392
1410
  /**
1393
1411
  * Checks whether an opaque inventory key contains only canonical slash-separated
1394
1412
  * segments. Empty, `.` and `..` segments are rejected without rewriting the
@@ -1549,7 +1567,14 @@ export declare const isSurfaceSymbol: Guard<SurfaceSymbol>;
1549
1567
 
1550
1568
  /**
1551
1569
  * Joins the declaration head starting at `start` into one space-separated
1552
- * line, consuming lines until the first that ends with `{`.
1570
+ * line, consuming lines until the first that opens a body: one that ends with
1571
+ * `{`, or one that closes an empty body with `{}` or `{ }`.
1572
+ *
1573
+ * @remarks
1574
+ * A line ending with `{}` closes an empty body only when every angle, round,
1575
+ * and square bracket the head opened outside quoted text has closed; inside
1576
+ * one, `{}` is a type or an argument, and an arrow's `=>` closes nothing. A
1577
+ * head that reaches the next column-zero `export` line opens no body.
1553
1578
  *
1554
1579
  * @param lines - The file's source lines
1555
1580
  * @param start - The index of the head's first line
@@ -1558,6 +1583,7 @@ export declare const isSurfaceSymbol: Guard<SurfaceSymbol>;
1558
1583
  * @example
1559
1584
  * ```ts
1560
1585
  * joinHead(['export class X {'], 0) // { text: 'export class X {', end: 0 }
1586
+ * joinHead(['export interface Y extends X {}'], 0) // { text: 'export interface Y extends X {}', end: 0 }
1561
1587
  * ```
1562
1588
  */
1563
1589
  export declare function joinHead(lines: readonly string[], start: number): DeclarationHead | undefined;
@@ -102,12 +102,14 @@ export declare function buildTable(table: TableNode, row: number, column: number
102
102
  * optional heritage clause between the identifier and the opening `{`; the identifier is the head's
103
103
  * own run up to that list or clause, so it enters the key as literal text and no name reaches a
104
104
  * `RegExp`. Body lines are the raw source between the head and the first projected column-zero `}`,
105
- * keeping JSDoc evidence intact. Every balanced `<...>` span is removed from the head before its
105
+ * keeping JSDoc evidence intact; a head whose last line closes its own body with `{}` or `{ }`
106
+ * records an empty body. Every balanced `<...>` span is removed from the head before its
106
107
  * `extends` clause is read, so a `T extends Base` type parameter is never a base and `Base<T>`
107
108
  * reads as `Base`; a class's `implements` clause and everything after it is excluded, and a
108
109
  * qualified base such as `namespace.Base` is returned verbatim. The first head of a key that opens
109
110
  * a column-zero close answers for that key: a head that opens none records nothing, and a later
110
- * head of a key already collected adds nothing.
111
+ * head of a key already collected adds nothing unless the earlier head recorded neither a body
112
+ * nor bases, which declares nothing as {@link Source} reads it, so the later head replaces it.
111
113
  *
112
114
  * @param source - The file's source text to read
113
115
  * @returns One entry per collected declaration, keyed `${keyword} ${name}`
@@ -490,7 +492,7 @@ export declare function createSurfaceSymbolContract(): ContractInterface<Surface
490
492
  * {@link collectDeclarations}).
491
493
  */
492
494
  export declare interface Declaration {
493
- /** Holds the declaration's raw body lines, between the head and the column-zero closing `}`. */
495
+ /** Holds the declaration's raw body lines, between the head and the column-zero closing `}`; empty when the head's last line closes its own body. */
494
496
  readonly body: readonly string[];
495
497
  /** Lists the base identifiers its head extends, in head order. */
496
498
  readonly bases: readonly string[];
@@ -504,7 +506,7 @@ export declare interface Declaration {
504
506
  export declare interface DeclarationHead {
505
507
  /** Holds the joined, space-separated head text. */
506
508
  readonly text: string;
507
- /** Holds the index (within the source `lines`) of the line ending in `{`. */
509
+ /** Holds the index (within the source `lines`) of the line that carries the opening `{`. */
508
510
  readonly end: number;
509
511
  }
510
512
 
@@ -1389,6 +1391,22 @@ export declare interface GuideInterface {
1389
1391
  */
1390
1392
  export declare type GuideModule = string | readonly string[];
1391
1393
 
1394
+ /**
1395
+ * Checks whether a source declares at least one behavioural member — a `class` or `interface`
1396
+ * in its surface that carries a call-signature member — so a guide owes a `## Methods` group only
1397
+ * where the source has one to document.
1398
+ *
1399
+ * @param source - The reflected source under parity
1400
+ * @returns True if a surface `class` or `interface` declares a member; false otherwise
1401
+ *
1402
+ * @example
1403
+ * ```ts
1404
+ * hasBehaviouralSurface(createSource({ files: { 'src/types.ts': 'export interface Widget { render(): void }' }, module: 'src' })) // true
1405
+ * hasBehaviouralSurface(createSource({ files: { 'src/constants.ts': 'export const NAMES = Object.freeze({})' }, module: 'src' })) // false
1406
+ * ```
1407
+ */
1408
+ export declare function hasBehaviouralSurface(source: SourceInterface): boolean;
1409
+
1392
1410
  /**
1393
1411
  * Checks whether an opaque inventory key contains only canonical slash-separated
1394
1412
  * segments. Empty, `.` and `..` segments are rejected without rewriting the
@@ -1549,7 +1567,14 @@ export declare const isSurfaceSymbol: Guard<SurfaceSymbol>;
1549
1567
 
1550
1568
  /**
1551
1569
  * Joins the declaration head starting at `start` into one space-separated
1552
- * line, consuming lines until the first that ends with `{`.
1570
+ * line, consuming lines until the first that opens a body: one that ends with
1571
+ * `{`, or one that closes an empty body with `{}` or `{ }`.
1572
+ *
1573
+ * @remarks
1574
+ * A line ending with `{}` closes an empty body only when every angle, round,
1575
+ * and square bracket the head opened outside quoted text has closed; inside
1576
+ * one, `{}` is a type or an argument, and an arrow's `=>` closes nothing. A
1577
+ * head that reaches the next column-zero `export` line opens no body.
1553
1578
  *
1554
1579
  * @param lines - The file's source lines
1555
1580
  * @param start - The index of the head's first line
@@ -1558,6 +1583,7 @@ export declare const isSurfaceSymbol: Guard<SurfaceSymbol>;
1558
1583
  * @example
1559
1584
  * ```ts
1560
1585
  * joinHead(['export class X {'], 0) // { text: 'export class X {', end: 0 }
1586
+ * joinHead(['export interface Y extends X {}'], 0) // { text: 'export interface Y extends X {}', end: 0 }
1561
1587
  * ```
1562
1588
  */
1563
1589
  export declare function joinHead(lines: readonly string[], start: number): DeclarationHead | undefined;
@@ -851,6 +851,23 @@ function findMissingSymbols(symbols, source) {
851
851
  return findMissing(symbols.map(computeSymbolKey), source.map(computeSymbolKey));
852
852
  }
853
853
  /**
854
+ * Checks whether a source declares at least one behavioural member — a `class` or `interface`
855
+ * in its surface that carries a call-signature member — so a guide owes a `## Methods` group only
856
+ * where the source has one to document.
857
+ *
858
+ * @param source - The reflected source under parity
859
+ * @returns True if a surface `class` or `interface` declares a member; false otherwise
860
+ *
861
+ * @example
862
+ * ```ts
863
+ * hasBehaviouralSurface(createSource({ files: { 'src/types.ts': 'export interface Widget { render(): void }' }, module: 'src' })) // true
864
+ * hasBehaviouralSurface(createSource({ files: { 'src/constants.ts': 'export const NAMES = Object.freeze({})' }, module: 'src' })) // false
865
+ * ```
866
+ */
867
+ function hasBehaviouralSurface(source) {
868
+ return source.surface().some((symbol) => (symbol.keyword === "class" || symbol.keyword === "interface") && source.methods(symbol.name).length > 0);
869
+ }
870
+ /**
854
871
  * Finds the names in `names` that have no example — a fence containing the name at a
855
872
  * word boundary in `fences`, or a membership in `examples`, both count as
856
873
  * "has an example"; presence-only, fence and JSDoc content are never checked.
@@ -1228,7 +1245,14 @@ function extractHidden(source) {
1228
1245
  }
1229
1246
  /**
1230
1247
  * Joins the declaration head starting at `start` into one space-separated
1231
- * line, consuming lines until the first that ends with `{`.
1248
+ * line, consuming lines until the first that opens a body: one that ends with
1249
+ * `{`, or one that closes an empty body with `{}` or `{ }`.
1250
+ *
1251
+ * @remarks
1252
+ * A line ending with `{}` closes an empty body only when every angle, round,
1253
+ * and square bracket the head opened outside quoted text has closed; inside
1254
+ * one, `{}` is a type or an argument, and an arrow's `=>` closes nothing. A
1255
+ * head that reaches the next column-zero `export` line opens no body.
1232
1256
  *
1233
1257
  * @param lines - The file's source lines
1234
1258
  * @param start - The index of the head's first line
@@ -1237,6 +1261,7 @@ function extractHidden(source) {
1237
1261
  * @example
1238
1262
  * ```ts
1239
1263
  * joinHead(['export class X {'], 0) // { text: 'export class X {', end: 0 }
1264
+ * joinHead(['export interface Y extends X {}'], 0) // { text: 'export interface Y extends X {}', end: 0 }
1240
1265
  * ```
1241
1266
  */
1242
1267
  function joinHead(lines, start) {
@@ -1244,8 +1269,15 @@ function joinHead(lines, start) {
1244
1269
  for (let index = start; index < lines.length; index += 1) {
1245
1270
  const line = lines[index];
1246
1271
  if (line === void 0) break;
1247
- parts.push(index === start ? line.trimEnd() : line.trim());
1248
- if (line.trimEnd().endsWith("{")) return {
1272
+ const text = line.trimEnd();
1273
+ if (index > start && text.startsWith("export ")) return void 0;
1274
+ parts.push(index === start ? text : text.trimStart());
1275
+ if (text.endsWith("{")) return {
1276
+ text: parts.join(" "),
1277
+ end: index
1278
+ };
1279
+ const bare = parts.join(" ").replace(/'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"/g, "");
1280
+ if ((bare.match(/</g)?.length ?? 0) <= (bare.match(/(?<!=)>/g)?.length ?? 0) && (bare.match(/\(/g)?.length ?? 0) <= (bare.match(/\)/g)?.length ?? 0) && (bare.match(/\[/g)?.length ?? 0) <= (bare.match(/\]/g)?.length ?? 0) && /\{\s*\}$/.test(text)) return {
1249
1281
  text: parts.join(" "),
1250
1282
  end: index
1251
1283
  };
@@ -1286,12 +1318,14 @@ function escapeRegExp(value) {
1286
1318
  * optional heritage clause between the identifier and the opening `{`; the identifier is the head's
1287
1319
  * own run up to that list or clause, so it enters the key as literal text and no name reaches a
1288
1320
  * `RegExp`. Body lines are the raw source between the head and the first projected column-zero `}`,
1289
- * keeping JSDoc evidence intact. Every balanced `<...>` span is removed from the head before its
1321
+ * keeping JSDoc evidence intact; a head whose last line closes its own body with `{}` or `{ }`
1322
+ * records an empty body. Every balanced `<...>` span is removed from the head before its
1290
1323
  * `extends` clause is read, so a `T extends Base` type parameter is never a base and `Base<T>`
1291
1324
  * reads as `Base`; a class's `implements` clause and everything after it is excluded, and a
1292
1325
  * qualified base such as `namespace.Base` is returned verbatim. The first head of a key that opens
1293
1326
  * a column-zero close answers for that key: a head that opens none records nothing, and a later
1294
- * head of a key already collected adds nothing.
1327
+ * head of a key already collected adds nothing unless the earlier head recorded neither a body
1328
+ * nor bases, which declares nothing as {@link Source} reads it, so the later head replaces it.
1295
1329
  *
1296
1330
  * @param source - The file's source text to read
1297
1331
  * @returns One entry per collected declaration, keyed `${keyword} ${name}`
@@ -1305,7 +1339,7 @@ function escapeRegExp(value) {
1305
1339
  function collectDeclarations(source) {
1306
1340
  const declarations = /* @__PURE__ */ new Map();
1307
1341
  const opener = /^export (?:class|interface) /;
1308
- const grammar = /^export (class|interface) ([^\s<]+)(?:<.*>)?(?: .*)? \{$/;
1342
+ const grammar = /^export (class|interface) ([^\s<]+)(?:<.*>)?(?: .*)? \{(?:\s*\})?$/;
1309
1343
  const lines = extractSourceLines(source);
1310
1344
  const projected = lines.map((line) => line.code);
1311
1345
  for (let index = 0; index < projected.length; index += 1) {
@@ -1318,14 +1352,22 @@ function collectDeclarations(source) {
1318
1352
  const name = declared?.[2];
1319
1353
  if (keyword === void 0 || name === void 0) continue;
1320
1354
  const key = `${keyword} ${name}`;
1321
- if (declarations.has(key)) continue;
1355
+ const known = declarations.get(key);
1356
+ if (known !== void 0 && (known.body.length > 0 || known.bases.length > 0)) continue;
1322
1357
  let depth = 0;
1323
1358
  let flat = "";
1324
- for (const character of head.text.slice(`export ${key}`.length, -1)) if (character === "<") depth += 1;
1359
+ for (const character of head.text.slice(`export ${key}`.length, head.text.lastIndexOf("{"))) if (character === "<") depth += 1;
1325
1360
  else if (character === ">") depth = Math.max(0, depth - 1);
1326
1361
  else if (depth === 0) flat += character;
1327
1362
  const clause = flat.replace(/\bimplements\b[\s\S]*$/, "").match(/\bextends\b([\s\S]*)$/)?.[1];
1328
1363
  const bases = clause === void 0 ? [] : clause.split(",").map((base) => base.trim()).filter(isNonEmptyString);
1364
+ if (head.text.endsWith("}")) {
1365
+ declarations.set(key, {
1366
+ body: [],
1367
+ bases
1368
+ });
1369
+ continue;
1370
+ }
1329
1371
  for (let close = head.end + 1; close < projected.length; close += 1) {
1330
1372
  if (projected[close] !== "}") continue;
1331
1373
  declarations.set(key, {
@@ -3615,7 +3657,7 @@ var Parity = class Parity {
3615
3657
  text: `${row.entry.spec} has no ## ${heading} section.`
3616
3658
  });
3617
3659
  }
3618
- if (row.guide.methods().length === 0) findings.push({
3660
+ if (row.guide.methods().length === 0 && hasBehaviouralSurface(row.source)) findings.push({
3619
3661
  spec: row.entry.spec,
3620
3662
  text: `${row.entry.spec} has no documented method groups.`
3621
3663
  });
@@ -4087,6 +4129,6 @@ function createManifestEntryContract() {
4087
4129
  return createContract(manifestEntryShape);
4088
4130
  }
4089
4131
  //#endregion
4090
- export { DRIFT_CATEGORIES, EXPORT_KEYWORDS, EXTERNAL_SCHEMES, Guide, KIND, MANIFEST, METHODS, Parity, SUMMARY, SURFACE, Source, SourceManager, TESTS, WRAP_WIDTH, buildCell, buildComment, buildFence, buildTable, collectDeclarations, collectExamples, collectFences, collectGroups, collectKeys, collectSummaries, collectTitles, compareMembership, computeDrift, computeModuleKey, computeSymbolKey, createDriftContract, createGuide, createManifestEntryContract, createMethodEntryContract, createMethodGroupContract, createSource, createSourceExampleContract, createSourceManager, createSurfaceSymbolContract, driftShape, escapeRegExp, extractBodyLines, extractCellLinks, extractCellText, extractDeclaration, extractExampleLines, extractExampleMethods, extractExamples, extractExports, extractFenceImports, extractFences, extractHidden, extractLinks, extractMemberMethods, extractMethods, extractRowEntry, extractRowSummary, extractRowSymbol, extractSourceComments, extractSourceLines, extractSurface, extractTagline, extractTests, extractUnnamed, findColumnIndex, findDrift, findFirstCode, findMissing, findMissingSymbols, findUnexampled, findUnlisted, formatDrift, formatSide, hasCanonicalSegments, identifyDrift, isDrift, isDriftCategory, isExportKeyword, isExternalLink, isManifestEntry, isMethodEntry, isMethodGroup, isSourceExample, isSurfaceSymbol, joinHead, locateComment, manifestEntryShape, maskFences, methodEntryShape, methodGroupShape, normalizeComment, normalizeDirectories, normalizeIdentifier, normalizeSummary, parseManifest, renderExample, renderMethods, renderSurface, replaceCell, replaceExample, replaceFence, replaceSummary, resolveLink, resolvePath, selectModuleKeys, selectSectionBlocks, sourceExampleShape, spliceSpan, surfaceSymbolShape, unwrapComment, wrapText };
4132
+ export { DRIFT_CATEGORIES, EXPORT_KEYWORDS, EXTERNAL_SCHEMES, Guide, KIND, MANIFEST, METHODS, Parity, SUMMARY, SURFACE, Source, SourceManager, TESTS, WRAP_WIDTH, buildCell, buildComment, buildFence, buildTable, collectDeclarations, collectExamples, collectFences, collectGroups, collectKeys, collectSummaries, collectTitles, compareMembership, computeDrift, computeModuleKey, computeSymbolKey, createDriftContract, createGuide, createManifestEntryContract, createMethodEntryContract, createMethodGroupContract, createSource, createSourceExampleContract, createSourceManager, createSurfaceSymbolContract, driftShape, escapeRegExp, extractBodyLines, extractCellLinks, extractCellText, extractDeclaration, extractExampleLines, extractExampleMethods, extractExamples, extractExports, extractFenceImports, extractFences, extractHidden, extractLinks, extractMemberMethods, extractMethods, extractRowEntry, extractRowSummary, extractRowSymbol, extractSourceComments, extractSourceLines, extractSurface, extractTagline, extractTests, extractUnnamed, findColumnIndex, findDrift, findFirstCode, findMissing, findMissingSymbols, findUnexampled, findUnlisted, formatDrift, formatSide, hasBehaviouralSurface, hasCanonicalSegments, identifyDrift, isDrift, isDriftCategory, isExportKeyword, isExternalLink, isManifestEntry, isMethodEntry, isMethodGroup, isSourceExample, isSurfaceSymbol, joinHead, locateComment, manifestEntryShape, maskFences, methodEntryShape, methodGroupShape, normalizeComment, normalizeDirectories, normalizeIdentifier, normalizeSummary, parseManifest, renderExample, renderMethods, renderSurface, replaceCell, replaceExample, replaceFence, replaceSummary, resolveLink, resolvePath, selectModuleKeys, selectSectionBlocks, sourceExampleShape, spliceSpan, surfaceSymbolShape, unwrapComment, wrapText };
4091
4133
 
4092
4134
  //# sourceMappingURL=index.js.map