glosslint 0.1.1 → 0.2.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.
package/README.md CHANGED
@@ -27,7 +27,7 @@ Write your product's terms in `.agents/glossary.md`. This excerpt comes from the
27
27
 
28
28
  The words the rider app and the help center use.
29
29
 
30
- Extends: tech, inclusive
30
+ Presets: tech, inclusive
31
31
  Allow: check out our, roof rack
32
32
 
33
33
  ## Dock
@@ -49,7 +49,7 @@ Links:
49
49
  Case: context
50
50
  ```
51
51
 
52
- `eBike` gets `Case: exact` automatically because of its inner capital. `Day Pass (DP)` sets the abbreviation `DP` and enforces Title Case in labels and lowercase in sentences. Every runner reads `.agents/glossary.md` by default; `defineCorpus` in `glosslint.config.ts` is available when you need fields such as `skip`, `forms` or `translations`.
52
+ `eBike` gets `Case: exact` automatically because of its inner capital. `Day Pass (DP)` sets the abbreviation `DP` and enforces Title Case in labels and lowercase in sentences. Every runner reads `.agents/glossary.md` by default. When you need fields such as `skip`, `forms` or `translations`, build a corpus with `defineCorpus` and pass it to the runner: `glosslint({ corpus })` in ESLint or x18n, `--corpus <module>` in the CLI.
53
53
 
54
54
  ## Install
55
55
 
package/dist/cli.d.mts CHANGED
@@ -1,8 +1,21 @@
1
- import { t as GlossaryProblem } from "./glossary-DmTK_e1d.mjs";
1
+ import { t as GlossaryProblem } from "./glossary-text-C9pAOd4h.mjs";
2
2
  import { c as Corpus, o as CliFinding, v as Matcher } from "./types-Bbp_cYfZ.mjs";
3
+ /**
4
+ * Blanks what is not prose in Markdown, keeping every offset: frontmatter, fenced code, HTML
5
+ * comments and tags, inline code, link targets and references, and the markers of headings, lists
6
+ * and quotes. In MDX, `import` and `export` lines too; in other Markdown, Comark component markup.
7
+ */
8
+ export declare function maskMarkdown(text: string, options?: {
9
+ mdx?: boolean;
10
+ }): string;
11
+ /** Checks one file's text. Markdown is masked first, so code and link targets are never reported. */
12
+ export declare function checkFileText(matcher: Matcher, text: string, file: string, options?: {
13
+ markdown?: boolean;
14
+ mdx?: boolean;
15
+ }): CliFinding[];
3
16
  /** Where a command reads and writes, so tests can run commands without a process. */
4
17
  export interface CliIo {
5
- /** The folder paths and the config are resolved from. */
18
+ /** The folder paths and the corpus module are resolved from. */
6
19
  cwd: string;
7
20
  stdout: (text: string) => void;
8
21
  stderr: (text: string) => void;
@@ -11,9 +24,9 @@ export interface CliIo {
11
24
  }
12
25
  /** Options every command takes. */
13
26
  export interface CommandOptions {
14
- /** The config file. Default: `glosslint.config.{ts,mts,js,mjs}` in `cwd`. */
15
- config?: string;
16
- /** The glossary file, read when there is no `config`. Default: `.agents/glossary.md` in `cwd`. */
27
+ /** A module whose default export is a corpus, such as one that calls `defineCorpus`. */
28
+ corpus?: string;
29
+ /** The glossary file, read when there is no `corpus`. Default: `.agents/glossary.md` in `cwd`. */
17
30
  glossary?: string;
18
31
  /** Color the output. Default: `io.color`. */
19
32
  color?: boolean;
@@ -58,40 +71,24 @@ export interface DoctorReport {
58
71
  }
59
72
  /** Codes of the errors the CLI prints itself, next to the corpus's `GLOSSLINT_C00x`. */
60
73
  export declare const CLI_ERRORS: {
61
- readonly noConfig: "GLOSSLINT_C009";
62
- readonly loadConfig: "GLOSSLINT_C010";
74
+ readonly noCorpus: "GLOSSLINT_C009";
75
+ readonly loadModule: "GLOSSLINT_C010";
63
76
  readonly notCorpus: "GLOSSLINT_C008";
64
77
  readonly usage: "GLOSSLINT_USAGE";
65
78
  readonly failed: "GLOSSLINT_ERROR";
66
79
  };
67
- /** What `loadCorpus` read: a config, or a glossary file it then never checks. */
80
+ /** What `loadCorpus` read: a corpus module, or a glossary file it then never checks. */
68
81
  export interface LoadedCorpus {
69
82
  corpus: Corpus;
70
83
  /** The absolute path of the file read. */
71
84
  file: string;
72
- from: "config" | "glossary";
85
+ from: "module" | "glossary";
73
86
  }
74
- /**
75
- * Finds the corpus: `config`, else `glossary`, else `glosslint.config.{ts,mts,js,mjs}` in `cwd`, else
76
- * `.agents/glossary.md` in `cwd`.
77
- */
87
+ /** Finds the corpus: the `corpus` module, else the `glossary` file, else `.agents/glossary.md` in `cwd`. */
78
88
  export declare function loadCorpus(cwd: string, options?: {
79
- config?: string;
89
+ corpus?: string;
80
90
  glossary?: string;
81
91
  }): Promise<LoadedCorpus>;
82
- /**
83
- * Blanks what is not prose in Markdown, keeping every offset: frontmatter, fenced code, HTML
84
- * comments and tags, inline code, link targets and references, and the markers of headings, lists
85
- * and quotes. In MDX, `import` and `export` lines too; in other Markdown, Comark component markup.
86
- */
87
- export declare function maskMarkdown(text: string, options?: {
88
- mdx?: boolean;
89
- }): string;
90
- /** Checks one file's text. Markdown is masked first, so code and link targets are never reported. */
91
- export declare function checkFileText(matcher: Matcher, text: string, file: string, options?: {
92
- markdown?: boolean;
93
- mdx?: boolean;
94
- }): CliFinding[];
95
92
  /** The files `check` reads: named files as they are, folders by extension, and glob patterns. */
96
93
  export declare function collectFiles(paths: readonly string[], cwd: string, extensions?: readonly string[]): Promise<string[]>;
97
94
  /** `glosslint check`: reports every finding in the files, as text or JSON. Exits 1 on findings. */
package/dist/cli.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { n as formatFindings, r as toJson } from "./format-E5eFHoQT.mjs";
3
- import { a as explain, c as testCorpus, d as createMatcher, h as kindOf, i as readGlossary, m as isTextName, n as GLOSSARY_PROBLEMS, o as explainMatches, s as printCorpus, t as DEFAULT_GLOSSARY, y as isCodeShape } from "./glossary-ztPpmozR.mjs";
2
+ import { a as readGlossary, b as isCodeShape, c as printCorpus, f as createMatcher, g as kindOf, h as isTextName, l as testCorpus, n as DEFAULT_GLOSSARY, o as explain, r as GLOSSARY_PROBLEMS, s as explainMatches } from "./glossary-text-DB0WoR1i.mjs";
3
+ import { i as toJson, r as formatFindings, t as formatDoctor } from "./format-BVGriClu.mjs";
4
4
  import { existsSync, readFileSync, realpathSync, statSync, writeFileSync } from "node:fs";
5
5
  import { extname, relative, resolve, sep } from "node:path";
6
6
  import { pathToFileURL } from "node:url";
@@ -8,7 +8,7 @@ import process from "node:process";
8
8
  import { cac } from "cac";
9
9
  import { escapePath, glob, isDynamicPattern } from "tinyglobby";
10
10
  // package.json
11
- var version = "0.1.1";
11
+ var version = "0.2.0";
12
12
  // src/comark.ts
13
13
  const OPENER = /^[ \t]*(:{2,})[A-Za-z][\w-]*/;
14
14
  const BARE = /^[ \t]*:[A-Za-z][\w-]*[ \t]*\r?$/;
@@ -284,141 +284,7 @@ function maskComark(lines, blank) {
284
284
  props
285
285
  };
286
286
  }
287
- // src/cli.ts
288
- /** Codes of the errors the CLI prints itself, next to the corpus's `GLOSSLINT_C00x`. */
289
- const CLI_ERRORS = {
290
- noConfig: "GLOSSLINT_C009",
291
- loadConfig: "GLOSSLINT_C010",
292
- notCorpus: "GLOSSLINT_C008",
293
- usage: "GLOSSLINT_USAGE",
294
- failed: "GLOSSLINT_ERROR"
295
- };
296
- const CONFIG_FILES = [
297
- "glosslint.config.ts",
298
- "glosslint.config.mts",
299
- "glosslint.config.js",
300
- "glosslint.config.mjs"
301
- ];
302
- const DEFAULT_EXTENSIONS = [
303
- "md",
304
- "mdx",
305
- "txt"
306
- ];
307
- const MARKDOWN = /* @__PURE__ */ new Set([
308
- ".md",
309
- ".mdx",
310
- ".markdown"
311
- ]);
312
- /** An error the CLI prints as a tree and exits 2 on: a bad config or a bad command line. */
313
- var CliError = class extends Error {
314
- code;
315
- why;
316
- fix;
317
- term;
318
- config;
319
- constructor(options) {
320
- super(options.why);
321
- this.code = options.code;
322
- this.why = options.why;
323
- this.fix = options.fix;
324
- if (options.term !== void 0) this.term = options.term;
325
- if (options.config !== void 0) this.config = options.config;
326
- }
327
- };
328
- function isConfigError(error) {
329
- return error instanceof Error && error.name === "GlosslintConfigError" && typeof error.code === "string" && typeof error.fix === "string";
330
- }
331
- function isCorpus(value) {
332
- return typeof value === "object" && value !== null && value.kind === "glosslint.corpus" && Array.isArray(value.terms) && Array.isArray(value.allow);
333
- }
334
- const paint = (on, code, text) => on ? `\u001B[${code}m${text}\u001B[0m` : text;
335
- const toPosix = (path) => path.split(sep).join("/");
336
- function displayPath(cwd, file) {
337
- return toPosix(relative(cwd, file)) || ".";
338
- }
339
- /**
340
- * Finds the corpus: `config`, else `glossary`, else `glosslint.config.{ts,mts,js,mjs}` in `cwd`, else
341
- * `.agents/glossary.md` in `cwd`.
342
- */
343
- async function loadCorpus(cwd, options = {}) {
344
- const { config, glossary } = options;
345
- if (config !== void 0 && glossary !== void 0) throw usage("--config and --glossary both name the corpus.", "Pass one of them: --glossary for a glossary file, --config for a config.");
346
- if (config !== void 0) return importConfig(cwd, resolve(cwd, config), config);
347
- if (glossary !== void 0) return loadGlossary(cwd, glossary, true);
348
- const found = CONFIG_FILES.map((name) => resolve(cwd, name)).find((path) => existsSync(path));
349
- if (found) return importConfig(cwd, found);
350
- if (existsSync(resolve(cwd, ".agents/glossary.md"))) return loadGlossary(cwd, DEFAULT_GLOSSARY, false);
351
- throw new CliError({
352
- code: CLI_ERRORS.noConfig,
353
- why: `No ${DEFAULT_GLOSSARY} and no glosslint.config.ts, .mts, .js or .mjs in the current folder.`,
354
- fix: `Create ${DEFAULT_GLOSSARY} with \`# Glossary\` and a \`## Term\` section per term, or pass --glossary <path> or --config <path>.`
355
- });
356
- }
357
- /** `G004` to `G008`: the problems only a person can fix, which leave no corpus. */
358
- function leavesNoCorpus(problem) {
359
- return !problem.fixable && problem.code !== GLOSSARY_PROBLEMS.failingExample;
360
- }
361
- function missingGlossary(cwd, file, given) {
362
- const shown = displayPath(cwd, file);
363
- return new CliError({
364
- code: CLI_ERRORS.noConfig,
365
- why: given ? `The glossary "${shown}" does not exist.` : `No glossary at ${shown}.`,
366
- fix: given ? "Check the path given to --glossary." : `Create ${shown} with \`# Glossary\` and a \`## Term\` section per term, or pass --glossary <path>.`
367
- });
368
- }
369
- /** Reads a glossary file as a corpus, or throws its first problem that leaves no corpus. */
370
- function loadGlossary(cwd, path, given) {
371
- const file = resolve(cwd, path);
372
- if (!existsSync(file)) throw missingGlossary(cwd, file, given);
373
- const { problems, corpus } = readGlossary(readFileSync(file, "utf8"));
374
- if (corpus) return {
375
- corpus,
376
- file,
377
- from: "glossary"
378
- };
379
- const blocking = problems.filter(leavesNoCorpus);
380
- const first = blocking[0];
381
- const doctor = given ? `glosslint doctor --glossary ${path}` : "glosslint doctor";
382
- const more = blocking.length > 1 ? ` ${count(blocking.length - 1, "more problem")}: run \`${doctor}\` to list them.` : "";
383
- throw new CliError({
384
- code: first.code,
385
- why: `${displayPath(cwd, file)}:${first.line}: ${first.why}`,
386
- fix: `${first.fix}${more}`,
387
- ...first.term === void 0 ? {} : { term: first.term }
388
- });
389
- }
390
- /** Imports a config and returns its default export, which must be a corpus. */
391
- async function importConfig(cwd, file, given) {
392
- if (given !== void 0 && !existsSync(file)) throw new CliError({
393
- code: CLI_ERRORS.noConfig,
394
- why: `The config "${given}" does not exist.`,
395
- fix: "Check the path given to --config."
396
- });
397
- const shown = displayPath(cwd, file);
398
- let loaded;
399
- try {
400
- loaded = await import(pathToFileURL(file).href);
401
- } catch (error) {
402
- if (isConfigError(error)) throw Object.assign(error, { config: shown });
403
- throw new CliError({
404
- code: CLI_ERRORS.loadConfig,
405
- why: `Could not load ${shown}: ${error instanceof Error ? error.message : String(error)}`,
406
- fix: "Fix the error in the config, then run glosslint again.",
407
- config: shown
408
- });
409
- }
410
- if (!isCorpus(loaded.default)) throw new CliError({
411
- code: CLI_ERRORS.notCorpus,
412
- why: `${shown} does not export a corpus as its default export.`,
413
- fix: "End the config with `export default defineCorpus({ … })`.",
414
- config: shown
415
- });
416
- return {
417
- corpus: loaded.default,
418
- file,
419
- from: "config"
420
- };
421
- }
287
+ // src/check-text.ts
422
288
  /** Blanks a span with spaces, keeping line breaks, so every offset and line stays where it was. */
423
289
  function blank(text) {
424
290
  return text.replace(/[^\n\r]/g, " ");
@@ -614,6 +480,127 @@ function toCliFinding(finding, at) {
614
480
  ...rest.see ? { see: rest.see } : {}
615
481
  };
616
482
  }
483
+ // src/cli.ts
484
+ /** Codes of the errors the CLI prints itself, next to the corpus's `GLOSSLINT_C00x`. */
485
+ const CLI_ERRORS = {
486
+ noCorpus: "GLOSSLINT_C009",
487
+ loadModule: "GLOSSLINT_C010",
488
+ notCorpus: "GLOSSLINT_C008",
489
+ usage: "GLOSSLINT_USAGE",
490
+ failed: "GLOSSLINT_ERROR"
491
+ };
492
+ const DEFAULT_EXTENSIONS = [
493
+ "md",
494
+ "mdx",
495
+ "txt"
496
+ ];
497
+ const MARKDOWN = /* @__PURE__ */ new Set([
498
+ ".md",
499
+ ".mdx",
500
+ ".markdown"
501
+ ]);
502
+ /** An error the CLI prints as a tree and exits 2 on: a bad corpus or a bad command line. */
503
+ var CliError = class extends Error {
504
+ code;
505
+ why;
506
+ fix;
507
+ term;
508
+ corpus;
509
+ constructor(options) {
510
+ super(options.why);
511
+ this.code = options.code;
512
+ this.why = options.why;
513
+ this.fix = options.fix;
514
+ if (options.term !== void 0) this.term = options.term;
515
+ if (options.corpus !== void 0) this.corpus = options.corpus;
516
+ }
517
+ };
518
+ function isConfigError(error) {
519
+ return error instanceof Error && error.name === "GlosslintConfigError" && typeof error.code === "string" && typeof error.fix === "string";
520
+ }
521
+ function isCorpus(value) {
522
+ return typeof value === "object" && value !== null && value.kind === "glosslint.corpus" && Array.isArray(value.terms) && Array.isArray(value.allow);
523
+ }
524
+ const paint = (on, code, text) => on ? `\u001B[${code}m${text}\u001B[0m` : text;
525
+ const toPosix = (path) => path.split(sep).join("/");
526
+ function displayPath(cwd, file) {
527
+ return toPosix(relative(cwd, file)) || ".";
528
+ }
529
+ /** Finds the corpus: the `corpus` module, else the `glossary` file, else `.agents/glossary.md` in `cwd`. */
530
+ async function loadCorpus(cwd, options = {}) {
531
+ const { corpus, glossary } = options;
532
+ if (corpus !== void 0 && glossary !== void 0) throw usage("--corpus and --glossary both name the corpus.", "Pass one of them: --glossary for a glossary file, --corpus for a module that exports a corpus.");
533
+ if (corpus !== void 0) return importCorpus(cwd, corpus);
534
+ return loadGlossary(cwd, glossary ?? ".agents/glossary.md", glossary !== void 0);
535
+ }
536
+ /** `G004` to `G008`: the problems only a person can fix, which leave no corpus. */
537
+ function leavesNoCorpus(problem) {
538
+ return !problem.fixable && problem.code !== GLOSSARY_PROBLEMS.failingExample;
539
+ }
540
+ /** `takesCorpus`: whether the command also takes `--corpus`, which `doctor` does not. */
541
+ function missingGlossary(cwd, file, given, takesCorpus) {
542
+ const shown = displayPath(cwd, file);
543
+ const pass = takesCorpus ? "--glossary <path> or --corpus <module>" : "--glossary <path>";
544
+ return new CliError({
545
+ code: CLI_ERRORS.noCorpus,
546
+ why: given ? `The glossary "${shown}" does not exist.` : `No glossary at ${shown}.`,
547
+ fix: given ? "Check the path given to --glossary." : `Create ${shown} with \`# Glossary\` and a \`## Term\` section per term, or pass ${pass}.`
548
+ });
549
+ }
550
+ /** Reads a glossary file as a corpus, or throws its first problem that leaves no corpus. */
551
+ function loadGlossary(cwd, path, given) {
552
+ const file = resolve(cwd, path);
553
+ if (!existsSync(file)) throw missingGlossary(cwd, file, given, true);
554
+ const { problems, corpus } = readGlossary(readFileSync(file, "utf8"));
555
+ if (corpus) return {
556
+ corpus,
557
+ file,
558
+ from: "glossary"
559
+ };
560
+ const blocking = problems.filter(leavesNoCorpus);
561
+ const first = blocking[0];
562
+ const doctor = given ? `glosslint doctor --glossary ${path}` : "glosslint doctor";
563
+ const more = blocking.length > 1 ? ` ${count(blocking.length - 1, "more problem")}: run \`${doctor}\` to list them.` : "";
564
+ throw new CliError({
565
+ code: first.code,
566
+ why: `${displayPath(cwd, file)}:${first.line}: ${first.why}`,
567
+ fix: `${first.fix}${more}`,
568
+ ...first.term === void 0 ? {} : { term: first.term }
569
+ });
570
+ }
571
+ /** Imports the module given to `--corpus` and returns its default export, which must be a corpus. */
572
+ async function importCorpus(cwd, given) {
573
+ const file = resolve(cwd, given);
574
+ if (!existsSync(file)) throw new CliError({
575
+ code: CLI_ERRORS.noCorpus,
576
+ why: `The corpus module "${given}" does not exist.`,
577
+ fix: "Check the path given to --corpus."
578
+ });
579
+ const shown = displayPath(cwd, file);
580
+ let loaded;
581
+ try {
582
+ loaded = await import(pathToFileURL(file).href);
583
+ } catch (error) {
584
+ if (isConfigError(error)) throw Object.assign(error, { corpus: shown });
585
+ throw new CliError({
586
+ code: CLI_ERRORS.loadModule,
587
+ why: `Could not load ${shown}: ${error instanceof Error ? error.message : String(error)}`,
588
+ fix: "Fix the error in the module, then run glosslint again.",
589
+ corpus: shown
590
+ });
591
+ }
592
+ if (!isCorpus(loaded.default)) throw new CliError({
593
+ code: CLI_ERRORS.notCorpus,
594
+ why: `${shown} does not export a corpus as its default export.`,
595
+ fix: "End the module with `export default defineCorpus({ … })`.",
596
+ corpus: shown
597
+ });
598
+ return {
599
+ corpus: loaded.default,
600
+ file,
601
+ from: "module"
602
+ };
603
+ }
617
604
  function usage(why, fix) {
618
605
  return new CliError({
619
606
  code: CLI_ERRORS.usage,
@@ -746,16 +733,6 @@ async function runExplain(query, options, io) {
746
733
  io.stdout(`${explain(corpus, query)}\n`);
747
734
  return explainMatches(corpus, query).length > 0 ? 0 : 1;
748
735
  }
749
- function formatProblem(problem, color) {
750
- const lines = [["fix", problem.fix]];
751
- if (problem.term && !problem.why.includes(`"${problem.term}"`)) lines.unshift(["term", problem.term]);
752
- const branches = lines.map(([label, text], index) => {
753
- const branch = index === lines.length - 1 ? "╰▶" : "├▶";
754
- return `${paint(color, "2", branch)} ${paint(color, "1", `${label}:`)} ${text}`;
755
- });
756
- const where = paint(color, "36", `${problem.file}:${problem.line}`);
757
- return [`${paint(color, "1;31", `[${problem.code}]`)} ${where}: ${problem.why}`, ...branches].join("\n");
758
- }
759
736
  /**
760
737
  * `glosslint doctor`: reports the problems of the glossary file, and with `fix` rewrites it in canonical
761
738
  * form when no problem would drop text. Exits 0 with no problems left, 1 with problems, 2 with no file.
@@ -764,7 +741,7 @@ async function runDoctor(options, io) {
764
741
  const format = options.format ?? "text";
765
742
  if (format !== "text" && format !== "json") throw usage(`--format is "${format}".`, "Use --format text or --format json.");
766
743
  const file = resolve(io.cwd, options.glossary ?? ".agents/glossary.md");
767
- if (!existsSync(file)) throw missingGlossary(io.cwd, file, options.glossary !== void 0);
744
+ if (!existsSync(file)) throw missingGlossary(io.cwd, file, options.glossary !== void 0, false);
768
745
  const shown = displayPath(io.cwd, file);
769
746
  let result = readGlossary(readFileSync(file, "utf8"));
770
747
  let fixed = 0;
@@ -791,27 +768,24 @@ async function runDoctor(options, io) {
791
768
  io.stdout(`${JSON.stringify(report, null, 2)}\n`);
792
769
  return problems.length > 0 ? 1 : 0;
793
770
  }
794
- const color = useColor(options, io);
795
- const summary = [];
796
- if (fixed > 0) summary.push(`Fixed ${count(fixed, "problem")} in ${shown}.`);
797
- if (problems.length === 0) {
798
- if (fixed === 0) summary.push(`No problems in ${shown}.`);
799
- } else if (fixed > 0) summary.push(`${count(problems.length, "problem")} left.`);
800
- else {
801
- const canFix = result.fixed !== void 0 ? `, ${fixable} fixable with --fix` : "";
802
- summary.push(`${count(problems.length, "problem")} in ${shown}${canFix}.`);
803
- if (options.fix && fixable > 0) summary.push("The file is unchanged: --fix would drop text, so fix the other problems first.");
804
- }
805
- const blocks = problems.map((problem) => formatProblem(problem, color));
806
- io.stdout(`${[...blocks, summary.join(" ")].join("\n\n")}\n`);
771
+ const text = formatDoctor({
772
+ file: shown,
773
+ problems: result.problems,
774
+ fixed,
775
+ rewritable: result.fixed !== void 0
776
+ }, {
777
+ color: useColor(options, io),
778
+ fix: options.fix ?? false
779
+ });
780
+ io.stdout(`${text}\n`);
807
781
  return problems.length > 0 ? 1 : 0;
808
782
  }
809
- /** Prints a config or usage error as a tree on stderr. */
783
+ /** Prints a corpus or usage error as a tree on stderr. */
810
784
  function printError(error, io, color) {
811
785
  const branches = [];
812
786
  if (error.term && !error.why.includes(`"${error.term}"`)) branches.push(["term", error.term]);
813
787
  branches.push(["fix", error.fix]);
814
- if (error.config) branches.push(["config", error.config]);
788
+ if (error.corpus) branches.push(["corpus", error.corpus]);
815
789
  const lines = branches.map(([label, text], index) => {
816
790
  const branch = index === branches.length - 1 ? "╰▶" : "├▶";
817
791
  return `${paint(color, "2", branch)} ${paint(color, "1", `${label}:`)} ${text}`;
@@ -831,19 +805,19 @@ async function main(argv, io = defaultIo()) {
831
805
  const cli = cac("glosslint");
832
806
  let run;
833
807
  let color = io.color ?? false;
834
- const configOption = "Config file (default: glosslint.config.{ts,mts,js,mjs})";
835
- const glossaryOption = `Glossary file, read when there is no config (default: ${DEFAULT_GLOSSARY})`;
808
+ const corpusOption = "Module whose default export is a corpus, instead of a glossary file";
809
+ const glossaryOption = `Glossary file (default: ${DEFAULT_GLOSSARY})`;
836
810
  const colorOption = "Color the output (default: when writing to a terminal)";
837
- cli.command("[...paths]", "Check Markdown and text files against the corpus").alias("check").option("--glossary <path>", glossaryOption).option("--config <path>", configOption).option("--format <format>", "Output format: text or json", { default: "text" }).option("--ext <list>", "Extensions read in folders, comma-separated (default: md,mdx,txt)").option("--color", colorOption).action((paths, options) => {
811
+ cli.command("[...paths]", "Check Markdown and text files against the corpus").alias("check").option("--glossary <path>", glossaryOption).option("--corpus <module>", corpusOption).option("--format <format>", "Output format: text or json", { default: "text" }).option("--ext <list>", "Extensions read in folders, comma-separated (default: md,mdx,txt)").option("--color", colorOption).action((paths, options) => {
838
812
  run = () => runCheck(paths, options, io);
839
813
  });
840
- cli.command("test", "Check every term's good and bad examples").option("--glossary <path>", glossaryOption).option("--config <path>", configOption).option("--color", colorOption).action((options) => {
814
+ cli.command("test", "Check every term's good and bad examples").option("--glossary <path>", glossaryOption).option("--corpus <module>", corpusOption).option("--color", colorOption).action((options) => {
841
815
  run = () => runTest(options, io);
842
816
  });
843
- cli.command("print", "Print the corpus as a Markdown glossary or JSON").option("--glossary <path>", glossaryOption).option("--config <path>", configOption).option("--format <format>", "Output format: md or json", { default: "md" }).action((options) => {
817
+ cli.command("print", "Print the corpus as a Markdown glossary or JSON").option("--glossary <path>", glossaryOption).option("--corpus <module>", corpusOption).option("--format <format>", "Output format: md or json", { default: "md" }).action((options) => {
844
818
  run = () => runPrint(options, io);
845
819
  });
846
- cli.command("explain <query>", "Show what the corpus says about a word or phrase").option("--glossary <path>", glossaryOption).option("--config <path>", configOption).action((query, options) => {
820
+ cli.command("explain <query>", "Show what the corpus says about a word or phrase").option("--glossary <path>", glossaryOption).option("--corpus <module>", corpusOption).action((query, options) => {
847
821
  run = () => runExplain(String(query), options, io);
848
822
  });
849
823
  cli.command("doctor", "Report the glossary file's problems, and fix the ones it can with --fix").option("--glossary <path>", `Glossary file (default: ${DEFAULT_GLOSSARY})`).option("--fix", "Rewrite the file in canonical form, unless that would drop text").option("--format <format>", "Output format: text or json", { default: "text" }).option("--color", colorOption).action((options) => {
package/dist/eslint.mjs CHANGED
@@ -1,5 +1,6 @@
1
- import { g as CONFIG_ERRORS, r as fromGlossary, x as GlosslintConfigError } from "./glossary-ztPpmozR.mjs";
2
- import { n as DEFAULT_IGNORE_CALLEES, t as createRules } from "./rules-D9Jd07u1.mjs";
1
+ import { S as GlosslintConfigError, _ as CONFIG_ERRORS } from "./glossary-text-DB0WoR1i.mjs";
2
+ import { n as DEFAULT_IGNORE_CALLEES, t as createRules } from "./rules-RPbpYGR5.mjs";
3
+ import { t as fromGlossary } from "./glossary-DvBgwOUw.mjs";
3
4
  // src/eslint.ts
4
5
  /**
5
6
  * ESLint flat configs that run glosslint's rules: `...glosslint()`. The corpus comes from `corpus`, else
@@ -1,4 +1,4 @@
1
- import { v as capitalise } from "./glossary-ztPpmozR.mjs";
1
+ import { y as capitalise } from "./glossary-text-DB0WoR1i.mjs";
2
2
  // src/format.ts
3
3
  const CODES = [
4
4
  "GLOSSLINT_TERM",
@@ -63,4 +63,31 @@ function toJson(findings, files) {
63
63
  }
64
64
  };
65
65
  }
66
- export { formatFindings as n, toJson as r, formatFinding as t };
66
+ function formatProblem(problem, file, color) {
67
+ const lines = [["fix", problem.fix]];
68
+ if (problem.term && !problem.why.includes(`"${problem.term}"`)) lines.unshift(["term", problem.term]);
69
+ const branches = lines.map(([label, text], index) => {
70
+ const branch = index === lines.length - 1 ? "╰▶" : "├▶";
71
+ return `${paint(color, "2", branch)} ${paint(color, "1", `${label}:`)} ${text}`;
72
+ });
73
+ const where = paint(color, "36", `${file}:${problem.line}`);
74
+ return [`${paint(color, "1;31", `[${problem.code}]`)} ${where}: ${problem.why}`, ...branches].join("\n");
75
+ }
76
+ /** The text `glosslint doctor` prints: each problem as a tree, then a summary line. */
77
+ function formatDoctor(result, options = {}) {
78
+ const { file, problems, fixed } = result;
79
+ const color = options.color ?? false;
80
+ const fixable = problems.filter((problem) => problem.fixable).length;
81
+ const summary = [];
82
+ if (fixed > 0) summary.push(`Fixed ${plural(fixed, "problem")} in ${file}.`);
83
+ if (problems.length === 0) {
84
+ if (fixed === 0) summary.push(`No problems in ${file}.`);
85
+ } else if (fixed > 0) summary.push(`${plural(problems.length, "problem")} left.`);
86
+ else {
87
+ const canFix = result.rewritable ? `, ${fixable} fixable with --fix` : "";
88
+ summary.push(`${plural(problems.length, "problem")} in ${file}${canFix}.`);
89
+ if (options.fix && fixable > 0) summary.push("The file is unchanged: --fix would drop text, so fix the other problems first.");
90
+ }
91
+ return [...problems.map((problem) => formatProblem(problem, file, color)), summary.join(" ")].join("\n\n");
92
+ }
93
+ export { toJson as i, formatFinding as n, formatFindings as r, formatDoctor as t };
@@ -0,0 +1,39 @@
1
+ import { S as GlosslintConfigError, _ as CONFIG_ERRORS, i as parseGlossary, n as DEFAULT_GLOSSARY, t as BLOCKING } from "./glossary-text-DB0WoR1i.mjs";
2
+ import { existsSync, readFileSync } from "node:fs";
3
+ import { isAbsolute, relative, resolve } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ // src/glossary.ts
6
+ function displayPath(file) {
7
+ const shown = relative(process.cwd(), file);
8
+ return shown && !shown.startsWith("..") && !isAbsolute(shown) ? shown : file;
9
+ }
10
+ /** The absolute path of a glossary: a string resolves from the current folder. */
11
+ function glossaryPath(path = DEFAULT_GLOSSARY) {
12
+ return typeof path === "string" ? resolve(process.cwd(), path) : fileURLToPath(path);
13
+ }
14
+ /**
15
+ * Reads a glossary file, `.agents/glossary.md` by default, as a corpus. Throws a `GlosslintConfigError`
16
+ * when the file is missing (`GLOSSLINT_C009`) or has a problem only a person can fix (`G004` to `G008`).
17
+ * A file with only fixable problems loads as its fixed form would.
18
+ */
19
+ function fromGlossary(path = DEFAULT_GLOSSARY) {
20
+ const file = glossaryPath(path);
21
+ const shown = displayPath(file);
22
+ if (!existsSync(file)) throw new GlosslintConfigError({
23
+ code: CONFIG_ERRORS.noGlossary,
24
+ why: `No glossary at ${shown}.`,
25
+ fix: `Create ${shown} with \`# Glossary\` and a \`## Term\` section per term, or pass the path of your glossary.`
26
+ });
27
+ const { problems, corpus } = parseGlossary(readFileSync(file, "utf8"), false);
28
+ if (corpus) return corpus;
29
+ const blocking = problems.filter((problem) => BLOCKING.has(problem.code));
30
+ const [first] = blocking;
31
+ const more = blocking.length > 1 ? ` ${blocking.length - 1} more problem${blocking.length > 2 ? "s" : ""}: run \`glosslint doctor\` to list them.` : "";
32
+ throw new GlosslintConfigError({
33
+ code: first.code,
34
+ why: `${shown}:${first.line}: ${first.why}`,
35
+ fix: `${first.fix}${more}`,
36
+ ...first.term === void 0 ? {} : { term: first.term }
37
+ });
38
+ }
39
+ export { fromGlossary as t };
@@ -23,10 +23,4 @@ declare function readGlossary(text: string): {
23
23
  corpus?: Corpus;
24
24
  fixed?: string;
25
25
  };
26
- /**
27
- * Reads a glossary file, `.agents/glossary.md` by default, as a corpus. Throws a `GlosslintConfigError`
28
- * when the file is missing (`GLOSSLINT_C009`) or has a problem only a person can fix (`G004` to `G008`).
29
- * A file with only fixable problems loads as its fixed form would.
30
- */
31
- declare function fromGlossary(path?: string | URL): Corpus;
32
- export { fromGlossary as n, readGlossary as r, GlossaryProblem as t };
26
+ export { readGlossary as n, GlossaryProblem as t };
@@ -1,9 +1,6 @@
1
1
  import { t as corpus } from "./inclusive-CP6oU8NW.mjs";
2
2
  import { t as corpus$1 } from "./tech-D0v3ss45.mjs";
3
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
4
  // src/errors.ts
8
5
  /** A problem in the corpus or the config, with what to change. */
9
6
  var GlosslintConfigError = class extends Error {
@@ -447,6 +444,7 @@ function byName(name, text) {
447
444
  const words = splitWords(name ?? "").map((word) => HEADING_TAG.test(word) ? "heading" : word.toLowerCase().replace(/\d+$/, ""));
448
445
  const last = words.at(-1) ?? "";
449
446
  const header = words.some((word) => HEADER_WORD.test(word));
447
+ if (SENTENCE_WORD.test(last)) return "sentence";
450
448
  if ((header || words.some((word) => LABEL_WORD.test(word)) || last === "name") && !endsSentence && splitWords(trimmed).length <= 7) return header ? "header" : "label";
451
449
  if (words.some((word) => SENTENCE_WORD.test(word)) || endsSentence) return "sentence";
452
450
  return "unknown";
@@ -1220,7 +1218,7 @@ function toX18nGlossary(corpus) {
1220
1218
  };
1221
1219
  });
1222
1220
  }
1223
- // src/glossary.ts
1221
+ // src/glossary-text.ts
1224
1222
  /** The codes of `GlossaryProblem`. */
1225
1223
  const GLOSSARY_PROBLEMS = {
1226
1224
  title: "GLOSSLINT_G001",
@@ -1251,7 +1249,7 @@ const BLOCKING = /* @__PURE__ */ new Set([
1251
1249
  const DEFAULT_GLOSSARY = ".agents/glossary.md";
1252
1250
  const CORPUS_FIELDS = [
1253
1251
  {
1254
- name: "Extends",
1252
+ name: "Presets",
1255
1253
  kind: "list",
1256
1254
  comma: true
1257
1255
  },
@@ -1299,9 +1297,15 @@ const TERM_FIELDS = [
1299
1297
  {
1300
1298
  name: "Case",
1301
1299
  kind: "value"
1300
+ },
1301
+ {
1302
+ name: "Casing",
1303
+ kind: "list",
1304
+ comma: true
1302
1305
  }
1303
1306
  ];
1304
1307
  const ALIASES = {
1308
+ extends: "Presets",
1305
1309
  description: "What",
1306
1310
  meaning: "What",
1307
1311
  notes: "How",
@@ -1706,7 +1710,7 @@ var Reader = class {
1706
1710
  for (const item of node.items) {
1707
1711
  const text = itemText(item);
1708
1712
  if (text === "") bad(item.line, `An item of ${name} is empty.`, "Write the item, or remove its line.");
1709
- else if (name === "Extends" && !(text in PRESETS)) bad(item.line, `"${text}" is not a preset.`, `Use ${quoteList(Object.keys(PRESETS))}.`);
1713
+ else if (name === "Presets" && !Object.hasOwn(PRESETS, text)) bad(item.line, `"${text}" is not a preset.`, `Use ${quoteList(Object.keys(PRESETS))}.`);
1710
1714
  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`.");
1711
1715
  else if (name === "Avoid" && termKey(parseAvoid(text).word) === "") bad(item.line, `"${text}" has no word to avoid.`, "Write it as `word` or `word: reason`.");
1712
1716
  else if (name === "Links" && !LINK.test(text)) {
@@ -1785,21 +1789,28 @@ function buildTerm(node) {
1785
1789
  }] : [];
1786
1790
  });
1787
1791
  if (links.length) term.links = links;
1792
+ const casing = parseCasing(items("Casing"));
1793
+ if (Object.keys(casing).length) term.casing = casing;
1788
1794
  const mode = field("Case")?.value;
1789
1795
  if (mode) term.case = mode;
1790
- else if (isExactName(node.name)) term.case = "exact";
1796
+ else if (!term.casing && isExactName(node.name)) term.case = "exact";
1791
1797
  return term;
1792
1798
  }
1793
- function buildCorpus(doc, terms) {
1794
- const items = (name) => doc.corpus.get(name)?.items.map(itemText).filter(Boolean) ?? [];
1799
+ /** `label sentence, sentence as-written` as a `Casing`. */
1800
+ function parseCasing(pairs) {
1795
1801
  const casing = {};
1796
- for (const pair of items("Casing")) {
1802
+ for (const pair of pairs) {
1797
1803
  const [, kind, style] = CASING.exec(pair);
1798
1804
  casing[kind] = style;
1799
1805
  }
1806
+ return casing;
1807
+ }
1808
+ function buildCorpus(doc, terms) {
1809
+ const items = (name) => doc.corpus.get(name)?.items.map(itemText).filter(Boolean) ?? [];
1810
+ const casing = parseCasing(items("Casing"));
1800
1811
  const allow = items("Allow");
1801
1812
  return defineCorpus({
1802
- extends: items("Extends").map((name) => PRESETS[name]),
1813
+ extends: items("Presets").map((name) => PRESETS[name]),
1803
1814
  terms,
1804
1815
  ...allow.length ? { allow } : {},
1805
1816
  ...Object.keys(casing).length ? { casing } : {}
@@ -1827,7 +1838,8 @@ function failingExamples(reader, doc, corpus, own) {
1827
1838
  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);
1828
1839
  }
1829
1840
  }
1830
- function parse(text, examples) {
1841
+ /** Reads a glossary's text, and with `examples` runs each term's examples too (`G009`). */
1842
+ function parseGlossary(text, examples) {
1831
1843
  const lines = text.split(/\r?\n/);
1832
1844
  if (lines.at(-1) === "") lines.pop();
1833
1845
  const reader = new Reader(lines);
@@ -1867,39 +1879,6 @@ function parse(text, examples) {
1867
1879
  * `fixed`, the canonical text, when the file can be rewritten and differs from it.
1868
1880
  */
1869
1881
  function readGlossary(text) {
1870
- return parse(text, true);
1871
- }
1872
- function displayPath(file) {
1873
- const shown = relative(process.cwd(), file);
1874
- return shown && !shown.startsWith("..") && !isAbsolute(shown) ? shown : file;
1875
- }
1876
- /** The absolute path of a glossary: a string resolves from the current folder. */
1877
- function glossaryPath(path = DEFAULT_GLOSSARY) {
1878
- return typeof path === "string" ? resolve(process.cwd(), path) : fileURLToPath(path);
1879
- }
1880
- /**
1881
- * Reads a glossary file, `.agents/glossary.md` by default, as a corpus. Throws a `GlosslintConfigError`
1882
- * when the file is missing (`GLOSSLINT_C009`) or has a problem only a person can fix (`G004` to `G008`).
1883
- * A file with only fixable problems loads as its fixed form would.
1884
- */
1885
- function fromGlossary(path = DEFAULT_GLOSSARY) {
1886
- const file = glossaryPath(path);
1887
- const shown = displayPath(file);
1888
- if (!existsSync(file)) throw new GlosslintConfigError({
1889
- code: CONFIG_ERRORS.noGlossary,
1890
- why: `No glossary at ${shown}.`,
1891
- fix: `Create ${shown} with \`# Glossary\` and a \`## Term\` section per term, or pass the path of your glossary.`
1892
- });
1893
- const { problems, corpus } = parse(readFileSync(file, "utf8"), false);
1894
- if (corpus) return corpus;
1895
- const blocking = problems.filter((problem) => BLOCKING.has(problem.code));
1896
- const [first] = blocking;
1897
- const more = blocking.length > 1 ? ` ${blocking.length - 1} more problem${blocking.length > 2 ? "s" : ""}: run \`glosslint doctor\` to list them.` : "";
1898
- throw new GlosslintConfigError({
1899
- code: first.code,
1900
- why: `${shown}:${first.line}: ${first.why}`,
1901
- fix: `${first.fix}${more}`,
1902
- ...first.term === void 0 ? {} : { term: first.term }
1903
- });
1882
+ return parseGlossary(text, true);
1904
1883
  }
1905
- export { defineCorpus as _, explain as a, splitWords as b, testCorpus as c, createMatcher as d, caseModeOf as f, CONFIG_ERRORS as g, kindOf as h, readGlossary as i, toX18nGlossary as l, isTextName 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, capitalise as v, GlosslintConfigError as x, isCodeShape as y };
1884
+ export { GlosslintConfigError as S, CONFIG_ERRORS as _, readGlossary as a, isCodeShape as b, printCorpus as c, check as d, createMatcher as f, kindOf as g, isTextName as h, parseGlossary as i, testCorpus as l, classify as m, DEFAULT_GLOSSARY as n, explain as o, caseModeOf as p, GLOSSARY_PROBLEMS as r, explainMatches as s, BLOCKING as t, toX18nGlossary as u, defineCorpus as v, splitWords as x, capitalise as y };
package/dist/index.d.mts CHANGED
@@ -1,5 +1,11 @@
1
1
  import { S as X18nGlossaryEntry, _ as Link, a as CasingKind, b as TermSummary, c as Corpus, d as Finding, f as FindingCode, g as KindSite, h as KindOf, i as Casing, l as CorpusInput, m as FixKind, n as CaseMode, o as CliFinding, p as Fix, r as CaseStyle, s as CliReport, t as Avoid, u as CorpusTestFailure, v as Matcher, x as TextKind, y as Term } from "./types-Bbp_cYfZ.mjs";
2
- import { n as fromGlossary, r as readGlossary, t as GlossaryProblem } from "./glossary-DmTK_e1d.mjs";
2
+ import { n as readGlossary, t as GlossaryProblem } from "./glossary-text-C9pAOd4h.mjs";
3
+ /**
4
+ * Reads a glossary file, `.agents/glossary.md` by default, as a corpus. Throws a `GlosslintConfigError`
5
+ * when the file is missing (`GLOSSLINT_C009`) or has a problem only a person can fix (`G004` to `G008`).
6
+ * A file with only fixable problems loads as its fixed form would.
7
+ */
8
+ export declare function fromGlossary(path?: string | URL): Corpus;
3
9
  /** Stable codes of `GlosslintConfigError`. */
4
10
  export declare const CONFIG_ERRORS: {
5
11
  readonly unknownField: "GLOSSLINT_C001";
@@ -71,4 +77,4 @@ export declare function printCorpus(corpus: Corpus, format: "md" | "json"): stri
71
77
  export declare function explain(corpus: Corpus, query: string): string;
72
78
  /** The corpus as x18n `glossary` entries, with only the fields x18n accepts. */
73
79
  export declare function toX18nGlossary(corpus: Corpus): X18nGlossaryEntry[];
74
- export { type Avoid, type CaseMode, type CaseStyle, type Casing, type CasingKind, type CliFinding, type CliReport, type Corpus, type CorpusInput, type CorpusTestFailure, type Finding, type FindingCode, type Fix, type FixKind, type FormatOptions, type GlossaryProblem, type KindOf, type KindSite, type Link, type Matcher, type MatcherOptions, type Term, type TermSummary, type TextKind, type X18nGlossaryEntry, fromGlossary, readGlossary };
80
+ export { type Avoid, type CaseMode, type CaseStyle, type Casing, type CasingKind, type CliFinding, type CliReport, type Corpus, type CorpusInput, type CorpusTestFailure, type Finding, type FindingCode, type Fix, type FixKind, type FormatOptions, type GlossaryProblem, type KindOf, type KindSite, type Link, type Matcher, type MatcherOptions, type Term, type TermSummary, type TextKind, type X18nGlossaryEntry, readGlossary };
package/dist/index.mjs CHANGED
@@ -1,3 +1,4 @@
1
- import { _ as defineCorpus, a as explain, c as testCorpus, d as createMatcher, g as CONFIG_ERRORS, h as kindOf, i as readGlossary, l as toX18nGlossary, r as fromGlossary, s as printCorpus, u as check, x as GlosslintConfigError } from "./glossary-ztPpmozR.mjs";
2
- import { n as formatFindings, r as toJson, t as formatFinding } from "./format-E5eFHoQT.mjs";
1
+ import { S as GlosslintConfigError, _ as CONFIG_ERRORS, a as readGlossary, c as printCorpus, d as check, f as createMatcher, g as kindOf, l as testCorpus, o as explain, u as toX18nGlossary, v as defineCorpus } from "./glossary-text-DB0WoR1i.mjs";
2
+ import { i as toJson, n as formatFinding, r as formatFindings } from "./format-BVGriClu.mjs";
3
+ import { t as fromGlossary } from "./glossary-DvBgwOUw.mjs";
3
4
  export { CONFIG_ERRORS, GlosslintConfigError, check, createMatcher, defineCorpus, explain, formatFinding, formatFindings, fromGlossary, kindOf, printCorpus, readGlossary, testCorpus, toJson, toX18nGlossary };
package/dist/oxlint.mjs CHANGED
@@ -1,5 +1,6 @@
1
- import { n as DEFAULT_IGNORE_CALLEES, t as createRules } from "./rules-D9Jd07u1.mjs";
2
- import { r as fromGlossary } from "./glossary-ztPpmozR.mjs";
1
+ import "./glossary-text-DB0WoR1i.mjs";
2
+ import { n as DEFAULT_IGNORE_CALLEES, t as createRules } from "./rules-RPbpYGR5.mjs";
3
+ import { t as fromGlossary } from "./glossary-DvBgwOUw.mjs";
3
4
  import { resolve } from "node:path";
4
5
  // src/oxlint.ts
5
6
  const corpora = /* @__PURE__ */ new Map();
@@ -1,4 +1,4 @@
1
- import { b as splitWords, d as createMatcher, f as caseModeOf, p as classify, y as isCodeShape } from "./glossary-ztPpmozR.mjs";
1
+ import { b as isCodeShape, f as createMatcher, m as classify, p as caseModeOf, x as splitWords } from "./glossary-text-DB0WoR1i.mjs";
2
2
  // src/eslint/offsets.ts
3
3
  /**
4
4
  * Maps from a string's cooked value back to its source text. Each map has one entry per UTF-16 unit of
package/dist/x18n.mjs CHANGED
@@ -1,5 +1,6 @@
1
- import { d as createMatcher, f as caseModeOf, g as CONFIG_ERRORS, p as classify, r as fromGlossary, x as GlosslintConfigError } from "./glossary-ztPpmozR.mjs";
2
- // src/x18n.ts
1
+ import { S as GlosslintConfigError, _ as CONFIG_ERRORS, f as createMatcher, m as classify, p as caseModeOf } from "./glossary-text-DB0WoR1i.mjs";
2
+ import { t as fromGlossary } from "./glossary-DvBgwOUw.mjs";
3
+ // src/x18n/plugin.ts
3
4
  const CHECKS = [
4
5
  {
5
6
  id: "glosslint-term",
@@ -82,17 +83,9 @@ function messageFixes(message, value, finding, autofixes) {
82
83
  ops: set([finding])
83
84
  }];
84
85
  }
85
- /**
86
- * An x18n plugin that checks source-locale messages and hard strings against the corpus. The corpus comes from
87
- * `corpus`, else from the `glossary` file, else from `.agents/glossary.md`, read once when the plugin is built.
88
- */
89
- function glosslint(options = {}) {
90
- if (options.corpus && options.glossary !== void 0) throw new GlosslintConfigError({
91
- code: CONFIG_ERRORS.glossaryAndCorpus,
92
- why: "glosslint() takes `glossary` or `corpus`, not both.",
93
- fix: "Pass `glossary` to read a file, or `corpus` with `extends: [fromGlossary(…)]` to add to one."
94
- });
95
- const matcher = createMatcher(options.corpus ?? fromGlossary(options.glossary));
86
+ /** The x18n plugin for a corpus. `x18n.ts` reads the corpus from a glossary file when it is given none. */
87
+ function createPlugin(corpus, options = {}) {
88
+ const matcher = createMatcher(corpus);
96
89
  function* collect(ctx) {
97
90
  const locale = options.sourceLocale ?? ctx.sourceLocale;
98
91
  const paths = new Map(ctx.resources.map((resource) => [resource.id, resource.path]));
@@ -161,4 +154,18 @@ function glosslint(options = {}) {
161
154
  }))
162
155
  };
163
156
  }
157
+ // src/x18n.ts
158
+ /**
159
+ * An x18n plugin that checks source-locale messages and hard strings against the corpus. The corpus comes from
160
+ * `corpus`, else from the `glossary` file, else from `.agents/glossary.md`, read once when the plugin is built.
161
+ */
162
+ function glosslint(options = {}) {
163
+ if (options.corpus && options.glossary !== void 0) throw new GlosslintConfigError({
164
+ code: CONFIG_ERRORS.glossaryAndCorpus,
165
+ why: "glosslint() takes `glossary` or `corpus`, not both.",
166
+ fix: "Pass `glossary` to read a file, or `corpus` with `extends: [fromGlossary(…)]` to add to one."
167
+ });
168
+ const { glossary, corpus, ...settings } = options;
169
+ return createPlugin(corpus ?? fromGlossary(glossary), settings);
170
+ }
164
171
  export { glosslint as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "glosslint",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Lint product terms against a corpus of words to use and avoid, with what each one means, in ESLint, x18n and a CLI",
5
5
  "keywords": [
6
6
  "case-police",