glosslint 0.1.1 → 0.1.2

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/dist/cli.d.mts CHANGED
@@ -1,5 +1,18 @@
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
18
  /** The folder paths and the config are resolved from. */
@@ -79,19 +92,6 @@ export declare function loadCorpus(cwd: string, options?: {
79
92
  config?: string;
80
93
  glossary?: string;
81
94
  }): 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
95
  /** The files `check` reads: named files as they are, folders by extension, and glob patterns. */
96
96
  export declare function collectFiles(paths: readonly string[], cwd: string, extensions?: readonly string[]): Promise<string[]>;
97
97
  /** `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-C09ByS5j.mjs";
3
+ import { i as toJson, r as formatFindings, t as formatDoctor } from "./format-DSSwOlXH.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.1.2";
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,141 @@ 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
+ noConfig: "GLOSSLINT_C009",
487
+ loadConfig: "GLOSSLINT_C010",
488
+ notCorpus: "GLOSSLINT_C008",
489
+ usage: "GLOSSLINT_USAGE",
490
+ failed: "GLOSSLINT_ERROR"
491
+ };
492
+ const CONFIG_FILES = [
493
+ "glosslint.config.ts",
494
+ "glosslint.config.mts",
495
+ "glosslint.config.js",
496
+ "glosslint.config.mjs"
497
+ ];
498
+ const DEFAULT_EXTENSIONS = [
499
+ "md",
500
+ "mdx",
501
+ "txt"
502
+ ];
503
+ const MARKDOWN = /* @__PURE__ */ new Set([
504
+ ".md",
505
+ ".mdx",
506
+ ".markdown"
507
+ ]);
508
+ /** An error the CLI prints as a tree and exits 2 on: a bad config or a bad command line. */
509
+ var CliError = class extends Error {
510
+ code;
511
+ why;
512
+ fix;
513
+ term;
514
+ config;
515
+ constructor(options) {
516
+ super(options.why);
517
+ this.code = options.code;
518
+ this.why = options.why;
519
+ this.fix = options.fix;
520
+ if (options.term !== void 0) this.term = options.term;
521
+ if (options.config !== void 0) this.config = options.config;
522
+ }
523
+ };
524
+ function isConfigError(error) {
525
+ return error instanceof Error && error.name === "GlosslintConfigError" && typeof error.code === "string" && typeof error.fix === "string";
526
+ }
527
+ function isCorpus(value) {
528
+ return typeof value === "object" && value !== null && value.kind === "glosslint.corpus" && Array.isArray(value.terms) && Array.isArray(value.allow);
529
+ }
530
+ const paint = (on, code, text) => on ? `\u001B[${code}m${text}\u001B[0m` : text;
531
+ const toPosix = (path) => path.split(sep).join("/");
532
+ function displayPath(cwd, file) {
533
+ return toPosix(relative(cwd, file)) || ".";
534
+ }
535
+ /**
536
+ * Finds the corpus: `config`, else `glossary`, else `glosslint.config.{ts,mts,js,mjs}` in `cwd`, else
537
+ * `.agents/glossary.md` in `cwd`.
538
+ */
539
+ async function loadCorpus(cwd, options = {}) {
540
+ const { config, glossary } = options;
541
+ 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.");
542
+ if (config !== void 0) return importConfig(cwd, resolve(cwd, config), config);
543
+ if (glossary !== void 0) return loadGlossary(cwd, glossary, true);
544
+ const found = CONFIG_FILES.map((name) => resolve(cwd, name)).find((path) => existsSync(path));
545
+ if (found) return importConfig(cwd, found);
546
+ if (existsSync(resolve(cwd, ".agents/glossary.md"))) return loadGlossary(cwd, DEFAULT_GLOSSARY, false);
547
+ throw new CliError({
548
+ code: CLI_ERRORS.noConfig,
549
+ why: `No ${DEFAULT_GLOSSARY} and no glosslint.config.ts, .mts, .js or .mjs in the current folder.`,
550
+ fix: `Create ${DEFAULT_GLOSSARY} with \`# Glossary\` and a \`## Term\` section per term, or pass --glossary <path> or --config <path>.`
551
+ });
552
+ }
553
+ /** `G004` to `G008`: the problems only a person can fix, which leave no corpus. */
554
+ function leavesNoCorpus(problem) {
555
+ return !problem.fixable && problem.code !== GLOSSARY_PROBLEMS.failingExample;
556
+ }
557
+ function missingGlossary(cwd, file, given) {
558
+ const shown = displayPath(cwd, file);
559
+ return new CliError({
560
+ code: CLI_ERRORS.noConfig,
561
+ why: given ? `The glossary "${shown}" does not exist.` : `No glossary at ${shown}.`,
562
+ fix: given ? "Check the path given to --glossary." : `Create ${shown} with \`# Glossary\` and a \`## Term\` section per term, or pass --glossary <path>.`
563
+ });
564
+ }
565
+ /** Reads a glossary file as a corpus, or throws its first problem that leaves no corpus. */
566
+ function loadGlossary(cwd, path, given) {
567
+ const file = resolve(cwd, path);
568
+ if (!existsSync(file)) throw missingGlossary(cwd, file, given);
569
+ const { problems, corpus } = readGlossary(readFileSync(file, "utf8"));
570
+ if (corpus) return {
571
+ corpus,
572
+ file,
573
+ from: "glossary"
574
+ };
575
+ const blocking = problems.filter(leavesNoCorpus);
576
+ const first = blocking[0];
577
+ const doctor = given ? `glosslint doctor --glossary ${path}` : "glosslint doctor";
578
+ const more = blocking.length > 1 ? ` ${count(blocking.length - 1, "more problem")}: run \`${doctor}\` to list them.` : "";
579
+ throw new CliError({
580
+ code: first.code,
581
+ why: `${displayPath(cwd, file)}:${first.line}: ${first.why}`,
582
+ fix: `${first.fix}${more}`,
583
+ ...first.term === void 0 ? {} : { term: first.term }
584
+ });
585
+ }
586
+ /** Imports a config and returns its default export, which must be a corpus. */
587
+ async function importConfig(cwd, file, given) {
588
+ if (given !== void 0 && !existsSync(file)) throw new CliError({
589
+ code: CLI_ERRORS.noConfig,
590
+ why: `The config "${given}" does not exist.`,
591
+ fix: "Check the path given to --config."
592
+ });
593
+ const shown = displayPath(cwd, file);
594
+ let loaded;
595
+ try {
596
+ loaded = await import(pathToFileURL(file).href);
597
+ } catch (error) {
598
+ if (isConfigError(error)) throw Object.assign(error, { config: shown });
599
+ throw new CliError({
600
+ code: CLI_ERRORS.loadConfig,
601
+ why: `Could not load ${shown}: ${error instanceof Error ? error.message : String(error)}`,
602
+ fix: "Fix the error in the config, then run glosslint again.",
603
+ config: shown
604
+ });
605
+ }
606
+ if (!isCorpus(loaded.default)) throw new CliError({
607
+ code: CLI_ERRORS.notCorpus,
608
+ why: `${shown} does not export a corpus as its default export.`,
609
+ fix: "End the config with `export default defineCorpus({ … })`.",
610
+ config: shown
611
+ });
612
+ return {
613
+ corpus: loaded.default,
614
+ file,
615
+ from: "config"
616
+ };
617
+ }
617
618
  function usage(why, fix) {
618
619
  return new CliError({
619
620
  code: CLI_ERRORS.usage,
@@ -746,16 +747,6 @@ async function runExplain(query, options, io) {
746
747
  io.stdout(`${explain(corpus, query)}\n`);
747
748
  return explainMatches(corpus, query).length > 0 ? 0 : 1;
748
749
  }
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
750
  /**
760
751
  * `glosslint doctor`: reports the problems of the glossary file, and with `fix` rewrites it in canonical
761
752
  * form when no problem would drop text. Exits 0 with no problems left, 1 with problems, 2 with no file.
@@ -791,19 +782,16 @@ async function runDoctor(options, io) {
791
782
  io.stdout(`${JSON.stringify(report, null, 2)}\n`);
792
783
  return problems.length > 0 ? 1 : 0;
793
784
  }
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`);
785
+ const text = formatDoctor({
786
+ file: shown,
787
+ problems: result.problems,
788
+ fixed,
789
+ rewritable: result.fixed !== void 0
790
+ }, {
791
+ color: useColor(options, io),
792
+ fix: options.fix ?? false
793
+ });
794
+ io.stdout(`${text}\n`);
807
795
  return problems.length > 0 ? 1 : 0;
808
796
  }
809
797
  /** Prints a config or usage error as a tree on stderr. */
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-C09ByS5j.mjs";
2
+ import { n as DEFAULT_IGNORE_CALLEES, t as createRules } from "./rules-CjMuomuR.mjs";
3
+ import { t as fromGlossary } from "./glossary-CWqmN9Bg.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-C09ByS5j.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-C09ByS5j.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 };
@@ -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 {
@@ -1220,7 +1217,7 @@ function toX18nGlossary(corpus) {
1220
1217
  };
1221
1218
  });
1222
1219
  }
1223
- // src/glossary.ts
1220
+ // src/glossary-text.ts
1224
1221
  /** The codes of `GlossaryProblem`. */
1225
1222
  const GLOSSARY_PROBLEMS = {
1226
1223
  title: "GLOSSLINT_G001",
@@ -1827,7 +1824,8 @@ function failingExamples(reader, doc, corpus, own) {
1827
1824
  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
1825
  }
1829
1826
  }
1830
- function parse(text, examples) {
1827
+ /** Reads a glossary's text, and with `examples` runs each term's examples too (`G009`). */
1828
+ function parseGlossary(text, examples) {
1831
1829
  const lines = text.split(/\r?\n/);
1832
1830
  if (lines.at(-1) === "") lines.pop();
1833
1831
  const reader = new Reader(lines);
@@ -1867,39 +1865,6 @@ function parse(text, examples) {
1867
1865
  * `fixed`, the canonical text, when the file can be rewritten and differs from it.
1868
1866
  */
1869
1867
  function readGlossary(text) {
1870
- return parse(text, true);
1868
+ return parseGlossary(text, true);
1871
1869
  }
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
- });
1904
- }
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 };
1870
+ 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 };
@@ -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 };
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-C09ByS5j.mjs";
2
+ import { i as toJson, n as formatFinding, r as formatFindings } from "./format-DSSwOlXH.mjs";
3
+ import { t as fromGlossary } from "./glossary-CWqmN9Bg.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-C09ByS5j.mjs";
2
+ import { n as DEFAULT_IGNORE_CALLEES, t as createRules } from "./rules-CjMuomuR.mjs";
3
+ import { t as fromGlossary } from "./glossary-CWqmN9Bg.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-C09ByS5j.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-C09ByS5j.mjs";
2
+ import { t as fromGlossary } from "./glossary-CWqmN9Bg.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.1.2",
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",