glosslint 0.1.0 → 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/README.md +4 -1
- package/dist/cli.d.mts +14 -14
- package/dist/cli.mjs +461 -172
- package/dist/eslint.d.mts +2 -1
- package/dist/eslint.mjs +5 -3
- package/dist/{format-CQ9xdJYe.mjs → format-DSSwOlXH.mjs} +29 -2
- package/dist/glossary-CWqmN9Bg.mjs +39 -0
- package/dist/{glossary-lk7EwGey.mjs → glossary-text-C09ByS5j.mjs} +43 -45
- package/dist/{glossary-DmTK_e1d.d.mts → glossary-text-C9pAOd4h.d.mts} +1 -7
- package/dist/index.d.mts +8 -3
- package/dist/index.mjs +3 -2
- package/dist/oxlint.mjs +3 -2
- package/dist/{rules-D-PrDySk.mjs → rules-CjMuomuR.mjs} +34 -10
- package/dist/x18n.mjs +20 -13
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -23,6 +23,8 @@ Write your product's terms in `.agents/glossary.md`. This excerpt comes from the
|
|
|
23
23
|
```md
|
|
24
24
|
# Glossary
|
|
25
25
|
|
|
26
|
+
<!-- Format and checks: https://glosslint.onmax.me/guide/glossary -->
|
|
27
|
+
|
|
26
28
|
The words the rider app and the help center use.
|
|
27
29
|
|
|
28
30
|
Extends: tech, inclusive
|
|
@@ -77,7 +79,8 @@ Here is one finding from `examples/basic`:
|
|
|
77
79
|
|
|
78
80
|
## Where it checks
|
|
79
81
|
|
|
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.
|
|
82
|
+
- [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 and JSON locale values.
|
|
83
|
+
- [Nuxt and vue-i18n](https://glosslint.onmax.me/integrations/nuxt): one spread in the `withNuxt()` config, no module.
|
|
81
84
|
- [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
85
|
- [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
86
|
- [CLI](https://glosslint.onmax.me/integrations/cli): checks Markdown, MDX and text files, tests term examples, prints corpora and explains words from the terminal.
|
package/dist/cli.d.mts
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
|
-
import { t as GlossaryProblem } from "./glossary-
|
|
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.
|
|
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
|
|
3
|
-
import {
|
|
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,142 +8,283 @@ 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.
|
|
12
|
-
// src/
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
11
|
+
var version = "0.1.2";
|
|
12
|
+
// src/comark.ts
|
|
13
|
+
const OPENER = /^[ \t]*(:{2,})[A-Za-z][\w-]*/;
|
|
14
|
+
const BARE = /^[ \t]*:[A-Za-z][\w-]*[ \t]*\r?$/;
|
|
15
|
+
const CLOSER = /^[ \t]*:{2,}[ \t]*\r?$/;
|
|
16
|
+
const SLOT = /^[ \t]*#[A-Za-z][\w-]*/;
|
|
17
|
+
const RULE = /^[ \t]*---[ \t]*\r?$/;
|
|
18
|
+
const YAML_ENTRY = /^([ \t]*)([\w.-]+):[ \t]*(.*?)[ \t]*\r?$/;
|
|
19
|
+
/** Reads `{key="value" key='v' key=v bool .class #id :bind='json'}` from `at`, or `undefined` if it doesn't close. */
|
|
20
|
+
function scanAttributes(line, at) {
|
|
21
|
+
const attributes = [];
|
|
22
|
+
let index = at + 1;
|
|
23
|
+
while (index < line.length) {
|
|
24
|
+
const char = line[index];
|
|
25
|
+
if (char === "}") return {
|
|
26
|
+
end: index + 1,
|
|
27
|
+
attributes
|
|
28
|
+
};
|
|
29
|
+
if (/\s/.test(char)) {
|
|
30
|
+
index++;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const key = /^[^\s=}"']+/.exec(line.slice(index));
|
|
34
|
+
if (!key) return void 0;
|
|
35
|
+
const name = key[0];
|
|
36
|
+
index += name.length;
|
|
37
|
+
if (line[index] !== "=") {
|
|
38
|
+
attributes.push({ name });
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
index++;
|
|
42
|
+
const quote = line[index];
|
|
43
|
+
if (quote === "\"" || quote === "'") {
|
|
44
|
+
let end = index + 1;
|
|
45
|
+
while (end < line.length && line[end] !== quote) end += line[end] === "\\" ? 2 : 1;
|
|
46
|
+
if (end >= line.length) return void 0;
|
|
47
|
+
attributes.push({
|
|
48
|
+
name,
|
|
49
|
+
value: {
|
|
50
|
+
start: index + 1,
|
|
51
|
+
end
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
index = end + 1;
|
|
55
|
+
} else {
|
|
56
|
+
const value = /^[^\s}]*/.exec(line.slice(index))[0];
|
|
57
|
+
attributes.push({
|
|
58
|
+
name,
|
|
59
|
+
value: {
|
|
60
|
+
start: index,
|
|
61
|
+
end: index + value.length
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
index += value.length;
|
|
65
|
+
}
|
|
51
66
|
}
|
|
52
|
-
};
|
|
53
|
-
function isConfigError(error) {
|
|
54
|
-
return error instanceof Error && error.name === "GlosslintConfigError" && typeof error.code === "string" && typeof error.fix === "string";
|
|
55
67
|
}
|
|
56
|
-
|
|
57
|
-
|
|
68
|
+
/** Reads `[text]` from `at`, allowing nested brackets, or `undefined` if it doesn't close. */
|
|
69
|
+
function scanBrackets(line, at) {
|
|
70
|
+
let depth = 0;
|
|
71
|
+
for (let index = at; index < line.length; index++) {
|
|
72
|
+
const char = line[index];
|
|
73
|
+
if (char === "\\") index++;
|
|
74
|
+
else if (char === "[") depth++;
|
|
75
|
+
else if (char === "]" && --depth === 0) return index + 1;
|
|
76
|
+
}
|
|
58
77
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
function displayPath(cwd, file) {
|
|
62
|
-
return toPosix(relative(cwd, file)) || ".";
|
|
78
|
+
function isText(name, value) {
|
|
79
|
+
return !name.startsWith(":") && isTextName(name) && value.trim() !== "" && !isCodeShape(value);
|
|
63
80
|
}
|
|
64
81
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
82
|
+
* Reads what follows a component's name: optional `[text]`, then optional `{props}`. Returns where it
|
|
83
|
+
* ends, the text props and the kept `[text]`, or `undefined` when a bracket or brace doesn't close.
|
|
67
84
|
*/
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return
|
|
85
|
+
function readComponent(line, nameEnd) {
|
|
86
|
+
let index = nameEnd;
|
|
87
|
+
let content;
|
|
88
|
+
if (line[index] === "[") {
|
|
89
|
+
const end = scanBrackets(line, index);
|
|
90
|
+
if (end === void 0) return void 0;
|
|
91
|
+
content = [index + 1, end - 1];
|
|
92
|
+
index = end;
|
|
93
|
+
}
|
|
94
|
+
const props = [];
|
|
95
|
+
if (line[index] === "{") {
|
|
96
|
+
const scanned = readProps(line, index);
|
|
97
|
+
if (!scanned) return void 0;
|
|
98
|
+
props.push(...scanned.props);
|
|
99
|
+
index = scanned.end;
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
end: index,
|
|
103
|
+
props,
|
|
104
|
+
...content ? { content } : {}
|
|
105
|
+
};
|
|
85
106
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
107
|
+
/** Reads `{props}` at `at`, keeping the values of text props. */
|
|
108
|
+
function readProps(line, at) {
|
|
109
|
+
const scanned = scanAttributes(line, at);
|
|
110
|
+
if (!scanned) return void 0;
|
|
111
|
+
const props = [];
|
|
112
|
+
for (const attribute of scanned.attributes) if (attribute.value && isText(attribute.name, line.slice(attribute.value.start, attribute.value.end))) props.push({
|
|
113
|
+
name: attribute.name,
|
|
114
|
+
...attribute.value
|
|
92
115
|
});
|
|
116
|
+
return {
|
|
117
|
+
end: scanned.end,
|
|
118
|
+
props
|
|
119
|
+
};
|
|
93
120
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
121
|
+
const INLINE_NAME = /(?<![\p{L}\p{N}_:\\/]):[A-Za-z][\w-]*(?=[[{])/uy;
|
|
122
|
+
/** A link or image target after its `]`, with an optional title: `(/map "Map")`. */
|
|
123
|
+
const LINK_TARGET = /(?<=\])\((?:[^()\s]|\([^()\s]*\))*(?:\s+(?:"[^"\n]*"|'[^'\n]*'|\([^()\n]*\)))?\s*\)/g;
|
|
124
|
+
const LINK_TARGET_AT = new RegExp(LINK_TARGET.source, "y");
|
|
125
|
+
/**
|
|
126
|
+
* Blanks inline markup in `line` between `from` and `to`, left to right: components such as
|
|
127
|
+
* `:badge[v4.4]{color="info"}`, whose `[text]` is kept and scanned in turn, and `{attrs}` right after a
|
|
128
|
+
* `]` or a link target, as in `[map](/map){target="_blank"}`. Link targets are skipped, as the CLI blanks
|
|
129
|
+
* them anyway. Returns the line and the text props it found.
|
|
130
|
+
*/
|
|
131
|
+
function maskInline(line, blank, from = 0, to = line.length) {
|
|
132
|
+
let out = line;
|
|
133
|
+
const props = [];
|
|
134
|
+
const scan = (start, end) => {
|
|
135
|
+
let attrsAt = -1;
|
|
136
|
+
for (let index = start; index < end;) {
|
|
137
|
+
INLINE_NAME.lastIndex = index;
|
|
138
|
+
const name = INLINE_NAME.exec(line);
|
|
139
|
+
const component = name && readComponent(line, index + name[0].length);
|
|
140
|
+
if (component && component.end <= end) {
|
|
141
|
+
out = out.slice(0, index) + blank(out.slice(index, component.end)) + out.slice(component.end);
|
|
142
|
+
props.push(...component.props);
|
|
143
|
+
if (component.content) {
|
|
144
|
+
const [open, close] = component.content;
|
|
145
|
+
out = out.slice(0, open) + line.slice(open, close) + out.slice(close);
|
|
146
|
+
scan(open, close);
|
|
147
|
+
}
|
|
148
|
+
index = component.end;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
const char = line[index];
|
|
152
|
+
if (char === "{" && index === attrsAt) {
|
|
153
|
+
const attrs = readProps(line, index);
|
|
154
|
+
if (attrs && attrs.end <= end) {
|
|
155
|
+
out = out.slice(0, index) + blank(out.slice(index, attrs.end)) + out.slice(attrs.end);
|
|
156
|
+
props.push(...attrs.props);
|
|
157
|
+
index = attrs.end;
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (char === "(" && line[index - 1] === "]") {
|
|
162
|
+
LINK_TARGET_AT.lastIndex = index;
|
|
163
|
+
const target = LINK_TARGET_AT.exec(line);
|
|
164
|
+
if (target && index + target[0].length <= end) {
|
|
165
|
+
index += target[0].length;
|
|
166
|
+
attrsAt = index;
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (char === "\\") index++;
|
|
171
|
+
else if (char === "]") attrsAt = index + 1;
|
|
172
|
+
index++;
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
scan(from, to);
|
|
176
|
+
return {
|
|
177
|
+
line: out,
|
|
178
|
+
props
|
|
103
179
|
};
|
|
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
180
|
}
|
|
115
|
-
/**
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
let
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
181
|
+
/** Reads a YAML props block's top-level `key: value` lines, keeping single-line scalars of text props. */
|
|
182
|
+
function yamlProps(line, offset, indent) {
|
|
183
|
+
const entry = YAML_ENTRY.exec(line);
|
|
184
|
+
if (!entry) return void 0;
|
|
185
|
+
const [, space, name, raw] = entry;
|
|
186
|
+
indent.value ??= space.length;
|
|
187
|
+
if (space.length !== indent.value || raw === "" || /^[|>[{&*!]/.test(raw)) return void 0;
|
|
188
|
+
let start = line.indexOf(raw, space.length + name.length + 1);
|
|
189
|
+
let value = raw;
|
|
190
|
+
if (raw[0] === "\"" || raw[0] === "'") {
|
|
191
|
+
const close = raw.indexOf(raw[0], 1);
|
|
192
|
+
if (close === -1 || raw.slice(close + 1).replace(/[ \t]+#.*$/, "") !== "") return void 0;
|
|
193
|
+
start++;
|
|
194
|
+
value = raw.slice(1, close);
|
|
195
|
+
} else value = raw.replace(/[ \t]+#.*$/, "");
|
|
196
|
+
if (!isText(name, value)) return void 0;
|
|
197
|
+
return {
|
|
198
|
+
name,
|
|
199
|
+
start: offset + start,
|
|
200
|
+
end: offset + start + value.length,
|
|
201
|
+
text: value
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Blanks Comark component markup in Markdown whose fences and code spans are already blanked, keeping
|
|
206
|
+
* every offset.
|
|
207
|
+
* Returns the lines with markup blanked and the text props to check on their own.
|
|
208
|
+
*/
|
|
209
|
+
function maskComark(lines, blank) {
|
|
210
|
+
const out = [...lines];
|
|
211
|
+
const props = [];
|
|
212
|
+
const offsets = [];
|
|
213
|
+
let offset = 0;
|
|
214
|
+
for (const line of lines) {
|
|
215
|
+
offsets.push(offset);
|
|
216
|
+
offset += line.length + 1;
|
|
217
|
+
}
|
|
218
|
+
let depth = 0;
|
|
219
|
+
for (let index = 0; index < lines.length; index++) {
|
|
220
|
+
const line = lines[index];
|
|
221
|
+
if (CLOSER.test(line)) {
|
|
222
|
+
out[index] = blank(line);
|
|
223
|
+
depth = Math.max(0, depth - 1);
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
const at = (spans) => props.push(...spans.map((span) => ({
|
|
227
|
+
name: span.name,
|
|
228
|
+
start: offsets[index] + span.start,
|
|
229
|
+
end: offsets[index] + span.end,
|
|
230
|
+
text: line.slice(span.start, span.end)
|
|
231
|
+
})));
|
|
232
|
+
const slot = depth > 0 ? SLOT.exec(line) : null;
|
|
233
|
+
if (slot) {
|
|
234
|
+
const end = slot[0].length;
|
|
235
|
+
const attrs = line[end] === "{" ? readProps(line, end) : {
|
|
236
|
+
end,
|
|
237
|
+
props: []
|
|
238
|
+
};
|
|
239
|
+
if (attrs && line.slice(attrs.end).trim() === "") {
|
|
240
|
+
out[index] = blank(line);
|
|
241
|
+
at(attrs.props);
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const opener = OPENER.exec(line);
|
|
246
|
+
const read = opener ? readComponent(line, opener[0].length) : void 0;
|
|
247
|
+
if (!opener || !read || line.slice(read.end).trim() !== "") {
|
|
248
|
+
const inline = BARE.test(line) ? {
|
|
249
|
+
line: blank(line),
|
|
250
|
+
props: []
|
|
251
|
+
} : maskInline(line, blank);
|
|
252
|
+
out[index] = inline.line;
|
|
253
|
+
at(inline.props);
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
out[index] = blank(line);
|
|
257
|
+
at(read.props);
|
|
258
|
+
if (read.content) {
|
|
259
|
+
const [start, end] = read.content;
|
|
260
|
+
const inline = maskInline(line, blank, start, end);
|
|
261
|
+
at(inline.props);
|
|
262
|
+
props.push({
|
|
263
|
+
name: "",
|
|
264
|
+
start: offsets[index] + start,
|
|
265
|
+
end: offsets[index] + end,
|
|
266
|
+
text: inline.line.slice(start, end).replace(LINK_TARGET, blank)
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
depth++;
|
|
270
|
+
if (!RULE.test(lines[index + 1] ?? "")) continue;
|
|
271
|
+
let close = index + 2;
|
|
272
|
+
while (close < lines.length && !RULE.test(lines[close]) && !CLOSER.test(lines[close])) close++;
|
|
273
|
+
if (close >= lines.length || !RULE.test(lines[close])) continue;
|
|
274
|
+
const indent = {};
|
|
275
|
+
for (let row = index + 1; row <= close; row++) {
|
|
276
|
+
out[row] = blank(lines[row]);
|
|
277
|
+
const prop = yamlProps(lines[row], offsets[row], indent);
|
|
278
|
+
if (prop) props.push(prop);
|
|
279
|
+
}
|
|
280
|
+
index = close;
|
|
134
281
|
}
|
|
135
|
-
if (!isCorpus(loaded.default)) throw new CliError({
|
|
136
|
-
code: CLI_ERRORS.notCorpus,
|
|
137
|
-
why: `${shown} does not export a corpus as its default export.`,
|
|
138
|
-
fix: "End the config with `export default defineCorpus({ … })`.",
|
|
139
|
-
config: shown
|
|
140
|
-
});
|
|
141
282
|
return {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
from: "config"
|
|
283
|
+
lines: out,
|
|
284
|
+
props
|
|
145
285
|
};
|
|
146
286
|
}
|
|
287
|
+
// src/check-text.ts
|
|
147
288
|
/** Blanks a span with spaces, keeping line breaks, so every offset and line stays where it was. */
|
|
148
289
|
function blank(text) {
|
|
149
290
|
return text.replace(/[^\n\r]/g, " ");
|
|
@@ -152,7 +293,6 @@ const FRONTMATTER = /^(?:---|\+\+\+)\r?\n[\s\S]*?\r?\n(?:---|\+\+\+|\.\.\.)[ \t]
|
|
|
152
293
|
const FENCE = /^[ \t]*((?:>[ \t]?)*)[ \t]*((?:[-*+]|\d{1,9}[.)])[ \t]+)?(`{3,}|~{3,})([^\n]*)$/;
|
|
153
294
|
const HTML_COMMENT = /<!--[\s\S]*?(?:-->|$)/g;
|
|
154
295
|
const INLINE_CODE = /(?<!`)(`+)(?!`)(?:(?!\r?\n[ \t]*\r?\n)[\s\S])*?[^`]\1(?!`)/g;
|
|
155
|
-
const LINK_TARGET = /(?<=\])\((?:[^()\s]|\([^()\s]*\))*(?:\s+(?:"[^"\n]*"|'[^'\n]*'|\([^()\n]*\)))?\s*\)/g;
|
|
156
296
|
const LINK_REFERENCE = /(?<=\])\[[^\]\n]*\]/g;
|
|
157
297
|
const REFERENCE_DEFINITION = /^ {0,3}\[[^\]\n]+\]:[ \t]*\S.*$/gm;
|
|
158
298
|
const AUTOLINK = /<(?:[a-z][a-z\d+.-]*:[^\s<>]*|[^\s<>@]+@[^\s<>]+)>/gi;
|
|
@@ -163,9 +303,13 @@ const LIST_ITEM = /^ {0,3}(?:>[ \t]?)*(?:[-*+]|\d{1,9}[.)])[ \t]/;
|
|
|
163
303
|
/**
|
|
164
304
|
* Blanks what is not prose in Markdown, keeping every offset: frontmatter, fenced code, HTML
|
|
165
305
|
* comments and tags, inline code, link targets and references, and the markers of headings, lists
|
|
166
|
-
* and quotes. In MDX, `import` and `export` lines too.
|
|
306
|
+
* and quotes. In MDX, `import` and `export` lines too; in other Markdown, Comark component markup.
|
|
167
307
|
*/
|
|
168
308
|
function maskMarkdown(text, options = {}) {
|
|
309
|
+
return maskMarkdownParts(text, options).masked;
|
|
310
|
+
}
|
|
311
|
+
/** {@link maskMarkdown}, plus the Comark text props it blanked, which are checked on their own. */
|
|
312
|
+
function maskMarkdownParts(text, options) {
|
|
169
313
|
let out = text.replace(FRONTMATTER, blank);
|
|
170
314
|
const lines = out.split("\n");
|
|
171
315
|
let fence;
|
|
@@ -184,19 +328,26 @@ function maskMarkdown(text, options = {}) {
|
|
|
184
328
|
lines[index] = blank(line);
|
|
185
329
|
} else if (options.mdx && /^(?:import|export)\s/.test(line)) lines[index] = blank(line);
|
|
186
330
|
}
|
|
187
|
-
out = lines.join("\n");
|
|
188
|
-
|
|
189
|
-
|
|
331
|
+
out = lines.join("\n").replace(HTML_COMMENT, blank).replace(INLINE_CODE, blank);
|
|
332
|
+
let props = [];
|
|
333
|
+
if (!options.mdx) {
|
|
334
|
+
const comark = maskComark(out.split("\n"), blank);
|
|
335
|
+
out = comark.lines.join("\n");
|
|
336
|
+
props = comark.props;
|
|
337
|
+
}
|
|
190
338
|
out = out.replace(REFERENCE_DEFINITION, blank);
|
|
191
339
|
out = out.replace(LINK_TARGET, blank);
|
|
192
340
|
out = out.replace(LINK_REFERENCE, blank);
|
|
193
341
|
out = out.replace(AUTOLINK, blank);
|
|
194
342
|
out = out.replace(TAG, blank);
|
|
195
|
-
return
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
343
|
+
return {
|
|
344
|
+
masked: out.split("\n").map((line) => {
|
|
345
|
+
let masked = line.replace(LINE_PREFIX, blank);
|
|
346
|
+
if (HEADING.test(line)) masked = masked.replace(/[ \t]#+[ \t]*(?=\r?$)/, blank);
|
|
347
|
+
return masked;
|
|
348
|
+
}).join("\n"),
|
|
349
|
+
props
|
|
350
|
+
};
|
|
200
351
|
}
|
|
201
352
|
const TABLE_DELIMITER = /^\s*\|?\s*:?-+:?\s*(?:\|\s*:?-+:?\s*)*\|?\s*\r?$/;
|
|
202
353
|
/** Splits text into the pieces checked one at a time: headings, table cells, list items and paragraphs. */
|
|
@@ -260,7 +411,10 @@ function summarize(term) {
|
|
|
260
411
|
/** Checks one file's text. Markdown is masked first, so code and link targets are never reported. */
|
|
261
412
|
function checkFileText(matcher, text, file, options = {}) {
|
|
262
413
|
const markdown = options.markdown ?? false;
|
|
263
|
-
const masked = markdown ?
|
|
414
|
+
const { masked, props } = markdown ? maskMarkdownParts(text, { mdx: options.mdx ?? false }) : {
|
|
415
|
+
masked: text,
|
|
416
|
+
props: []
|
|
417
|
+
};
|
|
264
418
|
const lineStarts = [0];
|
|
265
419
|
for (let index = text.indexOf("\n"); index !== -1; index = text.indexOf("\n", index + 1)) lineStarts.push(index + 1);
|
|
266
420
|
const lineOf = (offset) => {
|
|
@@ -275,22 +429,35 @@ function checkFileText(matcher, text, file, options = {}) {
|
|
|
275
429
|
};
|
|
276
430
|
const lineEnd = (line) => (lineStarts[line + 1] ?? text.length + 1) - 1;
|
|
277
431
|
const findings = [];
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
432
|
+
const all = [...blocks(text, masked, markdown), ...props.map((prop) => ({
|
|
433
|
+
start: prop.start,
|
|
434
|
+
end: prop.end,
|
|
435
|
+
kind: kindOf({
|
|
436
|
+
text: prop.text,
|
|
437
|
+
name: prop.name,
|
|
438
|
+
shown: true
|
|
439
|
+
}),
|
|
440
|
+
text: prop.text
|
|
441
|
+
}))].sort((a, b) => a.start - b.start);
|
|
442
|
+
for (const block of all) {
|
|
443
|
+
const read = block.text ?? masked.slice(block.start, block.end);
|
|
444
|
+
for (const finding of matcher.check(read, block.kind)) {
|
|
445
|
+
const start = block.start + finding.start;
|
|
446
|
+
const end = block.start + finding.end;
|
|
447
|
+
const line = lineOf(start);
|
|
448
|
+
const lineStart = lineStarts[line];
|
|
449
|
+
findings.push(toCliFinding(finding, {
|
|
450
|
+
file,
|
|
451
|
+
text,
|
|
452
|
+
start,
|
|
453
|
+
end,
|
|
454
|
+
line,
|
|
455
|
+
lineStart,
|
|
456
|
+
lineEnd: lineEnd(lineOf(end))
|
|
457
|
+
}));
|
|
458
|
+
}
|
|
292
459
|
}
|
|
293
|
-
return findings;
|
|
460
|
+
return findings.sort((a, b) => a.start - b.start);
|
|
294
461
|
}
|
|
295
462
|
function toCliFinding(finding, at) {
|
|
296
463
|
const { fix, term, start: _start, end: _end, ...rest } = finding;
|
|
@@ -313,6 +480,141 @@ function toCliFinding(finding, at) {
|
|
|
313
480
|
...rest.see ? { see: rest.see } : {}
|
|
314
481
|
};
|
|
315
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
|
+
}
|
|
316
618
|
function usage(why, fix) {
|
|
317
619
|
return new CliError({
|
|
318
620
|
code: CLI_ERRORS.usage,
|
|
@@ -445,16 +747,6 @@ async function runExplain(query, options, io) {
|
|
|
445
747
|
io.stdout(`${explain(corpus, query)}\n`);
|
|
446
748
|
return explainMatches(corpus, query).length > 0 ? 0 : 1;
|
|
447
749
|
}
|
|
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
750
|
/**
|
|
459
751
|
* `glosslint doctor`: reports the problems of the glossary file, and with `fix` rewrites it in canonical
|
|
460
752
|
* form when no problem would drop text. Exits 0 with no problems left, 1 with problems, 2 with no file.
|
|
@@ -490,19 +782,16 @@ async function runDoctor(options, io) {
|
|
|
490
782
|
io.stdout(`${JSON.stringify(report, null, 2)}\n`);
|
|
491
783
|
return problems.length > 0 ? 1 : 0;
|
|
492
784
|
}
|
|
493
|
-
const
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
}
|
|
504
|
-
const blocks = problems.map((problem) => formatProblem(problem, color));
|
|
505
|
-
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`);
|
|
506
795
|
return problems.length > 0 ? 1 : 0;
|
|
507
796
|
}
|
|
508
797
|
/** Prints a config or usage error as a tree on stderr. */
|
package/dist/eslint.d.mts
CHANGED
|
@@ -24,6 +24,7 @@ export interface GlosslintEslintOptions {
|
|
|
24
24
|
/**
|
|
25
25
|
* ESLint flat configs that run glosslint's rules: `...glosslint()`. The corpus comes from `corpus`, else
|
|
26
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
|
|
27
|
+
* no parser: your config supplies typescript-eslint, vue-eslint-parser, yaml-eslint-parser or
|
|
28
|
+
* jsonc-eslint-parser.
|
|
28
29
|
*/
|
|
29
30
|
export default function glosslint(options?: GlosslintEslintOptions): Linter.Config[];
|
package/dist/eslint.mjs
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as DEFAULT_IGNORE_CALLEES, t as createRules } from "./rules-
|
|
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
|
|
6
7
|
* from the `glossary` file, else from `.agents/glossary.md`, read once when the config is built. They set
|
|
7
|
-
* no parser: your config supplies typescript-eslint, vue-eslint-parser
|
|
8
|
+
* no parser: your config supplies typescript-eslint, vue-eslint-parser, yaml-eslint-parser or
|
|
9
|
+
* jsonc-eslint-parser.
|
|
8
10
|
*/
|
|
9
11
|
function glosslint(options = {}) {
|
|
10
12
|
if (options.corpus && options.glossary !== void 0) throw new GlosslintConfigError({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
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 {
|
|
@@ -87,8 +84,17 @@ const APOSTROPHE = /['’]/;
|
|
|
87
84
|
const PLACEHOLDER = /\{\{[\s\S]*?\}\}|\{\s*[\p{L}\p{N}_$.-]+\s*(?:,\s*(?:number|date|time)[^{}]*)?\}/gu;
|
|
88
85
|
const ICU_HEAD = /\{\s*[\p{L}\p{N}_$.-]+\s*,\s*(?:plural|select|selectordinal)\s*,/gu;
|
|
89
86
|
const ICU_BRANCH = /(?:=\d+|[\p{L}\p{N}_]+)\s*\{|[{}#]/gu;
|
|
90
|
-
const URL = /\b[a-z][a-z\d+.-]*:\/\/[^\s<>"'`)\]]*|\bwww\.[^\s<>"'`)\]]+|\bmailto:[^\s<>"'`)\]]
|
|
87
|
+
const URL = /\b[a-z][a-z\d+.-]*:\/\/[^\s<>"'`)\]]*|\bwww\.[^\s<>"'`)\]]+|\bmailto:[^\s<>"'`)\]]+/giu;
|
|
88
|
+
const EMAIL = /[\w.+-]+@[\w-]+(?:\.[\w-]+)+/gu;
|
|
91
89
|
const BACKTICKS = /(`+)[\s\S]*?\1/gu;
|
|
90
|
+
/** One pass, so the span that starts first wins: a URL keeps a package inside it, an email its `www.` domain. */
|
|
91
|
+
const CODE_SPAN = new RegExp([
|
|
92
|
+
URL,
|
|
93
|
+
/@(?:\.\p{L}+)?:(?:\{\s*'(?:[^'\\]|\\.)*'\s*\}|[\p{L}\p{N}_$.-]+)/gu,
|
|
94
|
+
/(?<![\p{L}\p{N}_./@-])[\p{L}\p{N}][\p{L}\p{N}_.-]*\/[\p{L}\p{N}_.-]+(?:#\d+|@[\p{L}\p{N}_.-]*[\p{L}\p{N}])/gu,
|
|
95
|
+
/(?<![\p{L}\p{N}_.@])@[\p{L}\p{N}][\p{L}\p{N}_.~-]*\/[\p{L}\p{N}][\p{L}\p{N}_.~-]*/gu,
|
|
96
|
+
EMAIL
|
|
97
|
+
].map((pattern) => pattern.source).join("|"), "giu");
|
|
92
98
|
const PATH = /(?<![\p{L}\p{N}.~])(?:\.{1,2}|~)?\/[\p{L}\p{N}_.~/-]+/gu;
|
|
93
99
|
const CHUNK = /[\p{L}\p{N}_]+(?:[-.][\p{L}\p{N}_]+)*/gu;
|
|
94
100
|
const CAMEL = /\p{Ll}\p{Lu}/u;
|
|
@@ -121,12 +127,13 @@ function isKept(key, keep) {
|
|
|
121
127
|
return keep.has(key) || key.endsWith("s") && keep.has(key.slice(0, -1)) || key.endsWith("es") && keep.has(key.slice(0, -2));
|
|
122
128
|
}
|
|
123
129
|
/**
|
|
124
|
-
* Blanks out what is code rather than words, keeping every offset: placeholders,
|
|
125
|
-
* code, and camel, snake and slug tokens unless their
|
|
130
|
+
* Blanks out what is code rather than words, keeping every offset: placeholders, linked messages, URLs,
|
|
131
|
+
* paths, backtick code, scoped packages, repository refs, and camel, snake and slug tokens unless their
|
|
132
|
+
* key is in `keep`.
|
|
126
133
|
*/
|
|
127
134
|
function mask(text, keep = /* @__PURE__ */ new Set()) {
|
|
128
135
|
let out = blankAll(text, BACKTICKS);
|
|
129
|
-
out = blankAll(out,
|
|
136
|
+
out = blankAll(out, CODE_SPAN);
|
|
130
137
|
out = blankAll(out, PATH);
|
|
131
138
|
if (out.search(ICU_HEAD) !== -1) {
|
|
132
139
|
const icu = maskIcu(out);
|
|
@@ -177,6 +184,16 @@ function tokenize(text, keep = /* @__PURE__ */ new Set()) {
|
|
|
177
184
|
}
|
|
178
185
|
return tokens;
|
|
179
186
|
}
|
|
187
|
+
/** A string with no spaces, all in lowercase, shaped like a key, slug, path or single code word. */
|
|
188
|
+
const LOWER_SHAPE = /^[\p{Ll}\p{N}_\-./:#@~]+$/u;
|
|
189
|
+
/** A camelCase name, such as a column id. Capitalised words and hyphenated labels don't match. */
|
|
190
|
+
const CAMEL_SHAPE = /^\p{Ll}[\p{Ll}\p{N}]*\p{Lu}[\p{L}\p{N}_\-./:]*$/u;
|
|
191
|
+
/** A dotted path of names that each start in lowercase, such as the i18n key `alarm.activeAlarms`. */
|
|
192
|
+
const PATH_SHAPE = /^\p{Ll}[\p{L}\p{N}_$-]*(?:\.[\p{Ll}\p{N}_$][\p{L}\p{N}_$-]*)+$/u;
|
|
193
|
+
/** Whether a JS string, attribute or prop value is shaped like code, so it is skipped (decision 7). */
|
|
194
|
+
function isCodeShape(text) {
|
|
195
|
+
return LOWER_SHAPE.test(text) || CAMEL_SHAPE.test(text) || PATH_SHAPE.test(text);
|
|
196
|
+
}
|
|
180
197
|
// src/corpus.ts
|
|
181
198
|
const INPUT_FIELDS = [
|
|
182
199
|
"extends",
|
|
@@ -432,6 +449,14 @@ function byName(name, text) {
|
|
|
432
449
|
return "unknown";
|
|
433
450
|
}
|
|
434
451
|
/**
|
|
452
|
+
* Whether a key or prop holds text people read, from its words alone: `title`, `cardLabel` and `name`
|
|
453
|
+
* do, `to`, `icon` and `className` don't.
|
|
454
|
+
*/
|
|
455
|
+
function isTextName(name) {
|
|
456
|
+
const words = splitWords(name).map((word) => word.toLowerCase().replace(/\d+$/, ""));
|
|
457
|
+
return name === "name" || words.some((word) => LABEL_WORD.test(word) || HEADER_WORD.test(word) || SENTENCE_WORD.test(word));
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
435
460
|
* The kind of shown text from its shape alone: a label when it is a few words that don't open like a
|
|
436
461
|
* sentence, or when it is written in Title Case, else a sentence.
|
|
437
462
|
*/
|
|
@@ -694,6 +719,10 @@ function allowPattern(phrase) {
|
|
|
694
719
|
return new RegExp(`(?<![\\p{L}\\p{N}])${body}(?:e?s)?(?![\\p{L}\\p{N}])`, "giu");
|
|
695
720
|
}
|
|
696
721
|
/** Compiles a corpus for matching. Build it once and reuse it. */
|
|
722
|
+
/** A lowercase word against a slash, as in `nuxt/nuxt` or `nuxt/modules`, names a repository or path. */
|
|
723
|
+
function againstSlash(text, hit) {
|
|
724
|
+
return !/\p{Lu}/u.test(text.slice(hit.start, hit.end)) && (text[hit.start - 1] === "/" || text[hit.end] === "/");
|
|
725
|
+
}
|
|
697
726
|
function createMatcher(corpus, options = {}) {
|
|
698
727
|
const terms = /* @__PURE__ */ new Map();
|
|
699
728
|
const abbrs = /* @__PURE__ */ new Map();
|
|
@@ -801,6 +830,7 @@ function createMatcher(corpus, options = {}) {
|
|
|
801
830
|
} : void 0);
|
|
802
831
|
}
|
|
803
832
|
if (shouted) return void 0;
|
|
833
|
+
if (againstSlash(text, hit)) return void 0;
|
|
804
834
|
const want = exact ? entry.canonical : contextWant;
|
|
805
835
|
const where = exact || contextWant === void 0 ? "" : ` in ${kind}s`;
|
|
806
836
|
if (want === void 0 || surface.replace(/\s+/g, " ") === want) return void 0;
|
|
@@ -886,7 +916,7 @@ function createMatcher(corpus, options = {}) {
|
|
|
886
916
|
continue;
|
|
887
917
|
}
|
|
888
918
|
const style = styleOf(hit.value.term, kind);
|
|
889
|
-
if (hit.value.mode === "context" && (style === "title" || style === "upper")) styled = {
|
|
919
|
+
if (hit.value.mode === "context" && !againstSlash(text, hit) && (style === "title" || style === "upper")) styled = {
|
|
890
920
|
term: hit.value.term,
|
|
891
921
|
style
|
|
892
922
|
};
|
|
@@ -1187,7 +1217,7 @@ function toX18nGlossary(corpus) {
|
|
|
1187
1217
|
};
|
|
1188
1218
|
});
|
|
1189
1219
|
}
|
|
1190
|
-
// src/glossary.ts
|
|
1220
|
+
// src/glossary-text.ts
|
|
1191
1221
|
/** The codes of `GlossaryProblem`. */
|
|
1192
1222
|
const GLOSSARY_PROBLEMS = {
|
|
1193
1223
|
title: "GLOSSLINT_G001",
|
|
@@ -1794,7 +1824,8 @@ function failingExamples(reader, doc, corpus, own) {
|
|
|
1794
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);
|
|
1795
1825
|
}
|
|
1796
1826
|
}
|
|
1797
|
-
|
|
1827
|
+
/** Reads a glossary's text, and with `examples` runs each term's examples too (`G009`). */
|
|
1828
|
+
function parseGlossary(text, examples) {
|
|
1798
1829
|
const lines = text.split(/\r?\n/);
|
|
1799
1830
|
if (lines.at(-1) === "") lines.pop();
|
|
1800
1831
|
const reader = new Reader(lines);
|
|
@@ -1834,39 +1865,6 @@ function parse(text, examples) {
|
|
|
1834
1865
|
* `fixed`, the canonical text, when the file can be rewritten and differs from it.
|
|
1835
1866
|
*/
|
|
1836
1867
|
function readGlossary(text) {
|
|
1837
|
-
return
|
|
1838
|
-
}
|
|
1839
|
-
function displayPath(file) {
|
|
1840
|
-
const shown = relative(process.cwd(), file);
|
|
1841
|
-
return shown && !shown.startsWith("..") && !isAbsolute(shown) ? shown : file;
|
|
1842
|
-
}
|
|
1843
|
-
/** The absolute path of a glossary: a string resolves from the current folder. */
|
|
1844
|
-
function glossaryPath(path = DEFAULT_GLOSSARY) {
|
|
1845
|
-
return typeof path === "string" ? resolve(process.cwd(), path) : fileURLToPath(path);
|
|
1846
|
-
}
|
|
1847
|
-
/**
|
|
1848
|
-
* Reads a glossary file, `.agents/glossary.md` by default, as a corpus. Throws a `GlosslintConfigError`
|
|
1849
|
-
* when the file is missing (`GLOSSLINT_C009`) or has a problem only a person can fix (`G004` to `G008`).
|
|
1850
|
-
* A file with only fixable problems loads as its fixed form would.
|
|
1851
|
-
*/
|
|
1852
|
-
function fromGlossary(path = DEFAULT_GLOSSARY) {
|
|
1853
|
-
const file = glossaryPath(path);
|
|
1854
|
-
const shown = displayPath(file);
|
|
1855
|
-
if (!existsSync(file)) throw new GlosslintConfigError({
|
|
1856
|
-
code: CONFIG_ERRORS.noGlossary,
|
|
1857
|
-
why: `No glossary at ${shown}.`,
|
|
1858
|
-
fix: `Create ${shown} with \`# Glossary\` and a \`## Term\` section per term, or pass the path of your glossary.`
|
|
1859
|
-
});
|
|
1860
|
-
const { problems, corpus } = parse(readFileSync(file, "utf8"), false);
|
|
1861
|
-
if (corpus) return corpus;
|
|
1862
|
-
const blocking = problems.filter((problem) => BLOCKING.has(problem.code));
|
|
1863
|
-
const [first] = blocking;
|
|
1864
|
-
const more = blocking.length > 1 ? ` ${blocking.length - 1} more problem${blocking.length > 2 ? "s" : ""}: run \`glosslint doctor\` to list them.` : "";
|
|
1865
|
-
throw new GlosslintConfigError({
|
|
1866
|
-
code: first.code,
|
|
1867
|
-
why: `${shown}:${first.line}: ${first.why}`,
|
|
1868
|
-
fix: `${first.fix}${more}`,
|
|
1869
|
-
...first.term === void 0 ? {} : { term: first.term }
|
|
1870
|
-
});
|
|
1868
|
+
return parseGlossary(text, true);
|
|
1871
1869
|
}
|
|
1872
|
-
export {
|
|
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
|
|
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";
|
|
@@ -57,7 +63,6 @@ interface MatcherOptions {
|
|
|
57
63
|
/** Report avoid words inside identifiers too. Off by default, since renaming touches every caller. */
|
|
58
64
|
identifierAvoid?: boolean;
|
|
59
65
|
}
|
|
60
|
-
/** Compiles a corpus for matching. Build it once and reuse it. */
|
|
61
66
|
export declare function createMatcher(corpus: Corpus, options?: MatcherOptions): Matcher;
|
|
62
67
|
/** Finds every problem in `text`, read as `kind` (default `unknown`). */
|
|
63
68
|
export declare function check(matcher: Matcher, text: string, kind?: TextKind): Finding[];
|
|
@@ -72,4 +77,4 @@ export declare function printCorpus(corpus: Corpus, format: "md" | "json"): stri
|
|
|
72
77
|
export declare function explain(corpus: Corpus, query: string): string;
|
|
73
78
|
/** The corpus as x18n `glossary` entries, with only the fields x18n accepts. */
|
|
74
79
|
export declare function toX18nGlossary(corpus: Corpus): X18nGlossaryEntry[];
|
|
75
|
-
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,
|
|
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 {
|
|
2
|
-
import {
|
|
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
|
|
2
|
-
import {
|
|
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 {
|
|
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
|
|
@@ -170,6 +170,7 @@ const SKIPPED_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
|
170
170
|
"slot",
|
|
171
171
|
"is",
|
|
172
172
|
"for",
|
|
173
|
+
"keypath",
|
|
173
174
|
"aria-labelledby",
|
|
174
175
|
"aria-describedby",
|
|
175
176
|
"aria-controls",
|
|
@@ -205,14 +206,6 @@ const NAME_WRAPPERS = /* @__PURE__ */ new Set([
|
|
|
205
206
|
"TemplateLiteral",
|
|
206
207
|
"BinaryExpression"
|
|
207
208
|
]);
|
|
208
|
-
/** A string with no spaces, all in lowercase, shaped like a key, slug, path or single code word. */
|
|
209
|
-
const LOWER_SHAPE = /^[\p{Ll}\p{N}_\-./:#@~]+$/u;
|
|
210
|
-
/** A camelCase name, such as a column id. Capitalised words and hyphenated labels don't match. */
|
|
211
|
-
const CAMEL_SHAPE = /^\p{Ll}[\p{Ll}\p{N}]*\p{Lu}[\p{L}\p{N}_\-./:]*$/u;
|
|
212
|
-
/** Whether a JS string or attribute value is shaped like code, so it is skipped (decision 7). */
|
|
213
|
-
function isCodeShape(text) {
|
|
214
|
-
return LOWER_SHAPE.test(text) || CAMEL_SHAPE.test(text);
|
|
215
|
-
}
|
|
216
209
|
function isSkippedAttribute(name) {
|
|
217
210
|
if (name === void 0) return false;
|
|
218
211
|
const lower = name.toLowerCase();
|
|
@@ -317,6 +310,8 @@ function noneOf(...forbidden) {
|
|
|
317
310
|
return (replace) => !forbidden.some((text) => replace.includes(text));
|
|
318
311
|
}
|
|
319
312
|
const NEWLINES = ["\n", "\r"];
|
|
313
|
+
/** U+0000 to U+001F, which JSON allows in a string only escaped. */
|
|
314
|
+
const JSON_CONTROL = Array.from({ length: 32 }, (_, code) => String.fromCharCode(code));
|
|
320
315
|
/** Builds the sites of a JS string literal or template literal, or none when it is skipped. */
|
|
321
316
|
function esSites(node, source, ignoreCallees, inTemplate, decide) {
|
|
322
317
|
if (isSkippedString(node, ignoreCallees)) return [];
|
|
@@ -479,6 +474,34 @@ function yamlSite(node, decide) {
|
|
|
479
474
|
};
|
|
480
475
|
}
|
|
481
476
|
}
|
|
477
|
+
function jsonKeyName(node) {
|
|
478
|
+
for (let current = node.parent; current; current = current.parent) {
|
|
479
|
+
if (current.type !== "JSONProperty") continue;
|
|
480
|
+
const key = current.key;
|
|
481
|
+
if (key.type === "JSONIdentifier") return key.name;
|
|
482
|
+
return typeof key.value === "string" ? key.value : void 0;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
/** Builds the site of a JSON string value; keys are never checked. */
|
|
486
|
+
function jsonSite(node, decide) {
|
|
487
|
+
if (typeof node.value !== "string" || node.value.trim() === "") return void 0;
|
|
488
|
+
const parent = node.parent;
|
|
489
|
+
if (parent?.type === "JSONProperty" && parent.key === node) return void 0;
|
|
490
|
+
const text = node.value;
|
|
491
|
+
const raw = node.raw;
|
|
492
|
+
return {
|
|
493
|
+
text,
|
|
494
|
+
...decide({
|
|
495
|
+
name: jsonKeyName(node),
|
|
496
|
+
text,
|
|
497
|
+
shown: true
|
|
498
|
+
}),
|
|
499
|
+
base: node.range[0] + 1,
|
|
500
|
+
map: jsMap(raw.slice(1, -1), text),
|
|
501
|
+
within: node.range,
|
|
502
|
+
safe: noneOf(raw[0], "\\", ...JSON_CONTROL)
|
|
503
|
+
};
|
|
504
|
+
}
|
|
482
505
|
function escapeRegExp(text) {
|
|
483
506
|
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
484
507
|
}
|
|
@@ -526,7 +549,8 @@ function stringListener(context, ignoreCallees, kindOf, onSite) {
|
|
|
526
549
|
const script = {
|
|
527
550
|
Literal: es(false),
|
|
528
551
|
TemplateLiteral: es(false),
|
|
529
|
-
YAMLScalar: (node) => emit(yamlSite(node, decide))
|
|
552
|
+
YAMLScalar: (node) => emit(yamlSite(node, decide)),
|
|
553
|
+
JSONLiteral: (node) => emit(jsonSite(node, decide))
|
|
530
554
|
};
|
|
531
555
|
const services = context.sourceCode.parserServices;
|
|
532
556
|
if (!services?.defineTemplateBodyVisitor) return script;
|
package/dist/x18n.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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
|
-
|
|
87
|
-
|
|
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.
|
|
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",
|
|
@@ -101,6 +101,7 @@
|
|
|
101
101
|
"case-police": "2.2.1",
|
|
102
102
|
"eslint": "^10.15.0",
|
|
103
103
|
"eslint-vitest-rule-tester": "^3.2.0",
|
|
104
|
+
"jsonc-eslint-parser": "^3.3.0",
|
|
104
105
|
"oxlint": "1.94.0",
|
|
105
106
|
"publint": "^0.3.25",
|
|
106
107
|
"tsrs": "7.1.0-beta.tsrs5",
|