@heyramzi/lint 2.11.1 → 2.11.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 CHANGED
@@ -317,7 +317,12 @@ No allowlist, no config.
317
317
  ### Slop Gate and Jev
318
318
 
319
319
  `heyramzi-slop <file|dir|->` runs the exact patterns, and `--register=<name>` adds the rates of a
320
- voice. `--jev` also asks TypeSafe Jev (`jev.js`) to score each sentence and paragraph against the
320
+ voice. By default each check reports its first hit per file, which settles pass or fail. `--all`
321
+ lists every hit of every check with its line (`line` in `--json`), and the exit code doesn't
322
+ change. A refused push prints that command with this checkout's path: inside a repo, `npx
323
+ heyramzi-slop` runs the repo's installed copy, which can be older than the gate's.
324
+
325
+ `--jev` also asks TypeSafe Jev (`jev.js`) to score each sentence and paragraph against the
321
326
  humanizer shapes. Those scores are a report unless `--shape-block=<0.6-1>` names a bar. Jev reads
322
327
  `JEV_BASE_URL` and `JEV_API_KEY` from the env, else Proton Pass (Dev vault, item `AI endpoints`).
323
328
  A base ending in `/ai/run` is Cloudflare Workers AI, which also reads `JEV_GATEWAY_ID`.
@@ -71,7 +71,8 @@ import { titleTells } from "#lint/data/slop/title-tells.js";
71
71
  import { FAIL, REVIEW, isUnavailable, proseOf } from "#lint/jev-core.js";
72
72
  import { auditShapes, jevKey as readJevKey } from "#lint/jev.js";
73
73
  import { declaredLanguage } from "#lint/slop-language.js";
74
- import { slopGate } from "#lint/slop.js";
74
+ import { everyHit, hitLines } from "#lint/slop-lines.js";
75
+ import { markupLines, slopGate } from "#lint/slop.js";
75
76
 
76
77
  // =========================
77
78
  // CONSTANTS
@@ -109,14 +110,20 @@ function gate(file, register, repoPatterns) {
109
110
  // reads as a start. `withStringStarts` in slop.js carries what that cost.
110
111
  const code = /\.(m?[jt]sx?|json)$/i.test(file);
111
112
  if (/\.board\.json$/i.test(file)) return { raw, result: gateBoard(raw, register) };
113
+ // `proseOfMarkdown` keeps every line, so a markdown hit's line is the file's.
112
114
  const text = /\.mdx?$/i.test(file) ? proseOfMarkdown(raw) : raw;
113
115
  // Read from the raw file, because `proseOfMarkdown` blanks the frontmatter that carries `lang`.
114
116
  const language = declaredLanguage(raw, file);
115
- const result = slopGate(text, { markup, code, register, language });
117
+ const result = slopGate(text, { markup, code, register, language, all });
116
118
  // Read on the cleaned text, so a ban split by a tag or an invisible character still matches.
119
+ const lines = all && (markup ? markupLines(raw) : hitLines(result.text));
117
120
  for (const p of repoPatterns) {
118
- const m = result.text.match(p.test);
119
- if (m) result.findings.push({ kind: "repo-pattern", id: p.id, detail: m[0].slice(0, 90) });
121
+ const found = all ? [...result.text.matchAll(everyHit(p.test))] : [result.text.match(p.test)];
122
+ for (const m of found.filter(Boolean)) {
123
+ const hit = { kind: "repo-pattern", id: p.id, detail: m[0].slice(0, 90) };
124
+ const line = lines && (markup ? lines.find(p.id, m[0]) : lines.lineOf(m.index));
125
+ result.findings.push(line ? { ...hit, line } : hit);
126
+ }
120
127
  }
121
128
  result.ok = result.findings.length === 0;
122
129
  return { raw, result };
@@ -186,7 +193,9 @@ function gateBoard(raw, register) {
186
193
  if ((BOARD_TITLE.has(key) && !BOARD_CAPTION.has(kind)) || heading) titles.push(node);
187
194
  else if (BOARD_PROSE.has(key) || BOARD_TITLE.has(key)) prose.push(node);
188
195
  })(JSON.parse(raw));
189
- const result = slopGate([...titles, ...prose].join("\n\n"), { register });
196
+ const result = slopGate([...titles, ...prose].join("\n\n"), { register, all });
197
+ // A line in the joined strings is no line of the board file.
198
+ for (const f of result.findings) delete f.line;
190
199
  for (const title of titles)
191
200
  for (const t of titleTells.filter((t) => t.test.test(title)))
192
201
  result.findings.push({
@@ -227,7 +236,12 @@ function report(file, result, fixed) {
227
236
  for (const r of result.removed) {
228
237
  console.log(` invisible ${r.what} x${r.count}${fixed ? " (removed)" : ""}`);
229
238
  }
230
- for (const f of result.findings) console.log(` ${f.kind.padEnd(13)} ${f.id} ${f.detail}`);
239
+ for (const f of result.findings) {
240
+ // Under `--all` each hit is one line of output, so a dash's context loses its line breaks.
241
+ const at = f.line ? `line ${f.line} ` : "";
242
+ const detail = all ? f.detail.replace(/\s+/g, " ").trim() : f.detail;
243
+ console.log(` ${f.kind.padEnd(13)} ${f.id} ${at}${detail}`);
244
+ }
231
245
  for (const r of result.review) console.log(` ${r.kind.padEnd(13)} ${r.id} ${r.detail}`);
232
246
  if (result.removed.length === 0 && result.ok) console.log("clean");
233
247
  }
@@ -241,11 +255,15 @@ const paths = args.filter((a) => !a.startsWith("--"));
241
255
 
242
256
  if (paths.length === 0) {
243
257
  process.stderr.write(
244
- "usage: heyramzi-slop <file|dir|-> [more...] [--fix] [--json] [--jev [--shape-block=0.6-1]] [--quiet] [--register=spoken|shorts|written|forum [--thread=post.md]] [--only=kind|id,...] [--patterns=module.mjs]\n",
258
+ "usage: heyramzi-slop <file|dir|-> [more...] [--all] [--fix] [--json] [--jev [--shape-block=0.6-1]] [--quiet] [--register=spoken|shorts|written|forum [--thread=post.md]] [--only=kind|id,...] [--patterns=module.mjs]\n",
245
259
  );
246
260
  process.exit(2);
247
261
  }
248
262
 
263
+ // `--all` lists every hit of every check with its line. Without it each check stops at its first
264
+ // hit per file, which settles pass or fail; the exit code is the same either way.
265
+ const all = flags.has("--all");
266
+
249
267
  const registerFlag = args.find((a) => a.startsWith("--register"));
250
268
  // A bare `--register`, or one written with a space, used to grade nothing and exit 0.
251
269
 
@@ -392,6 +410,9 @@ if (!flags.has("--quiet")) {
392
410
  }
393
411
  const scope = files.length === 1 ? "" : ` across ${files.length} files`;
394
412
  console.log(`\n${hits} hits, ${review} to review by hand${scope}.`);
413
+ if (hits > 0 && !all) {
414
+ console.log("Each check shows its first hit per file. --all lists every hit with its line.");
415
+ }
395
416
  // Counted, never typed: the same two numbers were hand-written in this line
396
417
  // and in SKILL.md, and both were stale within a week of the last promotion.
397
418
  console.log(
@@ -53,4 +53,5 @@ export const TAIL_WORD =
53
53
  /*
54
54
  * A blank line is a real paragraph start, and `.!?:;` plus a space is a real sentence start.
55
55
  */
56
- export const SENTENCE_OPEN = "(?:^|(?<=[.!?:;][\"'’”)\\]]?\\**[ \\t])|(?<=\\n\\n)|(?<=\\n\\n[ \\t]))";
56
+ export const SENTENCE_OPEN =
57
+ "(?:^|(?<=[.!?:;][\"'’”)\\]]?\\**[ \\t])|(?<=\\n\\n)|(?<=\\n\\n[ \\t]))";
@@ -1,4 +1,14 @@
1
- import { SUBJECT_STOP, PARTICIPLE, NOUN_PHRASE_STOP, INTRANSITIVE_PAST, PREPOSITION, FINITE_AUXILIARY, CLAUSE_SUBJECT, PRESENT_VERB, OBJECT_DETERMINER } from "#lint/data/slop/pattern-parts.js";
1
+ import {
2
+ SUBJECT_STOP,
3
+ PARTICIPLE,
4
+ NOUN_PHRASE_STOP,
5
+ INTRANSITIVE_PAST,
6
+ PREPOSITION,
7
+ FINITE_AUXILIARY,
8
+ CLAUSE_SUBJECT,
9
+ PRESENT_VERB,
10
+ OBJECT_DETERMINER,
11
+ } from "#lint/data/slop/pattern-parts.js";
2
12
 
3
13
  /** Patterns for parallel, paired and countdown sentence shapes. */
4
14
  export const patternsParallelShapes = [
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@heyramzi/lint",
3
- "version": "2.11.1",
3
+ "version": "2.11.2",
4
4
  "description": "Shared oxlint rules, base config and gates for Studio projects",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "https://github.com/heyramzi/vibe-kit.git",
9
- "directory": "packages/lint"
8
+ "url": "https://github.com/heyramzi/upsys.git",
9
+ "directory": "kit/packages/lint"
10
10
  },
11
11
  "bin": {
12
12
  "heyramzi-comment-length": "./bin/heyramzi-comment-length.js",
@@ -43,7 +43,9 @@
43
43
  "push-diff.js",
44
44
  "slop.d.ts",
45
45
  "slop.js",
46
+ "slop-clean.js",
46
47
  "slop-language.js",
48
+ "slop-lines.js",
47
49
  "slop-views.js",
48
50
  "ui-rules.js",
49
51
  "ui-rules-css.js",
@@ -20,7 +20,8 @@ import { join } from "node:path";
20
20
  // =========================
21
21
  const BENCH = join(import.meta.dirname, "../data/reddit-bench.json");
22
22
  const ACCOUNT = "heyramzi";
23
- const UPSYS = process.env.UPSYS_DIR || join(homedir(), "Studio/upsys");
23
+ const UPSYS =
24
+ process.env.UPSYS_DIR || join(process.env.STUDIO_DIR || join(homedir(), "Studio"), "upsys");
24
25
  /** A listing page holds 100; 10 pages is past every comment the account has written. */
25
26
  const PAGES = 10;
26
27
  /** Human replies kept per thread: the most upvoted, long enough to have a shape. */
package/slop-clean.js ADDED
@@ -0,0 +1,153 @@
1
+ /**
2
+ * Layer 1 of the publish gate: what `slopGate` cleans before `auditSlop` reads it.
3
+ */
4
+
5
+ /*
6
+ * Markup goes to prose and invisible characters go. Both rewrite the text, so they live apart from the audit, which never does.
7
+ */
8
+
9
+ import {
10
+ EMOJI_GLUE,
11
+ SEPARATORS,
12
+ SPACE_HOMOGLYPHS,
13
+ hex,
14
+ invisibleKind,
15
+ isInvisible,
16
+ } from "#lint/data/invisibles.js";
17
+ import { hitLines } from "#lint/slop-lines.js";
18
+
19
+ /**
20
+ * HTML in, prose out, so an email body and a markdown draft audit the same way.
21
+ */
22
+
23
+ /*
24
+ * Entities go before tags. A preheader is deliberately padded with zero-width entities, and decoding those first would turn the padding into real characters and make every length count downstream wrong.
25
+ */
26
+ export function stripMarkup(raw, { keepLines = false } = {}) {
27
+ // `keepLines` leaves each removed block's line breaks behind, so a hit's line is the file's line.
28
+ // The audit itself reads the collapsed text, whose matches every gate run has agreed with.
29
+ const gap = keepLines ? (m) => ` ${m.replace(/[^\n]/g, "")}` : " ";
30
+ const text = raw
31
+ .replace(/<(script|style)[\s\S]*?<\/\1>/gi, gap)
32
+ // A markup comment is a note to the next developer, not copy.
33
+
34
+ // It goes with the script block: the CBAM pages rule their sections with `<!-- name -->` in rows of em dashes, which reported 8 dashes nobody reads.
35
+ .replace(/<!--[\s\S]*?-->/g, gap)
36
+ .replace(/&[a-z]+;|&#\d+;/gi, " ")
37
+ .replace(/<[^>]+>/g, gap);
38
+ // Svelte and Vue control blocks are code that survives tag stripping, and their loop variables read as prose: `{#each items as row,
39
+
40
+ // i (row)}` counted `i` as a first-person pronoun and failed 3 pages on the pronoun ledger.
41
+
42
+ // Only `{#`, `{:`, `{/` and `{@` go; a plain `{value}` interpolation is left alone, because the copy it stands for is audited where it is written.
43
+ const prose = withoutTemplateTags(text, gap).replace(/[ \t]+/g, " ");
44
+ return keepLines ? prose : prose.trim();
45
+ }
46
+
47
+ /**
48
+ * Drops every `{#`, `{:`, `{/` and `{@` block up to its balancing brace, skipping braces inside quotes.
49
+ */
50
+
51
+ /*
52
+ * A `[^}]*` regex stopped at the first nested brace, so a JSON-LD object inside `{@html}` read as copy and failed `comma-run` on a CBAM news page, 27 Oct 2026.
53
+ */
54
+ export function withoutTemplateTags(text, gap = " ") {
55
+ let out = "";
56
+ let i = 0;
57
+ while (i < text.length) {
58
+ if (text[i] !== "{" || !"#:/@".includes(text[i + 1] ?? "")) {
59
+ out += text[i++];
60
+ continue;
61
+ }
62
+ let depth = 0;
63
+ let quote = "";
64
+ let j = i;
65
+ for (; j < text.length; j++) {
66
+ const c = text[j];
67
+ if (quote) {
68
+ if (c === "\\") j++;
69
+ else if (c === quote) quote = "";
70
+ } else if (c === '"' || c === "'" || c === "`") quote = c;
71
+ else if (c === "{") depth++;
72
+ else if (c === "}" && --depth === 0) break;
73
+ }
74
+ out += typeof gap === "function" ? gap(text.slice(i, j + 1)) : gap;
75
+ i = j + 1;
76
+ }
77
+ return out;
78
+ }
79
+
80
+ const isPictographic = (ch) => /\p{Extended_Pictographic}/u.test(ch);
81
+
82
+ /**
83
+ * Remove every invisible character, normalise the fake spaces, and report what went.
84
+ */
85
+
86
+ /*
87
+ * The one exception is emoji glue.
88
+ */
89
+
90
+ /*
91
+ * A zero-width joiner or a variation selector sitting after an emoji is part of a visible sequence: strip it and a family becomes three people and a red heart loses
92
+ */
93
+
94
+ /*
95
+ * its colour. Anywhere else the same character is a carrier and goes.
96
+ */
97
+
98
+ /*
99
+ * `normalizeSpaces` is on by default. Turn it off only when editing a file whose spacing is deliberate; for anything headed into a web form, leave it on,
100
+ */
101
+
102
+ /*
103
+ * because a no-break space between two words is invisible to the writer and breaks wrapping for the reader.
104
+ */
105
+ export function stripInvisibles(text, { normalizeSpaces = true } = {}) {
106
+ const chars = [...text];
107
+ const removed = new Map();
108
+ const note = (cp) => {
109
+ const key = `${invisibleKind(cp)} ${hex(cp)}`;
110
+ removed.set(key, (removed.get(key) ?? 0) + 1);
111
+ };
112
+
113
+ let out = "";
114
+ for (let i = 0; i < chars.length; i += 1) {
115
+ const ch = chars[i];
116
+ const cp = ch.codePointAt(0);
117
+
118
+ if (EMOJI_GLUE.has(cp) && i > 0 && isPictographic(chars[i - 1])) {
119
+ out += ch;
120
+ continue;
121
+ }
122
+ if (isInvisible(cp)) {
123
+ note(cp);
124
+ continue;
125
+ }
126
+ if (SEPARATORS.has(cp)) {
127
+ note(cp);
128
+ out += SEPARATORS.get(cp);
129
+ continue;
130
+ }
131
+ if (normalizeSpaces && SPACE_HOMOGLYPHS.has(cp)) {
132
+ note(cp);
133
+ out += SPACE_HOMOGLYPHS.get(cp);
134
+ continue;
135
+ }
136
+ out += ch;
137
+ }
138
+
139
+ return {
140
+ text: out,
141
+ removed: [...removed].map(([what, count]) => ({ what, count })),
142
+ };
143
+ }
144
+
145
+ /** True when the text carries nothing invisible. The cheap gate. */
146
+ export function isClean(text) {
147
+ return stripInvisibles(text).removed.length === 0;
148
+ }
149
+
150
+ /** A markup file's prose with its own line breaks kept, to find a hit's line in. */
151
+ export function markupLines(raw, { normalizeSpaces = true } = {}) {
152
+ return hitLines(stripInvisibles(stripMarkup(raw, { keepLines: true }), { normalizeSpaces }).text);
153
+ }
package/slop-lines.js ADDED
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Where a slop hit sits, as a 1-based line, for `heyramzi-slop --all`.
3
+ */
4
+
5
+ /*
6
+ * Some views keep every index (masked URLs, blanked comments), so a hit there maps straight to its line.
7
+ * Others drop code spans or join string literals, so the hit's own text is searched for, after the last
8
+ * hit of the same check: the third passive sentence of a post is found after the second, never on top of it.
9
+ * A hit that can't be found again gets no line rather than a wrong one.
10
+ */
11
+ export function hitLines(text) {
12
+ const starts = [0];
13
+ for (let i = 0; i < text.length; i += 1) if (text[i] === "\n") starts.push(i + 1);
14
+ const lineOf = (index) => {
15
+ let lo = 0;
16
+ let hi = starts.length - 1;
17
+ while (lo < hi) {
18
+ const mid = (lo + hi + 1) >> 1;
19
+ if (starts[mid] <= index) lo = mid;
20
+ else hi = mid - 1;
21
+ }
22
+ return lo + 1;
23
+ };
24
+ const after = new Map();
25
+ /** The line of `hit` found after the previous one under `key`, or undefined. */
26
+ const find = (key, hit) => {
27
+ const needle = hit
28
+ .slice(firstWord(hit))
29
+ .split("\n")
30
+ .map((s) => s.trim())
31
+ .find(Boolean)
32
+ ?.slice(0, 40);
33
+ if (!needle) return undefined;
34
+ const at = text.indexOf(needle, after.get(key) ?? 0);
35
+ if (at < 0) return undefined;
36
+ after.set(key, at + 1);
37
+ return lineOf(at);
38
+ };
39
+ return { lineOf, find };
40
+ }
41
+
42
+ /**
43
+ * Where a hit's first letter or digit sits in it, else 0. An anchored pattern's hit opens on the
44
+ * end of the sentence before (". Every"), and that full stop can be lines above the word it flags.
45
+ */
46
+ export const firstWord = (hit) => Math.max(0, hit.search(/[\p{L}\p{N}]/u));
47
+
48
+ /** The same regex with the `g` flag, so `matchAll` walks every hit. */
49
+ export const everyHit = (re) => (re.global ? re : new RegExp(re.source, `${re.flags}g`));
package/slop.d.ts CHANGED
@@ -5,6 +5,8 @@ export type SlopFinding = {
5
5
  id: string;
6
6
  /** The offending text, trimmed to something readable in a terminal. */
7
7
  detail: string;
8
+ /** The 1-based line of the hit, set only under `all` and only when the hit could be placed. */
9
+ line?: number;
8
10
  };
9
11
 
10
12
  export type SlopAudit = {
@@ -29,7 +31,16 @@ export type SlopLint = SlopAudit & {
29
31
  };
30
32
 
31
33
  /** HTML in, plain text out, so an email body audits the same way a post does. */
32
- export declare function stripMarkup(raw: string): string;
34
+ export declare function stripMarkup(raw: string, options?: { keepLines?: boolean }): string;
35
+
36
+ /** A markup file's prose with its line breaks kept, to find a hit's line in. */
37
+ export declare function markupLines(
38
+ raw: string,
39
+ options?: { normalizeSpaces?: boolean },
40
+ ): {
41
+ lineOf(index: number): number;
42
+ find(key: string, hit: string): number | undefined;
43
+ };
33
44
 
34
45
  /** Remove the invisible characters and normalise the fake spaces. */
35
46
  export declare function stripInvisibles(
@@ -49,7 +60,8 @@ export declare function declaredLanguage(source?: string, path?: string): string
49
60
  /** The enumerable half of the humanizer, over one string. Never rewrites. */
50
61
  export declare function auditSlop(
51
62
  text: string,
52
- options?: { code?: boolean; language?: string },
63
+ /** `all` reports every hit of every check with its line, not the first per check. */
64
+ options?: { code?: boolean; language?: string; all?: boolean },
53
65
  ): SlopAudit;
54
66
 
55
67
  /** Clean, then audit. The one call a publishing path makes. */
@@ -62,5 +74,7 @@ export declare function slopGate(
62
74
  register?: import("./register.js").RegisterName;
63
75
  /** A 2-letter code the caller already knows. The word, phrase and sentence lists run only on `en` and `fr`. */
64
76
  language?: string;
77
+ /** Every hit of every check with its line, not the first per check. `ok` is the same either way. */
78
+ all?: boolean;
65
79
  },
66
80
  ): SlopLint;
package/slop.js CHANGED
@@ -38,18 +38,12 @@
38
38
  * Both lists are imported, never restated: `data/invisibles.js` and `data/slop/` are the one home for each.
39
39
  */
40
40
 
41
- import {
42
- EMOJI_GLUE,
43
- SEPARATORS,
44
- SPACE_HOMOGLYPHS,
45
- hex,
46
- invisibleKind,
47
- isInvisible,
48
- } from "#lint/data/invisibles.js";
49
41
  import { phrases, words } from "#lint/data/slop-words.js";
50
42
  import { artifacts } from "#lint/data/slop/artifacts.js";
51
43
  import { patterns } from "#lint/data/slop/patterns.js";
52
44
  import { auditRegister, keepsExact } from "#lint/register.js";
45
+ import { isClean, markupLines, stripInvisibles, stripMarkup } from "#lint/slop-clean.js";
46
+ import { everyHit, firstWord, hitLines } from "#lint/slop-lines.js";
53
47
  import {
54
48
  LISTED_LANGUAGES,
55
49
  PRONOUNS,
@@ -69,7 +63,7 @@ import {
69
63
  import { auditShorts } from "@heyramzi/social/shorts";
70
64
 
71
65
  // Part of the `@heyramzi/lint/slop` API that `slop.d.ts` declares.
72
- export { declaredLanguage, detectLanguage };
66
+ export { declaredLanguage, detectLanguage, isClean, markupLines, stripInvisibles, stripMarkup };
73
67
 
74
68
  const escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
75
69
 
@@ -84,137 +78,11 @@ const escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
84
78
  /*
85
79
  * and unenforced. The lookarounds do the same job over `\p{L}`, in both languages.
86
80
  */
87
- const bounded = (word) =>
88
- new RegExp(`(?<![\\p{L}\\p{N}_])${escapeRe(word)}(?![\\p{L}\\p{N}_])`, "iu");
89
-
90
- /**
91
- * HTML in, prose out, so an email body and a markdown draft audit the same way.
92
- */
93
-
94
- /*
95
- * Entities go before tags. A preheader is deliberately padded with zero-width entities, and decoding those first would turn the padding into real characters and make every length count downstream wrong.
96
- */
97
- export function stripMarkup(raw) {
98
- const text = raw
99
- .replace(/<(script|style)[\s\S]*?<\/\1>/gi, " ")
100
- // A markup comment is a note to the next developer, not copy.
101
-
102
- // It goes with the script block: the CBAM pages rule their sections with `<!-- name -->` in rows of em dashes, which reported 8 dashes nobody reads.
103
- .replace(/<!--[\s\S]*?-->/g, " ")
104
- .replace(/&[a-z]+;|&#\d+;/gi, " ")
105
- .replace(/<[^>]+>/g, " ");
106
- // Svelte and Vue control blocks are code that survives tag stripping, and their loop variables read as prose: `{#each items as row,
107
-
108
- // i (row)}` counted `i` as a first-person pronoun and failed 3 pages on the pronoun ledger.
109
-
110
- // Only `{#`, `{:`, `{/` and `{@` go; a plain `{value}` interpolation is left alone, because the copy it stands for is audited where it is written.
111
- return withoutTemplateTags(text)
112
- .replace(/[ \t]+/g, " ")
113
- .trim();
114
- }
115
-
116
- /**
117
- * Drops every `{#`, `{:`, `{/` and `{@` block up to its balancing brace, skipping braces inside quotes.
118
- */
119
-
120
- /*
121
- * A `[^}]*` regex stopped at the first nested brace, so a JSON-LD object inside `{@html}` read as copy and failed `comma-run` on a CBAM news page, 27 Oct 2026.
122
- */
123
- export function withoutTemplateTags(text) {
124
- let out = "";
125
- let i = 0;
126
- while (i < text.length) {
127
- if (text[i] !== "{" || !"#:/@".includes(text[i + 1] ?? "")) {
128
- out += text[i++];
129
- continue;
130
- }
131
- let depth = 0;
132
- let quote = "";
133
- let j = i;
134
- for (; j < text.length; j++) {
135
- const c = text[j];
136
- if (quote) {
137
- if (c === "\\") j++;
138
- else if (c === quote) quote = "";
139
- } else if (c === '"' || c === "'" || c === "`") quote = c;
140
- else if (c === "{") depth++;
141
- else if (c === "}" && --depth === 0) break;
142
- }
143
- out += " ";
144
- i = j + 1;
145
- }
146
- return out;
147
- }
81
+ const bounded = (word, flags = "iu") =>
82
+ new RegExp(`(?<![\\p{L}\\p{N}_])${escapeRe(word)}(?![\\p{L}\\p{N}_])`, flags);
148
83
 
149
- const isPictographic = (ch) => /\p{Extended_Pictographic}/u.test(ch);
150
-
151
- /**
152
- * Remove every invisible character, normalise the fake spaces, and report what went.
153
- */
154
-
155
- /*
156
- * The one exception is emoji glue.
157
- */
158
-
159
- /*
160
- * A zero-width joiner or a variation selector sitting after an emoji is part of a visible sequence: strip it and a family becomes three people and a red heart loses
161
- */
162
-
163
- /*
164
- * its colour. Anywhere else the same character is a carrier and goes.
165
- */
166
-
167
- /*
168
- * `normalizeSpaces` is on by default. Turn it off only when editing a file whose spacing is deliberate; for anything headed into a web form, leave it on,
169
- */
170
-
171
- /*
172
- * because a no-break space between two words is invisible to the writer and breaks wrapping for the reader.
173
- */
174
- export function stripInvisibles(text, { normalizeSpaces = true } = {}) {
175
- const chars = [...text];
176
- const removed = new Map();
177
- const note = (cp) => {
178
- const key = `${invisibleKind(cp)} ${hex(cp)}`;
179
- removed.set(key, (removed.get(key) ?? 0) + 1);
180
- };
181
-
182
- let out = "";
183
- for (let i = 0; i < chars.length; i += 1) {
184
- const ch = chars[i];
185
- const cp = ch.codePointAt(0);
186
-
187
- if (EMOJI_GLUE.has(cp) && i > 0 && isPictographic(chars[i - 1])) {
188
- out += ch;
189
- continue;
190
- }
191
- if (isInvisible(cp)) {
192
- note(cp);
193
- continue;
194
- }
195
- if (SEPARATORS.has(cp)) {
196
- note(cp);
197
- out += SEPARATORS.get(cp);
198
- continue;
199
- }
200
- if (normalizeSpaces && SPACE_HOMOGLYPHS.has(cp)) {
201
- note(cp);
202
- out += SPACE_HOMOGLYPHS.get(cp);
203
- continue;
204
- }
205
- out += ch;
206
- }
207
-
208
- return {
209
- text: out,
210
- removed: [...removed].map(([what, count]) => ({ what, count })),
211
- };
212
- }
213
-
214
- /** True when the text carries nothing invisible. The cheap gate. */
215
- export function isClean(text) {
216
- return stripInvisibles(text).removed.length === 0;
217
- }
84
+ /** Each `all` finding's matched text, kept off the finding so `--json` doesn't print it. `slopGate` finds a markup hit's line by it. */
85
+ const lineNeedles = new WeakMap();
218
86
 
219
87
  /**
220
88
  * A regex over these fires on ordinary English, so they are reported as `review` rather than as a hit and never fail the gate.
@@ -371,12 +239,26 @@ function auditStructure(text, language) {
371
239
  /*
372
240
  * Those are claims about the world, and a string is all this function gets.
373
241
  */
374
- export function auditSlop(draft, { code = false, language: declared } = {}) {
242
+ export function auditSlop(draft, { code = false, language: declared, all = false } = {}) {
375
243
  const source = code ? withoutComments(draft) : draft;
376
244
  // Every layer but `artifacts` reads the draft with its link addresses masked: `withoutUrls` carries why.
377
245
  const text = withoutUrls(source);
378
246
  const findings = [];
379
- const add = (kind, id, detail) => findings.push({ kind, id, detail });
247
+ const add = (kind, id, detail, line, needle) => {
248
+ const finding = all && line ? { kind, id, detail, line } : { kind, id, detail };
249
+ if (all && needle) lineNeedles.set(finding, needle);
250
+ findings.push(finding);
251
+ };
252
+ // `all` lists every hit with its line. The default stops at the first hit of each check, which is
253
+ // what a pass or fail needs. On 11 Nov 2026 4 agents fixing ~200 passive sentences across 20 posts
254
+ // pushed once per hit to learn where the next one was.
255
+ // `withoutUrls` and `withoutComments` keep each line, and the URL mask keeps each index too.
256
+ const lines = all ? hitLines(text) : null;
257
+ const hits = (re, s) => {
258
+ if (all) return [...s.matchAll(everyHit(re))];
259
+ const m = s.match(re);
260
+ return m ? [m] : [];
261
+ };
380
262
  const language = declared ?? declaredLanguage(draft) ?? detectLanguage(text);
381
263
  const listed = LISTED_LANGUAGES.has(language);
382
264
 
@@ -387,14 +269,15 @@ export function auditSlop(draft, { code = false, language: declared } = {}) {
387
269
  // The `patterns` below still read the whole text, where the surrounding sentence is what they are judging.
388
270
  const prose = withoutCode(text);
389
271
  for (const word of listed ? words : []) {
390
- const m = prose.match(bounded(word));
391
- if (m) add("word", word, m[0]);
272
+ for (const m of hits(bounded(word), prose))
273
+ add("word", word, m[0], all && lines.find(word, m[0]), m[0]);
392
274
  }
393
275
  for (const phrase of listed ? phrases : []) {
394
276
  // Bounded like a word, not `includes`. A substring test read "En sommeil" as the banned "en somme" and failed a dormant-status label on the UpSys site, 6 Sep 2026.
395
277
 
396
278
  // Every phrase here is whole words.
397
- if (bounded(phrase).test(prose)) add("phrase", phrase, phrase);
279
+ for (const m of hits(bounded(phrase), prose))
280
+ add("phrase", phrase, phrase, all && lines.find(phrase, m[0]), m[0]);
398
281
  }
399
282
  // A pattern names the view of the draft it judges, and defaults to the whole thing. Only `faqless` differs, for the reason `FAQ_TITLE` carries.
400
283
 
@@ -410,25 +293,46 @@ export function auditSlop(draft, { code = false, language: declared } = {}) {
410
293
  for (const pattern of patterns) {
411
294
  if (!listed && !pattern.anyLanguage) continue;
412
295
  const view = views[pattern.view ?? "anchored"];
413
- const m = view.match(pattern.test);
414
- if (!m) continue;
415
- // Masking keeps every index, so a hit on the masked text is shown as the writer typed it.
416
- const hit = view === text ? source.slice(m.index, m.index + m[0].length) : m[0];
417
- add("pattern", pattern.id, hit.slice(0, 90));
296
+ for (const m of hits(pattern.test, view)) {
297
+ // Masking keeps every index, so a hit on the masked text is shown as the writer typed it.
298
+ const hit = view === text ? source.slice(m.index, m.index + m[0].length) : m[0];
299
+ add("pattern", pattern.id, hit.slice(0, 90), all && lineOfView(view, m, pattern.id), m[0]);
300
+ }
301
+ }
302
+ /** The anchored views keep every index of `text`, the FAQ view every line; the prose views keep neither. */
303
+ function lineOfView(view, m, id) {
304
+ if (view.length === text.length) return lines.lineOf(m.index + firstWord(m[0]));
305
+ if (view === views.faqless) return view.slice(0, m.index + firstWord(m[0])).split("\n").length;
306
+ return lines.find(`pattern:${id}`, m[0]);
418
307
  }
419
308
  for (const artifact of artifacts) {
420
- const m = source.match(artifact.test);
421
- if (m) add("artifact", artifact.id, m[0].slice(0, 90));
309
+ for (const m of hits(artifact.test, source))
310
+ add(
311
+ "artifact",
312
+ artifact.id,
313
+ m[0].slice(0, 90),
314
+ all && lines.lineOf(m.index + firstWord(m[0])),
315
+ m[0],
316
+ );
422
317
  }
423
- for (const finding of auditStructure(text, language)) findings.push(finding);
318
+ for (const f of auditStructure(text, language))
319
+ add(f.kind, f.id, f.detail, all && lines.find(f.id, f.detail), f.detail);
320
+ // A dash or emoji is shown with 30 characters either side, but found again by what leads up to it on its line.
321
+ const upTo = (m) =>
322
+ text.slice(
323
+ Math.max(text.lastIndexOf("\n", m.index - 1) + 1, m.index - 20),
324
+ m.index + m[0].length,
325
+ );
424
326
  for (const m of text.matchAll(/[—–]/g)) {
425
- add("dash", "em-or-en-dash", source.slice(Math.max(0, m.index - 30), m.index + 30));
327
+ const around = source.slice(Math.max(0, m.index - 30), m.index + 30);
328
+ add("dash", "em-or-en-dash", around, all && lines.lineOf(m.index), upTo(m));
426
329
  }
427
330
  for (const m of text.matchAll(EMOJI)) {
428
- add("emoji", "emoji", source.slice(Math.max(0, m.index - 30), m.index + 30));
331
+ const around = source.slice(Math.max(0, m.index - 30), m.index + 30);
332
+ add("emoji", "emoji", around, all && lines.lineOf(m.index), upTo(m));
429
333
  }
430
334
  for (const m of withoutCode(text).matchAll(HASHTAG)) {
431
- add("hashtag", "hashtag", m[0]);
335
+ add("hashtag", "hashtag", m[0], all && lines.find("hashtag", m[0]), m[0]);
432
336
  }
433
337
 
434
338
  const ledgerText = code ? copyStrings(text) : text;
@@ -493,11 +397,20 @@ export function auditSlop(draft, { code = false, language: declared } = {}) {
493
397
  */
494
398
  export function slopGate(
495
399
  raw,
496
- { markup = false, code = false, normalizeSpaces = true, register, language } = {},
400
+ { markup = false, code = false, normalizeSpaces = true, register, language, all = false } = {},
497
401
  ) {
498
402
  const source = markup ? stripMarkup(raw) : raw;
499
403
  const cleaned = stripInvisibles(source, { normalizeSpaces });
500
- const audit = auditSlop(cleaned.text, { code, language });
404
+ const audit = auditSlop(cleaned.text, { code, language, all });
405
+ // Stripped markup has lost the file's lines, so each hit is found again in a copy that kept them.
406
+ if (all && markup) {
407
+ const lines = markupLines(raw, { normalizeSpaces });
408
+ for (const f of audit.findings) {
409
+ delete f.line;
410
+ const line = lines.find(`${f.kind}:${f.id}`, lineNeedles.get(f) ?? f.detail);
411
+ if (line) f.line = line;
412
+ }
413
+ }
501
414
  // A ban list cannot see the fault that produced the 9 Sep 2026 Shorts batch: every script passed the words and still read as somebody else,
502
415
 
503
416
  // because the register was written and the delivery was spoken. `register.js` carries why.