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.
- package/README.md +53 -36
- package/dist/cli.d.mts +48 -4
- package/dist/cli.mjs +142 -35
- package/dist/eslint.d.mts +9 -6
- package/dist/eslint.mjs +18 -771
- package/dist/format-CQ9xdJYe.mjs +66 -0
- package/dist/glossary-DmTK_e1d.d.mts +32 -0
- package/dist/glossary-lk7EwGey.mjs +1872 -0
- package/dist/inclusive-CP6oU8NW.mjs +520 -0
- package/dist/index.d.mts +6 -26
- package/dist/index.mjs +3 -459
- package/dist/oxlint.d.mts +26 -0
- package/dist/oxlint.mjs +33 -0
- package/dist/presets/inclusive.d.mts +1 -1
- package/dist/presets/inclusive.mjs +1 -520
- package/dist/presets/tech.d.mts +1 -1
- package/dist/presets/tech.mjs +1 -2401
- package/dist/rules-D-PrDySk.mjs +768 -0
- package/dist/tech-D0v3ss45.mjs +2401 -0
- package/dist/{types-CBQGgzID.d.mts → types-Bbp_cYfZ.d.mts} +3 -1
- package/dist/x18n.d.mts +10 -5
- package/dist/x18n.mjs +12 -4
- package/package.json +16 -2
- package/dist/matcher-Xz4vspsE.mjs +0 -715
- package/dist/tools-BrdtyK9t.mjs +0 -275
package/README.md
CHANGED
|
@@ -11,54 +11,62 @@
|
|
|
11
11
|
|
|
12
12
|
[](https://glosslint.onmax.me)
|
|
13
13
|
|
|
14
|
-
glosslint checks
|
|
14
|
+
glosslint checks your product's vocabulary against one Markdown file, `.agents/glossary.md`. People and coding agents read that file directly, while ESLint, Oxlint, x18n and the CLI enforce it on code, translations and docs. Every finding carries the reason and meaning alongside the fix.
|
|
15
15
|
|
|
16
|
-
[Docs](https://glosslint.onmax.me) · [Installation](https://glosslint.onmax.me/guide/installation) · [The
|
|
16
|
+
[Docs](https://glosslint.onmax.me) · [Installation](https://glosslint.onmax.me/guide/installation) · [The glossary file](https://glosslint.onmax.me/guide/glossary) · [ESLint](https://glosslint.onmax.me/integrations/eslint) · [Oxlint](https://glosslint.onmax.me/integrations/oxlint) · [x18n](https://glosslint.onmax.me/integrations/x18n) · [CLI](https://glosslint.onmax.me/integrations/cli) · [For agents](https://glosslint.onmax.me/guide/agents)
|
|
17
17
|
|
|
18
|
-
##
|
|
18
|
+
## The glossary
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
Write your product's terms in `.agents/glossary.md`. This excerpt comes from the bike-share app in [`examples/basic/.agents/glossary.md`](https://github.com/onmax/glosslint/blob/main/examples/basic/.agents/glossary.md):
|
|
21
|
+
|
|
22
|
+
<!-- prettier-ignore -->
|
|
23
|
+
```md
|
|
24
|
+
# Glossary
|
|
23
25
|
|
|
24
|
-
|
|
26
|
+
The words the rider app and the help center use.
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
Extends: tech, inclusive
|
|
29
|
+
Allow: check out our, roof rack
|
|
27
30
|
|
|
28
|
-
|
|
31
|
+
## Dock
|
|
32
|
+
What: A powered stand where one bike is locked.
|
|
33
|
+
How: A station is a group of docks.
|
|
34
|
+
Avoid:
|
|
35
|
+
- rack: Racks are unpowered.
|
|
36
|
+
- bay
|
|
37
|
+
Good:
|
|
38
|
+
- Return the bike to any dock
|
|
39
|
+
Bad:
|
|
40
|
+
- Return the bike to any rack
|
|
41
|
+
Links:
|
|
42
|
+
- [Docks](https://example.com/docs/docks)
|
|
29
43
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
44
|
+
## eBike
|
|
45
|
+
|
|
46
|
+
## Day Pass (DP)
|
|
47
|
+
Case: context
|
|
34
48
|
```
|
|
35
49
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
terms: [
|
|
43
|
-
{
|
|
44
|
-
term: "Dock",
|
|
45
|
-
description: "A powered stand where one bike is locked.",
|
|
46
|
-
nuance: "A station is a group of docks.",
|
|
47
|
-
avoid: [{ word: "rack", why: "Racks are unpowered." }, "bay"],
|
|
48
|
-
examples: { good: ["Return the bike to any dock"], bad: ["Return the bike to any rack"] },
|
|
49
|
-
links: [{ title: "Docks", url: "https://example.com/docs/docks" }],
|
|
50
|
-
},
|
|
51
|
-
{ term: "eBike", case: "exact" },
|
|
52
|
-
],
|
|
53
|
-
});
|
|
50
|
+
`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`.
|
|
51
|
+
|
|
52
|
+
## Install
|
|
53
|
+
|
|
54
|
+
```sh
|
|
55
|
+
pnpm add -D glosslint
|
|
54
56
|
```
|
|
55
57
|
|
|
56
|
-
|
|
58
|
+
glosslint requires Node 22.18 or later. ESLint (`>=9.15.0`), Oxlint (`>=1.94.0`) and `@x18n/core` (`>=0.1.14`) are optional peer dependencies. Install only the ones you use.
|
|
59
|
+
|
|
60
|
+
## One finding
|
|
61
|
+
|
|
62
|
+
Run the CLI on Markdown docs:
|
|
57
63
|
|
|
58
64
|
```sh
|
|
59
65
|
npx glosslint check docs/guide
|
|
60
66
|
```
|
|
61
67
|
|
|
68
|
+
Here is one finding from `examples/basic`:
|
|
69
|
+
|
|
62
70
|
```txt
|
|
63
71
|
[GLOSSLINT_AVOID] "rack" in docs/guide/riding.md:3:56
|
|
64
72
|
├▶ why: Racks are unpowered.
|
|
@@ -69,13 +77,22 @@ npx glosslint check docs/guide
|
|
|
69
77
|
|
|
70
78
|
## Where it checks
|
|
71
79
|
|
|
72
|
-
- [ESLint](https://glosslint.onmax.me/integrations/eslint) checks strings, comments and
|
|
73
|
-
- [
|
|
74
|
-
- [
|
|
80
|
+
- [ESLint](https://glosslint.onmax.me/integrations/eslint): `glosslint()` reads `.agents/glossary.md` with no options and checks strings, comments and identifiers in JavaScript, TypeScript and Vue templates, plus YAML locale values.
|
|
81
|
+
- [Oxlint](https://glosslint.onmax.me/integrations/oxlint): add `"glosslint/oxlint"` to `jsPlugins` in `.oxlintrc.json` to run the four rules on JavaScript, TypeScript and Vue `<script>` blocks (Oxlint JS plugins are alpha).
|
|
82
|
+
- [x18n](https://glosslint.onmax.me/integrations/x18n): check source-locale messages and hard-coded strings, and pass the corpus to `toX18nGlossary` for x18n's glossary.
|
|
83
|
+
- [CLI](https://glosslint.onmax.me/integrations/cli): checks Markdown, MDX and text files, tests term examples, prints corpora and explains words from the terminal.
|
|
84
|
+
|
|
85
|
+
## Doctor
|
|
86
|
+
|
|
87
|
+
`glosslint doctor` checks `.agents/glossary.md` for format mistakes, bad values, duplicate terms and failing `Good`/`Bad` examples. Pass `--fix` to rewrite fixable layout, heading and field-name issues into canonical form without dropping text:
|
|
88
|
+
|
|
89
|
+
```sh
|
|
90
|
+
npx glosslint doctor --fix
|
|
91
|
+
```
|
|
75
92
|
|
|
76
93
|
## For agents
|
|
77
94
|
|
|
78
|
-
|
|
95
|
+
Coding agents read `.agents/glossary.md` directly, so link it from `AGENTS.md`. When an agent is unsure which word to use, `glosslint explain "<word>"` prints the term, its meaning, its usage notes and the words to avoid. [For agents](https://glosslint.onmax.me/guide/agents) covers the editing loop by `fix.kind`.
|
|
79
96
|
|
|
80
97
|
## License
|
|
81
98
|
|
package/dist/cli.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as GlossaryProblem } from "./glossary-DmTK_e1d.mjs";
|
|
2
|
+
import { c as Corpus, o as CliFinding, v as Matcher } from "./types-Bbp_cYfZ.mjs";
|
|
2
3
|
/** Where a command reads and writes, so tests can run commands without a process. */
|
|
3
4
|
export interface CliIo {
|
|
4
5
|
/** The folder paths and the config are resolved from. */
|
|
@@ -12,6 +13,8 @@ export interface CliIo {
|
|
|
12
13
|
export interface CommandOptions {
|
|
13
14
|
/** The config file. Default: `glosslint.config.{ts,mts,js,mjs}` in `cwd`. */
|
|
14
15
|
config?: string;
|
|
16
|
+
/** The glossary file, read when there is no `config`. Default: `.agents/glossary.md` in `cwd`. */
|
|
17
|
+
glossary?: string;
|
|
15
18
|
/** Color the output. Default: `io.color`. */
|
|
16
19
|
color?: boolean;
|
|
17
20
|
}
|
|
@@ -27,6 +30,32 @@ export interface PrintOptions extends CommandOptions {
|
|
|
27
30
|
/** `md` (default) or `json`. */
|
|
28
31
|
format?: string;
|
|
29
32
|
}
|
|
33
|
+
/** Options of `glosslint doctor`. */
|
|
34
|
+
export interface DoctorOptions {
|
|
35
|
+
/** The glossary file. Default: `.agents/glossary.md` in `cwd`. */
|
|
36
|
+
glossary?: string;
|
|
37
|
+
/** Rewrite the file in canonical form when that drops no text. */
|
|
38
|
+
fix?: boolean;
|
|
39
|
+
/** `text` (default) or `json`. */
|
|
40
|
+
format?: string;
|
|
41
|
+
/** Color the output. Default: `io.color`. */
|
|
42
|
+
color?: boolean;
|
|
43
|
+
}
|
|
44
|
+
/** One problem of the glossary, as `glosslint doctor --format json` prints it. */
|
|
45
|
+
export interface DoctorProblem extends GlossaryProblem {
|
|
46
|
+
/** The glossary, relative to `cwd`. */
|
|
47
|
+
file: string;
|
|
48
|
+
}
|
|
49
|
+
/** The JSON `glosslint doctor` prints: the problems left, and how many `--fix` fixed. */
|
|
50
|
+
export interface DoctorReport {
|
|
51
|
+
problems: DoctorProblem[];
|
|
52
|
+
summary: {
|
|
53
|
+
file: string;
|
|
54
|
+
problems: number;
|
|
55
|
+
fixable: number;
|
|
56
|
+
fixed: number;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
30
59
|
/** Codes of the errors the CLI prints itself, next to the corpus's `GLOSSLINT_C00x`. */
|
|
31
60
|
export declare const CLI_ERRORS: {
|
|
32
61
|
readonly noConfig: "GLOSSLINT_C009";
|
|
@@ -35,11 +64,21 @@ export declare const CLI_ERRORS: {
|
|
|
35
64
|
readonly usage: "GLOSSLINT_USAGE";
|
|
36
65
|
readonly failed: "GLOSSLINT_ERROR";
|
|
37
66
|
};
|
|
38
|
-
/**
|
|
39
|
-
export
|
|
67
|
+
/** What `loadCorpus` read: a config, or a glossary file it then never checks. */
|
|
68
|
+
export interface LoadedCorpus {
|
|
40
69
|
corpus: Corpus;
|
|
70
|
+
/** The absolute path of the file read. */
|
|
41
71
|
file: string;
|
|
42
|
-
|
|
72
|
+
from: "config" | "glossary";
|
|
73
|
+
}
|
|
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
|
+
*/
|
|
78
|
+
export declare function loadCorpus(cwd: string, options?: {
|
|
79
|
+
config?: string;
|
|
80
|
+
glossary?: string;
|
|
81
|
+
}): Promise<LoadedCorpus>;
|
|
43
82
|
/**
|
|
44
83
|
* Blanks what is not prose in Markdown, keeping every offset: frontmatter, fenced code, HTML
|
|
45
84
|
* comments and tags, inline code, link targets and references, and the markers of headings, lists
|
|
@@ -63,5 +102,10 @@ export declare function runTest(options: CommandOptions, io: CliIo): Promise<num
|
|
|
63
102
|
export declare function runPrint(options: PrintOptions, io: CliIo): Promise<number>;
|
|
64
103
|
/** `glosslint explain`: what the corpus says about a word or phrase. Exits 1 when no term matches. */
|
|
65
104
|
export declare function runExplain(query: string, options: CommandOptions, io: CliIo): Promise<number>;
|
|
105
|
+
/**
|
|
106
|
+
* `glosslint doctor`: reports the problems of the glossary file, and with `fix` rewrites it in canonical
|
|
107
|
+
* form when no problem would drop text. Exits 0 with no problems left, 1 with problems, 2 with no file.
|
|
108
|
+
*/
|
|
109
|
+
export declare function runDoctor(options: DoctorOptions, io: CliIo): Promise<number>;
|
|
66
110
|
/** Runs the CLI on `argv` (the arguments after the program name) and resolves to the exit code. */
|
|
67
111
|
export declare function main(argv: readonly string[], io?: CliIo): Promise<number>;
|
package/dist/cli.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import { a as kindOf, n as
|
|
4
|
-
import { existsSync, readFileSync, realpathSync, statSync } from "node:fs";
|
|
2
|
+
import { n as formatFindings, r as toJson } from "./format-CQ9xdJYe.mjs";
|
|
3
|
+
import { a as explain, c as testCorpus, d as createMatcher, i as readGlossary, m as kindOf, n as GLOSSARY_PROBLEMS, o as explainMatches, s as printCorpus, t as DEFAULT_GLOSSARY } from "./glossary-lk7EwGey.mjs";
|
|
4
|
+
import { existsSync, readFileSync, realpathSync, statSync, writeFileSync } from "node:fs";
|
|
5
5
|
import { extname, relative, resolve, sep } from "node:path";
|
|
6
|
-
import process from "node:process";
|
|
7
6
|
import { pathToFileURL } from "node:url";
|
|
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.0
|
|
11
|
+
var version = "0.1.0";
|
|
12
12
|
// src/cli.ts
|
|
13
13
|
/** Codes of the errors the CLI prints itself, next to the corpus's `GLOSSLINT_C00x`. */
|
|
14
14
|
const CLI_ERRORS = {
|
|
@@ -39,12 +39,14 @@ var CliError = class extends Error {
|
|
|
39
39
|
code;
|
|
40
40
|
why;
|
|
41
41
|
fix;
|
|
42
|
+
term;
|
|
42
43
|
config;
|
|
43
44
|
constructor(options) {
|
|
44
45
|
super(options.why);
|
|
45
46
|
this.code = options.code;
|
|
46
47
|
this.why = options.why;
|
|
47
48
|
this.fix = options.fix;
|
|
49
|
+
if (options.term !== void 0) this.term = options.term;
|
|
48
50
|
if (options.config !== void 0) this.config = options.config;
|
|
49
51
|
}
|
|
50
52
|
};
|
|
@@ -59,24 +61,64 @@ const toPosix = (path) => path.split(sep).join("/");
|
|
|
59
61
|
function displayPath(cwd, file) {
|
|
60
62
|
return toPosix(relative(cwd, file)) || ".";
|
|
61
63
|
}
|
|
62
|
-
/**
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
64
|
+
/**
|
|
65
|
+
* Finds the corpus: `config`, else `glossary`, else `glosslint.config.{ts,mts,js,mjs}` in `cwd`, else
|
|
66
|
+
* `.agents/glossary.md` in `cwd`.
|
|
67
|
+
*/
|
|
68
|
+
async function loadCorpus(cwd, options = {}) {
|
|
69
|
+
const { config, glossary } = options;
|
|
70
|
+
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.");
|
|
71
|
+
if (config !== void 0) return importConfig(cwd, resolve(cwd, config), config);
|
|
72
|
+
if (glossary !== void 0) return loadGlossary(cwd, glossary, true);
|
|
73
|
+
const found = CONFIG_FILES.map((name) => resolve(cwd, name)).find((path) => existsSync(path));
|
|
74
|
+
if (found) return importConfig(cwd, found);
|
|
75
|
+
if (existsSync(resolve(cwd, ".agents/glossary.md"))) return loadGlossary(cwd, DEFAULT_GLOSSARY, false);
|
|
76
|
+
throw new CliError({
|
|
77
|
+
code: CLI_ERRORS.noConfig,
|
|
78
|
+
why: `No ${DEFAULT_GLOSSARY} and no glosslint.config.ts, .mts, .js or .mjs in the current folder.`,
|
|
79
|
+
fix: `Create ${DEFAULT_GLOSSARY} with \`# Glossary\` and a \`## Term\` section per term, or pass --glossary <path> or --config <path>.`
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/** `G004` to `G008`: the problems only a person can fix, which leave no corpus. */
|
|
83
|
+
function leavesNoCorpus(problem) {
|
|
84
|
+
return !problem.fixable && problem.code !== GLOSSARY_PROBLEMS.failingExample;
|
|
85
|
+
}
|
|
86
|
+
function missingGlossary(cwd, file, given) {
|
|
87
|
+
const shown = displayPath(cwd, file);
|
|
88
|
+
return new CliError({
|
|
89
|
+
code: CLI_ERRORS.noConfig,
|
|
90
|
+
why: given ? `The glossary "${shown}" does not exist.` : `No glossary at ${shown}.`,
|
|
91
|
+
fix: given ? "Check the path given to --glossary." : `Create ${shown} with \`# Glossary\` and a \`## Term\` section per term, or pass --glossary <path>.`
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/** Reads a glossary file as a corpus, or throws its first problem that leaves no corpus. */
|
|
95
|
+
function loadGlossary(cwd, path, given) {
|
|
96
|
+
const file = resolve(cwd, path);
|
|
97
|
+
if (!existsSync(file)) throw missingGlossary(cwd, file, given);
|
|
98
|
+
const { problems, corpus } = readGlossary(readFileSync(file, "utf8"));
|
|
99
|
+
if (corpus) return {
|
|
100
|
+
corpus,
|
|
101
|
+
file,
|
|
102
|
+
from: "glossary"
|
|
103
|
+
};
|
|
104
|
+
const blocking = problems.filter(leavesNoCorpus);
|
|
105
|
+
const first = blocking[0];
|
|
106
|
+
const doctor = given ? `glosslint doctor --glossary ${path}` : "glosslint doctor";
|
|
107
|
+
const more = blocking.length > 1 ? ` ${count(blocking.length - 1, "more problem")}: run \`${doctor}\` to list them.` : "";
|
|
108
|
+
throw new CliError({
|
|
109
|
+
code: first.code,
|
|
110
|
+
why: `${displayPath(cwd, file)}:${first.line}: ${first.why}`,
|
|
111
|
+
fix: `${first.fix}${more}`,
|
|
112
|
+
...first.term === void 0 ? {} : { term: first.term }
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
/** Imports a config and returns its default export, which must be a corpus. */
|
|
116
|
+
async function importConfig(cwd, file, given) {
|
|
117
|
+
if (given !== void 0 && !existsSync(file)) throw new CliError({
|
|
118
|
+
code: CLI_ERRORS.noConfig,
|
|
119
|
+
why: `The config "${given}" does not exist.`,
|
|
120
|
+
fix: "Check the path given to --config."
|
|
121
|
+
});
|
|
80
122
|
const shown = displayPath(cwd, file);
|
|
81
123
|
let loaded;
|
|
82
124
|
try {
|
|
@@ -98,7 +140,8 @@ async function loadCorpus(cwd, config) {
|
|
|
98
140
|
});
|
|
99
141
|
return {
|
|
100
142
|
corpus: loaded.default,
|
|
101
|
-
file
|
|
143
|
+
file,
|
|
144
|
+
from: "config"
|
|
102
145
|
};
|
|
103
146
|
}
|
|
104
147
|
/** Blanks a span with spaces, keeping line breaks, so every offset and line stays where it was. */
|
|
@@ -315,9 +358,9 @@ async function runCheck(paths, options, io) {
|
|
|
315
358
|
const format = options.format ?? "text";
|
|
316
359
|
if (format !== "text" && format !== "json") throw usage(`--format is "${format}".`, "Use --format text or --format json.");
|
|
317
360
|
const extensions = parseExtensions(options.ext);
|
|
318
|
-
const
|
|
319
|
-
const matcher = createMatcher(corpus);
|
|
320
|
-
const files = await collectFiles(paths, io.cwd, extensions);
|
|
361
|
+
const loaded = await loadCorpus(io.cwd, options);
|
|
362
|
+
const matcher = createMatcher(loaded.corpus);
|
|
363
|
+
const files = (await collectFiles(paths, io.cwd, extensions)).filter((file) => loaded.from !== "glossary" || file !== loaded.file);
|
|
321
364
|
const findings = [];
|
|
322
365
|
for (const file of files) {
|
|
323
366
|
const extension = extname(file).toLowerCase();
|
|
@@ -359,7 +402,7 @@ function failureLines(failure) {
|
|
|
359
402
|
const count = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
|
|
360
403
|
/** `glosslint test`: checks every term's good and bad examples. Exits 1 when one fails. */
|
|
361
404
|
async function runTest(options, io) {
|
|
362
|
-
const { corpus } = await loadCorpus(io.cwd, options
|
|
405
|
+
const { corpus } = await loadCorpus(io.cwd, options);
|
|
363
406
|
const color = useColor(options, io);
|
|
364
407
|
const tested = corpus.terms.filter((term) => (term.examples?.good?.length ?? 0) + (term.examples?.bad?.length ?? 0) > 0);
|
|
365
408
|
if (tested.length === 0) {
|
|
@@ -392,16 +435,76 @@ async function runTest(options, io) {
|
|
|
392
435
|
async function runPrint(options, io) {
|
|
393
436
|
const format = options.format ?? "md";
|
|
394
437
|
if (format !== "md" && format !== "json") throw usage(`--format is "${format}".`, "Use --format md or --format json.");
|
|
395
|
-
const { corpus } = await loadCorpus(io.cwd, options
|
|
438
|
+
const { corpus } = await loadCorpus(io.cwd, options);
|
|
396
439
|
io.stdout(printCorpus(corpus, format));
|
|
397
440
|
return 0;
|
|
398
441
|
}
|
|
399
442
|
/** `glosslint explain`: what the corpus says about a word or phrase. Exits 1 when no term matches. */
|
|
400
443
|
async function runExplain(query, options, io) {
|
|
401
|
-
const { corpus } = await loadCorpus(io.cwd, options
|
|
444
|
+
const { corpus } = await loadCorpus(io.cwd, options);
|
|
402
445
|
io.stdout(`${explain(corpus, query)}\n`);
|
|
403
446
|
return explainMatches(corpus, query).length > 0 ? 0 : 1;
|
|
404
447
|
}
|
|
448
|
+
function formatProblem(problem, color) {
|
|
449
|
+
const lines = [["fix", problem.fix]];
|
|
450
|
+
if (problem.term && !problem.why.includes(`"${problem.term}"`)) lines.unshift(["term", problem.term]);
|
|
451
|
+
const branches = lines.map(([label, text], index) => {
|
|
452
|
+
const branch = index === lines.length - 1 ? "╰▶" : "├▶";
|
|
453
|
+
return `${paint(color, "2", branch)} ${paint(color, "1", `${label}:`)} ${text}`;
|
|
454
|
+
});
|
|
455
|
+
const where = paint(color, "36", `${problem.file}:${problem.line}`);
|
|
456
|
+
return [`${paint(color, "1;31", `[${problem.code}]`)} ${where}: ${problem.why}`, ...branches].join("\n");
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* `glosslint doctor`: reports the problems of the glossary file, and with `fix` rewrites it in canonical
|
|
460
|
+
* form when no problem would drop text. Exits 0 with no problems left, 1 with problems, 2 with no file.
|
|
461
|
+
*/
|
|
462
|
+
async function runDoctor(options, io) {
|
|
463
|
+
const format = options.format ?? "text";
|
|
464
|
+
if (format !== "text" && format !== "json") throw usage(`--format is "${format}".`, "Use --format text or --format json.");
|
|
465
|
+
const file = resolve(io.cwd, options.glossary ?? ".agents/glossary.md");
|
|
466
|
+
if (!existsSync(file)) throw missingGlossary(io.cwd, file, options.glossary !== void 0);
|
|
467
|
+
const shown = displayPath(io.cwd, file);
|
|
468
|
+
let result = readGlossary(readFileSync(file, "utf8"));
|
|
469
|
+
let fixed = 0;
|
|
470
|
+
if (options.fix && result.fixed !== void 0) {
|
|
471
|
+
fixed = result.problems.filter((problem) => problem.fixable).length;
|
|
472
|
+
writeFileSync(file, result.fixed);
|
|
473
|
+
result = readGlossary(result.fixed);
|
|
474
|
+
}
|
|
475
|
+
const problems = result.problems.map((problem) => ({
|
|
476
|
+
file: shown,
|
|
477
|
+
...problem
|
|
478
|
+
}));
|
|
479
|
+
const fixable = problems.filter((problem) => problem.fixable).length;
|
|
480
|
+
if (format === "json") {
|
|
481
|
+
const report = {
|
|
482
|
+
problems,
|
|
483
|
+
summary: {
|
|
484
|
+
file: shown,
|
|
485
|
+
problems: problems.length,
|
|
486
|
+
fixable,
|
|
487
|
+
fixed
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
io.stdout(`${JSON.stringify(report, null, 2)}\n`);
|
|
491
|
+
return problems.length > 0 ? 1 : 0;
|
|
492
|
+
}
|
|
493
|
+
const color = useColor(options, io);
|
|
494
|
+
const summary = [];
|
|
495
|
+
if (fixed > 0) summary.push(`Fixed ${count(fixed, "problem")} in ${shown}.`);
|
|
496
|
+
if (problems.length === 0) {
|
|
497
|
+
if (fixed === 0) summary.push(`No problems in ${shown}.`);
|
|
498
|
+
} else if (fixed > 0) summary.push(`${count(problems.length, "problem")} left.`);
|
|
499
|
+
else {
|
|
500
|
+
const canFix = result.fixed !== void 0 ? `, ${fixable} fixable with --fix` : "";
|
|
501
|
+
summary.push(`${count(problems.length, "problem")} in ${shown}${canFix}.`);
|
|
502
|
+
if (options.fix && fixable > 0) summary.push("The file is unchanged: --fix would drop text, so fix the other problems first.");
|
|
503
|
+
}
|
|
504
|
+
const blocks = problems.map((problem) => formatProblem(problem, color));
|
|
505
|
+
io.stdout(`${[...blocks, summary.join(" ")].join("\n\n")}\n`);
|
|
506
|
+
return problems.length > 0 ? 1 : 0;
|
|
507
|
+
}
|
|
405
508
|
/** Prints a config or usage error as a tree on stderr. */
|
|
406
509
|
function printError(error, io, color) {
|
|
407
510
|
const branches = [];
|
|
@@ -428,19 +531,23 @@ async function main(argv, io = defaultIo()) {
|
|
|
428
531
|
let run;
|
|
429
532
|
let color = io.color ?? false;
|
|
430
533
|
const configOption = "Config file (default: glosslint.config.{ts,mts,js,mjs})";
|
|
534
|
+
const glossaryOption = `Glossary file, read when there is no config (default: ${DEFAULT_GLOSSARY})`;
|
|
431
535
|
const colorOption = "Color the output (default: when writing to a terminal)";
|
|
432
|
-
cli.command("[...paths]", "Check Markdown and text files against the corpus").alias("check").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) => {
|
|
536
|
+
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) => {
|
|
433
537
|
run = () => runCheck(paths, options, io);
|
|
434
538
|
});
|
|
435
|
-
cli.command("test", "Check every term's good and bad examples").option("--config <path>", configOption).option("--color", colorOption).action((options) => {
|
|
539
|
+
cli.command("test", "Check every term's good and bad examples").option("--glossary <path>", glossaryOption).option("--config <path>", configOption).option("--color", colorOption).action((options) => {
|
|
436
540
|
run = () => runTest(options, io);
|
|
437
541
|
});
|
|
438
|
-
cli.command("print", "Print the corpus as a Markdown glossary or JSON").option("--config <path>", configOption).option("--format <format>", "Output format: md or json", { default: "md" }).action((options) => {
|
|
542
|
+
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) => {
|
|
439
543
|
run = () => runPrint(options, io);
|
|
440
544
|
});
|
|
441
|
-
cli.command("explain <query>", "Show what the corpus says about a word or phrase").option("--config <path>", configOption).action((query, options) => {
|
|
545
|
+
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) => {
|
|
442
546
|
run = () => runExplain(String(query), options, io);
|
|
443
547
|
});
|
|
548
|
+
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) => {
|
|
549
|
+
run = () => runDoctor(options, io);
|
|
550
|
+
});
|
|
444
551
|
cli.help();
|
|
445
552
|
cli.version(version);
|
|
446
553
|
try {
|
|
@@ -481,4 +588,4 @@ function isBin() {
|
|
|
481
588
|
}
|
|
482
589
|
}
|
|
483
590
|
if (isBin()) process.exitCode = await main(process.argv.slice(2));
|
|
484
|
-
export { CLI_ERRORS, checkFileText, collectFiles, loadCorpus, main, maskMarkdown, runCheck, runExplain, runPrint, runTest };
|
|
591
|
+
export { CLI_ERRORS, checkFileText, collectFiles, loadCorpus, main, maskMarkdown, runCheck, runDoctor, runExplain, runPrint, runTest };
|
package/dist/eslint.d.mts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { c as Corpus, h as KindOf } from "./types-
|
|
1
|
+
import { c as Corpus, h as KindOf } from "./types-Bbp_cYfZ.mjs";
|
|
2
2
|
import { Linter } from "eslint";
|
|
3
3
|
/** Options of the ESLint config. */
|
|
4
4
|
export interface GlosslintEslintOptions {
|
|
5
|
-
/** The
|
|
6
|
-
|
|
5
|
+
/** The glossary file to read instead of `.agents/glossary.md`. A string resolves from the current folder. */
|
|
6
|
+
glossary?: string | URL;
|
|
7
|
+
/** A corpus to use instead of a glossary file, such as `defineCorpus({ extends: [fromGlossary()], … })`. */
|
|
8
|
+
corpus?: Corpus;
|
|
7
9
|
/** Files the rules run on. */
|
|
8
10
|
files?: string[];
|
|
9
11
|
/**
|
|
@@ -20,7 +22,8 @@ export interface GlosslintEslintOptions {
|
|
|
20
22
|
kindOf?: KindOf;
|
|
21
23
|
}
|
|
22
24
|
/**
|
|
23
|
-
* ESLint flat configs that run glosslint's rules: `...glosslint(
|
|
24
|
-
*
|
|
25
|
+
* ESLint flat configs that run glosslint's rules: `...glosslint()`. The corpus comes from `corpus`, else
|
|
26
|
+
* from the `glossary` file, else from `.agents/glossary.md`, read once when the config is built. They set
|
|
27
|
+
* no parser: your config supplies typescript-eslint, vue-eslint-parser or yaml-eslint-parser.
|
|
25
28
|
*/
|
|
26
|
-
export default function glosslint(options
|
|
29
|
+
export default function glosslint(options?: GlosslintEslintOptions): Linter.Config[];
|