glosslint 0.1.0 → 0.1.1
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 +1 -1
- package/dist/cli.mjs +330 -29
- package/dist/eslint.d.mts +2 -1
- package/dist/eslint.mjs +4 -3
- package/dist/{format-CQ9xdJYe.mjs → format-E5eFHoQT.mjs} +1 -1
- package/dist/{glossary-lk7EwGey.mjs → glossary-ztPpmozR.mjs} +39 -6
- package/dist/index.d.mts +0 -1
- package/dist/index.mjs +2 -2
- package/dist/oxlint.mjs +2 -2
- package/dist/{rules-D-PrDySk.mjs → rules-D9Jd07u1.mjs} +34 -10
- package/dist/x18n.mjs +1 -1
- 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
|
@@ -82,7 +82,7 @@ export declare function loadCorpus(cwd: string, options?: {
|
|
|
82
82
|
/**
|
|
83
83
|
* Blanks what is not prose in Markdown, keeping every offset: frontmatter, fenced code, HTML
|
|
84
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.
|
|
85
|
+
* and quotes. In MDX, `import` and `export` lines too; in other Markdown, Comark component markup.
|
|
86
86
|
*/
|
|
87
87
|
export declare function maskMarkdown(text: string, options?: {
|
|
88
88
|
mdx?: boolean;
|
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-
|
|
3
|
-
import { a as explain, c as testCorpus, d as createMatcher, i as readGlossary, m as
|
|
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";
|
|
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,282 @@ 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.
|
|
11
|
+
var version = "0.1.1";
|
|
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
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
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
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function isText(name, value) {
|
|
79
|
+
return !name.startsWith(":") && isTextName(name) && value.trim() !== "" && !isCodeShape(value);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
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.
|
|
84
|
+
*/
|
|
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
|
+
};
|
|
106
|
+
}
|
|
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
|
|
115
|
+
});
|
|
116
|
+
return {
|
|
117
|
+
end: scanned.end,
|
|
118
|
+
props
|
|
119
|
+
};
|
|
120
|
+
}
|
|
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
|
|
179
|
+
};
|
|
180
|
+
}
|
|
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;
|
|
281
|
+
}
|
|
282
|
+
return {
|
|
283
|
+
lines: out,
|
|
284
|
+
props
|
|
285
|
+
};
|
|
286
|
+
}
|
|
12
287
|
// src/cli.ts
|
|
13
288
|
/** Codes of the errors the CLI prints itself, next to the corpus's `GLOSSLINT_C00x`. */
|
|
14
289
|
const CLI_ERRORS = {
|
|
@@ -152,7 +427,6 @@ const FRONTMATTER = /^(?:---|\+\+\+)\r?\n[\s\S]*?\r?\n(?:---|\+\+\+|\.\.\.)[ \t]
|
|
|
152
427
|
const FENCE = /^[ \t]*((?:>[ \t]?)*)[ \t]*((?:[-*+]|\d{1,9}[.)])[ \t]+)?(`{3,}|~{3,})([^\n]*)$/;
|
|
153
428
|
const HTML_COMMENT = /<!--[\s\S]*?(?:-->|$)/g;
|
|
154
429
|
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
430
|
const LINK_REFERENCE = /(?<=\])\[[^\]\n]*\]/g;
|
|
157
431
|
const REFERENCE_DEFINITION = /^ {0,3}\[[^\]\n]+\]:[ \t]*\S.*$/gm;
|
|
158
432
|
const AUTOLINK = /<(?:[a-z][a-z\d+.-]*:[^\s<>]*|[^\s<>@]+@[^\s<>]+)>/gi;
|
|
@@ -163,9 +437,13 @@ const LIST_ITEM = /^ {0,3}(?:>[ \t]?)*(?:[-*+]|\d{1,9}[.)])[ \t]/;
|
|
|
163
437
|
/**
|
|
164
438
|
* Blanks what is not prose in Markdown, keeping every offset: frontmatter, fenced code, HTML
|
|
165
439
|
* 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.
|
|
440
|
+
* and quotes. In MDX, `import` and `export` lines too; in other Markdown, Comark component markup.
|
|
167
441
|
*/
|
|
168
442
|
function maskMarkdown(text, options = {}) {
|
|
443
|
+
return maskMarkdownParts(text, options).masked;
|
|
444
|
+
}
|
|
445
|
+
/** {@link maskMarkdown}, plus the Comark text props it blanked, which are checked on their own. */
|
|
446
|
+
function maskMarkdownParts(text, options) {
|
|
169
447
|
let out = text.replace(FRONTMATTER, blank);
|
|
170
448
|
const lines = out.split("\n");
|
|
171
449
|
let fence;
|
|
@@ -184,19 +462,26 @@ function maskMarkdown(text, options = {}) {
|
|
|
184
462
|
lines[index] = blank(line);
|
|
185
463
|
} else if (options.mdx && /^(?:import|export)\s/.test(line)) lines[index] = blank(line);
|
|
186
464
|
}
|
|
187
|
-
out = lines.join("\n");
|
|
188
|
-
|
|
189
|
-
|
|
465
|
+
out = lines.join("\n").replace(HTML_COMMENT, blank).replace(INLINE_CODE, blank);
|
|
466
|
+
let props = [];
|
|
467
|
+
if (!options.mdx) {
|
|
468
|
+
const comark = maskComark(out.split("\n"), blank);
|
|
469
|
+
out = comark.lines.join("\n");
|
|
470
|
+
props = comark.props;
|
|
471
|
+
}
|
|
190
472
|
out = out.replace(REFERENCE_DEFINITION, blank);
|
|
191
473
|
out = out.replace(LINK_TARGET, blank);
|
|
192
474
|
out = out.replace(LINK_REFERENCE, blank);
|
|
193
475
|
out = out.replace(AUTOLINK, blank);
|
|
194
476
|
out = out.replace(TAG, blank);
|
|
195
|
-
return
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
477
|
+
return {
|
|
478
|
+
masked: out.split("\n").map((line) => {
|
|
479
|
+
let masked = line.replace(LINE_PREFIX, blank);
|
|
480
|
+
if (HEADING.test(line)) masked = masked.replace(/[ \t]#+[ \t]*(?=\r?$)/, blank);
|
|
481
|
+
return masked;
|
|
482
|
+
}).join("\n"),
|
|
483
|
+
props
|
|
484
|
+
};
|
|
200
485
|
}
|
|
201
486
|
const TABLE_DELIMITER = /^\s*\|?\s*:?-+:?\s*(?:\|\s*:?-+:?\s*)*\|?\s*\r?$/;
|
|
202
487
|
/** Splits text into the pieces checked one at a time: headings, table cells, list items and paragraphs. */
|
|
@@ -260,7 +545,10 @@ function summarize(term) {
|
|
|
260
545
|
/** Checks one file's text. Markdown is masked first, so code and link targets are never reported. */
|
|
261
546
|
function checkFileText(matcher, text, file, options = {}) {
|
|
262
547
|
const markdown = options.markdown ?? false;
|
|
263
|
-
const masked = markdown ?
|
|
548
|
+
const { masked, props } = markdown ? maskMarkdownParts(text, { mdx: options.mdx ?? false }) : {
|
|
549
|
+
masked: text,
|
|
550
|
+
props: []
|
|
551
|
+
};
|
|
264
552
|
const lineStarts = [0];
|
|
265
553
|
for (let index = text.indexOf("\n"); index !== -1; index = text.indexOf("\n", index + 1)) lineStarts.push(index + 1);
|
|
266
554
|
const lineOf = (offset) => {
|
|
@@ -275,22 +563,35 @@ function checkFileText(matcher, text, file, options = {}) {
|
|
|
275
563
|
};
|
|
276
564
|
const lineEnd = (line) => (lineStarts[line + 1] ?? text.length + 1) - 1;
|
|
277
565
|
const findings = [];
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
566
|
+
const all = [...blocks(text, masked, markdown), ...props.map((prop) => ({
|
|
567
|
+
start: prop.start,
|
|
568
|
+
end: prop.end,
|
|
569
|
+
kind: kindOf({
|
|
570
|
+
text: prop.text,
|
|
571
|
+
name: prop.name,
|
|
572
|
+
shown: true
|
|
573
|
+
}),
|
|
574
|
+
text: prop.text
|
|
575
|
+
}))].sort((a, b) => a.start - b.start);
|
|
576
|
+
for (const block of all) {
|
|
577
|
+
const read = block.text ?? masked.slice(block.start, block.end);
|
|
578
|
+
for (const finding of matcher.check(read, block.kind)) {
|
|
579
|
+
const start = block.start + finding.start;
|
|
580
|
+
const end = block.start + finding.end;
|
|
581
|
+
const line = lineOf(start);
|
|
582
|
+
const lineStart = lineStarts[line];
|
|
583
|
+
findings.push(toCliFinding(finding, {
|
|
584
|
+
file,
|
|
585
|
+
text,
|
|
586
|
+
start,
|
|
587
|
+
end,
|
|
588
|
+
line,
|
|
589
|
+
lineStart,
|
|
590
|
+
lineEnd: lineEnd(lineOf(end))
|
|
591
|
+
}));
|
|
592
|
+
}
|
|
292
593
|
}
|
|
293
|
-
return findings;
|
|
594
|
+
return findings.sort((a, b) => a.start - b.start);
|
|
294
595
|
}
|
|
295
596
|
function toCliFinding(finding, at) {
|
|
296
597
|
const { fix, term, start: _start, end: _end, ...rest } = finding;
|
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,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as DEFAULT_IGNORE_CALLEES, t as createRules } from "./rules-
|
|
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";
|
|
3
3
|
// src/eslint.ts
|
|
4
4
|
/**
|
|
5
5
|
* ESLint flat configs that run glosslint's rules: `...glosslint()`. The corpus comes from `corpus`, else
|
|
6
6
|
* 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
|
|
7
|
+
* no parser: your config supplies typescript-eslint, vue-eslint-parser, yaml-eslint-parser or
|
|
8
|
+
* jsonc-eslint-parser.
|
|
8
9
|
*/
|
|
9
10
|
function glosslint(options = {}) {
|
|
10
11
|
if (options.corpus && options.glossary !== void 0) throw new GlosslintConfigError({
|
|
@@ -87,8 +87,17 @@ const APOSTROPHE = /['’]/;
|
|
|
87
87
|
const PLACEHOLDER = /\{\{[\s\S]*?\}\}|\{\s*[\p{L}\p{N}_$.-]+\s*(?:,\s*(?:number|date|time)[^{}]*)?\}/gu;
|
|
88
88
|
const ICU_HEAD = /\{\s*[\p{L}\p{N}_$.-]+\s*,\s*(?:plural|select|selectordinal)\s*,/gu;
|
|
89
89
|
const ICU_BRANCH = /(?:=\d+|[\p{L}\p{N}_]+)\s*\{|[{}#]/gu;
|
|
90
|
-
const URL = /\b[a-z][a-z\d+.-]*:\/\/[^\s<>"'`)\]]*|\bwww\.[^\s<>"'`)\]]+|\bmailto:[^\s<>"'`)\]]
|
|
90
|
+
const URL = /\b[a-z][a-z\d+.-]*:\/\/[^\s<>"'`)\]]*|\bwww\.[^\s<>"'`)\]]+|\bmailto:[^\s<>"'`)\]]+/giu;
|
|
91
|
+
const EMAIL = /[\w.+-]+@[\w-]+(?:\.[\w-]+)+/gu;
|
|
91
92
|
const BACKTICKS = /(`+)[\s\S]*?\1/gu;
|
|
93
|
+
/** One pass, so the span that starts first wins: a URL keeps a package inside it, an email its `www.` domain. */
|
|
94
|
+
const CODE_SPAN = new RegExp([
|
|
95
|
+
URL,
|
|
96
|
+
/@(?:\.\p{L}+)?:(?:\{\s*'(?:[^'\\]|\\.)*'\s*\}|[\p{L}\p{N}_$.-]+)/gu,
|
|
97
|
+
/(?<![\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,
|
|
98
|
+
/(?<![\p{L}\p{N}_.@])@[\p{L}\p{N}][\p{L}\p{N}_.~-]*\/[\p{L}\p{N}][\p{L}\p{N}_.~-]*/gu,
|
|
99
|
+
EMAIL
|
|
100
|
+
].map((pattern) => pattern.source).join("|"), "giu");
|
|
92
101
|
const PATH = /(?<![\p{L}\p{N}.~])(?:\.{1,2}|~)?\/[\p{L}\p{N}_.~/-]+/gu;
|
|
93
102
|
const CHUNK = /[\p{L}\p{N}_]+(?:[-.][\p{L}\p{N}_]+)*/gu;
|
|
94
103
|
const CAMEL = /\p{Ll}\p{Lu}/u;
|
|
@@ -121,12 +130,13 @@ function isKept(key, keep) {
|
|
|
121
130
|
return keep.has(key) || key.endsWith("s") && keep.has(key.slice(0, -1)) || key.endsWith("es") && keep.has(key.slice(0, -2));
|
|
122
131
|
}
|
|
123
132
|
/**
|
|
124
|
-
* Blanks out what is code rather than words, keeping every offset: placeholders,
|
|
125
|
-
* code, and camel, snake and slug tokens unless their
|
|
133
|
+
* Blanks out what is code rather than words, keeping every offset: placeholders, linked messages, URLs,
|
|
134
|
+
* paths, backtick code, scoped packages, repository refs, and camel, snake and slug tokens unless their
|
|
135
|
+
* key is in `keep`.
|
|
126
136
|
*/
|
|
127
137
|
function mask(text, keep = /* @__PURE__ */ new Set()) {
|
|
128
138
|
let out = blankAll(text, BACKTICKS);
|
|
129
|
-
out = blankAll(out,
|
|
139
|
+
out = blankAll(out, CODE_SPAN);
|
|
130
140
|
out = blankAll(out, PATH);
|
|
131
141
|
if (out.search(ICU_HEAD) !== -1) {
|
|
132
142
|
const icu = maskIcu(out);
|
|
@@ -177,6 +187,16 @@ function tokenize(text, keep = /* @__PURE__ */ new Set()) {
|
|
|
177
187
|
}
|
|
178
188
|
return tokens;
|
|
179
189
|
}
|
|
190
|
+
/** A string with no spaces, all in lowercase, shaped like a key, slug, path or single code word. */
|
|
191
|
+
const LOWER_SHAPE = /^[\p{Ll}\p{N}_\-./:#@~]+$/u;
|
|
192
|
+
/** A camelCase name, such as a column id. Capitalised words and hyphenated labels don't match. */
|
|
193
|
+
const CAMEL_SHAPE = /^\p{Ll}[\p{Ll}\p{N}]*\p{Lu}[\p{L}\p{N}_\-./:]*$/u;
|
|
194
|
+
/** A dotted path of names that each start in lowercase, such as the i18n key `alarm.activeAlarms`. */
|
|
195
|
+
const PATH_SHAPE = /^\p{Ll}[\p{L}\p{N}_$-]*(?:\.[\p{Ll}\p{N}_$][\p{L}\p{N}_$-]*)+$/u;
|
|
196
|
+
/** Whether a JS string, attribute or prop value is shaped like code, so it is skipped (decision 7). */
|
|
197
|
+
function isCodeShape(text) {
|
|
198
|
+
return LOWER_SHAPE.test(text) || CAMEL_SHAPE.test(text) || PATH_SHAPE.test(text);
|
|
199
|
+
}
|
|
180
200
|
// src/corpus.ts
|
|
181
201
|
const INPUT_FIELDS = [
|
|
182
202
|
"extends",
|
|
@@ -432,6 +452,14 @@ function byName(name, text) {
|
|
|
432
452
|
return "unknown";
|
|
433
453
|
}
|
|
434
454
|
/**
|
|
455
|
+
* Whether a key or prop holds text people read, from its words alone: `title`, `cardLabel` and `name`
|
|
456
|
+
* do, `to`, `icon` and `className` don't.
|
|
457
|
+
*/
|
|
458
|
+
function isTextName(name) {
|
|
459
|
+
const words = splitWords(name).map((word) => word.toLowerCase().replace(/\d+$/, ""));
|
|
460
|
+
return name === "name" || words.some((word) => LABEL_WORD.test(word) || HEADER_WORD.test(word) || SENTENCE_WORD.test(word));
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
435
463
|
* The kind of shown text from its shape alone: a label when it is a few words that don't open like a
|
|
436
464
|
* sentence, or when it is written in Title Case, else a sentence.
|
|
437
465
|
*/
|
|
@@ -694,6 +722,10 @@ function allowPattern(phrase) {
|
|
|
694
722
|
return new RegExp(`(?<![\\p{L}\\p{N}])${body}(?:e?s)?(?![\\p{L}\\p{N}])`, "giu");
|
|
695
723
|
}
|
|
696
724
|
/** Compiles a corpus for matching. Build it once and reuse it. */
|
|
725
|
+
/** A lowercase word against a slash, as in `nuxt/nuxt` or `nuxt/modules`, names a repository or path. */
|
|
726
|
+
function againstSlash(text, hit) {
|
|
727
|
+
return !/\p{Lu}/u.test(text.slice(hit.start, hit.end)) && (text[hit.start - 1] === "/" || text[hit.end] === "/");
|
|
728
|
+
}
|
|
697
729
|
function createMatcher(corpus, options = {}) {
|
|
698
730
|
const terms = /* @__PURE__ */ new Map();
|
|
699
731
|
const abbrs = /* @__PURE__ */ new Map();
|
|
@@ -801,6 +833,7 @@ function createMatcher(corpus, options = {}) {
|
|
|
801
833
|
} : void 0);
|
|
802
834
|
}
|
|
803
835
|
if (shouted) return void 0;
|
|
836
|
+
if (againstSlash(text, hit)) return void 0;
|
|
804
837
|
const want = exact ? entry.canonical : contextWant;
|
|
805
838
|
const where = exact || contextWant === void 0 ? "" : ` in ${kind}s`;
|
|
806
839
|
if (want === void 0 || surface.replace(/\s+/g, " ") === want) return void 0;
|
|
@@ -886,7 +919,7 @@ function createMatcher(corpus, options = {}) {
|
|
|
886
919
|
continue;
|
|
887
920
|
}
|
|
888
921
|
const style = styleOf(hit.value.term, kind);
|
|
889
|
-
if (hit.value.mode === "context" && (style === "title" || style === "upper")) styled = {
|
|
922
|
+
if (hit.value.mode === "context" && !againstSlash(text, hit) && (style === "title" || style === "upper")) styled = {
|
|
890
923
|
term: hit.value.term,
|
|
891
924
|
style
|
|
892
925
|
};
|
|
@@ -1869,4 +1902,4 @@ function fromGlossary(path = DEFAULT_GLOSSARY) {
|
|
|
1869
1902
|
...first.term === void 0 ? {} : { term: first.term }
|
|
1870
1903
|
});
|
|
1871
1904
|
}
|
|
1872
|
-
export {
|
|
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 };
|
package/dist/index.d.mts
CHANGED
|
@@ -57,7 +57,6 @@ interface MatcherOptions {
|
|
|
57
57
|
/** Report avoid words inside identifiers too. Off by default, since renaming touches every caller. */
|
|
58
58
|
identifierAvoid?: boolean;
|
|
59
59
|
}
|
|
60
|
-
/** Compiles a corpus for matching. Build it once and reuse it. */
|
|
61
60
|
export declare function createMatcher(corpus: Corpus, options?: MatcherOptions): Matcher;
|
|
62
61
|
/** Finds every problem in `text`, read as `kind` (default `unknown`). */
|
|
63
62
|
export declare function check(matcher: Matcher, text: string, kind?: TextKind): Finding[];
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as explain, c as testCorpus, d as createMatcher, g as
|
|
2
|
-
import { n as formatFindings, r as toJson, t as formatFinding } from "./format-
|
|
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";
|
|
3
3
|
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,5 @@
|
|
|
1
|
-
import { n as DEFAULT_IGNORE_CALLEES, t as createRules } from "./rules-
|
|
2
|
-
import { r as fromGlossary } from "./glossary-
|
|
1
|
+
import { n as DEFAULT_IGNORE_CALLEES, t as createRules } from "./rules-D9Jd07u1.mjs";
|
|
2
|
+
import { r as fromGlossary } from "./glossary-ztPpmozR.mjs";
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
// src/oxlint.ts
|
|
5
5
|
const corpora = /* @__PURE__ */ new Map();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { d as createMatcher, f as caseModeOf, p as classify,
|
|
1
|
+
import { b as splitWords, d as createMatcher, f as caseModeOf, p as classify, y as isCodeShape } from "./glossary-ztPpmozR.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,4 +1,4 @@
|
|
|
1
|
-
import { d as createMatcher, f as caseModeOf,
|
|
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
2
|
// src/x18n.ts
|
|
3
3
|
const CHECKS = [
|
|
4
4
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "glosslint",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
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",
|