@heyramzi/lint 2.9.0 → 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 +6 -1
- package/bin/heyramzi-slop.js +82 -8
- package/data/slop/pattern-parts.js +2 -1
- package/data/slop/patterns/parallel-shapes.js +11 -1
- package/data/slop/patterns/subject-voice.js +19 -0
- package/data/slop/patterns/vague-and-flourish.js +19 -0
- package/data/slop/phrases-en-wikipedia.js +4 -0
- package/package.json +5 -3
- package/register.js +2 -1
- package/scripts/reddit-bench-harvest.mjs +2 -1
- package/slop-clean.js +153 -0
- package/slop-lines.js +49 -0
- package/slop.d.ts +16 -2
- package/slop.js +70 -157
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.
|
|
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`.
|
package/bin/heyramzi-slop.js
CHANGED
|
@@ -43,6 +43,13 @@
|
|
|
43
43
|
* `--jev` adds model-scored shapes. They are a report, never a failure: one sentence scored 0.71, then 0.78.
|
|
44
44
|
*/
|
|
45
45
|
|
|
46
|
+
/*
|
|
47
|
+
* A repo adds its own bans without touching this package: `--patterns=<module>`, or `"slop": { "patterns": ["<module>"] }`
|
|
48
|
+
* in the nearest package.json above the linted file. Each module default-exports `{ id, test, rule }` entries, and a
|
|
49
|
+
* hit fails as kind `repo-pattern`. Locameuble needed the accounting-monopoly phrasings, which are law for one product and
|
|
50
|
+
* noise for every other repo, so they live there (TSK-2087, 10 Nov 2026).
|
|
51
|
+
*/
|
|
52
|
+
|
|
46
53
|
/*
|
|
47
54
|
* `--shape-block=0.85` makes a shape at that score or above fail the run. Scores are cached per sentence.
|
|
48
55
|
*/
|
|
@@ -56,14 +63,16 @@
|
|
|
56
63
|
*/
|
|
57
64
|
|
|
58
65
|
import { readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
59
|
-
import { join } from "node:path";
|
|
66
|
+
import { dirname, join, resolve } from "node:path";
|
|
67
|
+
import { pathToFileURL } from "node:url";
|
|
60
68
|
import { shapes } from "#lint/data/slop-words.js";
|
|
61
69
|
import { patterns } from "#lint/data/slop/patterns.js";
|
|
62
70
|
import { titleTells } from "#lint/data/slop/title-tells.js";
|
|
63
71
|
import { FAIL, REVIEW, isUnavailable, proseOf } from "#lint/jev-core.js";
|
|
64
72
|
import { auditShapes, jevKey as readJevKey } from "#lint/jev.js";
|
|
65
73
|
import { declaredLanguage } from "#lint/slop-language.js";
|
|
66
|
-
import {
|
|
74
|
+
import { everyHit, hitLines } from "#lint/slop-lines.js";
|
|
75
|
+
import { markupLines, slopGate } from "#lint/slop.js";
|
|
67
76
|
|
|
68
77
|
// =========================
|
|
69
78
|
// CONSTANTS
|
|
@@ -91,7 +100,7 @@ function expand(path) {
|
|
|
91
100
|
.toSorted();
|
|
92
101
|
}
|
|
93
102
|
|
|
94
|
-
function gate(file, register) {
|
|
103
|
+
function gate(file, register, repoPatterns) {
|
|
95
104
|
const raw = file === "-" ? readFileSync(0, "utf8") : readFileSync(file, "utf8");
|
|
96
105
|
// HTML gets its tags stripped before anything is matched, so an email body audits the same way a post does.
|
|
97
106
|
|
|
@@ -101,10 +110,54 @@ function gate(file, register) {
|
|
|
101
110
|
// reads as a start. `withStringStarts` in slop.js carries what that cost.
|
|
102
111
|
const code = /\.(m?[jt]sx?|json)$/i.test(file);
|
|
103
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.
|
|
104
114
|
const text = /\.mdx?$/i.test(file) ? proseOfMarkdown(raw) : raw;
|
|
105
115
|
// Read from the raw file, because `proseOfMarkdown` blanks the frontmatter that carries `lang`.
|
|
106
116
|
const language = declaredLanguage(raw, file);
|
|
107
|
-
|
|
117
|
+
const result = slopGate(text, { markup, code, register, language, all });
|
|
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));
|
|
120
|
+
for (const p of repoPatterns) {
|
|
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
|
+
}
|
|
127
|
+
}
|
|
128
|
+
result.ok = result.findings.length === 0;
|
|
129
|
+
return { raw, result };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** The module paths for one file: the flag wins, else the nearest package.json above it with a `slop.patterns` key. */
|
|
133
|
+
function repoPatternPaths(file, flag) {
|
|
134
|
+
if (flag) return [resolve(flag)];
|
|
135
|
+
for (let dir = file === "-" ? process.cwd() : dirname(resolve(file)); ; dir = dirname(dir)) {
|
|
136
|
+
try {
|
|
137
|
+
const declared = JSON.parse(readFileSync(join(dir, "package.json"), "utf8")).slop?.patterns;
|
|
138
|
+
if (declared) return [declared].flat().map((p) => resolve(dir, p));
|
|
139
|
+
} catch {
|
|
140
|
+
// No package.json here, or not JSON: keep climbing.
|
|
141
|
+
}
|
|
142
|
+
if (dirname(dir) === dir) return [];
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const loadedModules = new Map();
|
|
147
|
+
async function loadRepoPatterns(file, flag) {
|
|
148
|
+
const loaded = [];
|
|
149
|
+
for (const p of repoPatternPaths(file, flag)) {
|
|
150
|
+
if (!loadedModules.has(p)) {
|
|
151
|
+
const list = (await import(pathToFileURL(p).href)).default;
|
|
152
|
+
if (!Array.isArray(list) || !list.every((e) => e?.id && e.test instanceof RegExp)) {
|
|
153
|
+
process.stderr.write(`${p} must default-export an array of { id, test: RegExp }\n`);
|
|
154
|
+
process.exit(2);
|
|
155
|
+
}
|
|
156
|
+
loadedModules.set(p, list);
|
|
157
|
+
}
|
|
158
|
+
loaded.push(...loadedModules.get(p));
|
|
159
|
+
}
|
|
160
|
+
return loaded;
|
|
108
161
|
}
|
|
109
162
|
|
|
110
163
|
/**
|
|
@@ -140,7 +193,9 @@ function gateBoard(raw, register) {
|
|
|
140
193
|
if ((BOARD_TITLE.has(key) && !BOARD_CAPTION.has(kind)) || heading) titles.push(node);
|
|
141
194
|
else if (BOARD_PROSE.has(key) || BOARD_TITLE.has(key)) prose.push(node);
|
|
142
195
|
})(JSON.parse(raw));
|
|
143
|
-
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;
|
|
144
199
|
for (const title of titles)
|
|
145
200
|
for (const t of titleTells.filter((t) => t.test.test(title)))
|
|
146
201
|
result.findings.push({
|
|
@@ -181,7 +236,12 @@ function report(file, result, fixed) {
|
|
|
181
236
|
for (const r of result.removed) {
|
|
182
237
|
console.log(` invisible ${r.what} x${r.count}${fixed ? " (removed)" : ""}`);
|
|
183
238
|
}
|
|
184
|
-
for (const f of result.findings)
|
|
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
|
+
}
|
|
185
245
|
for (const r of result.review) console.log(` ${r.kind.padEnd(13)} ${r.id} ${r.detail}`);
|
|
186
246
|
if (result.removed.length === 0 && result.ok) console.log("clean");
|
|
187
247
|
}
|
|
@@ -195,11 +255,15 @@ const paths = args.filter((a) => !a.startsWith("--"));
|
|
|
195
255
|
|
|
196
256
|
if (paths.length === 0) {
|
|
197
257
|
process.stderr.write(
|
|
198
|
-
"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,...]\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",
|
|
199
259
|
);
|
|
200
260
|
process.exit(2);
|
|
201
261
|
}
|
|
202
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
|
+
|
|
203
267
|
const registerFlag = args.find((a) => a.startsWith("--register"));
|
|
204
268
|
// A bare `--register`, or one written with a space, used to grade nothing and exit 0.
|
|
205
269
|
|
|
@@ -247,6 +311,13 @@ if (blockFlag) {
|
|
|
247
311
|
}
|
|
248
312
|
}
|
|
249
313
|
|
|
314
|
+
const patternsFlag = args.find((a) => a.startsWith("--patterns"));
|
|
315
|
+
if (patternsFlag && !patternsFlag.includes("=")) {
|
|
316
|
+
process.stderr.write("--patterns takes a module: --patterns=scripts/slop-patterns.mjs\n");
|
|
317
|
+
process.exit(2);
|
|
318
|
+
}
|
|
319
|
+
const patternsPath = patternsFlag?.split("=").slice(1).join("=");
|
|
320
|
+
|
|
250
321
|
const files = paths.flatMap(expand);
|
|
251
322
|
const results = [];
|
|
252
323
|
/** Looked up once, on the first file that needs Jev. */
|
|
@@ -255,7 +326,7 @@ let jevKey;
|
|
|
255
326
|
let jevDown = "";
|
|
256
327
|
|
|
257
328
|
for (const file of files) {
|
|
258
|
-
const { raw, result } = gate(file, register);
|
|
329
|
+
const { raw, result } = gate(file, register, await loadRepoPatterns(file, patternsPath));
|
|
259
330
|
if (only) {
|
|
260
331
|
result.findings = result.findings.filter((f) => only.has(f.kind) || only.has(f.id));
|
|
261
332
|
result.review = [];
|
|
@@ -339,6 +410,9 @@ if (!flags.has("--quiet")) {
|
|
|
339
410
|
}
|
|
340
411
|
const scope = files.length === 1 ? "" : ` across ${files.length} files`;
|
|
341
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
|
+
}
|
|
342
416
|
// Counted, never typed: the same two numbers were hand-written in this line
|
|
343
417
|
// and in SKILL.md, and both were stale within a week of the last promotion.
|
|
344
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 =
|
|
56
|
+
export const SENTENCE_OPEN =
|
|
57
|
+
"(?:^|(?<=[.!?:;][\"'’”)\\]]?\\**[ \\t])|(?<=\\n\\n)|(?<=\\n\\n[ \\t]))";
|
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
import {
|
|
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 = [
|
|
@@ -64,4 +64,23 @@ export const patternsSubjectVoice = [
|
|
|
64
64
|
example:
|
|
65
65
|
'"The best automation you own is the one that complains" / "The best client is the one who says no"',
|
|
66
66
|
},
|
|
67
|
+
{
|
|
68
|
+
id: "the-one-doing",
|
|
69
|
+
name: "You're the one doing updates",
|
|
70
|
+
// 0 of 267 human replies on data/reddit-bench.json, 9 Nov 2026. The lookahead keeps "the one thing" and "the one meeting" out.
|
|
71
|
+
test: /\b(?:is|are|was|were|['’](?:re|s|m))\s+(?:always\s+|usually\s+|still\s+|then\s+)?the\s+ones?\s+(?:who(?:['’]s|\s+(?:is|are|was|were))\s+)?(?:\w+ly\s+)?(?!(?:thing|things|nothing|something|everything|string|king|ring|spring|building|setting|meeting|listing|wing|ending|morning|evening)\b)[a-z]+ing\b/i,
|
|
72
|
+
rule: 'A person or thing cast as "the one" plus an -ing verb: you\'re the one doing updates, it\'s the one having the problem. It sounds like a sentence and isn\'t one anybody says. Give the subject the verb: "you do the updates", "it has the problem". Ramzi, 9 Nov 2026, on a lint-clean Reddit draft: "the grammar is weird".',
|
|
73
|
+
example:
|
|
74
|
+
'"self-hosting means you\'re the one doing updates" / "it\'s the one having the problem" / "you\'re the one who\'s paying for it"',
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
id: "passive-voice",
|
|
78
|
+
name: "Every scenario is named by its trigger",
|
|
79
|
+
// His rule, not a bot tell: 55 of 267 human replies on the Reddit bench use one, against 7 of our 72 bad ones (9 Nov 2026).
|
|
80
|
+
// A state word passes unless "by" names who did it: "Hive is not connected", "what's broken", "when we're done" (15 of upsys's 78, 10 Nov 2026).
|
|
81
|
+
test: /\b(?:is|are|was|were|be|been|being|['’]s|['’]re)\s+(?:not\s+|never\s+|already\s+|also\s+|still\s+|just\s+|then\s+|\w+ly\s+)?(?!(?:interested|based|related|supposed|used\s+to|tired|bored|excited|worried|scared|married|located|involved|impressed|devastated|surprised|confused|annoyed|pleased|stuck|qualified|indeed|need|feed|seed|speed|breed|greed|weed)\b|(?:closed|locked|unlocked|connected|disconnected|archived|enabled|disabled|un[a-z]{2,}ed)\b(?!\s+by\b)|broken\b(?!\s+(?:by|into|down|up|out|off)\b)|caught\s+up\b|done\b(?=\s*(?:[.!?,;:)]|$)))(?:[a-z]{3,}ed|built|made|done|given|taken|known|seen|written|shown|sent|kept|put|found|held|told|paid|brought|bought|caught|taught|chosen|driven|forgotten|hidden|broken|spoken|stolen|frozen|drawn|grown|thrown|worn|torn)\b/i,
|
|
82
|
+
rule: 'A passive: "is named", "was built", "are treated". Nobody does anything in it, so it reads as a report, not a person talking. Name who does it: "we name every scenario by its trigger". Ramzi, 9 Nov 2026, on a Reddit draft: "anything passive tense basically is bad, bad, bad".',
|
|
83
|
+
example:
|
|
84
|
+
'"Every scenario we build is named by its trigger" / "anything that comes through chat is treated as an emergency" / "the report was sent on Monday"',
|
|
85
|
+
},
|
|
67
86
|
];
|
|
@@ -11,6 +11,25 @@ export const patternsVagueAndFlourish = [
|
|
|
11
11
|
example:
|
|
12
12
|
'"A quote to sign before anything exists." / "You commit before anything is built." / "They bill you when nothing has happened."',
|
|
13
13
|
},
|
|
14
|
+
{
|
|
15
|
+
id: "your-way",
|
|
16
|
+
name: "Your way",
|
|
17
|
+
// Ramzi caught "Your ClickUp data, laid out your way" as a newsletter subject the gate passed (TSK-2000, 9 Nov 2026).
|
|
18
|
+
|
|
19
|
+
// Bounded to a shaping verb in front, so "on your way" and "find your way" pass.
|
|
20
|
+
test: /\b(?:laid out|set up|built|made|organi[sz]ed|arranged|tailored|customi[sz]ed|shaped|designed|done|works?|fits?|working)\s+(?:(?:exactly|just)\s+)?(?:your way|the way you (?:work|think|want|like)|how you (?:work|think|want))\b/i,
|
|
21
|
+
rule: "A tailored-to-you promise that fits any product and names nothing. The reader can't picture what changed. Say what the thing does: which view, which columns, what it saves them.",
|
|
22
|
+
example: '"Your ClickUp data, laid out your way" / "a dashboard that works the way you work"',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
id: "grading-their-choice",
|
|
26
|
+
name: "That makes sense",
|
|
27
|
+
// Ramzi, 9 Nov 2026 (TSK-2130). Only a verdict that ends the sentence, so "it only makes sense if" passes.
|
|
28
|
+
test: /\bmakes?\s+(?:(?:total|perfect|complete|a\s+lot\s+of|so\s+much|good)\s+)?sense(?=\s*[.!]|\s*$)|\b(?:smart|good|great|wise|right)\s+(?:move|call|idea|plan|choice)(?=\s*[.!,])|\b(?:totally|completely|very)\s+(?:understandable|fair)\b|\bc'est\s+(?:tout\s+à\s+fait\s+)?(?:logique|compréhensible)\b/i,
|
|
29
|
+
rule: "A line that grades the other person's decision. They didn't ask for your approval, so it reads as filler validation from a bot. Cut the sentence; the reply works without it. Ramzi, 9 Nov 2026, on a client reply: \"sounds like this stupid validation, the evaluator should have cut it.\"",
|
|
30
|
+
example:
|
|
31
|
+
'"Getting your internal onboarding in place first makes sense." / "Totally understandable." / "Smart move." / "Good call, let\'s wait."',
|
|
32
|
+
},
|
|
14
33
|
{
|
|
15
34
|
id: "unnamed-fix",
|
|
16
35
|
name: "Unnamed fix",
|
|
@@ -99,6 +99,10 @@ export const phrasesEnWikipedia = [
|
|
|
99
99
|
"i am sorry, but",
|
|
100
100
|
"you're absolutely right",
|
|
101
101
|
"you are absolutely right",
|
|
102
|
+
// The same agreement opener without the adverb: "You're right that supplier data from
|
|
103
|
+
// China is where importers get stuck" passed as a 0.80 shape in a LinkedIn DM (Ramzi, 10 Nov 2026).
|
|
104
|
+
"you're right that",
|
|
105
|
+
"you are right that",
|
|
102
106
|
"great question",
|
|
103
107
|
"would you like me to",
|
|
104
108
|
"let me know if you",
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heyramzi/lint",
|
|
3
|
-
"version": "2.
|
|
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/
|
|
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",
|
package/register.js
CHANGED
|
@@ -291,7 +291,8 @@ REGISTERS.forum = {
|
|
|
291
291
|
// The exact-pattern kinds that still count. Every other kind refused 68 of the 157 humans.
|
|
292
292
|
|
|
293
293
|
// `pattern:comma-and-you-can` is one pattern, not its kind: 0 of 265 humans, and Ramzi caught it in a Reddit draft on 5 Nov 2026.
|
|
294
|
-
|
|
294
|
+
// `the-one-doing` and `passive-voice` are Ramzi's, 9 Nov 2026, on lint-clean Reddit drafts.
|
|
295
|
+
exact: ["dash", "pattern:comma-and-you-can", "pattern:the-one-doing", "pattern:passive-voice"],
|
|
295
296
|
};
|
|
296
297
|
|
|
297
298
|
const DIRECTION = {
|
|
@@ -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 =
|
|
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
|
-
|
|
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}_])`,
|
|
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
|
-
|
|
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) =>
|
|
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
|
|
391
|
-
|
|
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
|
-
|
|
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
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
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
|
|
421
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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.
|