@descent-vtt/spec-brief 0.2.6 → 0.3.0

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.
Files changed (51) hide show
  1. package/CHANGELOG.md +100 -1
  2. package/README.md +162 -29
  3. package/dist/cli.d.ts +1 -1
  4. package/dist/cli.js +61 -43
  5. package/dist/cli.js.map +1 -1
  6. package/dist/collisions.js +13 -8
  7. package/dist/collisions.js.map +1 -1
  8. package/dist/config.js +2 -1
  9. package/dist/config.js.map +1 -1
  10. package/dist/corpus.d.ts +5 -0
  11. package/dist/corpus.js +7 -0
  12. package/dist/corpus.js.map +1 -1
  13. package/dist/glob.d.ts +6 -2
  14. package/dist/glob.js +27 -5
  15. package/dist/glob.js.map +1 -1
  16. package/dist/lint.js +1 -0
  17. package/dist/lint.js.map +1 -1
  18. package/dist/report.d.ts +18 -4
  19. package/dist/report.js +98 -28
  20. package/dist/report.js.map +1 -1
  21. package/dist/rules.d.ts +2 -0
  22. package/dist/rules.js +21 -8
  23. package/dist/rules.js.map +1 -1
  24. package/dist/schedule.js +12 -10
  25. package/dist/schedule.js.map +1 -1
  26. package/dist/schema.d.ts +5 -1
  27. package/dist/schema.js +6 -2
  28. package/dist/schema.js.map +1 -1
  29. package/dist/scope.d.ts +26 -4
  30. package/dist/scope.js +64 -8
  31. package/dist/scope.js.map +1 -1
  32. package/dist/trigger.js +59 -3
  33. package/dist/trigger.js.map +1 -1
  34. package/dist/types.d.ts +9 -0
  35. package/dist/types.js.map +1 -1
  36. package/dist/vendor/spec-core/markdown/frontmatter.d.ts +11 -1
  37. package/dist/vendor/spec-core/markdown/frontmatter.js +20 -3
  38. package/dist/vendor/spec-core/markdown/frontmatter.js.map +1 -1
  39. package/dist/vendor/spec-core/pattern/glob.d.ts +88 -2
  40. package/dist/vendor/spec-core/pattern/glob.js +234 -32
  41. package/dist/vendor/spec-core/pattern/glob.js.map +1 -1
  42. package/dist/vendor/spec-core/pattern/index.d.ts +2 -2
  43. package/dist/vendor/spec-core/pattern/index.js +1 -1
  44. package/dist/vendor/spec-core/pattern/index.js.map +1 -1
  45. package/dist/vendor/spec-core/text/index.d.ts +1 -0
  46. package/dist/vendor/spec-core/text/index.js +1 -0
  47. package/dist/vendor/spec-core/text/index.js.map +1 -1
  48. package/dist/vendor/spec-core/text/width.d.ts +30 -0
  49. package/dist/vendor/spec-core/text/width.js +113 -0
  50. package/dist/vendor/spec-core/text/width.js.map +1 -0
  51. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"corpus.js","sourceRoot":"","sources":["../src/corpus.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAc,MAAM,YAAY,CAAC;AAEpD,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAiB3C,MAAM,UAAU,WAAW,CAAC,KAA4B,EAAE,MAAc;IACtE,6CAA6C;IAC7C,MAAM,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC;SACtB,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SAC1C,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACvE,OAAO;QACL,MAAM;QACN,MAAM;QACN,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC;QAC9C,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,UAAU,CAAC;KACvD,CAAC;AACJ,CAAC;AAED;;;;GA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tH,OAAO,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,CAAC;YAC1B,CAAC;YACD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBACxB,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;gBACzB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACnB,CAAC;QACH,CAAC;IACH,CAAC;IACD,kFAAkF;IAClF,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AACxB,CAAC","sourcesContent":["/**\n * Every brief of a repository at once, and the dependency graph between them.\n */\n\nimport { parseBrief, type Brief } from './brief.js';\nimport type { Config } from './config.js';\nimport { normalisePath } from './links.js';\nimport type { Phase } from './types.js';\n\nexport interface SourceFile {\n readonly path: string;\n readonly text: string;\n readonly phase: Phase;\n}\n\nexport interface Corpus {\n readonly config: Config;\n /** Sorted by path. */\n readonly briefs: readonly Brief[];\n readonly live: readonly Brief[];\n readonly archived: readonly Brief[];\n}\n\nexport function buildCorpus(files: readonly SourceFile[], config: Config): Corpus {\n // Paths are unique, so no two compare equal.\n const briefs = [...files]\n .sort((a, b) => (a.path < b.path ? -1 : 1))\n .map((file) => parseBrief(file.path, file.text, config, file.phase));\n return {\n config,\n briefs,\n live: briefs.filter((b) => b.phase === 'live'),\n archived: briefs.filter((b) => b.phase === 'archived'),\n };\n}\n\n/**\n * The form in which ids are compared. Numeric ids compare by value, so a\n * dependency written `34` - which YAML would read as a number anyway - names\n * brief `034`.\n */\nexport function idKey(id: string): string {\n return /^\\d+$/.test(id) ? String(Number(id)) : id;\n}\n\n/** Briefs an id, a file name or a path names. More than one is an ambiguity the caller reports. */\nexport function findBriefs(corpus: Corpus, reference: string): Brief[] {\n const key = idKey(reference.trim());\n const byId = corpus.briefs.filter((b) => b.id !== null && idKey(b.id) === key);\n if (byId.length > 0) return byId;\n let path: string;\n try {\n path = normalisePath(reference);\n } catch {\n return [];\n }\n return corpus.briefs.filter((b) => b.file === path || b.name === path);\n}\n\n/** The brief a dependency names, preferring a live one when an id is ambiguous. */\nexport function resolveDependency(corpus: Corpus, id: string): Brief | undefined {\n const found = findBriefs(corpus, id);\n return found.find((b) => b.phase === 'live') ?? found[0];\n}\n\n/** Briefs grouped by id, for the ids more than one file claims. */\nexport function duplicateIds(corpus: Corpus): Map<string, Brief[]> {\n const groups = new Map<string, Brief[]>();\n for (const brief of corpus.briefs) {\n if (brief.id === null) continue;\n const key = idKey(brief.id);\n groups.set(key, [...(groups.get(key) ?? []), brief]);\n }\n return new Map([...groups].filter(([, members]) => members.length > 1));\n}\n\n/** The live dependencies of a brief that are not archived yet. */\nexport function pendingDependencies(corpus: Corpus, brief: Brief): string[] {\n return brief.dependsOn.filter((dependency) => {\n const target = resolveDependency(corpus, dependency);\n return target !== undefined && target.phase === 'live';\n });\n}\n\n/**\n * A live brief whose every dependency is archived can be executed now, unless\n * it is still being written or is deferred until its trigger.\n */\nexport function isReady(corpus: Corpus, brief: Brief): boolean {\n if (brief.phase !== 'live' || brief.status === 'draft' || brief.status === 'deferred') return false;\n return brief.dependsOn.every((dependency) => resolveDependency(corpus, dependency)?.phase === 'archived');\n}\n\nfunction label(brief: Brief): string {\n return brief.id ?? brief.name;\n}\n\n/** Briefs by id, numbers by value; by path where two ids agree. */\nexport function byId(a: Brief, b: Brief): number {\n const x = label(a);\n const y = label(b);\n const numeric = /^\\d+$/.test(x) && /^\\d+$/.test(y);\n if (numeric && Number(x) !== Number(y)) return Number(x) - Number(y);\n if (x < y) return -1;\n if (x > y) return 1;\n return a.file < b.file ? -1 : a.file > b.file ? 1 : 0;\n}\n\n/** The live briefs a brief depends on, by id. Archived ones are done, and unknown ones are the dependency rule's. */\nexport function liveDependencies(corpus: Corpus, brief: Brief): Brief[] {\n const targets = brief.dependsOn\n .map((d) => resolveDependency(corpus, d))\n .filter((t): t is Brief => t !== undefined && t !== brief && t.phase === 'live');\n return [...new Set(targets)].sort(byId);\n}\n\n/** A live brief that cannot start before deferred work, and the dependency it waits through. */\nexport interface Waiting {\n readonly brief: Brief;\n /** The deferred brief it depends on, or the brief through which it waits on one; the first by id. */\n readonly waitsOn: Brief;\n}\n\n/**\n * Live briefs that wait on deferred work: each depends on a deferred brief,\n * or on a brief that waits on one. Neither can start before an event nobody\n * has scheduled, so neither runs in a wave (ADR-0011): `schedule` places them\n * nowhere and `matrix` compares them with nothing. By id.\n */\nexport function waitingOnDeferred(corpus: Corpus): Waiting[] {\n const candidates = corpus.live.filter((b) => b.status !== 'deferred');\n const dependencies = new Map(candidates.map((b) => [b, liveDependencies(corpus, b)]));\n const held = new Set<Brief>();\n const holds = (d: Brief): boolean => d.status === 'deferred' || held.has(d);\n // Each pass holds another brief or is the last, so there is at most one pass more than there are briefs.\n for (let grew = true; grew; ) {\n grew = false;\n for (const brief of candidates) {\n if (held.has(brief) || !(dependencies.get(brief) as Brief[]).some(holds)) continue;\n held.add(brief);\n grew = true;\n }\n }\n return [...held].sort(byId).map((brief) => ({ brief, waitsOn: (dependencies.get(brief) as Brief[]).find(holds) as Brief }));\n}\n\n/**\n * Dependency cycles among live briefs, each as the ids along it with the first\n * repeated at the end. Found with Tarjan's algorithm; each strongly connected\n * component is reported once, starting from its first brief by path.\n */\nexport function dependencyCycles(corpus: Corpus): Brief[][] {\n const nodes = corpus.live;\n const edges = new Map<Brief, Brief[]>();\n for (const brief of nodes) {\n // A brief that depends on itself is the dependency rule's finding; left\n // in, the edge would be the shortest way round any cycle it is part of.\n const targets = brief.dependsOn\n .map((d) => resolveDependency(corpus, d))\n .filter((t): t is Brief => t !== undefined && t !== brief && t.phase === 'live');\n edges.set(brief, targets);\n }\n\n const index = new Map<Brief, number>();\n const low = new Map<Brief, number>();\n const stack: Brief[] = [];\n const onStack = new Set<Brief>();\n const components: Brief[][] = [];\n let counter = 0;\n\n // Recursion depth is bounded by the number of live briefs.\n const connect = (v: Brief): void => {\n index.set(v, counter);\n low.set(v, counter);\n counter += 1;\n stack.push(v);\n onStack.add(v);\n for (const w of edges.get(v) ?? []) {\n if (!index.has(w)) {\n connect(w);\n low.set(v, Math.min(low.get(v) as number, low.get(w) as number));\n } else if (onStack.has(w)) {\n low.set(v, Math.min(low.get(v) as number, index.get(w) as number));\n }\n }\n if (low.get(v) === index.get(v)) {\n const component: Brief[] = [];\n for (;;) {\n const w = stack.pop() as Brief;\n onStack.delete(w);\n component.push(w);\n if (w === v) break;\n }\n if (component.length > 1) components.push(component);\n }\n };\n for (const brief of nodes) if (!index.has(brief)) connect(brief);\n\n return components.map((component) => {\n const members = new Set(component);\n const start = [...component].sort((a, b) => (a.file < b.file ? -1 : 1))[0] as Brief;\n return cyclePath(start, members, edges);\n });\n}\n\n/** A path from `start` back to itself inside one component, found breadth-first. */\nfunction cyclePath(start: Brief, members: ReadonlySet<Brief>, edges: ReadonlyMap<Brief, Brief[]>): Brief[] {\n const previous = new Map<Brief, Brief>();\n const queue: Brief[] = [start];\n for (let head = 0; head < queue.length; head += 1) {\n const node = queue[head] as Brief;\n for (const next of edges.get(node) ?? []) {\n if (!members.has(next)) continue;\n if (next === start) {\n const path: Brief[] = [start];\n for (let at: Brief | undefined = node; at !== undefined && at !== start; at = previous.get(at)) path.splice(1, 0, at);\n return [...path, start];\n }\n if (!previous.has(next)) {\n previous.set(next, node);\n queue.push(next);\n }\n }\n }\n /* v8 ignore next -- a component of two or more always leads back to its start. */\n return [start, start];\n}\n"]}
1
+ {"version":3,"file":"corpus.js","sourceRoot":"","sources":["../src/corpus.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAc,MAAM,YAAY,CAAC;AAEpD,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAiB3C,MAAM,UAAU,WAAW,CAAC,KAA4B,EAAE,MAAc;IACtE,6CAA6C;IAC7C,MAAM,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC;SACtB,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAA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nimport { parseBrief, type Brief } from './brief.js';\nimport type { Config } from './config.js';\nimport { normalisePath } from './links.js';\nimport type { Phase } from './types.js';\n\nexport interface SourceFile {\n readonly path: string;\n readonly text: string;\n readonly phase: Phase;\n}\n\nexport interface Corpus {\n readonly config: Config;\n /** Sorted by path. */\n readonly briefs: readonly Brief[];\n readonly live: readonly Brief[];\n readonly archived: readonly Brief[];\n}\n\nexport function buildCorpus(files: readonly SourceFile[], config: Config): Corpus {\n // Paths are unique, so no two compare equal.\n const briefs = [...files]\n .sort((a, b) => (a.path < b.path ? -1 : 1))\n .map((file) => parseBrief(file.path, file.text, config, file.phase));\n return {\n config,\n briefs,\n live: briefs.filter((b) => b.phase === 'live'),\n archived: briefs.filter((b) => b.phase === 'archived'),\n };\n}\n\n/**\n * The form in which ids are compared. Numeric ids compare by value, so a\n * dependency written `34` - which YAML would read as a number anyway - names\n * brief `034`.\n */\nexport function idKey(id: string): string {\n return /^\\d+$/.test(id) ? String(Number(id)) : id;\n}\n\n/** Briefs an id, a file name or a path names. More than one is an ambiguity the caller reports. */\nexport function findBriefs(corpus: Corpus, reference: string): Brief[] {\n const key = idKey(reference.trim());\n const byId = corpus.briefs.filter((b) => b.id !== null && idKey(b.id) === key);\n if (byId.length > 0) return byId;\n let path: string;\n try {\n path = normalisePath(reference);\n } catch {\n return [];\n }\n return corpus.briefs.filter((b) => b.file === path || b.name === path);\n}\n\n/** The brief a dependency names, preferring a live one when an id is ambiguous. */\nexport function resolveDependency(corpus: Corpus, id: string): Brief | undefined {\n const found = findBriefs(corpus, id);\n return found.find((b) => b.phase === 'live') ?? found[0];\n}\n\n/** Briefs grouped by id, for the ids more than one file claims. */\nexport function duplicateIds(corpus: Corpus): Map<string, Brief[]> {\n const groups = new Map<string, Brief[]>();\n for (const brief of corpus.briefs) {\n if (brief.id === null) continue;\n const key = idKey(brief.id);\n groups.set(key, [...(groups.get(key) ?? []), brief]);\n }\n return new Map([...groups].filter(([, members]) => members.length > 1));\n}\n\n/** The live dependencies of a brief that are not archived yet. */\nexport function pendingDependencies(corpus: Corpus, brief: Brief): string[] {\n return brief.dependsOn.filter((dependency) => {\n const target = resolveDependency(corpus, dependency);\n return target !== undefined && target.phase === 'live';\n });\n}\n\n/**\n * A live brief whose every dependency is archived can be executed now, unless\n * it is still being written or is deferred until its trigger.\n */\nexport function isReady(corpus: Corpus, brief: Brief): boolean {\n if (brief.phase !== 'live' || brief.status === 'draft' || brief.status === 'deferred') return false;\n return brief.dependsOn.every((dependency) => resolveDependency(corpus, dependency)?.phase === 'archived');\n}\n\nfunction label(brief: Brief): string {\n return brief.id ?? brief.name;\n}\n\n/** Briefs by id, numbers by value; by path where two ids agree. */\nexport function byId(a: Brief, b: Brief): number {\n const x = label(a);\n const y = label(b);\n const numeric = /^\\d+$/.test(x) && /^\\d+$/.test(y);\n if (numeric && Number(x) !== Number(y)) return Number(x) - Number(y);\n if (x < y) return -1;\n if (x > y) return 1;\n return a.file < b.file ? -1 : a.file > b.file ? 1 : 0;\n}\n\n/** The live briefs a brief depends on, by id. Archived ones are done, and unknown ones are the dependency rule's. */\nexport function liveDependencies(corpus: Corpus, brief: Brief): Brief[] {\n const targets = brief.dependsOn\n .map((d) => resolveDependency(corpus, d))\n .filter((t): t is Brief => t !== undefined && t !== brief && t.phase === 'live');\n return [...new Set(targets)].sort(byId);\n}\n\n/** A live brief that cannot start before deferred work, and the dependency it waits through. */\nexport interface Waiting {\n readonly brief: Brief;\n /** The deferred brief it depends on, or the brief through which it waits on one; the first by id. */\n readonly waitsOn: Brief;\n}\n\n/**\n * Live briefs that wait on deferred work: each depends on a deferred brief,\n * or on a brief that waits on one. Neither can start before an event nobody\n * has scheduled, so neither runs in a wave (ADR-0011): `schedule` places them\n * nowhere and `matrix` compares them with nothing. By id.\n */\nexport function waitingOnDeferred(corpus: Corpus): Waiting[] {\n const candidates = corpus.live.filter((b) => b.status !== 'deferred');\n const dependencies = new Map(candidates.map((b) => [b, liveDependencies(corpus, b)]));\n const held = new Set<Brief>();\n const holds = (d: Brief): boolean => d.status === 'deferred' || held.has(d);\n // Each pass holds another brief or is the last, so there is at most one pass more than there are briefs.\n for (let grew = true; grew; ) {\n grew = false;\n for (const brief of candidates) {\n if (held.has(brief) || !(dependencies.get(brief) as Brief[]).some(holds)) continue;\n held.add(brief);\n grew = true;\n }\n }\n return [...held].sort(byId).map((brief) => ({ brief, waitsOn: (dependencies.get(brief) as Brief[]).find(holds) as Brief }));\n}\n\n/**\n * Dependency cycles among live briefs, each as the ids along it with the first\n * repeated at the end. Found with Tarjan's algorithm; each strongly connected\n * component is reported once, starting from its first brief by path.\n */\nexport function dependencyCycles(corpus: Corpus): Brief[][] {\n const nodes = corpus.live;\n const edges = new Map<Brief, Brief[]>();\n for (const brief of nodes) {\n // A brief that depends on itself is the dependency rule's finding; left\n // in, the edge would be the shortest way round any cycle it is part of.\n const targets = brief.dependsOn\n .map((d) => resolveDependency(corpus, d))\n .filter((t): t is Brief => t !== undefined && t !== brief && t.phase === 'live');\n edges.set(brief, targets);\n }\n\n const index = new Map<Brief, number>();\n const low = new Map<Brief, number>();\n const stack: Brief[] = [];\n const onStack = new Set<Brief>();\n const components: Brief[][] = [];\n let counter = 0;\n\n // Recursion depth is bounded by the number of live briefs.\n const connect = (v: Brief): void => {\n index.set(v, counter);\n low.set(v, counter);\n counter += 1;\n stack.push(v);\n onStack.add(v);\n for (const w of edges.get(v) ?? []) {\n if (!index.has(w)) {\n connect(w);\n low.set(v, Math.min(low.get(v) as number, low.get(w) as number));\n } else if (onStack.has(w)) {\n low.set(v, Math.min(low.get(v) as number, index.get(w) as number));\n }\n }\n if (low.get(v) === index.get(v)) {\n const component: Brief[] = [];\n for (;;) {\n const w = stack.pop() as Brief;\n onStack.delete(w);\n component.push(w);\n if (w === v) break;\n }\n if (component.length > 1) components.push(component);\n }\n };\n for (const brief of nodes) if (!index.has(brief)) connect(brief);\n\n return components.map((component) => {\n const members = new Set(component);\n const start = [...component].sort((a, b) => (a.file < b.file ? -1 : 1))[0] as Brief;\n return cyclePath(start, members, edges);\n });\n}\n\n/**\n * A cycle as a finding's subject: the briefs on it, each once, in order. `lint`\n * and `schedule` word a cycle differently and report it as one problem.\n */\nexport function cycleSubject(cycle: readonly Brief[]): string {\n return [...new Set(cycle.map((b) => b.id ?? b.name))].sort().join(', ');\n}\n\n/** A path from `start` back to itself inside one component, found breadth-first. */\nfunction cyclePath(start: Brief, members: ReadonlySet<Brief>, edges: ReadonlyMap<Brief, Brief[]>): Brief[] {\n const previous = new Map<Brief, Brief>();\n const queue: Brief[] = [start];\n for (let head = 0; head < queue.length; head += 1) {\n const node = queue[head] as Brief;\n for (const next of edges.get(node) ?? []) {\n if (!members.has(next)) continue;\n if (next === start) {\n const path: Brief[] = [start];\n for (let at: Brief | undefined = node; at !== undefined && at !== start; at = previous.get(at)) path.splice(1, 0, at);\n return [...path, start];\n }\n if (!previous.has(next)) {\n previous.set(next, node);\n queue.push(next);\n }\n }\n }\n /* v8 ignore next -- a component of two or more always leads back to its start. */\n return [start, start];\n}\n"]}
package/dist/glob.d.ts CHANGED
@@ -8,8 +8,12 @@
8
8
  * spec-brief adds around it:
9
9
  *
10
10
  * - A pattern is relative to the repository root, so a leading `/` is refused
11
- * rather than rooted at the filesystem; and a list entry's `!` has no list to
12
- * belong to in a scope, so it is refused rather than read.
11
+ * rather than rooted at the filesystem: on the pattern, and on a text its
12
+ * braces give, since spec-core reads `{/docs,x}` as `/docs` or `x`, and
13
+ * `docs` would fall out of the scope unsaid. A leading `./` goes with the
14
+ * slashes after it, as POSIX reads them: `.//docs` is `docs`, and
15
+ * `./{/docs,x}` is `docs` or `x`. A list entry's `!` has no list to belong
16
+ * to in a scope, so it is refused rather than read.
13
17
  * - Paths compare case-sensitively on every host, as git's do.
14
18
  * - A path with no glob syntax is read as the tree reads it: a file the tree
15
19
  * holds is that file, a directory it holds is everything beneath it, and a
package/dist/glob.js CHANGED
@@ -8,8 +8,12 @@
8
8
  * spec-brief adds around it:
9
9
  *
10
10
  * - A pattern is relative to the repository root, so a leading `/` is refused
11
- * rather than rooted at the filesystem; and a list entry's `!` has no list to
12
- * belong to in a scope, so it is refused rather than read.
11
+ * rather than rooted at the filesystem: on the pattern, and on a text its
12
+ * braces give, since spec-core reads `{/docs,x}` as `/docs` or `x`, and
13
+ * `docs` would fall out of the scope unsaid. A leading `./` goes with the
14
+ * slashes after it, as POSIX reads them: `.//docs` is `docs`, and
15
+ * `./{/docs,x}` is `docs` or `x`. A list entry's `!` has no list to belong
16
+ * to in a scope, so it is refused rather than read.
13
17
  * - Paths compare case-sensitively on every host, as git's do.
14
18
  * - A path with no glob syntax is read as the tree reads it: a file the tree
15
19
  * holds is that file, a directory it holds is everything beneath it, and a
@@ -25,7 +29,7 @@
25
29
  * size times the path's length, and a question about two scopes that cannot be
26
30
  * answered within the search's budget answers `undecided`, never a guess.
27
31
  */
28
- import { globCovers as coreCovers, globWitness as coreWitness, isGlobSyntax, parseGlob as coreParse, WITNESS_BUDGET, } from './vendor/spec-core/pattern/index.js';
32
+ import { globAlternatives, globCovers as coreCovers, globWitness as coreWitness, isGlobSyntax, parseGlob as coreParse, WITNESS_BUDGET, } from './vendor/spec-core/pattern/index.js';
29
33
  import { segments } from './vendor/spec-core/path/index.js';
30
34
  export { isGlobSyntax, WITNESS_BUDGET };
31
35
  /** Parses a scope pattern, or says why it cannot. */
@@ -33,7 +37,15 @@ export function parseGlob(source, options = {}) {
33
37
  const pattern = source.trim();
34
38
  if (pattern.startsWith('!'))
35
39
  return { ok: false, error: 'negated patterns are not supported; narrow the positive pattern' };
36
- if (pattern.startsWith('/'))
40
+ // spec-core's own reading of where each alternative starts, a leading `./`
41
+ // and `/` included (spec-core ADR-0003). A pattern it refuses, the core's
42
+ // parse refuses in the same words, so either may say so. It comes first so
43
+ // that a pattern led by `/`, which the core roots at the filesystem's root,
44
+ // is refused in spec-brief's words.
45
+ const read = globAlternatives(pattern);
46
+ if (!read.ok)
47
+ return { ok: false, error: read.error };
48
+ if (read.rooted)
37
49
  return { ok: false, error: 'a pattern is relative to the repository root and cannot start with "/"' };
38
50
  const given = options.literal ?? 'file';
39
51
  const literals = [];
@@ -45,7 +57,17 @@ export function parseGlob(source, options = {}) {
45
57
  // A pattern too large to compile is refused by the core, with its reason,
46
58
  // as a malformed one is; what the reading throws is a defect, and passes on.
47
59
  const parsed = coreParse(pattern, { dialect: 'path', caseSensitive: true, literal });
48
- return parsed.ok ? { ok: true, glob: { source, compiled: parsed.glob, literals } } : parsed;
60
+ if (!parsed.ok)
61
+ return parsed;
62
+ // Once the core has parsed the pattern, so that an alternative naming no
63
+ // path, `{/,x}`, is refused in the core's words. The text is named behind
64
+ // the `/` that roots it, as spec-core gives it: it reads the same written
65
+ // alone, so a `}` or `,` no group took is written as a class, `[}]`.
66
+ const rooted = read.alternatives.find((alternative) => alternative.rooted);
67
+ if (rooted !== undefined) {
68
+ return { ok: false, error: `a pattern is relative to the repository root, and the braces expand to "/${rooted.text}", which starts with "/"` };
69
+ }
70
+ return { ok: true, glob: { source, compiled: parsed.glob, literals } };
49
71
  }
50
72
  /**
51
73
  * Whether a path matches. The path is read as a repository path: empty and
package/dist/glob.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"glob.js","sourceRoot":"","sources":["../src/glob.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EACL,UAAU,IAAI,UAAU,EACxB,WAAW,IAAI,WAAW,EAC1B,YAAY,EACZ,SAAS,IAAI,SAAS,EAGtB,cAAc,GAEf,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAE5D,OAAO,EAAE,YAAY,EAAuB,cAAc,EAAgB,CAAC;AA+B3E,qDAAqD;AACrD,MAAM,UAAU,SAAS,CAAC,MAAc,EAAE,OAAO,GAAiB,EAAE;IAClE,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;IAC9B,IAAI,OAAO,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,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,KAAK,KAAK,CAAC,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,GAAG,CAAC,CAAC;YAAE,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;IAChI,CAAC;IACD,MAAM,IAAI,GAAG,EAAE,KAAK,EAAE,IAAI,GAAG,CAAC,KAAK,CAAC,EAAE,WAAW,EAAE,CAAC;IACpD,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACvB,OAAO,IAAI,CAAC;AACd,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,IAAI,CAAC,IAAU,EAAE,IAAY;IAC3C,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;QAAE,OAAO,MAAM,CAAC;IACxC,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC;AACzD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,KAA+B;IACvD,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC;IACxC,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC3B,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AAC7E,CAAC","sourcesContent":["/**\n * Scopes as globs: spec-core's `path` dialect, read the way spec-brief reads a\n * brief.\n *\n * The syntax, the automaton and the witness search are spec-core's, copied\n * into `src/vendor/` and verified by hash, so the family's tools read one\n * pattern the same way (spec-core ADR-0003). What is decided here is what\n * spec-brief adds around it:\n *\n * - A pattern is relative to the repository root, so a leading `/` is refused\n * rather than rooted at the filesystem; and a list entry's `!` has no list to\n * belong to in a scope, so it is refused rather than read.\n * - Paths compare case-sensitively on every host, as git's do.\n * - A path with no glob syntax is read as the tree reads it: a file the tree\n * holds is that file, a directory it holds is everything beneath it, and a\n * path it does not hold is a file, unless it is written with a trailing `/`.\n * The tree, not the spelling, knows that `Dockerfile` is a file and\n * `docs/v1.2` a directory (ADR-0005, amended 2026-09-26).\n * - A trailing `/**` is at least one segment, so `docs/**` is the directory's\n * contents and a collision witness is always a file. A trailing `/` means\n * the same on a brace alternative as on the whole pattern: `{src/,lib}` is\n * `src/` or `lib`, and the tree is asked about `lib` alone.\n *\n * Nothing here compiles to a `RegExp`. Matching costs at most the pattern's\n * size times the path's length, and a question about two scopes that cannot be\n * answered within the search's budget answers `undecided`, never a guess.\n */\n\nimport {\n globCovers as coreCovers,\n globWitness as coreWitness,\n isGlobSyntax,\n parseGlob as coreParse,\n type Glob as CoreGlob,\n type LiteralReading,\n WITNESS_BUDGET,\n type Witness,\n} from './vendor/spec-core/pattern/index.js';\nimport { segments } from './vendor/spec-core/path/index.js';\n\nexport { isGlobSyntax, type LiteralReading, WITNESS_BUDGET, type Witness };\n\n/** A literal path a pattern names, and how it was read. */\nexport interface Literal {\n readonly path: string;\n readonly reading: LiteralReading;\n}\n\nexport interface Glob {\n readonly source: string;\n /** The compiled pattern: spec-core's `path` dialect, case-sensitive. */\n readonly compiled: CoreGlob;\n /**\n * Each path the pattern names with no glob syntax and no trailing `/`, one\n * per brace alternative; empty when it has none.\n */\n readonly literals: readonly Literal[];\n}\n\nexport type GlobParse = { readonly ok: true; readonly glob: Glob } | { readonly ok: false; readonly error: string };\n\nexport interface ParseOptions {\n /**\n * How a path with no glob syntax is read: `file`, that path alone;\n * `directory`, everything beneath it; `either`, both. A function is asked\n * per literal path, as {@link readingIn} answers for a tree. `file` when\n * unset: a path nothing says is a directory is not read as one.\n */\n readonly literal?: LiteralReading | ((path: string) => LiteralReading) | undefined;\n}\n\n/** Parses a scope pattern, or says why it cannot. */\nexport function parseGlob(source: string, options: ParseOptions = {}): GlobParse {\n const pattern = source.trim();\n if (pattern.startsWith('!')) return { ok: false, error: 'negated patterns are not supported; narrow the positive pattern' };\n if (pattern.startsWith('/')) return { ok: false, error: 'a pattern is relative to the repository root and cannot start with \"/\"' };\n const given = options.literal ?? 'file';\n const literals: Literal[] = [];\n const literal = (path: string): LiteralReading => {\n const reading = typeof given === 'function' ? given(path) : given;\n literals.push({ path, reading });\n return reading;\n };\n // A pattern too large to compile is refused by the core, with its reason,\n // as a malformed one is; what the reading throws is a defect, and passes on.\n const parsed = coreParse(pattern, { dialect: 'path', caseSensitive: true, literal });\n return parsed.ok ? { ok: true, glob: { source, compiled: parsed.glob, literals } } : parsed;\n}\n\n/**\n * Whether a path matches. The path is read as a repository path: empty and\n * `.` segments are dropped, so `./src//a.ts` is `src/a.ts`.\n */\nexport function matchGlob(glob: Glob, path: string): boolean {\n const canonical = segments(path).join('/');\n return canonical !== '' && glob.compiled.match(canonical);\n}\n\n/**\n * A shortest path every glob in `include` matches and none in `exclude` does,\n * `none` as a proof that there is no such path, or `undecided` when the search\n * met its budget first.\n */\nexport function globWitness(include: readonly Glob[], exclude: readonly Glob[] = [], budget: number = WITNESS_BUDGET): Witness {\n return coreWitness(\n include.map((g) => g.compiled),\n exclude.map((g) => g.compiled),\n budget,\n );\n}\n\n/** Whether every path `inner` matches is matched by one of `outer`, or `undecided`. */\nexport function globCovers(outer: readonly Glob[], inner: Glob, budget: number = WITNESS_BUDGET): boolean | 'undecided' {\n return coreCovers(\n outer.map((g) => g.compiled),\n inner.compiled,\n budget,\n );\n}\n\n/**\n * A path both globs match, or `null` when there is none: the 0.1 interface,\n * kept for the library's callers. It cannot say `undecided`, so a search that\n * meets its budget throws; {@link globWitness} answers in three ways.\n */\nexport function intersectGlobs(a: Glob, b: Glob, budget: number = WITNESS_BUDGET): string | null {\n const witness = globWitness([a, b], [], budget);\n if (witness.kind === 'undecided') {\n throw new Error(`whether \"${a.source}\" and \"${b.source}\" meet is undecided within the search's budget`);\n }\n return witness.kind === 'found' ? witness.path : null;\n}\n\n/**\n * The directories a walk must enter to find every match, one per brace\n * alternative: the leading literal segments, or a literal file's directory.\n * `''` for an alternative that can match at the root.\n */\nexport function globBases(glob: Glob): readonly string[] {\n return glob.compiled.bases;\n}\n\n/** The first of {@link globBases}: the 0.1 interface, kept for the library's callers. */\nexport function globBase(glob: Glob): string {\n // One base per alternative, and a pattern has at least one.\n return glob.compiled.bases[0] as string;\n}\n\n/** A brace alternative as its pattern writes it, and the index in the pattern where it ends. */\nexport interface WrittenAlternative {\n readonly written: string;\n readonly end: number;\n}\n\n/**\n * Each alternative of a pattern as written, in the order the core expands\n * them, and where each ends, when a `/` written there ends that alternative\n * and no other: the pattern itself when it has no braces, or the alternatives\n * of braces that end the pattern and whose own braces end theirs -\n * `lib/{util,new}`, `{a,b/{c,d}}`. `null` when more of the pattern follows\n * braces, `{a,b}/new`, since every alternative they give ends where the\n * pattern does; and for a pattern with a class, which may hold a brace or a\n * comma of its own and which this does not read.\n *\n * spec-core expands braces and keeps nothing of where an alternative was\n * written, and a note's advice is built from what was written, as the core\n * builds its own. So this reads braces as the expansion does, for a pattern\n * that parses: a `\\` escapes the next character, and a `}` with no `{` open\n * is a literal.\n */\nexport function writtenAlternatives(pattern: string): WrittenAlternative[] | null {\n let depth = 0;\n let open = 0;\n const stops: number[] = [];\n for (let i = 0; i < pattern.length; i += 1) {\n const ch = pattern.charAt(i);\n if (ch === '\\\\') {\n i += 1;\n } else if (ch === '[') {\n return null;\n } else if (ch === '{') {\n if (depth === 0) open = i;\n depth += 1;\n } else if (ch === ',' && depth === 1) {\n stops.push(i);\n } else if (ch === '}' && depth > 0) {\n depth -= 1;\n if (depth === 0) return i === pattern.length - 1 ? optionsOf(pattern, open, [...stops, i]) : null;\n }\n }\n return [{ written: pattern, end: pattern.length }];\n}\n\n/** The alternatives of the braces opened at `open`, each option ending at one of `stops`. */\nfunction optionsOf(pattern: string, open: number, stops: readonly number[]): WrittenAlternative[] | null {\n const prefix = pattern.slice(0, open);\n const alternatives: WrittenAlternative[] = [];\n let start = open + 1;\n for (const stop of stops) {\n const inner = writtenAlternatives(pattern.slice(start, stop));\n if (inner === null) return null;\n for (const { written, end } of inner) alternatives.push({ written: prefix + written, end: start + end });\n start = stop + 1;\n }\n return alternatives;\n}\n\n/** A name with an extension, `login.ts` or `.eslintrc.json`, and not a dot-name such as `.github`. */\nexport function hasExtension(name: string): boolean {\n return /.\\.[^.]+$/.test(name);\n}\n\n/** The files a tree holds, and every directory above one. */\nexport interface Tree {\n readonly files: ReadonlySet<string>;\n readonly directories: ReadonlySet<string>;\n}\n\nconst trees = new WeakMap<readonly string[], Tree>();\n\n/** The tree a list of files describes. Built once per list, which every brief of a run shares. */\nexport function treeOf(files: readonly string[]): Tree {\n const known = trees.get(files);\n if (known !== undefined) return known;\n const directories = new Set<string>();\n for (const file of files) {\n for (let slash = file.indexOf('/'); slash !== -1; slash = file.indexOf('/', slash + 1)) directories.add(file.slice(0, slash));\n }\n const tree = { files: new Set(files), directories };\n trees.set(files, tree);\n return tree;\n}\n\n/** What the tree holds at a path: a file, a directory, or nothing. */\nexport function held(tree: Tree, path: string): 'file' | 'directory' | null {\n if (tree.files.has(path)) return 'file';\n return tree.directories.has(path) ? 'directory' : null;\n}\n\n/**\n * How a tree reads a literal path: a directory it holds is a directory, and\n * anything else is a file. Without a tree nothing is known to be a directory,\n * so every literal is a file; a trailing `/` says otherwise, and never reaches\n * this question.\n */\nexport function readingIn(files: readonly string[] | null): (path: string) => LiteralReading {\n if (files === null) return () => 'file';\n const tree = treeOf(files);\n return (path) => (held(tree, path) === 'directory' ? 'directory' : 'file');\n}\n"]}
1
+ {"version":3,"file":"glob.js","sourceRoot":"","sources":["../src/glob.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAA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I,GAAG,EAAE,KAAK,EAAE,IAAI,GAAG,CAAC,KAAK,CAAC,EAAE,WAAW,EAAE,CAAC;IACpD,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACvB,OAAO,IAAI,CAAC;AACd,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,IAAI,CAAC,IAAU,EAAE,IAAY;IAC3C,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;QAAE,OAAO,MAAM,CAAC;IACxC,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC;AACzD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,KAA+B;IACvD,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC;IACxC,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC3B,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AAC7E,CAAC","sourcesContent":["/**\n * Scopes as globs: spec-core's `path` dialect, read the way spec-brief reads a\n * brief.\n *\n * The syntax, the automaton and the witness search are spec-core's, copied\n * into `src/vendor/` and verified by hash, so the family's tools read one\n * pattern the same way (spec-core ADR-0003). What is decided here is what\n * spec-brief adds around it:\n *\n * - A pattern is relative to the repository root, so a leading `/` is refused\n * rather than rooted at the filesystem: on the pattern, and on a text its\n * braces give, since spec-core reads `{/docs,x}` as `/docs` or `x`, and\n * `docs` would fall out of the scope unsaid. A leading `./` goes with the\n * slashes after it, as POSIX reads them: `.//docs` is `docs`, and\n * `./{/docs,x}` is `docs` or `x`. A list entry's `!` has no list to belong\n * to in a scope, so it is refused rather than read.\n * - Paths compare case-sensitively on every host, as git's do.\n * - A path with no glob syntax is read as the tree reads it: a file the tree\n * holds is that file, a directory it holds is everything beneath it, and a\n * path it does not hold is a file, unless it is written with a trailing `/`.\n * The tree, not the spelling, knows that `Dockerfile` is a file and\n * `docs/v1.2` a directory (ADR-0005, amended 2026-09-26).\n * - A trailing `/**` is at least one segment, so `docs/**` is the directory's\n * contents and a collision witness is always a file. A trailing `/` means\n * the same on a brace alternative as on the whole pattern: `{src/,lib}` is\n * `src/` or `lib`, and the tree is asked about `lib` alone.\n *\n * Nothing here compiles to a `RegExp`. Matching costs at most the pattern's\n * size times the path's length, and a question about two scopes that cannot be\n * answered within the search's budget answers `undecided`, never a guess.\n */\n\nimport {\n globAlternatives,\n globCovers as coreCovers,\n globWitness as coreWitness,\n isGlobSyntax,\n parseGlob as coreParse,\n type Glob as CoreGlob,\n type LiteralReading,\n WITNESS_BUDGET,\n type Witness,\n} from './vendor/spec-core/pattern/index.js';\nimport { segments } from './vendor/spec-core/path/index.js';\n\nexport { isGlobSyntax, type LiteralReading, WITNESS_BUDGET, type Witness };\n\n/** A literal path a pattern names, and how it was read. */\nexport interface Literal {\n readonly path: string;\n readonly reading: LiteralReading;\n}\n\nexport interface Glob {\n readonly source: string;\n /** The compiled pattern: spec-core's `path` dialect, case-sensitive. */\n readonly compiled: CoreGlob;\n /**\n * Each path the pattern names with no glob syntax and no trailing `/`, one\n * per brace alternative; empty when it has none.\n */\n readonly literals: readonly Literal[];\n}\n\nexport type GlobParse = { readonly ok: true; readonly glob: Glob } | { readonly ok: false; readonly error: string };\n\nexport interface ParseOptions {\n /**\n * How a path with no glob syntax is read: `file`, that path alone;\n * `directory`, everything beneath it; `either`, both. A function is asked\n * per literal path, as {@link readingIn} answers for a tree. `file` when\n * unset: a path nothing says is a directory is not read as one.\n */\n readonly literal?: LiteralReading | ((path: string) => LiteralReading) | undefined;\n}\n\n/** Parses a scope pattern, or says why it cannot. */\nexport function parseGlob(source: string, options: ParseOptions = {}): GlobParse {\n const pattern = source.trim();\n if (pattern.startsWith('!')) return { ok: false, error: 'negated patterns are not supported; narrow the positive pattern' };\n // spec-core's own reading of where each alternative starts, a leading `./`\n // and `/` included (spec-core ADR-0003). A pattern it refuses, the core's\n // parse refuses in the same words, so either may say so. It comes first so\n // that a pattern led by `/`, which the core roots at the filesystem's root,\n // is refused in spec-brief's words.\n const read = globAlternatives(pattern);\n if (!read.ok) return { ok: false, error: read.error };\n if (read.rooted) return { ok: false, error: 'a pattern is relative to the repository root and cannot start with \"/\"' };\n const given = options.literal ?? 'file';\n const literals: Literal[] = [];\n const literal = (path: string): LiteralReading => {\n const reading = typeof given === 'function' ? given(path) : given;\n literals.push({ path, reading });\n return reading;\n };\n // A pattern too large to compile is refused by the core, with its reason,\n // as a malformed one is; what the reading throws is a defect, and passes on.\n const parsed = coreParse(pattern, { dialect: 'path', caseSensitive: true, literal });\n if (!parsed.ok) return parsed;\n // Once the core has parsed the pattern, so that an alternative naming no\n // path, `{/,x}`, is refused in the core's words. The text is named behind\n // the `/` that roots it, as spec-core gives it: it reads the same written\n // alone, so a `}` or `,` no group took is written as a class, `[}]`.\n const rooted = read.alternatives.find((alternative) => alternative.rooted);\n if (rooted !== undefined) {\n return { ok: false, error: `a pattern is relative to the repository root, and the braces expand to \"/${rooted.text}\", which starts with \"/\"` };\n }\n return { ok: true, glob: { source, compiled: parsed.glob, literals } };\n}\n\n/**\n * Whether a path matches. The path is read as a repository path: empty and\n * `.` segments are dropped, so `./src//a.ts` is `src/a.ts`.\n */\nexport function matchGlob(glob: Glob, path: string): boolean {\n const canonical = segments(path).join('/');\n return canonical !== '' && glob.compiled.match(canonical);\n}\n\n/**\n * A shortest path every glob in `include` matches and none in `exclude` does,\n * `none` as a proof that there is no such path, or `undecided` when the search\n * met its budget first.\n */\nexport function globWitness(include: readonly Glob[], exclude: readonly Glob[] = [], budget: number = WITNESS_BUDGET): Witness {\n return coreWitness(\n include.map((g) => g.compiled),\n exclude.map((g) => g.compiled),\n budget,\n );\n}\n\n/** Whether every path `inner` matches is matched by one of `outer`, or `undecided`. */\nexport function globCovers(outer: readonly Glob[], inner: Glob, budget: number = WITNESS_BUDGET): boolean | 'undecided' {\n return coreCovers(\n outer.map((g) => g.compiled),\n inner.compiled,\n budget,\n );\n}\n\n/**\n * A path both globs match, or `null` when there is none: the 0.1 interface,\n * kept for the library's callers. It cannot say `undecided`, so a search that\n * meets its budget throws; {@link globWitness} answers in three ways.\n */\nexport function intersectGlobs(a: Glob, b: Glob, budget: number = WITNESS_BUDGET): string | null {\n const witness = globWitness([a, b], [], budget);\n if (witness.kind === 'undecided') {\n throw new Error(`whether \"${a.source}\" and \"${b.source}\" meet is undecided within the search's budget`);\n }\n return witness.kind === 'found' ? witness.path : null;\n}\n\n/**\n * The directories a walk must enter to find every match, one per brace\n * alternative: the leading literal segments, or a literal file's directory.\n * `''` for an alternative that can match at the root.\n */\nexport function globBases(glob: Glob): readonly string[] {\n return glob.compiled.bases;\n}\n\n/** The first of {@link globBases}: the 0.1 interface, kept for the library's callers. */\nexport function globBase(glob: Glob): string {\n // One base per alternative, and a pattern has at least one.\n return glob.compiled.bases[0] as string;\n}\n\n/** A brace alternative as its pattern writes it, and the index in the pattern where it ends. */\nexport interface WrittenAlternative {\n readonly written: string;\n readonly end: number;\n}\n\n/**\n * Each alternative of a pattern as written, in the order the core expands\n * them, and where each ends, when a `/` written there ends that alternative\n * and no other: the pattern itself when it has no braces, or the alternatives\n * of braces that end the pattern and whose own braces end theirs -\n * `lib/{util,new}`, `{a,b/{c,d}}`. `null` when more of the pattern follows\n * braces, `{a,b}/new`, since every alternative they give ends where the\n * pattern does; and for a pattern with a class, which may hold a brace or a\n * comma of its own and which this does not read.\n *\n * spec-core expands braces and keeps nothing of where an alternative was\n * written, and a note's advice is built from what was written, as the core\n * builds its own. So this reads braces as the expansion does, for a pattern\n * that parses: a `\\` escapes the next character, and a `}` with no `{` open\n * is a literal.\n */\nexport function writtenAlternatives(pattern: string): WrittenAlternative[] | null {\n let depth = 0;\n let open = 0;\n const stops: number[] = [];\n for (let i = 0; i < pattern.length; i += 1) {\n const ch = pattern.charAt(i);\n if (ch === '\\\\') {\n i += 1;\n } else if (ch === '[') {\n return null;\n } else if (ch === '{') {\n if (depth === 0) open = i;\n depth += 1;\n } else if (ch === ',' && depth === 1) {\n stops.push(i);\n } else if (ch === '}' && depth > 0) {\n depth -= 1;\n if (depth === 0) return i === pattern.length - 1 ? optionsOf(pattern, open, [...stops, i]) : null;\n }\n }\n return [{ written: pattern, end: pattern.length }];\n}\n\n/** The alternatives of the braces opened at `open`, each option ending at one of `stops`. */\nfunction optionsOf(pattern: string, open: number, stops: readonly number[]): WrittenAlternative[] | null {\n const prefix = pattern.slice(0, open);\n const alternatives: WrittenAlternative[] = [];\n let start = open + 1;\n for (const stop of stops) {\n const inner = writtenAlternatives(pattern.slice(start, stop));\n if (inner === null) return null;\n for (const { written, end } of inner) alternatives.push({ written: prefix + written, end: start + end });\n start = stop + 1;\n }\n return alternatives;\n}\n\n/** A name with an extension, `login.ts` or `.eslintrc.json`, and not a dot-name such as `.github`. */\nexport function hasExtension(name: string): boolean {\n return /.\\.[^.]+$/.test(name);\n}\n\n/** The files a tree holds, and every directory above one. */\nexport interface Tree {\n readonly files: ReadonlySet<string>;\n readonly directories: ReadonlySet<string>;\n}\n\nconst trees = new WeakMap<readonly string[], Tree>();\n\n/** The tree a list of files describes. Built once per list, which every brief of a run shares. */\nexport function treeOf(files: readonly string[]): Tree {\n const known = trees.get(files);\n if (known !== undefined) return known;\n const directories = new Set<string>();\n for (const file of files) {\n for (let slash = file.indexOf('/'); slash !== -1; slash = file.indexOf('/', slash + 1)) directories.add(file.slice(0, slash));\n }\n const tree = { files: new Set(files), directories };\n trees.set(files, tree);\n return tree;\n}\n\n/** What the tree holds at a path: a file, a directory, or nothing. */\nexport function held(tree: Tree, path: string): 'file' | 'directory' | null {\n if (tree.files.has(path)) return 'file';\n return tree.directories.has(path) ? 'directory' : null;\n}\n\n/**\n * How a tree reads a literal path: a directory it holds is a directory, and\n * anything else is a file. Without a tree nothing is known to be a directory,\n * so every literal is a file; a trailing `/` says otherwise, and never reaches\n * this question.\n */\nexport function readingIn(files: readonly string[] | null): (path: string) => LiteralReading {\n if (files === null) return () => 'file';\n const tree = treeOf(files);\n return (path) => (held(tree, path) === 'directory' ? 'directory' : 'file');\n}\n"]}
package/dist/lint.js CHANGED
@@ -68,6 +68,7 @@ export async function lint(corpus, options = {}) {
68
68
  line: Math.max(1, Math.trunc(result.line)),
69
69
  brief: brief.id ?? undefined,
70
70
  hint: result.hint,
71
+ subject: result.subject,
71
72
  });
72
73
  }
73
74
  }
package/dist/lint.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"lint.js","sourceRoot":"","sources":["../src/lint.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,eAAe,EAA4B,KAAK,EAAE,MAAM,YAAY,CAAC;AA4CtG,MAAM,IAAI,GAAuC,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;AAEnF,SAAS,KAAK,CAAC,CAAW,EAAE,CAAW;IACrC,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACpC,CAAC;AASD,0EAA0E;AAC1E,MAAM,UAAU,OAAO,CAAC,OAAO,GAAsB,EAAE;IACrD,OAAO;QACL,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACzB,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACnC,GAAG,aAAa,CAAC,GAAG,CAAC,CAA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from the configuration, plugins beside the\n * built-in rules, findings in a stable order.\n */\n\nimport type { Waiver } from './archive.js';\nimport type { Brief } from './brief.js';\nimport { ConfigError } from './config.js';\nimport type { Corpus } from './corpus.js';\nimport { analyse, ARCHIVE_RULES, COLLISION_RULES, type Rule, type RuleInfo, RULES } from './rules.js';\nimport type { Finding, Severity, SeveritySetting } from './types.js';\n\n/** What a plugin's `waive` hook is asked about: one archival, refused. */\nexport interface WaiveContext {\n /** The absolute root: the directory holding the configuration. */\n readonly root: string;\n readonly brief: { readonly id: string | null; readonly file: string; readonly text: string };\n /**\n * Every finding that refuses the archival, as a frozen copy: writing to it\n * throws, and the waivers are matched against the plan's own. A\n * `protected-file` finding names its `path`; an `out-of-scope` one lists its\n * `paths`. Only those two can be waived.\n */\n readonly findings: readonly Finding[];\n /** The base the round is measured from, as it was given; `null` when none was. */\n readonly base: string | null;\n /** The commit the round landed as; `null` when none was read. */\n readonly commit: string | null;\n}\n\nexport interface Plugin {\n /** Prefixes the plugin's rule ids: `<name>/<rule>`. */\n readonly name: string;\n readonly rules: readonly Rule[];\n /** The plugin's entry in the configuration, handed to each rule. */\n readonly options?: unknown;\n /**\n * Lifts refusals of an archival that the plugin's own check allows - a\n * protected file a verified ruling covers - by rule and path. Asked only\n * when the plan has a refusal it could lift. Returning nothing waives\n * nothing.\n */\n readonly waive?: ((context: WaiveContext) => readonly Waiver[] | void | Promise<readonly Waiver[] | void>) | undefined;\n}\n\nexport interface LintOptions {\n readonly plugins?: readonly Plugin[];\n /** Tracked files, for the rules that read the tree. */\n readonly repoFiles?: readonly string[] | null;\n /** Limit the findings to these briefs. The whole corpus is still read. */\n readonly only?: readonly Brief[];\n}\n\nconst RANK: Readonly<Record<Severity, number>> = { note: 0, warning: 1, error: 2 };\n\nfunction lower(a: Severity, b: Severity): Severity {\n return RANK[a] <= RANK[b] ? a : b;\n}\n\ninterface ActiveRule {\n readonly id: string;\n readonly rule: Rule;\n readonly severity: SeveritySetting;\n readonly options: unknown;\n}\n\n/** Every rule id a run knows: built-in, collision, archive and plugin. */\nexport function ruleIds(plugins: readonly Plugin[] = []): string[] {\n return [\n ...RULES.map((r) => r.id),\n ...COLLISION_RULES.map((r) => r.id),\n ...ARCHIVE_RULES.map((r) => r.id),\n ...plugins.flatMap((p) => p.rules.map((r) => `${p.name}/${r.id}`)),\n ];\n}\n\n/** The severity configuration assigns a rule, or its own. */\nexport function severityOf(corpus: Corpus, id: string, fallback: SeveritySetting): SeveritySetting {\n return corpus.config.rules[id] ?? fallback;\n}\n\n/** The severity of a built-in rule as configured, or `null` when it is off. */\nexport function configuredSeverity(corpus: Corpus, id: string): Severity | null {\n const rule = [...RULES, ...COLLISION_RULES, ...ARCHIVE_RULES].find((r) => r.id === id) as RuleInfo;\n const setting = severityOf(corpus, id, rule.severity);\n return setting === 'off' ? null : setting;\n}\n\n/** Refuses a configuration that names a rule nobody defines: a typo there silences nothing. */\nexport function checkRuleIds(corpus: Corpus, plugins: readonly Plugin[] = []): void {\n const known = new Set(ruleIds(plugins));\n const unknown = Object.keys(corpus.config.rules).filter((id) => !known.has(id));\n if (unknown.length > 0) {\n throw new ConfigError('configuration', unknown.map((id) => `\"rules.${id}\" names no rule`));\n }\n}\n\nexport async function lint(corpus: Corpus, options: LintOptions = {}): Promise<Finding[]> {\n const plugins = options.plugins ?? [];\n checkRuleIds(corpus, plugins);\n const active: ActiveRule[] = [\n ...RULES.map((rule) => ({ id: rule.id, rule, severity: severityOf(corpus, rule.id, rule.severity), options: undefined })),\n ...plugins.flatMap((plugin) =>\n plugin.rules.map((rule) => {\n const id = `${plugin.name}/${rule.id}`;\n return { id, rule, severity: severityOf(corpus, id, rule.severity), options: plugin.options };\n }),\n ),\n ].filter((r) => r.severity !== 'off');\n\n const shared = analyse(corpus);\n const targets = options.only ?? corpus.briefs;\n const findings: Finding[] = [];\n for (const brief of targets) {\n for (const { id, rule, severity, options: ruleOptions } of active) {\n const results = await rule.check({\n brief,\n corpus,\n config: corpus.config,\n repoFiles: options.repoFiles ?? null,\n shared,\n options: ruleOptions,\n });\n for (const result of results) {\n const configured = severity as Severity;\n findings.push({\n rule: id,\n severity: result.severity === undefined ? configured : lower(result.severity, configured),\n message: result.message,\n file: brief.file,\n line: Math.max(1, Math.trunc(result.line)),\n brief: brief.id ?? undefined,\n hint: result.hint,\n });\n }\n }\n }\n return sortFindings(findings);\n}\n\n/** Strings by code unit, which is the same order on every host and in every locale. */\nfunction order(a: string, b: string): number {\n if (a === b) return 0;\n return a < b ? -1 : 1;\n}\n\nexport function sortFindings(findings: readonly Finding[]): Finding[] {\n return [...findings].sort(\n (a, b) => order(a.file, b.file) || a.line - b.line || order(a.rule, b.rule) || order(a.message, b.message),\n );\n}\n\nexport interface Summary {\n readonly errors: number;\n readonly warnings: number;\n readonly notes: number;\n}\n\nexport function summarise(findings: readonly Finding[]): Summary {\n return {\n errors: findings.filter((f) => f.severity === 'error').length,\n warnings: findings.filter((f) => f.severity === 'warning').length,\n notes: findings.filter((f) => f.severity === 'note').length,\n };\n}\n\n/** Whether findings fail a run: any error, or any warning under `--strict`. */\nexport function failing(findings: readonly Finding[], strict: boolean): boolean {\n return findings.some((f) => f.severity === 'error' || (strict && f.severity === 'warning'));\n}\n"]}
1
+ {"version":3,"file":"lint.js","sourceRoot":"","sources":["../src/lint.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,eAAe,EAA4B,KAAK,EAAE,MAAM,YAAY,CAAC;AA4CtG,MAAM,IAAI,GAAuC,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;AAEnF,SAAS,KAAK,CAAC,CAAW,EAAE,CAAW;IACrC,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,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E,CAAC,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC,CAAC,MAAM;KAC5D,CAAC;AACJ,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,OAAO,CAAC,QAA4B,EAAE,MAAe;IACnE,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,OAAO,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC;AAC9F,CAAC","sourcesContent":["/**\n * Running rules: severities from the configuration, plugins beside the\n * built-in rules, findings in a stable order.\n */\n\nimport type { Waiver } from './archive.js';\nimport type { Brief } from './brief.js';\nimport { ConfigError } from './config.js';\nimport type { Corpus } from './corpus.js';\nimport { analyse, ARCHIVE_RULES, COLLISION_RULES, type Rule, type RuleInfo, RULES } from './rules.js';\nimport type { Finding, Severity, SeveritySetting } from './types.js';\n\n/** What a plugin's `waive` hook is asked about: one archival, refused. */\nexport interface WaiveContext {\n /** The absolute root: the directory holding the configuration. */\n readonly root: string;\n readonly brief: { readonly id: string | null; readonly file: string; readonly text: string };\n /**\n * Every finding that refuses the archival, as a frozen copy: writing to it\n * throws, and the waivers are matched against the plan's own. A\n * `protected-file` finding names its `path`; an `out-of-scope` one lists its\n * `paths`. Only those two can be waived.\n */\n readonly findings: readonly Finding[];\n /** The base the round is measured from, as it was given; `null` when none was. */\n readonly base: string | null;\n /** The commit the round landed as; `null` when none was read. */\n readonly commit: string | null;\n}\n\nexport interface Plugin {\n /** Prefixes the plugin's rule ids: `<name>/<rule>`. */\n readonly name: string;\n readonly rules: readonly Rule[];\n /** The plugin's entry in the configuration, handed to each rule. */\n readonly options?: unknown;\n /**\n * Lifts refusals of an archival that the plugin's own check allows - a\n * protected file a verified ruling covers - by rule and path. Asked only\n * when the plan has a refusal it could lift. Returning nothing waives\n * nothing.\n */\n readonly waive?: ((context: WaiveContext) => readonly Waiver[] | void | Promise<readonly Waiver[] | void>) | undefined;\n}\n\nexport interface LintOptions {\n readonly plugins?: readonly Plugin[];\n /** Tracked files, for the rules that read the tree. */\n readonly repoFiles?: readonly string[] | null;\n /** Limit the findings to these briefs. The whole corpus is still read. */\n readonly only?: readonly Brief[];\n}\n\nconst RANK: Readonly<Record<Severity, number>> = { note: 0, warning: 1, error: 2 };\n\nfunction lower(a: Severity, b: Severity): Severity {\n return RANK[a] <= RANK[b] ? a : b;\n}\n\ninterface ActiveRule {\n readonly id: string;\n readonly rule: Rule;\n readonly severity: SeveritySetting;\n readonly options: unknown;\n}\n\n/** Every rule id a run knows: built-in, collision, archive and plugin. */\nexport function ruleIds(plugins: readonly Plugin[] = []): string[] {\n return [\n ...RULES.map((r) => r.id),\n ...COLLISION_RULES.map((r) => r.id),\n ...ARCHIVE_RULES.map((r) => r.id),\n ...plugins.flatMap((p) => p.rules.map((r) => `${p.name}/${r.id}`)),\n ];\n}\n\n/** The severity configuration assigns a rule, or its own. */\nexport function severityOf(corpus: Corpus, id: string, fallback: SeveritySetting): SeveritySetting {\n return corpus.config.rules[id] ?? fallback;\n}\n\n/** The severity of a built-in rule as configured, or `null` when it is off. */\nexport function configuredSeverity(corpus: Corpus, id: string): Severity | null {\n const rule = [...RULES, ...COLLISION_RULES, ...ARCHIVE_RULES].find((r) => r.id === id) as RuleInfo;\n const setting = severityOf(corpus, id, rule.severity);\n return setting === 'off' ? null : setting;\n}\n\n/** Refuses a configuration that names a rule nobody defines: a typo there silences nothing. */\nexport function checkRuleIds(corpus: Corpus, plugins: readonly Plugin[] = []): void {\n const known = new Set(ruleIds(plugins));\n const unknown = Object.keys(corpus.config.rules).filter((id) => !known.has(id));\n if (unknown.length > 0) {\n throw new ConfigError('configuration', unknown.map((id) => `\"rules.${id}\" names no rule`));\n }\n}\n\nexport async function lint(corpus: Corpus, options: LintOptions = {}): Promise<Finding[]> {\n const plugins = options.plugins ?? [];\n checkRuleIds(corpus, plugins);\n const active: ActiveRule[] = [\n ...RULES.map((rule) => ({ id: rule.id, rule, severity: severityOf(corpus, rule.id, rule.severity), options: undefined })),\n ...plugins.flatMap((plugin) =>\n plugin.rules.map((rule) => {\n const id = `${plugin.name}/${rule.id}`;\n return { id, rule, severity: severityOf(corpus, id, rule.severity), options: plugin.options };\n }),\n ),\n ].filter((r) => r.severity !== 'off');\n\n const shared = analyse(corpus);\n const targets = options.only ?? corpus.briefs;\n const findings: Finding[] = [];\n for (const brief of targets) {\n for (const { id, rule, severity, options: ruleOptions } of active) {\n const results = await rule.check({\n brief,\n corpus,\n config: corpus.config,\n repoFiles: options.repoFiles ?? null,\n shared,\n options: ruleOptions,\n });\n for (const result of results) {\n const configured = severity as Severity;\n findings.push({\n rule: id,\n severity: result.severity === undefined ? configured : lower(result.severity, configured),\n message: result.message,\n file: brief.file,\n line: Math.max(1, Math.trunc(result.line)),\n brief: brief.id ?? undefined,\n hint: result.hint,\n subject: result.subject,\n });\n }\n }\n }\n return sortFindings(findings);\n}\n\n/** Strings by code unit, which is the same order on every host and in every locale. */\nfunction order(a: string, b: string): number {\n if (a === b) return 0;\n return a < b ? -1 : 1;\n}\n\nexport function sortFindings(findings: readonly Finding[]): Finding[] {\n return [...findings].sort(\n (a, b) => order(a.file, b.file) || a.line - b.line || order(a.rule, b.rule) || order(a.message, b.message),\n );\n}\n\nexport interface Summary {\n readonly errors: number;\n readonly warnings: number;\n readonly notes: number;\n}\n\nexport function summarise(findings: readonly Finding[]): Summary {\n return {\n errors: findings.filter((f) => f.severity === 'error').length,\n warnings: findings.filter((f) => f.severity === 'warning').length,\n notes: findings.filter((f) => f.severity === 'note').length,\n };\n}\n\n/** Whether findings fail a run: any error, or any warning under `--strict`. */\nexport function failing(findings: readonly Finding[], strict: boolean): boolean {\n return findings.some((f) => f.severity === 'error' || (strict && f.severity === 'warning'));\n}\n"]}
package/dist/report.d.ts CHANGED
@@ -38,10 +38,14 @@ export declare function sarif(findings: readonly Finding[], version: string): st
38
38
  /**
39
39
  * GitLab Code Quality: a JSON array of issues, which a merge request shows
40
40
  * beside the lines they are on. The fingerprint is how GitLab tells a new
41
- * issue from one it has seen, so it hashes the rule, the file and the message
42
- * and not the line: a finding that moves down a page is the same finding. Two
43
- * findings with the same three - a section duplicated twice - are told apart
44
- * by their order.
41
+ * issue from one it has seen, so it hashes the finding's identity and nothing
42
+ * that changes while the problem stays: not the line, so a finding that moves
43
+ * down a page is the same finding, and not the message, so rewording one, or
44
+ * naming another file two colliding briefs both write, does not show as one
45
+ * problem fixed and another found. Findings that share an identity - a front
46
+ * matter with two problems - are told apart by their order, the second hashed
47
+ * with a `2`, as spec-graph hashes them. The description carries the next
48
+ * action as well as the message.
45
49
  */
46
50
  export declare function gitlabCodeQuality(findings: readonly Finding[]): string;
47
51
  export declare function githubCommands(findings: readonly Finding[]): string;
@@ -53,6 +57,16 @@ export declare function briefJson(brief: Brief, extra?: Record<string, unknown>)
53
57
  * knows in advance.
54
58
  */
55
59
  export declare function sectionsJson(config: Config): Record<string, unknown>[];
60
+ /**
61
+ * A title as a table shows it, without the id it repeats: `new` writes
62
+ * `# 012 — Rotate tokens`, and the table has an id column already. Only the
63
+ * brief's own id comes off, compared as ids are, so that `12 - x` in brief
64
+ * `012` loses it and `0010 — x` in brief `001` keeps it, and only before a
65
+ * separator: `Fix - the login bug` and `2026:roadmap` are titles. For
66
+ * display alone: `Brief.title`, and every JSON document, keep the title as
67
+ * written.
68
+ */
69
+ export declare function titleWithoutId(title: string, id: string | null): string;
56
70
  export interface ListRow {
57
71
  readonly brief: Brief;
58
72
  readonly ready: boolean;
package/dist/report.js CHANGED
@@ -9,10 +9,13 @@
9
9
  * so the family is not GitHub's alone.
10
10
  */
11
11
  import { createHash } from 'node:crypto';
12
+ import { idKey } from './corpus.js';
12
13
  import { summarise } from './lint.js';
13
14
  import { ARCHIVE_RULES, COLLISION_RULES, RULES } from './rules.js';
14
15
  import { breachReasons, holds, moves, reasons } from './schedule.js';
16
+ import { witnessText } from './scope.js';
15
17
  import { inWords } from './text.js';
18
+ import { displayWidth } from './vendor/spec-core/text/index.js';
16
19
  export const FORMATS = ['pretty', 'json', 'sarif', 'github', 'gitlab'];
17
20
  /**
18
21
  * The version of the JSON documents this tool prints, every command's alike.
@@ -121,29 +124,44 @@ export function sarif(findings, version) {
121
124
  return `${JSON.stringify(document, null, 2)}\n`;
122
125
  }
123
126
  /**
124
- * GitLab's Code Quality severities. An error fails the run but is not a
125
- * security hole or a crash, which is what `critical` and `blocker` say in
127
+ * GitLab's Code Quality severities, as the family maps them: an error is
128
+ * `major`, a warning `minor`, a note `info`. An error fails the run but is not
129
+ * a security hole or a crash, which is what `critical` and `blocker` say in
126
130
  * GitLab's own reports, so the scale tops out at `major`.
127
131
  */
128
132
  const GITLAB_SEVERITY = { error: 'major', warning: 'minor', note: 'info' };
133
+ /**
134
+ * What a finding is, whatever it says: its rule, its file, its brief, and what
135
+ * it is about there - a section, a pattern, the other brief of a pair, the one
136
+ * path a refusal names. Never the message, the hint or the line.
137
+ */
138
+ function identity(f) {
139
+ return [f.rule, f.file, f.brief ?? '', f.subject ?? f.path ?? ''];
140
+ }
129
141
  /**
130
142
  * GitLab Code Quality: a JSON array of issues, which a merge request shows
131
143
  * beside the lines they are on. The fingerprint is how GitLab tells a new
132
- * issue from one it has seen, so it hashes the rule, the file and the message
133
- * and not the line: a finding that moves down a page is the same finding. Two
134
- * findings with the same three - a section duplicated twice - are told apart
135
- * by their order.
144
+ * issue from one it has seen, so it hashes the finding's identity and nothing
145
+ * that changes while the problem stays: not the line, so a finding that moves
146
+ * down a page is the same finding, and not the message, so rewording one, or
147
+ * naming another file two colliding briefs both write, does not show as one
148
+ * problem fixed and another found. Findings that share an identity - a front
149
+ * matter with two problems - are told apart by their order, the second hashed
150
+ * with a `2`, as spec-graph hashes them. The description carries the next
151
+ * action as well as the message.
136
152
  */
137
153
  export function gitlabCodeQuality(findings) {
138
154
  const seen = new Map();
139
155
  const issues = findings.map((f) => {
140
- const key = `${f.rule}\u0000${f.file}\u0000${f.message}`;
141
- const repeat = seen.get(key) ?? 0;
142
- seen.set(key, repeat + 1);
156
+ const key = JSON.stringify(identity(f));
157
+ const occurrence = (seen.get(key) ?? 0) + 1;
158
+ seen.set(key, occurrence);
143
159
  return {
144
160
  description: f.hint === undefined ? f.message : `${f.message}. ${f.hint}`,
145
161
  check_name: f.rule,
146
- fingerprint: createHash('sha256').update(repeat === 0 ? key : `${key}\u0000${repeat}`).digest('hex'),
162
+ fingerprint: createHash('sha256')
163
+ .update(occurrence === 1 ? key : JSON.stringify([...identity(f), occurrence]))
164
+ .digest('hex'),
147
165
  severity: GITLAB_SEVERITY[f.severity],
148
166
  location: { path: f.file, lines: { begin: f.line } },
149
167
  };
@@ -204,12 +222,56 @@ export function sectionsJson(config) {
204
222
  ...Object.entries(config.types).flatMap(([type, rules]) => rules.map((rule) => describe(rule, type))),
205
223
  ];
206
224
  }
207
- /** Columns padded to their widest cell; every row has the header's length. */
225
+ /**
226
+ * What may stand between an id and the rest of a title: an em or an en dash,
227
+ * a colon, ASCII or full-width, with or without spaces, or a hyphen with a
228
+ * space on each side, so that `001-2 migration` keeps its id.
229
+ */
230
+ const ID_SEPARATOR = /^(?:\s*[\u2014\u2013:\uff1a]|\s+-(?=\s))\s*(?=\S)/u;
231
+ /**
232
+ * A title as a table shows it, without the id it repeats: `new` writes
233
+ * `# 012 — Rotate tokens`, and the table has an id column already. Only the
234
+ * brief's own id comes off, compared as ids are, so that `12 - x` in brief
235
+ * `012` loses it and `0010 — x` in brief `001` keeps it, and only before a
236
+ * separator: `Fix - the login bug` and `2026:roadmap` are titles. For
237
+ * display alone: `Brief.title`, and every JSON document, keep the title as
238
+ * written.
239
+ */
240
+ export function titleWithoutId(title, id) {
241
+ if (id === null)
242
+ return title;
243
+ const text = title.trimStart();
244
+ // An id of digits is compared by value, so the title's own leading digits
245
+ // are the candidate. A title with none has `''`, which no id's key equals;
246
+ // any other text in its place fails `startsWith` and answers the same.
247
+ const lead = /^\d+$/.test(id) ? (/^\d+/.exec(text)?.[0] ?? '') : id;
248
+ if (!text.startsWith(lead) || idKey(lead) !== idKey(id))
249
+ return title;
250
+ const separator = ID_SEPARATOR.exec(text.slice(lead.length));
251
+ return separator === null ? title : text.slice(lead.length + separator[0].length);
252
+ }
253
+ function shownTitle(brief) {
254
+ return brief.title === null ? brief.name : titleWithoutId(brief.title, brief.id);
255
+ }
256
+ /**
257
+ * A text padded to `width` columns of a terminal. `padEnd` counts UTF-16
258
+ * units, and a Han character is one unit and two columns, so `已接受` padded
259
+ * so fell three columns short. Every width here is the widest of the texts it
260
+ * pads, so none is longer than its width.
261
+ */
262
+ function padEnd(text, width) {
263
+ return text + ' '.repeat(width - displayWidth(text));
264
+ }
265
+ /** A text padded on the left to `width` columns of a terminal, as {@link padEnd} pads on the right. */
266
+ function padStart(text, width) {
267
+ return ' '.repeat(width - displayWidth(text)) + text;
268
+ }
269
+ /** Columns padded to their widest cell, in a terminal's columns; every row has the header's length. */
208
270
  function table(header, rows) {
209
271
  const all = [header, ...rows];
210
- const widths = header.map((_, c) => Math.max(...all.map((r) => r[c].length)));
272
+ const widths = header.map((_, c) => Math.max(...all.map((r) => displayWidth(r[c]))));
211
273
  return all.map((r) => r
212
- .map((cell, c) => (c === r.length - 1 ? cell : cell.padEnd(widths[c])))
274
+ .map((cell, c) => (c === r.length - 1 ? cell : padEnd(cell, widths[c])))
213
275
  .join(' ')
214
276
  .trimEnd());
215
277
  }
@@ -218,11 +280,11 @@ export function prettyList(rows, style) {
218
280
  return 'no briefs';
219
281
  const lines = table(['ID', 'STATUS', 'WAVE', 'TASKS', 'READY', 'TITLE'], rows.map(({ brief, ready, waitingOn }) => [
220
282
  brief.id ?? '?',
221
- brief.status ?? brief.statusWord ?? '?',
283
+ brief.statusWord ?? brief.status ?? '?',
222
284
  brief.wave === null ? '-' : String(brief.wave),
223
285
  `${brief.tasks.filter((t) => t.checked).length}/${brief.tasks.length}`,
224
286
  brief.phase === 'archived' ? '-' : ready ? 'yes' : waitingOn.length > 0 ? `after ${waitingOn.join(', ')}` : 'no',
225
- brief.title ?? brief.name,
287
+ shownTitle(brief),
226
288
  ]));
227
289
  return [paint(style, 'dim', lines[0]), ...lines.slice(1)].join('\n');
228
290
  }
@@ -233,12 +295,12 @@ export function prettyMatrix(report, style) {
233
295
  const title = wave.wave === null ? 'all live briefs' : `wave ${wave.wave}`;
234
296
  out.push(paint(style, 'bold', `${title} \u00b7 ${plural(wave.briefs.length, 'brief')}`));
235
297
  const names = wave.briefs.map(label);
236
- const width = Math.max(3, ...names.map((n) => n.length));
298
+ const width = Math.max(3, ...names.map(displayWidth));
237
299
  const pairs = (list) => new Set(list.flatMap((p) => [`${label(p.a)}\u0000${label(p.b)}`, `${label(p.b)}\u0000${label(p.a)}`]));
238
300
  const hits = pairs(wave.collisions);
239
301
  const unknown = pairs(wave.undecided);
240
302
  const near = pairs(wave.shared);
241
- out.push(` ${''.padEnd(width)} ${names.map((n) => n.padStart(width)).join(' ')}`);
303
+ out.push(` ${' '.repeat(width)} ${names.map((n) => padStart(n, width)).join(' ')}`);
242
304
  for (const row of names) {
243
305
  const cells = names.map((col) => {
244
306
  const key = `${row}\u0000${col}`;
@@ -253,12 +315,12 @@ export function prettyMatrix(report, style) {
253
315
  : '\u00b7';
254
316
  return `${' '.repeat(width - 1)}${mark}`;
255
317
  });
256
- out.push(` ${row.padEnd(width)} ${cells.join(' ')}`);
318
+ out.push(` ${padEnd(row, width)} ${cells.join(' ')}`);
257
319
  }
258
320
  // One mark per pair of briefs; each further pair of patterns on a line beneath it.
259
321
  for (const c of wave.collisions) {
260
322
  c.overlaps.forEach((o, i) => {
261
- out.push(` ${i === 0 ? paint(style, 'red', 'X') : ' '} ${label(c.a)} "${o.patterns[0]}" and ${label(c.b)} "${o.patterns[1]}" both cover ${o.witness}`);
323
+ out.push(` ${i === 0 ? paint(style, 'red', 'X') : ' '} ${label(c.a)} "${o.patterns[0]}" and ${label(c.b)} "${o.patterns[1]}" both cover ${witnessText(o)}`);
262
324
  });
263
325
  }
264
326
  for (const u of wave.undecided) {
@@ -288,6 +350,15 @@ export function prettyMatrix(report, style) {
288
350
  out.push('no live briefs');
289
351
  return out.join('\n').trimEnd();
290
352
  }
353
+ /**
354
+ * A pair of patterns that meets, and the file named: `inTree` is `true` for a
355
+ * file the tree holds, `false` for an example the search built, `null` when
356
+ * the tree could not be read. Added to schema 2: a reader of it that does not
357
+ * know the field reads the rest as before.
358
+ */
359
+ function overlapJson(o) {
360
+ return { patterns: o.patterns, witness: o.witness, inTree: o.inTree };
361
+ }
291
362
  /** The matrix as JSON: briefs by id, and a collision per pair of briefs. */
292
363
  export function matrixJson(report) {
293
364
  return {
@@ -297,7 +368,7 @@ export function matrixJson(report) {
297
368
  collisions: w.collisions.map((c) => ({
298
369
  a: c.a.id,
299
370
  b: c.b.id,
300
- overlaps: c.overlaps.map((o) => ({ patterns: o.patterns, witness: o.witness })),
371
+ overlaps: c.overlaps.map(overlapJson),
301
372
  })),
302
373
  undecided: w.undecided.map((u) => ({ a: u.a.id, b: u.b.id, patterns: u.patterns })),
303
374
  sharedDirectories: w.shared.map((s) => ({ a: s.a.id, b: s.b.id, directories: s.directories })),
@@ -323,21 +394,20 @@ function wavesOf(s) {
323
394
  export function prettySchedule(s, written, style) {
324
395
  const label = (b) => b.id ?? b.name;
325
396
  const out = [];
326
- const width = Math.max(3, ...s.placements.map((p) => label(p.brief).length));
327
- const titleOf = (b) => b.title ?? b.name;
328
- const titles = Math.max(0, ...s.placements.map((p) => titleOf(p.brief).length));
397
+ const width = Math.max(3, ...s.placements.map((p) => displayWidth(label(p.brief))));
398
+ const titles = Math.max(0, ...s.placements.map((p) => displayWidth(shownTitle(p.brief))));
329
399
  const waves = wavesOf(s);
330
400
  for (const wave of waves) {
331
401
  const here = s.placements.filter((p) => p.proposed === wave);
332
402
  out.push(paint(style, 'bold', `wave ${wave} · ${plural(here.length, 'brief')}`));
333
403
  for (const p of here) {
334
- const title = titleOf(p.brief);
404
+ const title = shownTitle(p.brief);
335
405
  if (p.proposed === p.declared) {
336
- out.push(` ${label(p.brief).padEnd(width)} ${title}`);
406
+ out.push(` ${padEnd(label(p.brief), width)} ${title}`);
337
407
  continue;
338
408
  }
339
409
  const from = p.declared === null ? 'no wave' : `wave ${p.declared}`;
340
- out.push(` ${label(p.brief).padEnd(width)} ${title.padEnd(titles)} ${paint(style, 'yellow', `moves from ${from}`)}`);
410
+ out.push(` ${padEnd(label(p.brief), width)} ${padEnd(title, titles)} ${paint(style, 'yellow', `moves from ${from}`)}`);
341
411
  // Why the declared wave holds or does not comes first: it decides whether the move is asked for.
342
412
  const verdict = p.declared === null ? [] : holds(p) ? [`wave ${p.declared} also holds`] : [`wave ${p.declared} does not hold: ${breachReasons(p).join('; ')}`];
343
413
  for (const reason of [...verdict, ...reasons(p)])
@@ -379,12 +449,12 @@ export function prettySchedule(s, written, style) {
379
449
  /** The schedule as JSON: a row per placed brief with its declared and proposed wave and why. */
380
450
  export function scheduleJson(s) {
381
451
  const breach = (b) => b.reason === 'collision'
382
- ? { reason: b.reason, brief: b.brief.id, overlaps: b.overlaps.map((o) => ({ patterns: o.patterns, witness: o.witness })) }
452
+ ? { reason: b.reason, brief: b.brief.id, overlaps: b.overlaps.map(overlapJson) }
383
453
  : { reason: b.reason, brief: b.brief.id, wave: b.wave };
384
454
  const passed = (p) => {
385
455
  const base = { wave: p.wave, reason: p.reason, brief: p.brief.id };
386
456
  if (p.reason === 'collision')
387
- return { ...base, overlaps: p.overlaps.map((o) => ({ patterns: o.patterns, witness: o.witness })) };
457
+ return { ...base, overlaps: p.overlaps.map(overlapJson) };
388
458
  if (p.reason === 'undecided')
389
459
  return { ...base, patterns: p.patterns };
390
460
  return base;