glosslint 0.0.1 → 0.1.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.
@@ -0,0 +1,1872 @@
1
+ import { t as corpus } from "./inclusive-CP6oU8NW.mjs";
2
+ import { t as corpus$1 } from "./tech-D0v3ss45.mjs";
3
+ import { splitByCase } from "scule";
4
+ import { existsSync, readFileSync } from "node:fs";
5
+ import { isAbsolute, relative, resolve } from "node:path";
6
+ import { fileURLToPath } from "node:url";
7
+ // src/errors.ts
8
+ /** A problem in the corpus or the config, with what to change. */
9
+ var GlosslintConfigError = class extends Error {
10
+ /** A stable code, such as `GLOSSLINT_C005`. */
11
+ code;
12
+ /** Why the config is wrong. */
13
+ why;
14
+ /** What to change. */
15
+ fix;
16
+ /** The term the problem is in, when it is in one. */
17
+ term;
18
+ constructor(options) {
19
+ super(options.term ? `${options.why} (term "${options.term}")` : options.why);
20
+ this.name = "GlosslintConfigError";
21
+ this.code = options.code;
22
+ this.why = options.why;
23
+ this.fix = options.fix;
24
+ if (options.term !== void 0) this.term = options.term;
25
+ }
26
+ };
27
+ // src/words.ts
28
+ const SEPARATORS = [
29
+ " ",
30
+ " ",
31
+ "\n",
32
+ "-",
33
+ "‐",
34
+ "‑",
35
+ "_",
36
+ "/",
37
+ "."
38
+ ];
39
+ /** Splits text or an identifier into words: `dayPass`, `day-pass` and `day pass` all give day, pass. */
40
+ function splitWords(text) {
41
+ return splitByCase(text.trim(), SEPARATORS).filter((word) => word.length > 0);
42
+ }
43
+ /** A term's key: its words joined and lowercased, letters and digits only, so `Re-charge point` and `recharge point` share one. */
44
+ function termKey(text) {
45
+ return splitWords(text).join("").toLowerCase().replace(/[^\p{L}\p{N}]/gu, "");
46
+ }
47
+ /**
48
+ * Starts a reason that opens a sentence with a capital, so "riders confuse it" reads "Riders confuse it". A
49
+ * first word with a capital of its own, such as `eBike`, stays as written.
50
+ */
51
+ function capitalise(text) {
52
+ return text.replace(/^(\s*)(\p{Ll})(?=[\p{Ll}\p{N}'’-]*(?![\p{L}\p{N}]))/u, (_, space, letter) => space + letter.toUpperCase());
53
+ }
54
+ /** A word of shown text, for case styles: a letter, then letters, digits, periods and apostrophes. */
55
+ const WORD = /\p{L}[\p{L}\p{N}.'’]*/gu;
56
+ /** English words that Title Case leaves lowercase past a label's first word. */
57
+ const SMALL_WORDS = /* @__PURE__ */ new Set([
58
+ "a",
59
+ "an",
60
+ "and",
61
+ "as",
62
+ "at",
63
+ "by",
64
+ "for",
65
+ "from",
66
+ "in",
67
+ "of",
68
+ "on",
69
+ "or",
70
+ "per",
71
+ "the",
72
+ "to",
73
+ "via",
74
+ "vs",
75
+ "with"
76
+ ]);
77
+ const isUpper = (char) => char !== char.toLowerCase() && char === char.toUpperCase();
78
+ /** Whether every word but a small one past the first starts with a capital, as "Buy a Day Pass" does. */
79
+ function isTitled(text) {
80
+ const words = text.match(WORD) ?? [];
81
+ return words.length > 1 && words.every((word, index) => isUpper(word.charAt(0)) || index > 0 && SMALL_WORDS.has(word));
82
+ }
83
+ /** Characters allowed between the words of one term: spaces, hyphens and underscores. */
84
+ const WORD_GAP = /^[\s\-‐‑_]+$/;
85
+ const TOKEN = /[\p{L}\p{N}](?:[\p{L}\p{N}.]*[\p{L}\p{N}])?/gu;
86
+ const APOSTROPHE = /['’]/;
87
+ const PLACEHOLDER = /\{\{[\s\S]*?\}\}|\{\s*[\p{L}\p{N}_$.-]+\s*(?:,\s*(?:number|date|time)[^{}]*)?\}/gu;
88
+ const ICU_HEAD = /\{\s*[\p{L}\p{N}_$.-]+\s*,\s*(?:plural|select|selectordinal)\s*,/gu;
89
+ const ICU_BRANCH = /(?:=\d+|[\p{L}\p{N}_]+)\s*\{|[{}#]/gu;
90
+ const URL = /\b[a-z][a-z\d+.-]*:\/\/[^\s<>"'`)\]]*|\bwww\.[^\s<>"'`)\]]+|\bmailto:[^\s<>"'`)\]]+|[\w.+-]+@[\w-]+(?:\.[\w-]+)+/giu;
91
+ const BACKTICKS = /(`+)[\s\S]*?\1/gu;
92
+ const PATH = /(?<![\p{L}\p{N}.~])(?:\.{1,2}|~)?\/[\p{L}\p{N}_.~/-]+/gu;
93
+ const CHUNK = /[\p{L}\p{N}_]+(?:[-.][\p{L}\p{N}_]+)*/gu;
94
+ const CAMEL = /\p{Ll}\p{Lu}/u;
95
+ const SLUG = /^[\p{Ll}\p{N}]+(?:-[\p{Ll}\p{N}]+)+$/u;
96
+ const PATH_EDGE = /[/#@=]/;
97
+ function blank(text, start, end) {
98
+ return text.slice(0, start) + " ".repeat(end - start) + text.slice(end);
99
+ }
100
+ function blankAll(text, pattern) {
101
+ return text.replace(pattern, (match) => " ".repeat(match.length));
102
+ }
103
+ /**
104
+ * Blanks an ICU message's syntax and keeps the words of its branches, such as `docks` in
105
+ * `{n, plural, other {# docks}}`. Odd brace depth is an argument, even depth is branch text.
106
+ * Returns undefined when the braces don't balance.
107
+ */
108
+ function maskIcu(text) {
109
+ let depth = 0;
110
+ let out = "";
111
+ for (const char of text) {
112
+ if (char === "{") depth++;
113
+ else if (char === "}" && --depth < 0) return void 0;
114
+ const keep = char !== "{" && char !== "}" && (depth === 0 || depth % 2 === 0 && char !== "#");
115
+ out += keep ? char : " ".repeat(char.length);
116
+ }
117
+ return depth === 0 ? out : void 0;
118
+ }
119
+ /** Whether a token with this key is spared from masking because it names an exact term, singular or plural. */
120
+ function isKept(key, keep) {
121
+ return keep.has(key) || key.endsWith("s") && keep.has(key.slice(0, -1)) || key.endsWith("es") && keep.has(key.slice(0, -2));
122
+ }
123
+ /**
124
+ * Blanks out what is code rather than words, keeping every offset: placeholders, URLs, paths, backtick
125
+ * code, and camel, snake and slug tokens unless their key is in `keep`.
126
+ */
127
+ function mask(text, keep = /* @__PURE__ */ new Set()) {
128
+ let out = blankAll(text, BACKTICKS);
129
+ out = blankAll(out, URL);
130
+ out = blankAll(out, PATH);
131
+ if (out.search(ICU_HEAD) !== -1) {
132
+ const icu = maskIcu(out);
133
+ if (icu !== void 0) out = icu;
134
+ else {
135
+ out = blankAll(out, ICU_HEAD);
136
+ out = blankAll(out, ICU_BRANCH);
137
+ }
138
+ }
139
+ out = blankAll(out, PLACEHOLDER);
140
+ for (const match of out.matchAll(CHUNK)) {
141
+ const chunk = match[0];
142
+ const start = match.index;
143
+ const end = start + chunk.length;
144
+ if (chunk.includes("_")) {
145
+ if (!isKept(termKey(chunk), keep)) out = blank(out, start, end);
146
+ continue;
147
+ }
148
+ if (SLUG.test(chunk) && (chunk.split("-").length >= 3 || PATH_EDGE.test(text[start - 1] ?? "") || PATH_EDGE.test(text[end] ?? ""))) {
149
+ if (!isKept(termKey(chunk), keep)) out = blank(out, start, end);
150
+ continue;
151
+ }
152
+ let offset = start;
153
+ for (const part of chunk.split(/([-.])/)) {
154
+ if (CAMEL.test(part) && !isKept(termKey(part), keep)) out = blank(out, offset, offset + part.length);
155
+ offset += part.length;
156
+ }
157
+ }
158
+ return out;
159
+ }
160
+ /**
161
+ * The words of `text` with their offsets, after `mask`. A word right after an apostrophe that follows
162
+ * a letter, such as the `s` of a possessive or the `t` of `don't`, never forms a token.
163
+ */
164
+ function tokenize(text, keep = /* @__PURE__ */ new Set()) {
165
+ const masked = mask(text, keep);
166
+ const tokens = [];
167
+ for (const match of masked.matchAll(TOKEN)) {
168
+ const start = match.index;
169
+ if (APOSTROPHE.test(text[start - 1] ?? "") && /\p{L}/u.test(text[start - 2] ?? "")) continue;
170
+ const word = match[0];
171
+ tokens.push({
172
+ word,
173
+ key: word.toLowerCase().replace(/[^\p{L}\p{N}]/gu, ""),
174
+ start,
175
+ end: start + word.length
176
+ });
177
+ }
178
+ return tokens;
179
+ }
180
+ // src/corpus.ts
181
+ const INPUT_FIELDS = [
182
+ "extends",
183
+ "terms",
184
+ "allow",
185
+ "casing",
186
+ "wholeLabel"
187
+ ];
188
+ const TERM_FIELDS$1 = [
189
+ "term",
190
+ "description",
191
+ "nuance",
192
+ "why",
193
+ "abbr",
194
+ "avoid",
195
+ "examples",
196
+ "links",
197
+ "case",
198
+ "casing",
199
+ "skip",
200
+ "forms",
201
+ "translations"
202
+ ];
203
+ const AVOID_FIELDS = ["word", "why"];
204
+ const LINK_FIELDS = ["title", "url"];
205
+ const EXAMPLE_FIELDS = ["good", "bad"];
206
+ const CASE_MODES$1 = [
207
+ "exact",
208
+ "spelling",
209
+ "context"
210
+ ];
211
+ const SKIPS = ["lower", "upper"];
212
+ const CASING_KINDS = [
213
+ "label",
214
+ "header",
215
+ "sentence"
216
+ ];
217
+ const CASE_STYLES = [
218
+ "title",
219
+ "sentence",
220
+ "lower",
221
+ "upper",
222
+ "as-written"
223
+ ];
224
+ /** Stable codes of `GlosslintConfigError`. */
225
+ const CONFIG_ERRORS = {
226
+ unknownField: "GLOSSLINT_C001",
227
+ missingTerm: "GLOSSLINT_C002",
228
+ badCase: "GLOSSLINT_C003",
229
+ avoidIsTerm: "GLOSSLINT_C004",
230
+ duplicateTerm: "GLOSSLINT_C005",
231
+ badSkip: "GLOSSLINT_C006",
232
+ badType: "GLOSSLINT_C007",
233
+ notCorpus: "GLOSSLINT_C008",
234
+ noGlossary: "GLOSSLINT_C009",
235
+ badCasing: "GLOSSLINT_C011",
236
+ glossaryAndCorpus: "GLOSSLINT_C012"
237
+ };
238
+ function distance(a, b) {
239
+ const row = Array.from({ length: b.length + 1 }, (_, index) => index);
240
+ for (let i = 1; i <= a.length; i++) {
241
+ let diagonal = row[0];
242
+ row[0] = i;
243
+ for (let j = 1; j <= b.length; j++) {
244
+ const above = row[j];
245
+ row[j] = Math.min(row[j] + 1, row[j - 1] + 1, diagonal + (a[i - 1] === b[j - 1] ? 0 : 1));
246
+ diagonal = above;
247
+ }
248
+ }
249
+ return row[b.length];
250
+ }
251
+ /** The field nearest to `name` by edit distance, when it is close enough to be a typo. */
252
+ function nearest(name, fields) {
253
+ let best;
254
+ let bestDistance = Infinity;
255
+ for (const field of fields) {
256
+ const d = distance(name.toLowerCase(), field);
257
+ if (d < bestDistance) {
258
+ best = field;
259
+ bestDistance = d;
260
+ }
261
+ }
262
+ return bestDistance <= Math.max(2, Math.floor(name.length / 3)) ? best : void 0;
263
+ }
264
+ function isRecord(value) {
265
+ return typeof value === "object" && value !== null && !Array.isArray(value);
266
+ }
267
+ function quoteList$1(values) {
268
+ const quoted = values.map((value) => `"${value}"`);
269
+ return quoted.length > 1 ? `${quoted.slice(0, -1).join(", ")} or ${quoted.at(-1)}` : quoted[0] ?? "";
270
+ }
271
+ function checkFields(value, fields, where, fail) {
272
+ for (const name of Object.keys(value)) {
273
+ if (fields.includes(name)) continue;
274
+ const near = nearest(name, fields);
275
+ fail(CONFIG_ERRORS.unknownField, `Unknown field "${name}" in ${where}.`, near ? `Rename it to "${near}".` : `Remove it. The fields are ${quoteList$1(fields)}.`);
276
+ }
277
+ }
278
+ function isStringList(value) {
279
+ return Array.isArray(value) && value.every((item) => typeof item === "string" && item.trim() !== "");
280
+ }
281
+ function checkStringList(value, field, fail) {
282
+ if (value !== void 0 && !isStringList(value)) fail(CONFIG_ERRORS.badType, `"${field}" must be a list of non-empty strings.`, `Write it as ["…", "…"].`);
283
+ }
284
+ function checkLocaleMap(value, field, list, fail) {
285
+ if (value === void 0) return;
286
+ if (!(isRecord(value) && Object.values(value).every((item) => list ? isStringList(item) : typeof item === "string"))) fail(CONFIG_ERRORS.badType, `"${field}" must map each locale to ${list ? "a list of strings" : "a string"}.`, list ? `Write it as { de: ["…"] }.` : `Write it as { de: "…" }.`);
287
+ }
288
+ function checkTerm(input, index) {
289
+ const name = isRecord(input) && typeof input.term === "string" ? input.term : void 0;
290
+ const fail = (code, why, fix) => {
291
+ throw new GlosslintConfigError({
292
+ code,
293
+ why,
294
+ fix,
295
+ ...name === void 0 ? {} : { term: name }
296
+ });
297
+ };
298
+ if (!isRecord(input)) fail(CONFIG_ERRORS.badType, `Entry ${index + 1} of "terms" is not an object.`, `Write it as { term: "…" }.`);
299
+ const term = input;
300
+ checkFields(term, TERM_FIELDS$1, name === void 0 ? `entry ${index + 1} of "terms"` : `term "${name}"`, fail);
301
+ if (name === void 0 || termKey(name) === "") fail(CONFIG_ERRORS.missingTerm, name === void 0 ? `Entry ${index + 1} of "terms" has no "term".` : `The term "${name}" has no letters or digits.`, `Add the words to use, such as { term: "Dock" }.`);
302
+ for (const field of [
303
+ "description",
304
+ "nuance",
305
+ "why"
306
+ ]) if (term[field] !== void 0 && typeof term[field] !== "string") fail(CONFIG_ERRORS.badType, `"${field}" must be a string.`, `Write it as one sentence in quotes.`);
307
+ if (term.case !== void 0 && !CASE_MODES$1.includes(term.case)) fail(CONFIG_ERRORS.badCase, `"case" is ${JSON.stringify(term.case)}.`, `Use ${quoteList$1(CASE_MODES$1)}.`);
308
+ checkCasing(term.casing, `term "${name}"`, fail);
309
+ if (term.skip !== void 0) {
310
+ const bad = Array.isArray(term.skip) ? term.skip.find((item) => !SKIPS.includes(item)) : term.skip;
311
+ if (!Array.isArray(term.skip) || bad !== void 0) fail(CONFIG_ERRORS.badSkip, `"skip" has ${JSON.stringify(bad)}.`, `Use a list of ${quoteList$1(SKIPS)}, such as ["lower", "upper"].`);
312
+ }
313
+ checkStringList(term.abbr, "abbr", fail);
314
+ if (term.avoid !== void 0) {
315
+ if (!Array.isArray(term.avoid)) fail(CONFIG_ERRORS.badType, `"avoid" must be a list.`, `Write it as ["word", { word: "…", why: "…" }].`);
316
+ for (const avoid of term.avoid) {
317
+ if (isRecord(avoid)) {
318
+ checkFields(avoid, AVOID_FIELDS, `an avoid word of "${name}"`, fail);
319
+ if (avoid.why !== void 0 && typeof avoid.why !== "string") fail(CONFIG_ERRORS.badType, `The "why" of an avoid word must be a string.`, `Write the reason in quotes.`);
320
+ }
321
+ const word = isRecord(avoid) ? avoid.word : avoid;
322
+ if (typeof word !== "string" || termKey(word) === "") fail(CONFIG_ERRORS.badType, `An avoid word of "${name}" is empty or not a string.`, `Write each one as "word" or { word: "…", why: "…" }.`);
323
+ if (word.trim().replace(/\s+/g, " ").toLowerCase() === name.trim().replace(/\s+/g, " ").toLowerCase()) fail(CONFIG_ERRORS.avoidIsTerm, `"${word}" is both the term and one of its avoid words.`, `Remove it from "avoid". To require one casing, set case: "exact".`);
324
+ }
325
+ }
326
+ if (term.examples !== void 0) {
327
+ if (!isRecord(term.examples)) fail(CONFIG_ERRORS.badType, `"examples" must be an object.`, `Write it as { good: ["…"], bad: ["…"] }.`);
328
+ checkFields(term.examples, EXAMPLE_FIELDS, `the examples of "${name}"`, fail);
329
+ checkStringList(term.examples.good, "examples.good", fail);
330
+ checkStringList(term.examples.bad, "examples.bad", fail);
331
+ }
332
+ if (term.links !== void 0) {
333
+ if (!Array.isArray(term.links)) fail(CONFIG_ERRORS.badType, `"links" must be a list.`, `Write it as [{ title: "…", url: "https://…" }].`);
334
+ for (const link of term.links) {
335
+ if (!isRecord(link)) fail(CONFIG_ERRORS.badType, `A link of "${name}" is not an object.`, `Write it as { title: "…", url: "https://…" }.`);
336
+ checkFields(link, LINK_FIELDS, `a link of "${name}"`, fail);
337
+ if (typeof link.title !== "string" || typeof link.url !== "string") fail(CONFIG_ERRORS.badType, `A link of "${name}" needs a "title" and a "url".`, `Write it as { title: "…", url: "https://…" }.`);
338
+ }
339
+ }
340
+ checkLocaleMap(term.forms, "forms", true, fail);
341
+ checkLocaleMap(term.translations, "translations", false, fail);
342
+ return term;
343
+ }
344
+ function checkCasing(value, where, fail) {
345
+ if (value === void 0) return;
346
+ if (!isRecord(value)) fail(CONFIG_ERRORS.badCasing, `"casing" of ${where} must be an object.`, `Write it as { label: "title", header: "upper", sentence: "sentence" }.`);
347
+ for (const [kind, style] of Object.entries(value)) {
348
+ if (!CASING_KINDS.includes(kind)) fail(CONFIG_ERRORS.badCasing, `"casing" of ${where} has the kind "${kind}".`, `Use ${quoteList$1(CASING_KINDS)}.`);
349
+ if (!CASE_STYLES.includes(style)) fail(CONFIG_ERRORS.badCasing, `"casing.${kind}" of ${where} is ${JSON.stringify(style)}.`, `Use ${quoteList$1(CASE_STYLES)}.`);
350
+ }
351
+ }
352
+ function isCorpus(value) {
353
+ return isRecord(value) && value.kind === "glosslint.corpus" && Array.isArray(value.terms) && Array.isArray(value.allow);
354
+ }
355
+ /**
356
+ * Sets `key` and moves it to the end, so `terms` lists them from lowest to highest precedence and a term's
357
+ * abbreviations and avoid words beat those of the terms before it.
358
+ */
359
+ function setLast(map, key, term) {
360
+ map.delete(key);
361
+ map.set(key, term);
362
+ }
363
+ /** Validates a corpus, merges what it extends, and returns it flat. Throws a `GlosslintConfigError` on a bad term. */
364
+ function defineCorpus(input) {
365
+ const fail = (code, why, fix) => {
366
+ throw new GlosslintConfigError({
367
+ code,
368
+ why,
369
+ fix
370
+ });
371
+ };
372
+ const raw = input;
373
+ if (!isRecord(raw)) fail(CONFIG_ERRORS.badType, `defineCorpus takes an object.`, `Pass { extends, terms, allow }.`);
374
+ checkFields(raw, INPUT_FIELDS, "the corpus", fail);
375
+ if (input.extends !== void 0 && !Array.isArray(input.extends)) fail(CONFIG_ERRORS.badType, `"extends" must be a list of corpora.`, `Write it as [tech, inclusive].`);
376
+ if (input.terms !== void 0 && !Array.isArray(input.terms)) fail(CONFIG_ERRORS.badType, `"terms" must be a list.`, `Write it as [{ term: "…" }].`);
377
+ checkStringList(input.allow, "allow", fail);
378
+ checkCasing(input.casing, "the corpus", fail);
379
+ if (input.wholeLabel !== void 0 && typeof input.wholeLabel !== "boolean") fail(CONFIG_ERRORS.badType, `"wholeLabel" must be true or false.`, `Write it as wholeLabel: true.`);
380
+ const merged = /* @__PURE__ */ new Map();
381
+ const allow = [];
382
+ const casing = {};
383
+ let wholeLabel;
384
+ for (const [index, corpus] of (input.extends ?? []).entries()) {
385
+ if (!isCorpus(corpus)) fail(CONFIG_ERRORS.notCorpus, `Entry ${index + 1} of "extends" is not a corpus.`, `Pass a preset, fromGlossary(…) or the result of defineCorpus(…).`);
386
+ for (const term of corpus.terms) setLast(merged, termKey(term.term), term);
387
+ allow.push(...corpus.allow);
388
+ Object.assign(casing, corpus.casing);
389
+ wholeLabel = corpus.wholeLabel ?? wholeLabel;
390
+ }
391
+ const own = /* @__PURE__ */ new Map();
392
+ for (const [index, raw] of (input.terms ?? []).entries()) {
393
+ const term = checkTerm(raw, index);
394
+ const key = termKey(term.term);
395
+ const previous = own.get(key);
396
+ if (previous) throw new GlosslintConfigError({
397
+ code: CONFIG_ERRORS.duplicateTerm,
398
+ why: `"${previous.term}" and "${term.term}" are the same words, so they are one term.`,
399
+ fix: `Keep one of them. A spelling to report goes in that term's "avoid" list.`,
400
+ term: term.term
401
+ });
402
+ own.set(key, term);
403
+ }
404
+ for (const [key, term] of own) setLast(merged, key, term);
405
+ allow.push(...input.allow ?? []);
406
+ Object.assign(casing, input.casing);
407
+ wholeLabel = input.wholeLabel ?? wholeLabel;
408
+ return Object.freeze({
409
+ kind: "glosslint.corpus",
410
+ terms: Object.freeze([...merged.values()]),
411
+ allow: Object.freeze(allow),
412
+ ...Object.keys(casing).length > 0 ? { casing: Object.freeze(casing) } : {},
413
+ ...wholeLabel !== void 0 ? { wholeLabel } : {}
414
+ });
415
+ }
416
+ // src/kind.ts
417
+ const LABEL_WORD = /^(?:label|(?:sub)?title|button|tab|(?:sub)?heading)s?$/;
418
+ const HEADER_WORD = /^(?:header|column|col|th)s?$/;
419
+ const SENTENCE_WORD = /^(?:description|tooltip|text|message|intro|outro|hint|explanation|body|help)s?$/;
420
+ const HEADING_TAG = /^h[1-6]$/i;
421
+ /** First words that open a sentence rather than a label, as in "There are no rides". English only. */
422
+ const SENTENCE_OPENER = /^(?:there|this|that|these|those|it|you|we|they|i|is|are|was|were|do|does|did|can|could|will|would|should|has|have)$/i;
423
+ /** The kind a site's name gives it, with a closing stop always making a sentence. */
424
+ function byName(name, text) {
425
+ const trimmed = text.trim();
426
+ const endsSentence = /[.!?]$/.test(trimmed);
427
+ const words = splitWords(name ?? "").map((word) => HEADING_TAG.test(word) ? "heading" : word.toLowerCase().replace(/\d+$/, ""));
428
+ const last = words.at(-1) ?? "";
429
+ const header = words.some((word) => HEADER_WORD.test(word));
430
+ if ((header || words.some((word) => LABEL_WORD.test(word)) || last === "name") && !endsSentence && splitWords(trimmed).length <= 7) return header ? "header" : "label";
431
+ if (words.some((word) => SENTENCE_WORD.test(word)) || endsSentence) return "sentence";
432
+ return "unknown";
433
+ }
434
+ /**
435
+ * The kind of shown text from its shape alone: a label when it is a few words that don't open like a
436
+ * sentence, or when it is written in Title Case, else a sentence.
437
+ */
438
+ function byShape(text) {
439
+ const trimmed = text.trim().replace(/:$/, "");
440
+ const words = trimmed.split(/\s+/);
441
+ return words.length <= 4 && !SENTENCE_OPENER.test(words[0]) || isTitled(trimmed.replace(/\([^)]*\)/g, "")) ? "label" : "sentence";
442
+ }
443
+ /** Decides a site's kind: `custom` first, then the site's name, then, for shown text, its shape. */
444
+ function classify(site, custom) {
445
+ const own = custom?.(site);
446
+ if (own !== void 0) return {
447
+ kind: own,
448
+ guessed: false
449
+ };
450
+ const named = byName(site.name, site.text);
451
+ if (named !== "unknown" || !site.shown) return {
452
+ kind: named,
453
+ guessed: false
454
+ };
455
+ return {
456
+ kind: byShape(site.text),
457
+ guessed: true
458
+ };
459
+ }
460
+ /**
461
+ * glosslint's default kind for a string: from its key, attribute or element name, else from a closing
462
+ * stop, else, when `shown` is set, from its length and capitals. Every adapter uses it unless its
463
+ * `kindOf` option decides first.
464
+ */
465
+ function kindOf(site) {
466
+ return classify(site).kind;
467
+ }
468
+ /** How a term's capitals are checked: its `case`, else `context` when it sets `casing`, else `spelling`. */
469
+ function caseModeOf(term) {
470
+ return term.case ?? (term.casing ? "context" : "spelling");
471
+ }
472
+ // src/matcher.ts
473
+ const ALNUM = /[\p{L}\p{N}]/u;
474
+ const hasLower = (text) => /\p{Ll}/u.test(text);
475
+ const isAllCaps = (text) => /\p{Lu}.*\p{Lu}/u.test(text) && !hasLower(text);
476
+ const upperFirst = (text) => text.charAt(0).toUpperCase() + text.slice(1);
477
+ /** Keeps a word's capitals when it has one past its first letter, such as `DP` or `eBike`. */
478
+ const keepsCapitals = (word) => /^.+\p{Lu}/u.test(word);
479
+ /**
480
+ * Words in parentheses keep their case ("(from dock)"), and the first word after a dash or colon
481
+ * starts again, as in "Rentals - At Another Dock".
482
+ */
483
+ function titleCase(text) {
484
+ return text.replace(WORD, (word, offset) => {
485
+ const before = text.slice(0, offset);
486
+ if (before.split("(").length > before.split(")").length) return word;
487
+ if (!(!/\p{L}/u.test(before) || /[-–—:]\s*$/.test(before)) && SMALL_WORDS.has(word.toLowerCase())) return word.toLowerCase();
488
+ return word === word.toLowerCase() ? upperFirst(word) : word;
489
+ });
490
+ }
491
+ function lowerCase(text) {
492
+ return text.replace(WORD, (word) => keepsCapitals(word) ? word : word.toLowerCase());
493
+ }
494
+ function sentenceCase(text, atStart) {
495
+ const lower = lowerCase(text);
496
+ return atStart ? upperFirst(lower) : lower;
497
+ }
498
+ function applyStyle(style, text, atStart) {
499
+ if (style === "title") return titleCase(text);
500
+ if (style === "sentence") return sentenceCase(text, atStart);
501
+ if (style === "lower") return lowerCase(text);
502
+ if (style === "upper") return text.toUpperCase();
503
+ return text;
504
+ }
505
+ function squash$2(text) {
506
+ return text.toLowerCase().replace(/\s+/g, " ");
507
+ }
508
+ /** Words joined by single spaces, without periods, so `Approx. time` and `Approx-time` compare equal. */
509
+ function spaced(text) {
510
+ return text.replace(/\./g, "").replace(/[\s\-‐‑_]+/g, " ").trim();
511
+ }
512
+ /** Whether `written` is `word` with some of its periods left out, ignoring case and word gaps. */
513
+ function periodsFit(written, word) {
514
+ const flat = (text) => text.toLowerCase().replace(/(?<=[\p{L}\p{N}])\.(?=[\p{L}\p{N}])/gu, "").replace(/[\s\-‐‑_]+/g, "");
515
+ const w = flat(written);
516
+ const a = flat(word);
517
+ let j = 0;
518
+ for (const char of a) if (char === w[j]) j++;
519
+ else if (char !== ".") return false;
520
+ return j === w.length;
521
+ }
522
+ /** Splits `C++` into "", "C" and "++": the symbols before the first letter or digit, the rest, and the symbols after the last. */
523
+ function symbols(text) {
524
+ const lead = /^[^\p{L}\p{N}]*/u.exec(text)[0];
525
+ const trail = /[^\p{L}\p{N}]*$/u.exec(text.slice(lead.length))[0];
526
+ return {
527
+ lead,
528
+ core: text.slice(lead.length, text.length - trail.length),
529
+ trail
530
+ };
531
+ }
532
+ /** Writes `canonical` with the writer's capitals: each word starts as the writer's letter at that place does. */
533
+ function keepCapitals(canonical, surface) {
534
+ if (isAllCaps(surface)) return canonical.toUpperCase();
535
+ const letters = Array.from(surface).filter((char) => ALNUM.test(char));
536
+ const chars = Array.from(canonical);
537
+ let index = 0;
538
+ let out = "";
539
+ for (const [position, char] of chars.entries()) {
540
+ if (!ALNUM.test(char)) {
541
+ out += char;
542
+ continue;
543
+ }
544
+ const wordStart = position === 0 || !ALNUM.test(chars[position - 1]);
545
+ const written = letters[index++];
546
+ out += wordStart && written !== void 0 ? isUpper(written) ? char.toUpperCase() : char.toLowerCase() : char;
547
+ }
548
+ return index === letters.length ? out : canonical;
549
+ }
550
+ function plural(word) {
551
+ const ending = /(?:s|x|z|ch|sh)$/i.test(word) ? "es" : "s";
552
+ return word + (isAllCaps(word) ? ending.toUpperCase() : ending);
553
+ }
554
+ function withSuffix(replace, suffix, abbr) {
555
+ if (suffix === "") return replace;
556
+ if (hasLower(replace) || abbr) return replace + suffix.toLowerCase();
557
+ return replace + suffix;
558
+ }
559
+ /** Words whose period ends the word, not the sentence, beside those the corpus writes with one, such as `hrs.`. */
560
+ const DOTTED_WORDS = [
561
+ "e.g.",
562
+ "i.e.",
563
+ "vs.",
564
+ "approx.",
565
+ "incl.",
566
+ "excl.",
567
+ "avg.",
568
+ "no."
569
+ ];
570
+ /**
571
+ * Whether a term at `start` begins a sentence. After a colon, either case is right, so the writer's
572
+ * first letter decides. A period after a word in `dotted`, such as `hrs.`, ends no sentence.
573
+ */
574
+ function atSentenceStart(text, start, dotted) {
575
+ const before = text.slice(0, start);
576
+ if (/^[\s\p{Ps}\p{Pi}"'*_•-]*$/u.test(before)) return true;
577
+ if (/\|\s*[\p{Ps}\p{Pi}"'*_]*$/u.test(before)) return true;
578
+ const end = /(\S*)([.!?:])["'\p{Pf}\p{Pe}]*\s+[\p{Ps}\p{Pi}"'*_]*$/u.exec(before);
579
+ if (!end) return false;
580
+ if (end[2] === ":") return isUpper(text.charAt(start));
581
+ return !(end[2] === "." && dotted.has(`${end[1].toLowerCase()}.`));
582
+ }
583
+ function endSentence(text) {
584
+ const trimmed = text.trim().replace(/\s+/g, " ");
585
+ return /[.!?:]$/.test(trimmed) ? trimmed : `${trimmed}.`;
586
+ }
587
+ function makeFinding(code, start, end, text, term, headline, fix, reason) {
588
+ const see = term.links?.[0]?.url;
589
+ const why = reason ?? term.nuance;
590
+ return {
591
+ code,
592
+ start,
593
+ end,
594
+ text,
595
+ message: [
596
+ headline,
597
+ reason && endSentence(capitalise(reason)),
598
+ term.description && `${term.term}: ${endSentence(term.description)}`,
599
+ term.nuance && term.nuance !== reason ? endSentence(term.nuance) : void 0,
600
+ see && `See ${see}`
601
+ ].filter(Boolean).join(" "),
602
+ ...why ? { why } : {},
603
+ ...fix ? { fix } : {},
604
+ term,
605
+ ...see ? { see } : {}
606
+ };
607
+ }
608
+ /** Finds a key in `map`, as written or as a plural ending in `s` or `es`. */
609
+ function lookup(map, key) {
610
+ const exact = map.get(key);
611
+ if (exact) return {
612
+ value: exact,
613
+ suffix: 0
614
+ };
615
+ if (key.length > 2 && key.endsWith("s")) {
616
+ const single = map.get(key.slice(0, -1));
617
+ if (single) return {
618
+ value: single,
619
+ suffix: 1
620
+ };
621
+ const es = key.endsWith("es") ? map.get(key.slice(0, -2)) : void 0;
622
+ if (es) return {
623
+ value: es,
624
+ suffix: 2
625
+ };
626
+ }
627
+ }
628
+ /** The longest run of words from `index` whose joined key `find` knows, up to `max` words. */
629
+ function longest(text, words, index, max, gap, find, accept = (hit) => hit) {
630
+ let count = 1;
631
+ while (count < max && index + count < words.length && gap(text.slice(words[index + count - 1].end, words[index + count].start))) count++;
632
+ for (let n = count; n >= 1; n--) {
633
+ const run = words.slice(index, index + n);
634
+ const found = find(run.map((word) => word.key).join(""));
635
+ const start = run[0].start;
636
+ const end = run.at(-1).end;
637
+ for (const candidate of [found].flat()) {
638
+ if (!candidate) continue;
639
+ const hit = accept({
640
+ value: candidate.value,
641
+ start,
642
+ end,
643
+ next: index + n,
644
+ suffix: text.slice(end - candidate.suffix, end)
645
+ });
646
+ if (hit) return hit;
647
+ }
648
+ }
649
+ }
650
+ function identifierWords(text) {
651
+ const words = [];
652
+ let cursor = 0;
653
+ for (const word of splitWords(text)) {
654
+ const found = text.indexOf(word, cursor);
655
+ if (found === -1) continue;
656
+ cursor = found + word.length;
657
+ const lead = /^[^\p{L}\p{N}]*/u.exec(word)?.[0].length ?? 0;
658
+ const trail = /[^\p{L}\p{N}]*$/u.exec(word)?.[0].length ?? 0;
659
+ const start = found + lead;
660
+ const end = Math.max(start, cursor - trail);
661
+ const key = word.toLowerCase().replace(/[^\p{L}\p{N}]/gu, "");
662
+ if (key) words.push({
663
+ key,
664
+ start,
665
+ end
666
+ });
667
+ }
668
+ return words;
669
+ }
670
+ /**
671
+ * The separator `part` uses: `_` or `-` between its words, none between camel humps, and for a
672
+ * single word the one joining it to a neighbouring word of `identifier`. A leading `_`, as in
673
+ * `_dockCount`, joins no words, so it is not a separator.
674
+ */
675
+ function separatorOf(part, identifier, start, end) {
676
+ const inner = /[\p{L}\p{N}]([_-])[\p{L}\p{N}]/u.exec(part)?.[1];
677
+ if (inner) return inner;
678
+ if (splitWords(part).length > 1) return "";
679
+ const before = identifier[start - 1] ?? "";
680
+ if (/[_-]/.test(before) && ALNUM.test(identifier[start - 2] ?? "")) return before;
681
+ const after = identifier[end] ?? "";
682
+ if (/[_-]/.test(after) && ALNUM.test(identifier[end + 1] ?? "")) return after;
683
+ return "";
684
+ }
685
+ /** Writes words in the casing style of `part`, the matched words of an identifier: snake, kebab or camel. */
686
+ function identifierStyle(words, part, separator) {
687
+ if (isAllCaps(part)) return words.join(separator || "_").toUpperCase();
688
+ if (separator) return words.join(separator);
689
+ const camel = words.map((word, index) => index === 0 ? word : upperFirst(word)).join("");
690
+ return isUpper(part.charAt(0)) ? upperFirst(camel) : camel;
691
+ }
692
+ function allowPattern(phrase) {
693
+ const body = phrase.trim().split(/\s+/).map((word) => word.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("[\\s\\-‐‑_]+");
694
+ return new RegExp(`(?<![\\p{L}\\p{N}])${body}(?:e?s)?(?![\\p{L}\\p{N}])`, "giu");
695
+ }
696
+ /** Compiles a corpus for matching. Build it once and reuse it. */
697
+ function createMatcher(corpus, options = {}) {
698
+ const terms = /* @__PURE__ */ new Map();
699
+ const abbrs = /* @__PURE__ */ new Map();
700
+ const keep = /* @__PURE__ */ new Set();
701
+ let maxWords = 1;
702
+ for (const term of corpus.terms) {
703
+ const key = termKey(term.term);
704
+ const { lead, core, trail } = symbols(term.term);
705
+ const entry = {
706
+ term,
707
+ canonical: term.term,
708
+ mode: caseModeOf(term),
709
+ skip: new Set(term.skip),
710
+ words: splitWords(core || term.term).map((word) => word.toLowerCase()),
711
+ lead,
712
+ trail
713
+ };
714
+ terms.set(key, entry);
715
+ if (entry.mode === "exact") keep.add(key);
716
+ maxWords = Math.max(maxWords, entry.words.length);
717
+ for (const abbr of term.abbr ?? []) {
718
+ const abbrKey = termKey(abbr);
719
+ const parts = symbols(abbr);
720
+ const words = splitWords(parts.core || abbr).map((w) => w.toLowerCase());
721
+ abbrs.set(abbrKey, {
722
+ ...entry,
723
+ canonical: abbr,
724
+ mode: "abbr",
725
+ words,
726
+ lead: parts.lead,
727
+ trail: parts.trail
728
+ });
729
+ keep.add(abbrKey);
730
+ maxWords = Math.max(maxWords, words.length);
731
+ }
732
+ }
733
+ const avoids = /* @__PURE__ */ new Map();
734
+ let maxAvoidWords = 1;
735
+ for (const entry of terms.values()) for (const avoid of entry.term.avoid ?? []) {
736
+ const { word, why } = typeof avoid === "string" ? {
737
+ word: avoid,
738
+ why: void 0
739
+ } : avoid;
740
+ const key = termKey(word);
741
+ if (terms.has(key)) continue;
742
+ avoids.delete(key);
743
+ avoids.set(key, {
744
+ term: entry.term,
745
+ entry,
746
+ word,
747
+ ...why ? { why } : {},
748
+ caseSensitive: /\p{Lu}{2}/u.test(word)
749
+ });
750
+ maxAvoidWords = Math.max(maxAvoidWords, splitWords(word).length);
751
+ }
752
+ const allow = corpus.allow.map(allowPattern);
753
+ const dotted = new Set(DOTTED_WORDS);
754
+ for (const written of [...[...terms.values(), ...abbrs.values()].map((entry) => entry.canonical), ...[...avoids.values()].map((avoid) => avoid.word)]) {
755
+ const last = written.split(/\s+/).at(-1);
756
+ if (last.endsWith(".")) dotted.add(last.toLowerCase());
757
+ }
758
+ const startsSentence = (text, start) => atSentenceStart(text, start, dotted);
759
+ const casing = corpus.casing ?? {};
760
+ /** The case style of `term` in `kind` of text, or undefined where casing isn't checked. */
761
+ const styleOf = (term, kind) => {
762
+ const own = term.casing ?? {};
763
+ if (kind === "header") return own.header ?? casing.header ?? own.label ?? casing.label ?? "title";
764
+ if (kind === "label") return own.label ?? casing.label ?? "title";
765
+ if (kind === "sentence") return own.sentence ?? casing.sentence ?? "sentence";
766
+ };
767
+ const termLimit = maxWords + 1;
768
+ const avoidLimit = maxAvoidWords + 1;
769
+ const textGap = (between) => WORD_GAP.test(between);
770
+ const avoidGap = (between) => WORD_GAP.test(between.replace(/^\./, ""));
771
+ const findTerm = (key) => [lookup(terms, key), lookup(abbrs, key)];
772
+ const withSymbols = (text) => (hit) => {
773
+ const { lead, trail } = hit.value;
774
+ if (lead === "" && trail === "") return hit;
775
+ if (trail !== "" && hit.suffix !== "") return void 0;
776
+ if (text.slice(hit.start - lead.length, hit.start) !== lead) return void 0;
777
+ if (text.slice(hit.end, hit.end + trail.length) !== trail) return void 0;
778
+ return {
779
+ ...hit,
780
+ start: hit.start - lead.length,
781
+ end: hit.end + trail.length
782
+ };
783
+ };
784
+ function termFinding(text, hit, kind) {
785
+ const entry = hit.value;
786
+ const written = text.slice(hit.start, hit.end);
787
+ const surface = written.slice(0, written.length - hit.suffix.length);
788
+ const exact = entry.mode === "exact" || entry.mode === "abbr";
789
+ if (entry.mode === "abbr" && !/\p{Lu}/u.test(surface)) return void 0;
790
+ if (entry.skip.has("lower") && !/\p{Lu}/u.test(surface)) return void 0;
791
+ if (entry.skip.has("upper") && !hasLower(surface)) return void 0;
792
+ const fixable = !/[\r\n]/.test(written);
793
+ const style = styleOf(entry.term, kind);
794
+ const contextWant = entry.mode === "context" && style ? applyStyle(style, entry.canonical, startsSentence(text, hit.start)) : void 0;
795
+ const shouted = style === "upper" && !hasLower(surface);
796
+ if (squash$2(surface) !== squash$2(entry.canonical)) {
797
+ const replace = withSuffix(shouted ? entry.canonical.toUpperCase() : exact ? entry.canonical : contextWant ?? keepCapitals(entry.canonical, surface), hit.suffix, entry.mode === "abbr");
798
+ return makeFinding("GLOSSLINT_TERM", hit.start, hit.end, written, entry.term, `"${written}" is spelled "${replace}".`, fixable ? {
799
+ kind: "autofix",
800
+ replace
801
+ } : void 0);
802
+ }
803
+ if (shouted) return void 0;
804
+ const want = exact ? entry.canonical : contextWant;
805
+ const where = exact || contextWant === void 0 ? "" : ` in ${kind}s`;
806
+ if (want === void 0 || surface.replace(/\s+/g, " ") === want) return void 0;
807
+ const replace = withSuffix(want, hit.suffix, entry.mode === "abbr");
808
+ return makeFinding("GLOSSLINT_CASE", hit.start, hit.end, written, entry.term, `"${written}" is written "${replace}"${where}.`, fixable ? {
809
+ kind: "autofix",
810
+ replace
811
+ } : void 0);
812
+ }
813
+ function avoidFinding(text, hit, kind) {
814
+ const avoid = hit.value;
815
+ const end = hit.suffix === "" && avoid.word.endsWith(".") && text[hit.end] === "." ? hit.end + 1 : hit.end;
816
+ const written = text.slice(hit.start, end);
817
+ const surface = hit.suffix ? written.slice(0, -hit.suffix.length) : written;
818
+ if (!periodsFit(surface, avoid.word)) return void 0;
819
+ if (avoid.caseSensitive && spaced(surface) !== spaced(avoid.word)) return void 0;
820
+ const { entry } = avoid;
821
+ let base;
822
+ const style = styleOf(entry.term, kind);
823
+ if (style === "upper" && (entry.mode === "context" || !hasLower(surface))) base = entry.canonical.toUpperCase();
824
+ else if (entry.mode === "exact" || avoid.caseSensitive) base = entry.canonical;
825
+ else if (entry.mode === "context" && style && kind !== "sentence") base = applyStyle(style, entry.canonical, startsSentence(text, hit.start));
826
+ else if (entry.mode === "context" && style && style !== "sentence") base = applyStyle(style, entry.canonical, false);
827
+ else if (isAllCaps(surface) && hasLower(avoid.word)) base = entry.canonical.toUpperCase();
828
+ else if (isUpper(surface.charAt(0))) base = upperFirst(entry.canonical);
829
+ else base = lowerCase(entry.canonical);
830
+ const replace = hit.suffix ? plural(base) : base;
831
+ const words = splitWords(replace).map((word) => word.toLowerCase());
832
+ const before = /([\p{L}\p{N}]+)\s+$/u.exec(text.slice(0, hit.start))?.[1]?.toLowerCase();
833
+ const after = /^\s+([\p{L}\p{N}]+)/u.exec(text.slice(end))?.[1]?.toLowerCase();
834
+ if (before === words[0] || after === words.at(-1)) return void 0;
835
+ const stop = replace.endsWith(".") && text[end] === "." ? end + 1 : end;
836
+ return makeFinding("GLOSSLINT_AVOID", hit.start, stop, text.slice(hit.start, stop), avoid.term, `Use "${replace}" instead of "${written}".`, {
837
+ kind: "suggestion",
838
+ replace
839
+ }, avoid.why ?? avoid.term.why);
840
+ }
841
+ function checkText(text, kind) {
842
+ const tokens = tokenize(text, keep);
843
+ const accept = withSymbols(text);
844
+ const findings = [];
845
+ for (let index = 0; index < tokens.length;) {
846
+ const hit = longest(text, tokens, index, termLimit, textGap, findTerm, accept);
847
+ if (!hit) {
848
+ index++;
849
+ continue;
850
+ }
851
+ const finding = termFinding(text, hit, kind);
852
+ if (finding) findings.push(finding);
853
+ index = hit.next;
854
+ }
855
+ const findAvoid = (key) => lookup(avoids, key);
856
+ const acceptAvoid = (hit) => avoidFinding(text, hit, kind) ? hit : void 0;
857
+ for (let index = 0; index < tokens.length;) {
858
+ const hit = longest(text, tokens, index, avoidLimit, avoidGap, findAvoid, acceptAvoid);
859
+ const finding = hit && avoidFinding(text, hit, kind);
860
+ if (!hit || !finding) {
861
+ index++;
862
+ continue;
863
+ }
864
+ findings.push(finding);
865
+ index = hit.next;
866
+ }
867
+ const label = labelFinding(text, kind, tokens, findings, accept);
868
+ if (!label?.fix) return label ? [...findings, label] : findings;
869
+ return [...findings.map((finding) => {
870
+ if (finding.fix?.kind !== "autofix") return finding;
871
+ const { fix: _fix, ...rest } = finding;
872
+ return rest;
873
+ }), label];
874
+ }
875
+ /**
876
+ * With `wholeLabel`, a label or header in Title Case or ALL CAPS holding a context term is written in
877
+ * that style as a whole, so fixing the term alone doesn't leave "Day Pass prices".
878
+ */
879
+ function labelFinding(text, kind, tokens, findings, accept) {
880
+ if (!corpus.wholeLabel || kind !== "label" && kind !== "header") return void 0;
881
+ let styled;
882
+ for (let index = 0; index < tokens.length && !styled;) {
883
+ const hit = longest(text, tokens, index, termLimit, textGap, findTerm, accept);
884
+ if (!hit) {
885
+ index++;
886
+ continue;
887
+ }
888
+ const style = styleOf(hit.value.term, kind);
889
+ if (hit.value.mode === "context" && (style === "title" || style === "upper")) styled = {
890
+ term: hit.value.term,
891
+ style
892
+ };
893
+ index = hit.next;
894
+ }
895
+ if (!styled) return void 0;
896
+ let fixed = text;
897
+ let floor = Infinity;
898
+ for (const finding of [...findings].sort((a, b) => b.start - a.start)) {
899
+ if (finding.fix?.kind !== "autofix" || finding.end > floor) continue;
900
+ fixed = fixed.slice(0, finding.start) + finding.fix.replace + fixed.slice(finding.end);
901
+ floor = finding.start;
902
+ }
903
+ const lead = /^\s*/.exec(fixed)[0].length;
904
+ const body = fixed.trim();
905
+ const want = applyStyle(styled.style, body, true);
906
+ if (want === body || /[\r\n{}|]/.test(body)) return void 0;
907
+ const start = /^\s*/.exec(text)[0].length;
908
+ const end = text.trimEnd().length;
909
+ const where = styled.style === "upper" ? "ALL CAPS" : "Title Case";
910
+ return makeFinding("GLOSSLINT_CASE", start, end, text.slice(start, end), styled.term, `"${body}" is written "${want}": ${kind}s are in ${where}.`, lead === start ? {
911
+ kind: "autofix",
912
+ replace: want
913
+ } : void 0);
914
+ }
915
+ function checkIdentifier(text) {
916
+ const words = identifierWords(text);
917
+ const findings = [];
918
+ const anyGap = () => true;
919
+ const spelled = (key) => {
920
+ const found = lookup(terms, key);
921
+ return found && found.value.mode !== "exact" && !found.value.lead && !found.value.trail ? found : void 0;
922
+ };
923
+ for (let index = 0; index < words.length;) {
924
+ const hit = longest(text, words, index, termLimit, anyGap, spelled);
925
+ if (!hit) {
926
+ index++;
927
+ continue;
928
+ }
929
+ index = hit.next;
930
+ const written = text.slice(hit.start, hit.end);
931
+ if (splitWords(written.slice(0, written.length - hit.suffix.length)).map((word) => word.toLowerCase()).join(" ") === hit.value.words.join(" ") || isAllCaps(written) && !/[_-]/.test(written)) continue;
932
+ const separator = separatorOf(written, text, hit.start, hit.end);
933
+ const replace = identifierStyle(hit.value.words, written, separator) + hit.suffix;
934
+ findings.push(makeFinding("GLOSSLINT_TERM", hit.start, hit.end, written, hit.value.term, `Rename "${written}" to "${replace}": the term is "${hit.value.term.term}".`, {
935
+ kind: "rename",
936
+ replace
937
+ }));
938
+ }
939
+ if (!options.identifierAvoid) return findings;
940
+ for (let index = 0; index < words.length;) {
941
+ const hit = longest(text, words, index, avoidLimit, anyGap, (key) => lookup(avoids, key));
942
+ if (!hit) {
943
+ index++;
944
+ continue;
945
+ }
946
+ index = hit.next;
947
+ const written = text.slice(hit.start, hit.end);
948
+ const separator = separatorOf(written, text, hit.start, hit.end);
949
+ const base = identifierStyle(hit.value.entry.words, written, separator);
950
+ const replace = hit.suffix ? plural(base) : base;
951
+ findings.push(makeFinding("GLOSSLINT_AVOID", hit.start, hit.end, written, hit.value.term, `Rename "${written}" to "${replace}".`, {
952
+ kind: "rename",
953
+ replace
954
+ }, hit.value.why ?? hit.value.term.why));
955
+ }
956
+ return findings;
957
+ }
958
+ function allowed(text) {
959
+ const ranges = [];
960
+ for (const pattern of allow) for (const match of text.matchAll(pattern)) ranges.push([match.index, match.index + match[0].length]);
961
+ return ranges;
962
+ }
963
+ return {
964
+ corpus,
965
+ check(text, kind = "unknown") {
966
+ const findings = kind === "identifier" ? checkIdentifier(text) : checkText(text, kind);
967
+ const ranges = findings.length > 0 ? allowed(text) : [];
968
+ return findings.filter((finding) => !ranges.some(([start, end]) => finding.start >= start && finding.end <= end)).sort((a, b) => a.start - b.start || a.code.localeCompare(b.code));
969
+ }
970
+ };
971
+ }
972
+ /** Finds every problem in `text`, read as `kind` (default `unknown`). */
973
+ function check(matcher, text, kind) {
974
+ return matcher.check(text, kind);
975
+ }
976
+ // src/tools.ts
977
+ /** Checks every term's examples: each `bad` one must be reported and each `good` one must not. */
978
+ function testCorpus(corpus) {
979
+ const matcher = createMatcher(corpus);
980
+ const failures = [];
981
+ for (const term of corpus.terms) {
982
+ const key = termKey(term.term);
983
+ const about = (finding) => termKey(finding.term.term) === key;
984
+ for (const example of term.examples?.good ?? []) {
985
+ const findings = matcher.check(example, kindOf({
986
+ text: example,
987
+ shown: true
988
+ }));
989
+ if (findings.some(about)) failures.push({
990
+ term,
991
+ example,
992
+ expected: "none",
993
+ findings
994
+ });
995
+ }
996
+ for (const example of term.examples?.bad ?? []) {
997
+ const findings = matcher.check(example, kindOf({
998
+ text: example,
999
+ shown: true
1000
+ }));
1001
+ if (!findings.some(about)) failures.push({
1002
+ term,
1003
+ example,
1004
+ expected: "finding",
1005
+ findings
1006
+ });
1007
+ }
1008
+ }
1009
+ return failures;
1010
+ }
1011
+ /** Whether a term says nothing but how it is spelled, so the Markdown glossary lists it on one line. */
1012
+ function isBare(term) {
1013
+ return !term.description && !term.nuance && !term.why && !term.avoid?.length && !term.examples?.good?.length && !term.examples?.bad?.length && !term.links?.length && term.case !== "context" && !term.casing;
1014
+ }
1015
+ function sentence(text) {
1016
+ const trimmed = text.trim().replace(/\s+/g, " ");
1017
+ return /[.!?:]$/.test(trimmed) ? trimmed : `${trimmed}.`;
1018
+ }
1019
+ /** A reason written as an aside: "Racks are unpowered." reads "racks are unpowered". */
1020
+ function aside(text) {
1021
+ const trimmed = text.trim().replace(/\s+/g, " ").replace(/[.!]$/, "");
1022
+ return /^\p{Lu}(?![\p{Lu}\p{N}])/u.test(trimmed) ? trimmed.charAt(0).toLowerCase() + trimmed.slice(1) : trimmed;
1023
+ }
1024
+ const quoted = (items) => items.map((item) => `"${item}"`).join(", ");
1025
+ function avoidList(term) {
1026
+ if (!term.avoid?.length) return void 0;
1027
+ return `${term.avoid.map((avoid) => typeof avoid === "string" ? avoid : avoid.why ? `${avoid.word} (${aside(avoid.why)})` : avoid.word).join(", ")}.`;
1028
+ }
1029
+ function examplesLine(term) {
1030
+ const parts = [];
1031
+ const list = (label, items) => `${label}: ${quoted(items)}${/[.!?]$/.test(items.at(-1).trim()) ? "" : "."}`;
1032
+ if (term.examples?.good?.length) parts.push(list("Good", term.examples.good));
1033
+ if (term.examples?.bad?.length) parts.push(list("Bad", term.examples.bad));
1034
+ return parts.length > 0 ? parts.join(" ") : void 0;
1035
+ }
1036
+ /** How the term is written, beyond its spelling: abbreviations and casing. */
1037
+ function writingLines(term) {
1038
+ const lines = [];
1039
+ if (term.abbr?.length) lines.push(`Abbreviation${term.abbr.length > 1 ? "s" : ""}: ${term.abbr.join(", ")}.`);
1040
+ if (term.case === "exact") lines.push(`Always written "${term.term}".`);
1041
+ if (term.casing && term.case !== "exact" && term.case !== "spelling") {
1042
+ const names = {
1043
+ title: "Title Case",
1044
+ sentence: "sentence case",
1045
+ lower: "lowercase",
1046
+ upper: "ALL CAPS"
1047
+ };
1048
+ const styles = Object.entries(term.casing).map(([kind, style]) => `${style === "as-written" ? `"${term.term}"` : names[style]} in ${kind}s`);
1049
+ lines.push(`Written ${styles.join(", ")}.`);
1050
+ } else if (term.case === "context") lines.push("Title Case in labels, lowercase in sentences.");
1051
+ return lines;
1052
+ }
1053
+ function spellingName(term) {
1054
+ return term.abbr?.length ? `${term.term} (${term.abbr.join(", ")})` : term.term;
1055
+ }
1056
+ function markdownEntry(term) {
1057
+ const lines = [`## ${term.term}`];
1058
+ if (term.description) lines.push(sentence(term.description));
1059
+ const bullets = [
1060
+ term.nuance && sentence(term.nuance),
1061
+ term.why && sentence(term.why),
1062
+ ...writingLines(term)
1063
+ ];
1064
+ const avoid = avoidList(term);
1065
+ if (avoid) bullets.push(`Don't write: ${avoid}`);
1066
+ bullets.push(examplesLine(term));
1067
+ if (term.links?.length) bullets.push(`See: ${term.links.map((link) => `[${link.title}](${link.url})`).join(", ")}.`);
1068
+ for (const bullet of bullets) if (bullet) lines.push(`- ${bullet}`);
1069
+ return lines.join("\n");
1070
+ }
1071
+ /**
1072
+ * The corpus as a Markdown glossary, for agents to read, or as JSON. The Markdown gives each term that
1073
+ * says more than its spelling a section, and lists the rest on one "Spelling" line.
1074
+ */
1075
+ function printCorpus(corpus, format) {
1076
+ if (format === "json") return `${JSON.stringify({
1077
+ terms: corpus.terms,
1078
+ allow: corpus.allow
1079
+ }, null, 2)}\n`;
1080
+ const sections = corpus.terms.filter((term) => !isBare(term)).map(markdownEntry);
1081
+ const bare = corpus.terms.filter(isBare);
1082
+ if (bare.length > 0) sections.push(`## Spelling\nWrite these as shown: ${bare.map(spellingName).join(", ")}.`);
1083
+ return `${sections.join("\n\n")}\n`;
1084
+ }
1085
+ function mentionPattern(term) {
1086
+ const words = splitWords(term.term).map((word) => word.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
1087
+ return new RegExp(`(?<![\\p{L}\\p{N}])${words.join("[\\s\\-‐‑_]*")}(?:e?s)?(?![\\p{L}\\p{N}])`, "iu");
1088
+ }
1089
+ /** Looks a key up as written, then as a plural ending in `s` or `es`. */
1090
+ function byKey(map, key) {
1091
+ return map.get(key) ?? (key.endsWith("s") ? map.get(key.slice(0, -1)) : void 0) ?? (key.endsWith("es") ? map.get(key.slice(0, -2)) : void 0);
1092
+ }
1093
+ const squash$1 = (text) => text.trim().replace(/\s+/g, " ").toLowerCase();
1094
+ /** The terms a word or phrase is about: as a term, an abbreviation, a form or an avoid word, else the terms it mentions. */
1095
+ function explainMatches(corpus, query) {
1096
+ const key = termKey(query);
1097
+ if (key === "") return [];
1098
+ const terms = /* @__PURE__ */ new Map();
1099
+ const abbrs = /* @__PURE__ */ new Map();
1100
+ const forms = /* @__PURE__ */ new Map();
1101
+ const avoids = /* @__PURE__ */ new Map();
1102
+ for (const term of corpus.terms) terms.set(termKey(term.term), term);
1103
+ for (const term of corpus.terms) {
1104
+ for (const abbr of term.abbr ?? []) abbrs.set(termKey(abbr), term);
1105
+ for (const list of Object.values(term.forms ?? {})) for (const form of list) if (!forms.has(termKey(form))) forms.set(termKey(form), term);
1106
+ for (const avoid of term.avoid ?? []) {
1107
+ const { word, why } = typeof avoid === "string" ? {
1108
+ word: avoid,
1109
+ why: void 0
1110
+ } : avoid;
1111
+ const avoidKey = termKey(word);
1112
+ avoids.set(avoidKey, {
1113
+ term,
1114
+ word,
1115
+ ...why ? { why } : {}
1116
+ });
1117
+ }
1118
+ }
1119
+ const matches = [];
1120
+ const add = (term, note) => {
1121
+ if (matches.some((match) => match.term === term)) return;
1122
+ matches.push(note ? {
1123
+ term,
1124
+ note
1125
+ } : { term });
1126
+ };
1127
+ const asTerm = byKey(terms, key);
1128
+ if (asTerm) add(asTerm, key === termKey(asTerm.term) && squash$1(query) !== squash$1(asTerm.term) ? `"${query.trim()}" is spelled "${asTerm.term}".` : void 0);
1129
+ const asAbbr = byKey(abbrs, key);
1130
+ if (asAbbr) add(asAbbr, `"${query.trim()}" abbreviates ${asAbbr.term}.`);
1131
+ const asForm = byKey(forms, key);
1132
+ if (asForm) add(asForm, `"${query.trim()}" is a form of ${asForm.term}.`);
1133
+ const asAvoid = byKey(avoids, key);
1134
+ if (asAvoid) {
1135
+ const why = asAvoid.why ? ` ${sentence(capitalise(asAvoid.why))}` : "";
1136
+ add(asAvoid.term, `"${asAvoid.word}" is an avoid word for ${asAvoid.term.term}.${why}`);
1137
+ }
1138
+ if (matches.length > 0) return matches;
1139
+ for (const finding of createMatcher(corpus).check(query)) {
1140
+ const note = finding.code === "GLOSSLINT_AVOID" ? `"${finding.text}" is an avoid word for ${finding.term.term}.` : `"${finding.text}" is spelled "${finding.fix?.replace ?? finding.term.term}".`;
1141
+ add(finding.term, note);
1142
+ }
1143
+ if (matches.length > 0) return matches;
1144
+ for (const term of corpus.terms) if (mentionPattern(term).test(query)) add(term);
1145
+ return matches;
1146
+ }
1147
+ /** Terms with more than a spelling that this term's description or nuance mentions, or whose name contains it. */
1148
+ function related(corpus, term) {
1149
+ const text = [term.description, term.nuance].filter(Boolean).join(" ");
1150
+ const own = mentionPattern(term);
1151
+ return corpus.terms.filter((other) => other !== term && !isBare(other) && termKey(other.term) !== termKey(term.term) && (mentionPattern(other).test(text) || own.test(other.term)));
1152
+ }
1153
+ function explainEntry(corpus, match) {
1154
+ const { term } = match;
1155
+ const lines = [
1156
+ match.note,
1157
+ term.description && sentence(term.description),
1158
+ term.nuance && sentence(term.nuance),
1159
+ term.why && sentence(term.why),
1160
+ ...writingLines(term)
1161
+ ];
1162
+ const avoid = avoidList(term);
1163
+ if (avoid) lines.push(`Avoid: ${avoid}`);
1164
+ lines.push(examplesLine(term));
1165
+ for (const link of term.links ?? []) lines.push(`See: ${link.title} ${link.url}`);
1166
+ const near = related(corpus, term);
1167
+ if (near.length > 0) lines.push(`Related: ${near.map((other) => other.term).join(", ")}`);
1168
+ return [term.term, ...lines.filter(Boolean).map((line) => ` ${line}`)].join("\n");
1169
+ }
1170
+ /** What the corpus says about a word or phrase: the term it belongs to, its meaning and nuance. */
1171
+ function explain(corpus, query) {
1172
+ const matches = explainMatches(corpus, query);
1173
+ if (matches.length === 0) return `No term in the corpus matches "${query.trim()}".`;
1174
+ return matches.map((match) => explainEntry(corpus, match)).join("\n\n");
1175
+ }
1176
+ /** The corpus as x18n `glossary` entries, with only the fields x18n accepts. */
1177
+ function toX18nGlossary(corpus) {
1178
+ return corpus.terms.map((term) => {
1179
+ const note = [term.description, term.nuance].filter((part) => Boolean(part)).map(sentence).join(" ");
1180
+ const keep = term.case === "exact" && !term.translations;
1181
+ return {
1182
+ term: term.term,
1183
+ ...term.translations ? { translations: term.translations } : {},
1184
+ ...term.forms ? { forms: term.forms } : {},
1185
+ ...note ? { note } : {},
1186
+ ...keep ? { doNotTranslate: true } : {}
1187
+ };
1188
+ });
1189
+ }
1190
+ // src/glossary.ts
1191
+ /** The codes of `GlossaryProblem`. */
1192
+ const GLOSSARY_PROBLEMS = {
1193
+ title: "GLOSSLINT_G001",
1194
+ fieldName: "GLOSSLINT_G002",
1195
+ layout: "GLOSSLINT_G003",
1196
+ noPlace: "GLOSSLINT_G004",
1197
+ twice: "GLOSSLINT_G005",
1198
+ badValue: "GLOSSLINT_G006",
1199
+ badHeading: "GLOSSLINT_G007",
1200
+ avoidIsTerm: "GLOSSLINT_G008",
1201
+ failingExample: "GLOSSLINT_G009"
1202
+ };
1203
+ const P = GLOSSARY_PROBLEMS;
1204
+ const FIXABLE = /* @__PURE__ */ new Set([
1205
+ P.title,
1206
+ P.fieldName,
1207
+ P.layout
1208
+ ]);
1209
+ /** The problems that leave no corpus: `G004` to `G008`. */
1210
+ const BLOCKING = /* @__PURE__ */ new Set([
1211
+ P.noPlace,
1212
+ P.twice,
1213
+ P.badValue,
1214
+ P.badHeading,
1215
+ P.avoidIsTerm
1216
+ ]);
1217
+ /** Where `fromGlossary` looks when it is given no path. */
1218
+ const DEFAULT_GLOSSARY = ".agents/glossary.md";
1219
+ const CORPUS_FIELDS = [
1220
+ {
1221
+ name: "Extends",
1222
+ kind: "list",
1223
+ comma: true
1224
+ },
1225
+ {
1226
+ name: "Allow",
1227
+ kind: "list",
1228
+ comma: true
1229
+ },
1230
+ {
1231
+ name: "Casing",
1232
+ kind: "list",
1233
+ comma: true
1234
+ }
1235
+ ];
1236
+ const TERM_FIELDS = [
1237
+ {
1238
+ name: "What",
1239
+ kind: "text"
1240
+ },
1241
+ {
1242
+ name: "How",
1243
+ kind: "text"
1244
+ },
1245
+ {
1246
+ name: "Why",
1247
+ kind: "text"
1248
+ },
1249
+ {
1250
+ name: "Avoid",
1251
+ kind: "list",
1252
+ comma: true
1253
+ },
1254
+ {
1255
+ name: "Good",
1256
+ kind: "list"
1257
+ },
1258
+ {
1259
+ name: "Bad",
1260
+ kind: "list"
1261
+ },
1262
+ {
1263
+ name: "Links",
1264
+ kind: "list"
1265
+ },
1266
+ {
1267
+ name: "Case",
1268
+ kind: "value"
1269
+ }
1270
+ ];
1271
+ const ALIASES = {
1272
+ description: "What",
1273
+ meaning: "What",
1274
+ notes: "How",
1275
+ nuance: "How",
1276
+ see: "Links",
1277
+ related: "Links",
1278
+ "related links": "Links"
1279
+ };
1280
+ const PRESETS = {
1281
+ tech: corpus$1,
1282
+ inclusive: corpus
1283
+ };
1284
+ const FIELD_NAMES = /* @__PURE__ */ new Set([...[...CORPUS_FIELDS, ...TERM_FIELDS].map((spec) => spec.name.toLowerCase()), ...Object.keys(ALIASES)]);
1285
+ const CASE_MODES = [
1286
+ "exact",
1287
+ "spelling",
1288
+ "context"
1289
+ ];
1290
+ const CASING = /^(label|header|sentence)\s+(title|sentence|lower|upper|as-written)$/;
1291
+ const HEADING = /^ {0,3}(#{1,6})(?:[ \t]+(.*?))?(?:[ \t]+#+)?[ \t]*$/;
1292
+ const FENCE = /^ {0,3}(`{3,}|~{3,})/;
1293
+ const ITEM = /^ {0,3}([-*+])(?:[ \t]+(.*))?$/;
1294
+ const TABLE = /^ {0,3}\|/;
1295
+ const FIELD = /^ {0,3}([A-Za-z]+(?: [A-Za-z]+){0,2}):(?:[ \t]+(.*))?$/;
1296
+ const LINK = /^\[([^\]]*\S[^\]]*)\]\((https?:\/\/[^\s()]+)\)$/;
1297
+ const BARE_URL = /^<?(https?:\/\/[^\s<>()]+)>?$/;
1298
+ /**
1299
+ * Whether a line starts a field: a field name or alias of the corpus or a term, in any case, then `:`.
1300
+ * A word of four or more letters one edit from a name, such as `Avod:`, starts one too, so a typo is
1301
+ * reported instead of joining the field above it.
1302
+ */
1303
+ function isFieldLine(line) {
1304
+ const name = FIELD.exec(line)?.[1]?.toLowerCase();
1305
+ if (name === void 0) return false;
1306
+ if (FIELD_NAMES.has(name)) return true;
1307
+ return /^[a-z]{4,}$/.test(name) && [...FIELD_NAMES].some((field) => distance(name, field) <= 1);
1308
+ }
1309
+ /** Splits the file into Markdown blocks. Blank lines end every block but a fence. */
1310
+ function scan(lines) {
1311
+ const blocks = [];
1312
+ let i = 0;
1313
+ const isBlank = (line) => line === void 0 || line.trim() === "";
1314
+ const startsBlock = (line) => HEADING.test(line) || FENCE.test(line) || ITEM.test(line) || TABLE.test(line);
1315
+ while (i < lines.length) {
1316
+ const line = lines[i];
1317
+ if (isBlank(line)) {
1318
+ i++;
1319
+ continue;
1320
+ }
1321
+ const first = i;
1322
+ const fence = FENCE.exec(line)?.[1];
1323
+ if (fence) {
1324
+ i++;
1325
+ const close = new RegExp(`^ {0,3}${fence[0] === "`" ? "`" : "~"}{${fence.length},}[ \\t]*$`);
1326
+ while (i < lines.length && !close.test(lines[i])) i++;
1327
+ i = Math.min(i + 1, lines.length);
1328
+ blocks.push({
1329
+ kind: "fence",
1330
+ start: first + 1,
1331
+ end: i,
1332
+ lines: lines.slice(first, i)
1333
+ });
1334
+ continue;
1335
+ }
1336
+ const heading = HEADING.exec(line);
1337
+ if (heading) {
1338
+ const level = heading[1].length;
1339
+ i++;
1340
+ blocks.push({
1341
+ kind: level === 1 ? "h1" : level === 2 ? "h2" : "heading",
1342
+ start: first + 1,
1343
+ end: first + 1,
1344
+ lines: [line],
1345
+ text: (heading[2] ?? "").trim()
1346
+ });
1347
+ continue;
1348
+ }
1349
+ if (TABLE.test(line)) {
1350
+ while (i < lines.length && !isBlank(lines[i]) && TABLE.test(lines[i])) i++;
1351
+ blocks.push({
1352
+ kind: "table",
1353
+ start: first + 1,
1354
+ end: i,
1355
+ lines: lines.slice(first, i)
1356
+ });
1357
+ continue;
1358
+ }
1359
+ if (ITEM.test(line)) {
1360
+ const items = [];
1361
+ while (i < lines.length && !isBlank(lines[i])) {
1362
+ const current = lines[i];
1363
+ const item = ITEM.exec(current);
1364
+ if (item) items.push({
1365
+ line: i + 1,
1366
+ bullet: item[1],
1367
+ lines: [(item[2] ?? "").trim()]
1368
+ });
1369
+ else if (/^[ \t]+\S/.test(current) && !startsBlock(current) && !isFieldLine(current)) items.at(-1).lines.push(current.trim());
1370
+ else break;
1371
+ i++;
1372
+ }
1373
+ blocks.push({
1374
+ kind: "list",
1375
+ start: first + 1,
1376
+ end: i,
1377
+ lines: lines.slice(first, i),
1378
+ items
1379
+ });
1380
+ continue;
1381
+ }
1382
+ while (i < lines.length && !isBlank(lines[i]) && (i === first || !startsBlock(lines[i]))) i++;
1383
+ blocks.push({
1384
+ kind: "paragraph",
1385
+ start: first + 1,
1386
+ end: i,
1387
+ lines: lines.slice(first, i)
1388
+ });
1389
+ }
1390
+ return blocks;
1391
+ }
1392
+ /** Splits a comma list, keeping commas inside backticks. */
1393
+ function splitCommas(text) {
1394
+ const parts = [];
1395
+ let current = "";
1396
+ let inCode = false;
1397
+ for (const char of text) {
1398
+ if (char === "`") inCode = !inCode;
1399
+ if (char === "," && !inCode) {
1400
+ parts.push(current);
1401
+ current = "";
1402
+ } else current += char;
1403
+ }
1404
+ parts.push(current);
1405
+ return parts.map((part) => part.trim()).filter(Boolean);
1406
+ }
1407
+ /** `word` or `word: reason`, split at the first colon followed by a space; backticks around the word are dropped. */
1408
+ function parseAvoid(raw) {
1409
+ const ticked = /^`([^`]*)`(?::(?:\s+([\s\S]*))?)?$/.exec(raw);
1410
+ if (ticked) {
1411
+ const why = ticked[2]?.trim();
1412
+ return why ? {
1413
+ word: ticked[1].trim(),
1414
+ why
1415
+ } : { word: ticked[1].trim() };
1416
+ }
1417
+ const at = raw.search(/:(?:\s|$)/);
1418
+ if (at < 0) return { word: raw.trim() };
1419
+ const why = raw.slice(at + 1).trim();
1420
+ return why ? {
1421
+ word: raw.slice(0, at).trim(),
1422
+ why
1423
+ } : { word: raw.slice(0, at).trim() };
1424
+ }
1425
+ /** A single word that is one capital or has a capital after its first letter, such as `DP`, `D` or `eB`. */
1426
+ function isAbbr(word) {
1427
+ return /^(?:\p{Lu}|\S+\p{Lu}\S*)$/u.test(word);
1428
+ }
1429
+ /** A capital right after a letter, as in `eBike` or `SOS`, makes a term `exact`. */
1430
+ function isExactName(name) {
1431
+ return /\p{L}\p{Lu}/u.test(name);
1432
+ }
1433
+ const itemText = (item) => item.lines.join(" ").trim();
1434
+ const textOf = (node) => node.text.flat().map((line) => line.trim()).filter(Boolean).join(" ");
1435
+ function quoteList(values) {
1436
+ const quoted = values.map((value) => `"${value}"`);
1437
+ return quoted.length > 1 ? `${quoted.slice(0, -1).join(", ")} or ${quoted.at(-1)}` : quoted[0] ?? "";
1438
+ }
1439
+ var Reader = class {
1440
+ problems = [];
1441
+ blocks;
1442
+ constructor(lines) {
1443
+ this.blocks = scan(lines);
1444
+ }
1445
+ add(code, line, why, fix, term) {
1446
+ this.problems.push({
1447
+ code,
1448
+ line,
1449
+ why,
1450
+ fix,
1451
+ fixable: FIXABLE.has(code),
1452
+ ...term === void 0 ? {} : { term }
1453
+ });
1454
+ }
1455
+ read() {
1456
+ const { blocks } = this;
1457
+ let index = 0;
1458
+ const title = blocks[0];
1459
+ if (title?.kind === "h1") {
1460
+ index = 1;
1461
+ if (title.text !== "Glossary") this.add(P.title, title.start, `The title is "${title.text}", not "Glossary".`, `Retitle it "# Glossary".`);
1462
+ } else this.add(P.title, title?.start ?? 1, "The file does not start with `# Glossary`.", "Add `# Glossary` as the first line.");
1463
+ const intro = [];
1464
+ while (index < blocks.length) {
1465
+ const block = blocks[index];
1466
+ if (block.kind === "h2" || block.kind === "paragraph" && FIELD.test(block.lines[0])) break;
1467
+ if (block.kind === "h1") this.secondTitle(block);
1468
+ else intro.push(block);
1469
+ index++;
1470
+ }
1471
+ for (let i = 1; i < blocks.length; i++) {
1472
+ const block = blocks[i];
1473
+ const gap = block.start - blocks[i - 1].end - 1;
1474
+ const want = i <= index || block.kind === "h1" || block.kind === "h2" || block.kind === "paragraph" && !isFieldLine(block.lines[0]) && blocks[i - 1].kind !== "h2" ? 1 : 0;
1475
+ if (gap === want) continue;
1476
+ this.add(P.layout, block.start, want === 1 ? gap === 0 ? "No blank line before this line." : `${gap} blank lines before this line.` : gap === 1 ? "A blank line before this line." : `${gap} blank lines before this line.`, want === 1 ? "Leave one blank line before a heading, after the introduction and between the paragraphs of one field." : "Remove it: a term's heading and its fields go on consecutive lines.");
1477
+ }
1478
+ let end = index;
1479
+ while (end < blocks.length && blocks[end].kind !== "h2") end++;
1480
+ const corpus = this.section(blocks.slice(index, end), CORPUS_FIELDS, void 0);
1481
+ const terms = [];
1482
+ const seen = /* @__PURE__ */ new Map();
1483
+ for (index = end; index < blocks.length; index = end) {
1484
+ const heading = blocks[index];
1485
+ end = index + 1;
1486
+ while (end < blocks.length && blocks[end].kind !== "h2") end++;
1487
+ const parsed = this.heading(heading);
1488
+ const fields = this.section(blocks.slice(index + 1, end), TERM_FIELDS, parsed.name);
1489
+ const key = termKey(parsed.name);
1490
+ if (key !== "") {
1491
+ const previous = seen.get(key);
1492
+ if (previous !== void 0) this.add(P.twice, heading.start, `"${parsed.name}" is written twice: "${previous}" is the same term.`, "Merge the two sections into one.", parsed.name);
1493
+ else seen.set(key, parsed.name);
1494
+ }
1495
+ terms.push({
1496
+ line: heading.start,
1497
+ name: parsed.name,
1498
+ abbr: parsed.abbr,
1499
+ fields
1500
+ });
1501
+ }
1502
+ return {
1503
+ intro,
1504
+ corpus,
1505
+ terms
1506
+ };
1507
+ }
1508
+ secondTitle(block) {
1509
+ this.add(P.noPlace, block.start, `A second H1, "${block.text}", has no place in a glossary.`, "Remove it, or make it a term with `##`.");
1510
+ }
1511
+ heading(block) {
1512
+ const text = block.text ?? "";
1513
+ const match = /^(.*?)\s*\(([^()]*)\)$/.exec(text);
1514
+ const name = (match ? match[1] : text).trim();
1515
+ const abbr = match ? match[2].split(",").map((part) => part.trim()) : [];
1516
+ const fail = (why, fix) => this.add(P.badHeading, block.start, why, fix, name);
1517
+ if (termKey(name) === "") fail(`The term heading "## ${text}" has no words.`, "Write the term after `## `.");
1518
+ else if (/[()]/.test(name) || match && !abbr.every(isAbbr)) fail(`The parentheses in "## ${text}" hold more than abbreviations.`, "Keep only abbreviations in parentheses, such as `## Day Pass (DP)`, and move the rest to `How`.");
1519
+ return {
1520
+ name,
1521
+ abbr: abbr.filter(Boolean)
1522
+ };
1523
+ }
1524
+ /** Reads the fields of the corpus (`term` undefined) or of one term. */
1525
+ section(blocks, specs, term) {
1526
+ const fields = /* @__PURE__ */ new Map();
1527
+ const sink = {
1528
+ spec: {
1529
+ name: "",
1530
+ kind: "text"
1531
+ },
1532
+ line: 0,
1533
+ text: [],
1534
+ items: [],
1535
+ form: "inline",
1536
+ value: "",
1537
+ lists: 0
1538
+ };
1539
+ let current;
1540
+ const noPlace = (line, what) => this.add(P.noPlace, line, `${what} has no place in a glossary${term === void 0 ? "" : " term"}.`, term === void 0 ? "Move it to the introduction above the first field, or remove it." : "Write it as a field, such as `How:`, or remove it.", term);
1541
+ for (const block of blocks) {
1542
+ if (block.kind === "list") {
1543
+ if (current === sink) continue;
1544
+ if (current?.spec.kind !== "list") {
1545
+ noPlace(block.start, current ? `A list after the ${current.spec.name} field` : "A list before the first field");
1546
+ current = sink;
1547
+ continue;
1548
+ }
1549
+ if (current.lists > 0) this.add(P.layout, block.start, `Blank lines split the list of ${current.spec.name}.`, "Write the list's items on consecutive lines.", term);
1550
+ else if (current.items.length > 0) this.add(P.layout, current.line, `${current.spec.name} has entries on its line and a list below it.`, "Move every entry into the `-` list.", term);
1551
+ const bullet = block.items.find((item) => item.bullet !== "-");
1552
+ if (bullet) this.add(P.layout, bullet.line, `A list item starts with "${bullet.bullet}".`, "Start each list item with `-`.", term);
1553
+ current.form = "list";
1554
+ current.lists++;
1555
+ current.items.push(...block.items);
1556
+ continue;
1557
+ }
1558
+ if (block.kind !== "paragraph") {
1559
+ if (block.kind === "h1") this.secondTitle(block);
1560
+ else noPlace(block.start, block.kind === "heading" ? `The heading "${block.lines[0].trim()}"` : block.kind === "table" ? "A table" : "A code block");
1561
+ current = sink;
1562
+ continue;
1563
+ }
1564
+ for (const segment of this.segments(block)) {
1565
+ const head = FIELD.exec(segment.lines[0]);
1566
+ if (!head) {
1567
+ if (current === sink) continue;
1568
+ if (current?.spec.kind === "text") current.text.push(segment.lines.map(trimEnd));
1569
+ else {
1570
+ noPlace(segment.line, current ? `Text after the ${current.spec.name} field` : term === void 0 ? "Text after the corpus fields" : `Text before the first field of "${term}"`);
1571
+ current = sink;
1572
+ }
1573
+ continue;
1574
+ }
1575
+ const written = head[1];
1576
+ const spec = this.resolve(written, specs, segment.line, term);
1577
+ if (!spec) {
1578
+ current = sink;
1579
+ continue;
1580
+ }
1581
+ if (fields.has(spec.name)) {
1582
+ this.add(P.twice, segment.line, `${spec.name} is written twice${term === void 0 ? "" : ` in "${term}"`}.`, "Merge the two into one field.", term);
1583
+ current = sink;
1584
+ continue;
1585
+ }
1586
+ const order = specs.indexOf(spec);
1587
+ const later = [...fields.values()].find((field) => specs.indexOf(field.spec) > order);
1588
+ if (later) this.add(P.layout, segment.line, `${spec.name} comes after ${later.spec.name}.`, `Write the fields in this order: ${specs.map((field) => field.name).join(", ")}.`, term);
1589
+ current = this.field(spec, segment.line, head[2] ?? "", segment.lines.slice(1), term);
1590
+ fields.set(spec.name, current);
1591
+ }
1592
+ }
1593
+ for (const field of fields.values()) this.check(field, term);
1594
+ return fields;
1595
+ }
1596
+ /** A paragraph's fields: a new one starts at each line that names a field. */
1597
+ segments(block) {
1598
+ const segments = [{
1599
+ line: block.start,
1600
+ lines: [block.lines[0]]
1601
+ }];
1602
+ for (let i = 1; i < block.lines.length; i++) {
1603
+ const line = block.lines[i];
1604
+ if (isFieldLine(line)) segments.push({
1605
+ line: block.start + i,
1606
+ lines: [line]
1607
+ });
1608
+ else segments.at(-1).lines.push(line);
1609
+ }
1610
+ return segments;
1611
+ }
1612
+ resolve(written, specs, line, term) {
1613
+ const lower = written.toLowerCase();
1614
+ const exact = specs.find((spec) => spec.name === written);
1615
+ if (exact) return exact;
1616
+ const byCase = specs.find((spec) => spec.name.toLowerCase() === lower);
1617
+ const alias = specs.find((spec) => ALIASES[lower] === spec.name);
1618
+ const elsewhere = (term === void 0 ? TERM_FIELDS : CORPUS_FIELDS).find((spec) => spec.name.toLowerCase() === lower || ALIASES[lower] === spec.name);
1619
+ const near = elsewhere ? void 0 : nearest(written, specs.map((spec) => spec.name.toLowerCase()));
1620
+ const spec = byCase ?? alias ?? (near ? specs.find((field) => field.name.toLowerCase() === near) : void 0);
1621
+ if (spec) {
1622
+ this.add(P.fieldName, line, byCase ? `"${written}" is written "${spec.name}".` : alias ? `"${written}" is another name for "${spec.name}".` : `"${written}" is not a field; "${spec.name}" is.`, `Rename it to "${spec.name}".`, term);
1623
+ return spec;
1624
+ }
1625
+ this.add(P.noPlace, line, elsewhere ? term === void 0 ? `${elsewhere.name} is a term field, written before the first term.` : `${elsewhere.name} is a glossary field, written inside the term "${term}".` : `"${written}" is not a field.`, elsewhere ? term === void 0 ? `Move it under the \`##\` heading of its term.` : "Move it above the first `##` term." : `Use ${quoteList(specs.map((spec) => spec.name))}, or reword the line so it does not start with "${written}:".`, term);
1626
+ }
1627
+ field(spec, line, rest, more, term) {
1628
+ const node = {
1629
+ spec,
1630
+ line,
1631
+ text: [],
1632
+ items: [],
1633
+ form: "inline",
1634
+ value: "",
1635
+ lists: 0
1636
+ };
1637
+ if (spec.kind === "text") {
1638
+ node.text.push([rest.trim(), ...more.map(trimEnd)]);
1639
+ return node;
1640
+ }
1641
+ const inline = [rest, ...more].map((part) => part.trim()).filter(Boolean).join(" ");
1642
+ if (spec.kind === "value") {
1643
+ node.value = inline;
1644
+ return node;
1645
+ }
1646
+ if (!inline) return node;
1647
+ if (spec.comma) {
1648
+ node.items = splitCommas(inline).map((part) => ({
1649
+ line,
1650
+ bullet: "",
1651
+ lines: [part]
1652
+ }));
1653
+ return node;
1654
+ }
1655
+ this.add(P.layout, line, `${spec.name} has its entry on the field's line.`, `Write ${spec.name} as a \`-\` list.`, term);
1656
+ node.form = "list";
1657
+ node.items = [{
1658
+ line,
1659
+ bullet: "-",
1660
+ lines: [inline]
1661
+ }];
1662
+ return node;
1663
+ }
1664
+ /** Reports bad values and rewrites bare URLs under `Links` as Markdown links. */
1665
+ check(node, term) {
1666
+ const bad = (line, why, fix) => this.add(P.badValue, line, why, fix, term);
1667
+ const { name } = node.spec;
1668
+ if (node.spec.kind === "text" ? textOf(node) === "" : node.spec.kind === "value" ? node.value === "" : node.items.every((item) => itemText(item) === "")) {
1669
+ bad(node.line, `${name} is empty.`, `Write a value after "${name}:", or remove the field.`);
1670
+ return;
1671
+ }
1672
+ if (name === "Case" && !CASE_MODES.includes(node.value)) bad(node.line, `Case is "${node.value}".`, `Use ${quoteList(CASE_MODES)}.`);
1673
+ for (const item of node.items) {
1674
+ const text = itemText(item);
1675
+ if (text === "") bad(item.line, `An item of ${name} is empty.`, "Write the item, or remove its line.");
1676
+ else if (name === "Extends" && !(text in PRESETS)) bad(item.line, `"${text}" is not a preset.`, `Use ${quoteList(Object.keys(PRESETS))}.`);
1677
+ else if (name === "Casing" && !CASING.test(text)) bad(item.line, `"${text}" is not a casing.`, "Write a kind (label, header or sentence) and a style (title, sentence, lower, upper or as-written), such as `label sentence`.");
1678
+ else if (name === "Avoid" && termKey(parseAvoid(text).word) === "") bad(item.line, `"${text}" has no word to avoid.`, "Write it as `word` or `word: reason`.");
1679
+ else if (name === "Links" && !LINK.test(text)) {
1680
+ const url = BARE_URL.exec(text)?.[1];
1681
+ if (url) {
1682
+ this.add(P.layout, item.line, `The link ${url} has no title.`, `Write it as [${url}](${url}), or give it a title.`, term);
1683
+ item.lines = [`[${url}](${url})`];
1684
+ } else bad(item.line, `"${text}" is not a link.`, "Write it as `[title](https://…)` with an http or https URL.");
1685
+ }
1686
+ }
1687
+ }
1688
+ };
1689
+ const squash = (text) => text.trim().replace(/\s+/g, " ").toLowerCase();
1690
+ function trimEnd(line) {
1691
+ return line.replace(/\s+$/, "");
1692
+ }
1693
+ /**
1694
+ * The canonical text of a glossary that has only fixable problems: one blank line between the title,
1695
+ * each introduction block, the corpus fields and each term, and none inside a term or the corpus fields.
1696
+ */
1697
+ function serialize(doc) {
1698
+ const sections = ["# Glossary"];
1699
+ for (const block of doc.intro) sections.push(block.lines.map(trimEnd).join("\n"));
1700
+ const fields = (map, specs) => specs.flatMap((spec) => {
1701
+ const node = map.get(spec.name);
1702
+ return node ? [renderField(node)] : [];
1703
+ });
1704
+ const corpus = fields(doc.corpus, CORPUS_FIELDS);
1705
+ if (corpus.length) sections.push(corpus.join("\n"));
1706
+ for (const term of doc.terms) sections.push([`## ${term.name}${term.abbr.length ? ` (${term.abbr.join(", ")})` : ""}`, ...fields(term.fields, TERM_FIELDS)].join("\n"));
1707
+ return `${sections.join("\n\n")}\n`;
1708
+ }
1709
+ /** A field's lines; the paragraphs of a text field after its first are set off by blank lines. */
1710
+ function renderField(node) {
1711
+ const { name, kind } = node.spec;
1712
+ if (kind === "text") {
1713
+ const [first = [""], ...rest] = node.text;
1714
+ return [[`${name}:${first[0] ? ` ${first[0]}` : ""}`, ...first.slice(1)], ...rest].map((paragraph) => paragraph.join("\n")).join("\n\n");
1715
+ }
1716
+ if (kind === "value") return `${name}: ${node.value}`;
1717
+ const items = node.items.filter((item) => itemText(item) !== "");
1718
+ if (node.form === "inline") return `${name}: ${items.map(itemText).join(", ")}`;
1719
+ return [`${name}:`, ...items.flatMap((item) => [`- ${item.lines[0]}`, ...item.lines.slice(1).map((line) => ` ${line}`)])].join("\n");
1720
+ }
1721
+ function buildTerm(node) {
1722
+ const term = { term: node.name };
1723
+ const field = (name) => node.fields.get(name);
1724
+ const items = (name) => field(name)?.items.map(itemText).filter(Boolean) ?? [];
1725
+ const text = (name) => {
1726
+ const found = field(name);
1727
+ return found ? textOf(found) : "";
1728
+ };
1729
+ if (text("What")) term.description = text("What");
1730
+ if (text("How")) term.nuance = text("How");
1731
+ if (text("Why")) term.why = text("Why");
1732
+ if (node.abbr.length) term.abbr = node.abbr;
1733
+ const avoid = items("Avoid").map((raw) => {
1734
+ const parsed = parseAvoid(raw);
1735
+ return parsed.why ? {
1736
+ word: parsed.word,
1737
+ why: parsed.why
1738
+ } : parsed.word;
1739
+ });
1740
+ if (avoid.length) term.avoid = avoid;
1741
+ const good = items("Good");
1742
+ const bad = items("Bad");
1743
+ if (good.length || bad.length) term.examples = {
1744
+ ...good.length ? { good } : {},
1745
+ ...bad.length ? { bad } : {}
1746
+ };
1747
+ const links = items("Links").flatMap((raw) => {
1748
+ const match = LINK.exec(raw);
1749
+ return match ? [{
1750
+ title: match[1].trim(),
1751
+ url: match[2]
1752
+ }] : [];
1753
+ });
1754
+ if (links.length) term.links = links;
1755
+ const mode = field("Case")?.value;
1756
+ if (mode) term.case = mode;
1757
+ else if (isExactName(node.name)) term.case = "exact";
1758
+ return term;
1759
+ }
1760
+ function buildCorpus(doc, terms) {
1761
+ const items = (name) => doc.corpus.get(name)?.items.map(itemText).filter(Boolean) ?? [];
1762
+ const casing = {};
1763
+ for (const pair of items("Casing")) {
1764
+ const [, kind, style] = CASING.exec(pair);
1765
+ casing[kind] = style;
1766
+ }
1767
+ const allow = items("Allow");
1768
+ return defineCorpus({
1769
+ extends: items("Extends").map((name) => PRESETS[name]),
1770
+ terms,
1771
+ ...allow.length ? { allow } : {},
1772
+ ...Object.keys(casing).length ? { casing } : {}
1773
+ });
1774
+ }
1775
+ /** Reports every avoid word that is a term of the file. */
1776
+ function avoidTerms(reader, doc) {
1777
+ const names = new Map(doc.terms.map((term) => [termKey(term.name), term.name]));
1778
+ for (const term of doc.terms) for (const item of term.fields.get("Avoid")?.items ?? []) {
1779
+ const { word } = parseAvoid(itemText(item));
1780
+ const own = squash(word) === squash(term.name);
1781
+ const other = own ? term.name : names.get(termKey(word));
1782
+ if (other === void 0 || other === term.name && !own) continue;
1783
+ reader.add(P.avoidIsTerm, item.line, other === term.name ? `"${word}" is both the term and one of its avoid words.` : `"${word}" is an avoid word of "${term.name}" and a term of its own.`, other === term.name ? "Remove it from Avoid. To require one casing, write `Case: exact`." : `Remove it from the Avoid list of "${term.name}", or remove the term "${other}".`, term.name);
1784
+ }
1785
+ }
1786
+ /** Reports every `Good` example that is reported and every `Bad` one that is not. */
1787
+ function failingExamples(reader, doc, corpus, own) {
1788
+ for (const failure of testCorpus(corpus)) {
1789
+ const node = own.get(failure.term);
1790
+ if (!node) continue;
1791
+ const field = node.fields.get(failure.expected === "none" ? "Good" : "Bad");
1792
+ const line = field?.items.find((item) => itemText(item) === failure.example)?.line ?? field?.line ?? node.line;
1793
+ const about = failure.findings.find((finding) => termKey(finding.term.term) === termKey(node.name));
1794
+ reader.add(P.failingExample, line, failure.expected === "none" ? `The good example "${failure.example}" is reported: ${about?.message ?? "a finding"}` : `The bad example "${failure.example}" is not reported.`, failure.expected === "none" ? "Narrow the avoid word, or fix the example." : "Add the wording to Avoid, or fix the example.", node.name);
1795
+ }
1796
+ }
1797
+ function parse(text, examples) {
1798
+ const lines = text.split(/\r?\n/);
1799
+ if (lines.at(-1) === "") lines.pop();
1800
+ const reader = new Reader(lines);
1801
+ const doc = reader.read();
1802
+ avoidTerms(reader, doc);
1803
+ const blocked = reader.problems.some((problem) => BLOCKING.has(problem.code));
1804
+ let corpus;
1805
+ let fixed;
1806
+ if (!blocked) {
1807
+ const own = /* @__PURE__ */ new Map();
1808
+ corpus = buildCorpus(doc, doc.terms.map((node) => {
1809
+ const term = buildTerm(node);
1810
+ own.set(term, node);
1811
+ return term;
1812
+ }));
1813
+ const canonical = serialize(doc);
1814
+ if (canonical !== text) {
1815
+ fixed = canonical;
1816
+ if (!reader.problems.some((problem) => problem.fixable)) {
1817
+ const want = canonical.split("\n");
1818
+ const have = text.split("\n");
1819
+ let at = 0;
1820
+ while (at < want.length && want[at] === have[at]) at++;
1821
+ reader.add(P.layout, Math.min(at + 1, have.length), "The spacing, indentation or line endings differ from the canonical form.", "Use LF line endings, a blank line only before a heading, after the introduction and between the paragraphs of one field, no trailing spaces and one final newline.");
1822
+ }
1823
+ }
1824
+ if (examples) failingExamples(reader, doc, corpus, own);
1825
+ }
1826
+ return {
1827
+ problems: [...reader.problems].sort((a, b) => a.line - b.line),
1828
+ ...corpus ? { corpus } : {},
1829
+ ...fixed === void 0 ? {} : { fixed }
1830
+ };
1831
+ }
1832
+ /**
1833
+ * Reads the text of a glossary file. `corpus` is set when no problem from `G004` to `G008` exists, and
1834
+ * `fixed`, the canonical text, when the file can be rewritten and differs from it.
1835
+ */
1836
+ function readGlossary(text) {
1837
+ return parse(text, true);
1838
+ }
1839
+ function displayPath(file) {
1840
+ const shown = relative(process.cwd(), file);
1841
+ return shown && !shown.startsWith("..") && !isAbsolute(shown) ? shown : file;
1842
+ }
1843
+ /** The absolute path of a glossary: a string resolves from the current folder. */
1844
+ function glossaryPath(path = DEFAULT_GLOSSARY) {
1845
+ return typeof path === "string" ? resolve(process.cwd(), path) : fileURLToPath(path);
1846
+ }
1847
+ /**
1848
+ * Reads a glossary file, `.agents/glossary.md` by default, as a corpus. Throws a `GlosslintConfigError`
1849
+ * when the file is missing (`GLOSSLINT_C009`) or has a problem only a person can fix (`G004` to `G008`).
1850
+ * A file with only fixable problems loads as its fixed form would.
1851
+ */
1852
+ function fromGlossary(path = DEFAULT_GLOSSARY) {
1853
+ const file = glossaryPath(path);
1854
+ const shown = displayPath(file);
1855
+ if (!existsSync(file)) throw new GlosslintConfigError({
1856
+ code: CONFIG_ERRORS.noGlossary,
1857
+ why: `No glossary at ${shown}.`,
1858
+ fix: `Create ${shown} with \`# Glossary\` and a \`## Term\` section per term, or pass the path of your glossary.`
1859
+ });
1860
+ const { problems, corpus } = parse(readFileSync(file, "utf8"), false);
1861
+ if (corpus) return corpus;
1862
+ const blocking = problems.filter((problem) => BLOCKING.has(problem.code));
1863
+ const [first] = blocking;
1864
+ const more = blocking.length > 1 ? ` ${blocking.length - 1} more problem${blocking.length > 2 ? "s" : ""}: run \`glosslint doctor\` to list them.` : "";
1865
+ throw new GlosslintConfigError({
1866
+ code: first.code,
1867
+ why: `${shown}:${first.line}: ${first.why}`,
1868
+ fix: `${first.fix}${more}`,
1869
+ ...first.term === void 0 ? {} : { term: first.term }
1870
+ });
1871
+ }
1872
+ export { capitalise as _, explain as a, testCorpus as c, createMatcher as d, caseModeOf as f, defineCorpus as g, CONFIG_ERRORS as h, readGlossary as i, toX18nGlossary as l, kindOf as m, GLOSSARY_PROBLEMS as n, explainMatches as o, classify as p, fromGlossary as r, printCorpus as s, DEFAULT_GLOSSARY as t, check as u, splitWords as v, GlosslintConfigError as y };