@heyramzi/lint 2.6.1 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/bin/heyramzi-slop.js +9 -2
- package/config/oxlintrc.json +1 -0
- package/data/slop/patterns/headings-and-laws.js +3 -0
- package/data/slop/patterns.js +4 -0
- package/index.js +2 -0
- package/package.json +2 -1
- package/rules/no-navigation-in-effect.js +114 -0
- package/slop-language.js +112 -0
- package/slop-views.js +27 -1
- package/slop.d.ts +13 -5
- package/slop.js +36 -80
package/README.md
CHANGED
|
@@ -34,6 +34,7 @@ deleted on 14 Sep 2026.
|
|
|
34
34
|
| `no-em-dash` | Error. Em and en dashes in comments, strings, template text and Svelte text. A spaced hyphen (` - `) fails there too, except where it isn't a dash: a string whose whole value is one em or en dash (an empty-value placeholder), a string or template that is code judged on content (SQL keywords like `SELECT … FROM` or `WHERE`, CSS `calc(` or `var(--`, GLSL `gl_` or `vec2`, JS `function x(`, `=>` or `const x =`), a markdown bullet at the start of a template line or comment line, `<style>`, and `sql`/`css`/`gql`/`html`/`raw` templates. Test and fixture files (`*.test.*`, `*.spec.*`, `__fixtures__/`, `fixtures/`) pass a spaced hyphen because their strings are inputs under test. A real em or en dash fails everywhere except a bare placeholder and a tagged template. |
|
|
35
35
|
| `no-svelte4-syntax` | Error. `export let` and `$:` in a `.svelte` file. Svelte 4 markup is the markup gate's job. |
|
|
36
36
|
| `no-app-stores` | Error. An import from `$app/stores`; read `page` from `$app/state`. |
|
|
37
|
+
| `no-navigation-in-effect` | Error. A shallow `goto`, `pushState` or `replaceState` in an `$effect` that tracks `page.state`, or `invalidate*` in one that tracks `page.data`. The call writes what the effect reads and it reruns forever: getwavenote.com/download?auto fired 13 DMGs and hung (TSK-1648). Read it in `untrack()` or move it to `onMount`. |
|
|
37
38
|
| `no-rune-outside-svelte-file` | Error. A rune in a file Svelte doesn't compile, which throws `rune_outside_svelte` at runtime. Rename it `.svelte.ts`. |
|
|
38
39
|
| `no-rune-shadowing-binding` | Error. A top-level binding named `state`, `derived`, `effect`… in a file that calls that rune, which throws `store_invalid_shape`. |
|
|
39
40
|
| `props-interface` | Error, with `--fix`. `type Props = {...}` in a component; write `interface Props`. A union, conditional or mapped type stays a type. |
|
package/bin/heyramzi-slop.js
CHANGED
|
@@ -48,7 +48,11 @@
|
|
|
48
48
|
*/
|
|
49
49
|
|
|
50
50
|
/*
|
|
51
|
-
* With the model unreachable the exact patterns still run, stderr says the model check didn't, and the exit code is theirs.
|
|
51
|
+
* With the model unreachable the exact patterns still run, stderr says the model check didn't, and the exit code is theirs.
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
/*
|
|
55
|
+
* `--register=forum` is the exception: it always asks Jev and fails when Jev can't answer.
|
|
52
56
|
*/
|
|
53
57
|
|
|
54
58
|
import { readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
@@ -58,6 +62,7 @@ import { patterns } from "#lint/data/slop/patterns.js";
|
|
|
58
62
|
import { titleTells } from "#lint/data/slop/title-tells.js";
|
|
59
63
|
import { FAIL, REVIEW, isUnavailable, proseOf } from "#lint/jev-core.js";
|
|
60
64
|
import { auditShapes, jevKey as readJevKey } from "#lint/jev.js";
|
|
65
|
+
import { declaredLanguage } from "#lint/slop-language.js";
|
|
61
66
|
import { slopGate } from "#lint/slop.js";
|
|
62
67
|
|
|
63
68
|
// =========================
|
|
@@ -97,7 +102,9 @@ function gate(file, register) {
|
|
|
97
102
|
const code = /\.(m?[jt]sx?|json)$/i.test(file);
|
|
98
103
|
if (/\.board\.json$/i.test(file)) return { raw, result: gateBoard(raw, register) };
|
|
99
104
|
const text = /\.mdx?$/i.test(file) ? proseOfMarkdown(raw) : raw;
|
|
100
|
-
|
|
105
|
+
// Read from the raw file, because `proseOfMarkdown` blanks the frontmatter that carries `lang`.
|
|
106
|
+
const language = declaredLanguage(raw, file);
|
|
107
|
+
return { raw, result: slopGate(text, { markup, code, register, language }) };
|
|
101
108
|
}
|
|
102
109
|
|
|
103
110
|
/**
|
package/config/oxlintrc.json
CHANGED
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"@heyramzi/lint/no-hardcoded-models": "error",
|
|
48
48
|
"@heyramzi/lint/no-redundant-prop-fallback": "error",
|
|
49
49
|
"@heyramzi/lint/no-app-stores": "error",
|
|
50
|
+
"@heyramzi/lint/no-navigation-in-effect": "error",
|
|
50
51
|
"@heyramzi/lint/no-rune-outside-svelte-file": "error",
|
|
51
52
|
"@heyramzi/lint/no-rune-shadowing-binding": "error",
|
|
52
53
|
"@heyramzi/lint/no-svelte4-syntax": "error",
|
|
@@ -11,6 +11,8 @@ export const patternsHeadingsAndLaws = [
|
|
|
11
11
|
|
|
12
12
|
// not in the outline.
|
|
13
13
|
view: "faqless",
|
|
14
|
+
// The `?` is the whole signature, so it reads the same in German as in English.
|
|
15
|
+
anyLanguage: true,
|
|
14
16
|
test: /^#{1,6}\s+[^\n?]{5,90}\?\s*$/m,
|
|
15
17
|
rule: "A section heading written as a question the writer then answers. It buys a beat of suspense the reader did not ask for and it makes the outline unscannable. Name the answer in the heading.",
|
|
16
18
|
example: '"## Why does this matter?" / "## Qu\'est-ce que le pilotage ?"',
|
|
@@ -21,6 +23,7 @@ export const patternsHeadingsAndLaws = [
|
|
|
21
23
|
// WP:AILIST. A bullet or a number, a bold run, then a colon, on either side of the closing stars because a chatbot writes it both ways.
|
|
22
24
|
|
|
23
25
|
// The colon is required: a list of bold link labels with no colon is ordinary markdown.
|
|
26
|
+
anyLanguage: true,
|
|
24
27
|
test: /^[ \t]*(?:[-*+•–—]|\d+[.)])\s+\*\*[^*\n]{2,60}(?:[::]\*\*|\*\*\s*[::])/m,
|
|
25
28
|
rule: "The bullet, bold label, colon, sentence shape a chatbot renders by default. It turns prose into a specification nobody asked for and the bold adds no emphasis because every line has it. Write the paragraph, or drop the bold and the colon.",
|
|
26
29
|
example:
|
package/data/slop/patterns.js
CHANGED
|
@@ -44,6 +44,10 @@ import { patternsDiagramAndScriptTells } from "#lint/data/slop/patterns/diagram-
|
|
|
44
44
|
/*
|
|
45
45
|
* `view` is optional and names which reading of the draft the regex judges: the whole draft by default, or `faqless` for the one check an FAQ is allowed to fail.
|
|
46
46
|
*/
|
|
47
|
+
|
|
48
|
+
/*
|
|
49
|
+
* `anyLanguage` is optional. A pattern runs only on English and French drafts, the languages its words are written in, unless it reads markdown shape alone and says so here.
|
|
50
|
+
*/
|
|
47
51
|
export const patterns = [
|
|
48
52
|
...patternsSubjectVoice,
|
|
49
53
|
...patternsRevealsAndTallies,
|
package/index.js
CHANGED
|
@@ -41,6 +41,7 @@ import svelteSectionOrder from "#lint/rules/svelte-section-order.js";
|
|
|
41
41
|
|
|
42
42
|
// Svelte and SvelteKit house rules
|
|
43
43
|
import noAppStores from "#lint/rules/no-app-stores.js";
|
|
44
|
+
import noNavigationInEffect from "#lint/rules/no-navigation-in-effect.js";
|
|
44
45
|
import noRuneOutsideSvelteFile from "#lint/rules/no-rune-outside-svelte-file.js";
|
|
45
46
|
import noRuneShadowingBinding from "#lint/rules/no-rune-shadowing-binding.js";
|
|
46
47
|
import noSkippedOrFocusedTests from "#lint/rules/no-skipped-or-focused-tests.js";
|
|
@@ -100,6 +101,7 @@ export default {
|
|
|
100
101
|
|
|
101
102
|
// Svelte and SvelteKit
|
|
102
103
|
"no-app-stores": noAppStores,
|
|
104
|
+
"no-navigation-in-effect": noNavigationInEffect,
|
|
103
105
|
"no-rune-outside-svelte-file": noRuneOutsideSvelteFile,
|
|
104
106
|
"no-rune-shadowing-binding": noRuneShadowingBinding,
|
|
105
107
|
"no-skipped-or-focused-tests": noSkippedOrFocusedTests,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heyramzi/lint",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"description": "Shared oxlint rules, base config and gates for Studio projects",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"push-diff.js",
|
|
44
44
|
"slop.d.ts",
|
|
45
45
|
"slop.js",
|
|
46
|
+
"slop-language.js",
|
|
46
47
|
"slop-views.js",
|
|
47
48
|
"ui-rules.js",
|
|
48
49
|
"ui-rules-css.js",
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ban a shallow navigation in an `$effect` that tracks `page.state`, and `invalidate*` in one that tracks `page.data`.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* The call writes the field the effect tracks, so it reruns forever: getwavenote.com/download?auto fired 13 DMGs and hung (TSK-1648). `untrack()` the read or run it in `onMount`.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** The `page` field each call writes. A plain `goto` leaves the page instead, so it never loops. */
|
|
10
|
+
const WRITES = {
|
|
11
|
+
goto: "state",
|
|
12
|
+
pushState: "state",
|
|
13
|
+
replaceState: "state",
|
|
14
|
+
invalidate: "data",
|
|
15
|
+
invalidateAll: "data",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const message =
|
|
19
|
+
"`{{name}}` writes `page.{{field}}`, which this `$effect` tracks, so it reruns forever. Read it in `untrack()` or move the call to `onMount`.";
|
|
20
|
+
|
|
21
|
+
function isEffectCall(node) {
|
|
22
|
+
if (node?.type !== "CallExpression") return false;
|
|
23
|
+
const { callee } = node;
|
|
24
|
+
if (callee.type === "Identifier") return callee.name === "$effect";
|
|
25
|
+
return (
|
|
26
|
+
callee.type === "MemberExpression" &&
|
|
27
|
+
callee.object.type === "Identifier" &&
|
|
28
|
+
callee.object.name === "$effect" &&
|
|
29
|
+
callee.property.type === "Identifier" &&
|
|
30
|
+
callee.property.name === "pre"
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The `$effect` call whose callback holds `node`, or null when an `untrack()` sits between them. */
|
|
35
|
+
function enclosingEffect(node) {
|
|
36
|
+
for (let child = node, parent = node.parent; parent; child = parent, parent = parent.parent) {
|
|
37
|
+
if (parent.type === "CallExpression" && parent.callee.type === "Identifier") {
|
|
38
|
+
if (parent.callee.name === "untrack" && parent.arguments[0] === child) return null;
|
|
39
|
+
}
|
|
40
|
+
if (isEffectCall(parent) && parent.arguments[0] === child) return parent;
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function isInPlace(name, call) {
|
|
46
|
+
if (name !== "goto") return true;
|
|
47
|
+
const options = call.arguments[1];
|
|
48
|
+
return (
|
|
49
|
+
options?.type === "ObjectExpression" &&
|
|
50
|
+
options.properties.some(
|
|
51
|
+
(prop) =>
|
|
52
|
+
prop.type === "Property" &&
|
|
53
|
+
(prop.key.name ?? prop.key.value) === "shallow" &&
|
|
54
|
+
prop.value.type === "Literal" &&
|
|
55
|
+
prop.value.value === true,
|
|
56
|
+
)
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export default {
|
|
61
|
+
meta: {
|
|
62
|
+
type: "problem",
|
|
63
|
+
docs: { description: "Disallow a navigation that writes the page field its $effect tracks." },
|
|
64
|
+
messages: { navigationInEffect: message },
|
|
65
|
+
schema: [],
|
|
66
|
+
},
|
|
67
|
+
create(context) {
|
|
68
|
+
const local = new Map();
|
|
69
|
+
const pageNames = new Set();
|
|
70
|
+
const pending = [];
|
|
71
|
+
const tracked = new Map();
|
|
72
|
+
return {
|
|
73
|
+
ImportDeclaration(node) {
|
|
74
|
+
if (node.source?.value === "$app/state") {
|
|
75
|
+
for (const specifier of node.specifiers) {
|
|
76
|
+
const imported = specifier.imported?.name ?? specifier.imported?.value;
|
|
77
|
+
if (imported === "page") pageNames.add(specifier.local.name);
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (node.source?.value !== "$app/navigation") return;
|
|
82
|
+
for (const specifier of node.specifiers) {
|
|
83
|
+
if (specifier.type !== "ImportSpecifier") continue;
|
|
84
|
+
const imported = specifier.imported.name ?? specifier.imported.value;
|
|
85
|
+
if (imported in WRITES) local.set(specifier.local.name, imported);
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
CallExpression(node) {
|
|
89
|
+
if (node.callee.type !== "Identifier" || !local.has(node.callee.name)) return;
|
|
90
|
+
if (!isInPlace(local.get(node.callee.name), node)) return;
|
|
91
|
+
const effect = enclosingEffect(node);
|
|
92
|
+
if (effect) pending.push({ node, effect });
|
|
93
|
+
},
|
|
94
|
+
Identifier(node) {
|
|
95
|
+
if (!pageNames.has(node.name)) return;
|
|
96
|
+
const { parent } = node;
|
|
97
|
+
if (parent?.type !== "MemberExpression" || parent.object !== node || parent.computed)
|
|
98
|
+
return;
|
|
99
|
+
const effect = enclosingEffect(node);
|
|
100
|
+
if (!effect) return;
|
|
101
|
+
if (!tracked.has(effect)) tracked.set(effect, new Set());
|
|
102
|
+
tracked.get(effect).add(parent.property.name);
|
|
103
|
+
},
|
|
104
|
+
"Program:exit"() {
|
|
105
|
+
for (const { node, effect } of pending) {
|
|
106
|
+
const field = WRITES[local.get(node.callee.name)];
|
|
107
|
+
if (!tracked.get(effect)?.has(field)) continue;
|
|
108
|
+
const data = { name: node.callee.name, field };
|
|
109
|
+
context.report({ node, messageId: "navigationInEffect", data });
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
},
|
|
114
|
+
};
|
package/slop-language.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which language the draft is in, so the checks that only work in one of them pick the right list.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* Stopword counting, not a library.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* The two sets share almost nothing, a draft of any length separates them by a wide margin, and the only caller that can be hurt by a wrong answer is
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/*
|
|
14
|
+
* the pronoun ledger, which reports rather than rewrites. English is the default on a tie, including on an empty string.
|
|
15
|
+
*/
|
|
16
|
+
const FR_STOPWORDS =
|
|
17
|
+
/(?<![\p{L}\p{N}_])(?:le|la|les|des|une|un|et|est|dans|pour|que|qui|pas|avec|sur|plus|cette|vous|nous|aux|mais|sont|être|ce|se|son|ses|leur|par|au|du|elle|il)(?![\p{L}\p{N}_])/giu;
|
|
18
|
+
const EN_STOPWORDS =
|
|
19
|
+
/(?<![\p{L}\p{N}_])(?:the|and|is|of|to|in|that|it|for|with|you|this|are|on|but|not|have|from|as|was|they|be|at|by|or|an|its|their)(?![\p{L}\p{N}_])/giu;
|
|
20
|
+
// None of these is an English or French word, so an English draft quoting one German phrase stays English.
|
|
21
|
+
const DE_STOPWORDS =
|
|
22
|
+
/(?<![\p{L}\p{N}_])(?:der|das|und|ist|nicht|mit|ein|eine|einen|einem|für|auf|sich|dem|auch|zu|von|wird|sind|oder|aber|wenn|nur|bei|nach|noch|wie|über|kann|ich|wir|Sie|zum|zur|dass|werden|haben)(?![\p{L}\p{N}_])/giu;
|
|
23
|
+
|
|
24
|
+
export function detectLanguage(text) {
|
|
25
|
+
// Japanese first, and by script rather than by stopword.
|
|
26
|
+
|
|
27
|
+
// A Japanese draft has no English or French stopwords of its own, so the count is decided by whatever it quotes, and every Japanese page on the Wavenote site came
|
|
28
|
+
|
|
29
|
+
// back "en" and was then graded on English pronouns it does not use.
|
|
30
|
+
const cjk = (text.match(/[\u3040-\u30ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff]/g) ?? []).length;
|
|
31
|
+
const letters = (text.match(/[\p{L}]/gu) ?? []).length;
|
|
32
|
+
if (letters > 0 && cjk / letters > 0.2) return "ja";
|
|
33
|
+
const en = (text.match(EN_STOPWORDS) ?? []).length;
|
|
34
|
+
const fr = (text.match(FR_STOPWORDS) ?? []).length;
|
|
35
|
+
const de = (text.match(DE_STOPWORDS) ?? []).length;
|
|
36
|
+
if (fr > en && fr >= de) return "fr";
|
|
37
|
+
if (de > en && de > fr) return "de";
|
|
38
|
+
return "en";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The language a file declares: frontmatter `lang`, `locale` or `language`, then the nearest folder named for one (`/de/`, `/ja-JP/`). Undefined when neither says.
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
/*
|
|
46
|
+
* Seam's German posts said it only by folder and were graded as English, 3 Nov 2026. `it` is left out: that folder is usually a department.
|
|
47
|
+
*/
|
|
48
|
+
const LANGUAGE_FOLDERS = new Set([
|
|
49
|
+
"en",
|
|
50
|
+
"fr",
|
|
51
|
+
"de",
|
|
52
|
+
"ja",
|
|
53
|
+
"es",
|
|
54
|
+
"pt",
|
|
55
|
+
"nl",
|
|
56
|
+
"zh",
|
|
57
|
+
"ko",
|
|
58
|
+
"pl",
|
|
59
|
+
"sv",
|
|
60
|
+
"da",
|
|
61
|
+
"fi",
|
|
62
|
+
"ru",
|
|
63
|
+
"tr",
|
|
64
|
+
]);
|
|
65
|
+
export function declaredLanguage(source = "", path = "") {
|
|
66
|
+
const front = /^---\r?\n([\s\S]*?)\r?\n---/.exec(source)?.[1] ?? "";
|
|
67
|
+
const tag = /^(?:lang|locale|language)[ \t]*:[ \t]*["']?([A-Za-z]{2})(?![A-Za-z])/m.exec(front);
|
|
68
|
+
if (tag) return tag[1].toLowerCase();
|
|
69
|
+
const folder = path
|
|
70
|
+
.split(/[\\/]/)
|
|
71
|
+
.slice(0, -1)
|
|
72
|
+
.toReversed()
|
|
73
|
+
.find((s) => /^[a-z]{2}(?:[-_][A-Za-z]{2})?$/.test(s) && LANGUAGE_FOLDERS.has(s.slice(0, 2)));
|
|
74
|
+
return folder?.slice(0, 2);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The word lists, phrases, sentence patterns, title case and pronoun ledger are written for these. German needs a comma before every relative clause, which `comma-run` read as a list.
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
/*
|
|
82
|
+
* The outline, dashes, emoji, hashtags, chatbot markup and any pattern marked `anyLanguage` still run in every language.
|
|
83
|
+
*/
|
|
84
|
+
export const LISTED_LANGUAGES = new Set(["en", "fr"]);
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The first person against the second, per language.
|
|
88
|
+
*/
|
|
89
|
+
|
|
90
|
+
/*
|
|
91
|
+
* The English-only sets were the whole check until 5 Sep 2026, so every French draft counted 0 against 0 and failed `selfish-framing` by construction.
|
|
92
|
+
*/
|
|
93
|
+
|
|
94
|
+
/*
|
|
95
|
+
* The check now runs on the detected language and only fires when the writer actually used the first person: copy with no pronouns at all is a reference page,
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
/*
|
|
99
|
+
* not a page about its author.
|
|
100
|
+
*/
|
|
101
|
+
export const PRONOUNS = {
|
|
102
|
+
en: {
|
|
103
|
+
// Case-sensitive: a lone `i` is a loop index, `US` a country, and `Annex I` a numeral.
|
|
104
|
+
first:
|
|
105
|
+
/(?<![\p{L}\p{N}_])(?:(?<!(?:Annex|Article|Title|Chapter|Part|Section|Phase|Tier) )I|[Ww]e|WE|[Mm]y|[Oo]urs?|OUR|[Mm]ine|[Uu]s)(?![\p{L}\p{N}_])/gu,
|
|
106
|
+
second: /(?<![\p{L}\p{N}_])(?:you|your|yours)(?![\p{L}\p{N}_])/giu,
|
|
107
|
+
},
|
|
108
|
+
fr: {
|
|
109
|
+
first: /(?<![\p{L}\p{N}_])(?:je|j'|nous|mon|ma|mes|notre|nos|moi|me)(?![\p{L}\p{N}_])/giu,
|
|
110
|
+
second: /(?<![\p{L}\p{N}_])(?:vous|votre|vos|tu|ton|ta|tes|toi)(?![\p{L}\p{N}_])/giu,
|
|
111
|
+
},
|
|
112
|
+
};
|
package/slop-views.js
CHANGED
|
@@ -79,7 +79,33 @@ export function withStringStarts(text) {
|
|
|
79
79
|
* and it holds its own subheadings by design. `question-heading` and `empty-section` skip it rather than asking a page to hide the question it answers.
|
|
80
80
|
*/
|
|
81
81
|
export const FAQ_TITLE =
|
|
82
|
-
/^(?:FAQ|F\.A\.Q\.?|Frequently asked questions|よくある質問|Questions? fréquentes
|
|
82
|
+
/^(?:FAQ|F\.A\.Q\.?|Frequently asked questions|よくある質問|Questions? fréquentes?|Häufig gestellte Fragen|Häufige Fragen)$/i;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* A link's address is not copy: the `/us/` in an App Store link counted as the English "us" on Seam's German brain-fm page, 3 Nov 2026.
|
|
86
|
+
*/
|
|
87
|
+
|
|
88
|
+
/*
|
|
89
|
+
* Letters and digits become `x` while length and punctuation stay, so every other check reads the same shape. Emptied, it moved 5 English hits.
|
|
90
|
+
*/
|
|
91
|
+
|
|
92
|
+
/*
|
|
93
|
+
* The chatbot `artifacts` read the raw address, because `utm_source=chatgpt.com` is the sign.
|
|
94
|
+
*/
|
|
95
|
+
const WEB_TLD = "(?:com|org|net|io|co|fm|app|dev|ai|eu|uk|de|fr|jp|me|so|gg|tv|ly|sh|xyz)";
|
|
96
|
+
const mask = (address) => address.replace(/[\p{L}\p{N}]/gu, "x");
|
|
97
|
+
export function withoutUrls(text) {
|
|
98
|
+
return text
|
|
99
|
+
.replace(
|
|
100
|
+
/(\]\()((?:[^()\s]|\([^()\s]*\))*)(?=(?:\s+"[^"\n]*")?\))/g,
|
|
101
|
+
(_, open, address) => open + mask(address),
|
|
102
|
+
)
|
|
103
|
+
.replace(/\b(?:https?:\/\/|www\.)[^\s<>"'`)\]]+/gi, mask)
|
|
104
|
+
.replace(
|
|
105
|
+
new RegExp(`(?<![\\p{L}\\p{N}@./-])(?:[a-z0-9-]+\\.)+${WEB_TLD}\\/[^\\s<>"'\`)\\]]*`, "gu"),
|
|
106
|
+
mask,
|
|
107
|
+
);
|
|
108
|
+
}
|
|
83
109
|
|
|
84
110
|
export function withoutFaqSections(text) {
|
|
85
111
|
let depth = 0;
|
package/slop.d.ts
CHANGED
|
@@ -12,8 +12,8 @@ export type SlopAudit = {
|
|
|
12
12
|
findings: SlopFinding[];
|
|
13
13
|
/** Shapes a regex cannot judge. Reported, never failed. */
|
|
14
14
|
review: SlopFinding[];
|
|
15
|
-
/** The language the checks ran in. English on a tie. */
|
|
16
|
-
language:
|
|
15
|
+
/** The language the checks ran in, as a 2-letter code: declared, else counted. English on a tie. */
|
|
16
|
+
language: string;
|
|
17
17
|
/** First-person against second-person word counts, in that language. */
|
|
18
18
|
ledger: { first: number; second: number };
|
|
19
19
|
words: number;
|
|
@@ -40,11 +40,17 @@ export declare function stripInvisibles(
|
|
|
40
40
|
/** True when the text carries nothing invisible. */
|
|
41
41
|
export declare function isClean(text: string): boolean;
|
|
42
42
|
|
|
43
|
-
/** Which language the draft is in, by stopword count. English on a tie. */
|
|
44
|
-
export declare function detectLanguage(text: string): "en" | "fr";
|
|
43
|
+
/** Which language the draft is in: `ja` by script, else `en`, `fr` or `de` by stopword count. English on a tie. */
|
|
44
|
+
export declare function detectLanguage(text: string): "en" | "fr" | "de" | "ja";
|
|
45
|
+
|
|
46
|
+
/** The language a file declares: frontmatter `lang`, `locale` or `language`, then a `/de/`-style folder in its path. */
|
|
47
|
+
export declare function declaredLanguage(source?: string, path?: string): string | undefined;
|
|
45
48
|
|
|
46
49
|
/** The enumerable half of the humanizer, over one string. Never rewrites. */
|
|
47
|
-
export declare function auditSlop(
|
|
50
|
+
export declare function auditSlop(
|
|
51
|
+
text: string,
|
|
52
|
+
options?: { code?: boolean; language?: string },
|
|
53
|
+
): SlopAudit;
|
|
48
54
|
|
|
49
55
|
/** Clean, then audit. The one call a publishing path makes. */
|
|
50
56
|
export declare function slopGate(
|
|
@@ -54,5 +60,7 @@ export declare function slopGate(
|
|
|
54
60
|
code?: boolean;
|
|
55
61
|
normalizeSpaces?: boolean;
|
|
56
62
|
register?: import("./register.js").RegisterName;
|
|
63
|
+
/** A 2-letter code the caller already knows. The word, phrase and sentence lists run only on `en` and `fr`. */
|
|
64
|
+
language?: string;
|
|
57
65
|
},
|
|
58
66
|
): SlopLint;
|
package/slop.js
CHANGED
|
@@ -50,6 +50,12 @@ import { phrases, words } from "#lint/data/slop-words.js";
|
|
|
50
50
|
import { artifacts } from "#lint/data/slop/artifacts.js";
|
|
51
51
|
import { patterns } from "#lint/data/slop/patterns.js";
|
|
52
52
|
import { REGISTERS, auditRegister } from "#lint/register.js";
|
|
53
|
+
import {
|
|
54
|
+
LISTED_LANGUAGES,
|
|
55
|
+
PRONOUNS,
|
|
56
|
+
declaredLanguage,
|
|
57
|
+
detectLanguage,
|
|
58
|
+
} from "#lint/slop-language.js";
|
|
53
59
|
import {
|
|
54
60
|
FAQ_TITLE,
|
|
55
61
|
copyStrings,
|
|
@@ -58,9 +64,13 @@ import {
|
|
|
58
64
|
withoutCode,
|
|
59
65
|
withoutComments,
|
|
60
66
|
withoutFaqSections,
|
|
67
|
+
withoutUrls,
|
|
61
68
|
} from "#lint/slop-views.js";
|
|
62
69
|
import { auditShorts } from "@heyramzi/social/shorts";
|
|
63
70
|
|
|
71
|
+
// Part of the `@heyramzi/lint/slop` API that `slop.d.ts` declares.
|
|
72
|
+
export { declaredLanguage, detectLanguage };
|
|
73
|
+
|
|
64
74
|
const escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
65
75
|
|
|
66
76
|
/**
|
|
@@ -89,7 +99,7 @@ export function stripMarkup(raw) {
|
|
|
89
99
|
.replace(/<(script|style)[\s\S]*?<\/\1>/gi, " ")
|
|
90
100
|
// A markup comment is a note to the next developer, not copy.
|
|
91
101
|
|
|
92
|
-
// It goes with the script block
|
|
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.
|
|
93
103
|
.replace(/<!--[\s\S]*?-->/g, " ")
|
|
94
104
|
.replace(/&[a-z]+;|&#\d+;/gi, " ")
|
|
95
105
|
.replace(/<[^>]+>/g, " ");
|
|
@@ -253,68 +263,6 @@ const EMOJI =
|
|
|
253
263
|
*/
|
|
254
264
|
const HASHTAG = /(?<=[^\n#]\s|^\s*\S[^\n]*?\s)#(?![0-9a-fA-F]{3,8}\b)(?!\d+\b)[A-Za-z][\w-]*/g;
|
|
255
265
|
|
|
256
|
-
/**
|
|
257
|
-
* Which language the draft is in, so the checks that only work in one of them pick the right list.
|
|
258
|
-
*/
|
|
259
|
-
|
|
260
|
-
/*
|
|
261
|
-
* Stopword counting, not a library.
|
|
262
|
-
*/
|
|
263
|
-
|
|
264
|
-
/*
|
|
265
|
-
* The two sets share almost nothing, a draft of any length separates them by a wide margin, and the only caller that can be hurt by a wrong answer is
|
|
266
|
-
*/
|
|
267
|
-
|
|
268
|
-
/*
|
|
269
|
-
* the pronoun ledger, which reports rather than rewrites. English is the default on a tie, including on an empty string.
|
|
270
|
-
*/
|
|
271
|
-
const FR_STOPWORDS =
|
|
272
|
-
/(?<![\p{L}\p{N}_])(?:le|la|les|des|une|un|et|est|dans|pour|que|qui|pas|avec|sur|plus|cette|vous|nous|aux|mais|sont|être|ce|se|son|ses|leur|par|au|du|elle|il)(?![\p{L}\p{N}_])/giu;
|
|
273
|
-
const EN_STOPWORDS =
|
|
274
|
-
/(?<![\p{L}\p{N}_])(?:the|and|is|of|to|in|that|it|for|with|you|this|are|on|but|not|have|from|as|was|they|be|at|by|or|an|its|their)(?![\p{L}\p{N}_])/giu;
|
|
275
|
-
|
|
276
|
-
export function detectLanguage(text) {
|
|
277
|
-
// Japanese first, and by script rather than by stopword.
|
|
278
|
-
|
|
279
|
-
// A Japanese draft has no English or French stopwords of its own, so the count is decided by whatever it quotes, and every Japanese page on the Wavenote site came
|
|
280
|
-
|
|
281
|
-
// back "en" and was then graded on English pronouns it does not use.
|
|
282
|
-
const cjk = (text.match(/[\u3040-\u30ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff]/g) ?? []).length;
|
|
283
|
-
const letters = (text.match(/[\p{L}]/gu) ?? []).length;
|
|
284
|
-
if (letters > 0 && cjk / letters > 0.2) return "ja";
|
|
285
|
-
const fr = (text.match(FR_STOPWORDS) ?? []).length;
|
|
286
|
-
const en = (text.match(EN_STOPWORDS) ?? []).length;
|
|
287
|
-
return fr > en ? "fr" : "en";
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* The first person against the second, per language.
|
|
292
|
-
*/
|
|
293
|
-
|
|
294
|
-
/*
|
|
295
|
-
* The English-only sets were the whole check until 5 Sep 2026, so every French draft counted 0 against 0 and failed `selfish-framing` by construction.
|
|
296
|
-
*/
|
|
297
|
-
|
|
298
|
-
/*
|
|
299
|
-
* The check now runs on the detected language and only fires when the writer actually used the first person: copy with no pronouns at all is a reference page,
|
|
300
|
-
*/
|
|
301
|
-
|
|
302
|
-
/*
|
|
303
|
-
* not a page about its author.
|
|
304
|
-
*/
|
|
305
|
-
const PRONOUNS = {
|
|
306
|
-
en: {
|
|
307
|
-
// Case-sensitive: a lone `i` is a loop index, `US` a country, and `Annex I` a numeral.
|
|
308
|
-
first:
|
|
309
|
-
/(?<![\p{L}\p{N}_])(?:(?<!(?:Annex|Article|Title|Chapter|Part|Section|Phase|Tier) )I|[Ww]e|WE|[Mm]y|[Oo]urs?|OUR|[Mm]ine|[Uu]s)(?![\p{L}\p{N}_])/gu,
|
|
310
|
-
second: /(?<![\p{L}\p{N}_])(?:you|your|yours)(?![\p{L}\p{N}_])/giu,
|
|
311
|
-
},
|
|
312
|
-
fr: {
|
|
313
|
-
first: /(?<![\p{L}\p{N}_])(?:je|j'|nous|mon|ma|mes|notre|nos|moi|me)(?![\p{L}\p{N}_])/giu,
|
|
314
|
-
second: /(?<![\p{L}\p{N}_])(?:vous|votre|vos|tu|ton|ta|tes|toi)(?![\p{L}\p{N}_])/giu,
|
|
315
|
-
},
|
|
316
|
-
};
|
|
317
|
-
|
|
318
266
|
/**
|
|
319
267
|
* The signs that are only visible across a whole document, so no regex over one sentence finds them: Wikipedia's title case, heading levels,
|
|
320
268
|
*/
|
|
@@ -326,7 +274,7 @@ const PRONOUNS = {
|
|
|
326
274
|
/*
|
|
327
275
|
* Markdown only. HTML is stripped to prose before it reaches here, so a page audits on its words and an `.md` draft audits on its words and its outline.
|
|
328
276
|
*/
|
|
329
|
-
function auditStructure(text) {
|
|
277
|
+
function auditStructure(text, language) {
|
|
330
278
|
const found = [];
|
|
331
279
|
const hit = (id, detail) => found.push({ kind: "structure", id, detail });
|
|
332
280
|
|
|
@@ -342,7 +290,7 @@ function auditStructure(text) {
|
|
|
342
290
|
|
|
343
291
|
// and 2 of them capitalised is the threshold: "Awards and Recognition" hits, "the ClickUp API" does not.
|
|
344
292
|
const names = properNouns(body);
|
|
345
|
-
for (const heading of headings) {
|
|
293
|
+
for (const heading of LISTED_LANGUAGES.has(language) ? headings : []) {
|
|
346
294
|
const rest = heading.title
|
|
347
295
|
.split(/\s+/)
|
|
348
296
|
.slice(1)
|
|
@@ -423,10 +371,14 @@ function auditStructure(text) {
|
|
|
423
371
|
/*
|
|
424
372
|
* Those are claims about the world, and a string is all this function gets.
|
|
425
373
|
*/
|
|
426
|
-
export function auditSlop(draft, { code = false } = {}) {
|
|
427
|
-
const
|
|
374
|
+
export function auditSlop(draft, { code = false, language: declared } = {}) {
|
|
375
|
+
const source = code ? withoutComments(draft) : draft;
|
|
376
|
+
// Every layer but `artifacts` reads the draft with its link addresses masked: `withoutUrls` carries why.
|
|
377
|
+
const text = withoutUrls(source);
|
|
428
378
|
const findings = [];
|
|
429
379
|
const add = (kind, id, detail) => findings.push({ kind, id, detail });
|
|
380
|
+
const language = declared ?? declaredLanguage(draft) ?? detectLanguage(text);
|
|
381
|
+
const listed = LISTED_LANGUAGES.has(language);
|
|
430
382
|
|
|
431
383
|
// The ban lists read the draft with its code spans removed, because an identifier is not a word somebody chose: `enhance` is a Worker directory and `enable` is an API
|
|
432
384
|
|
|
@@ -434,11 +386,11 @@ export function auditSlop(draft, { code = false } = {}) {
|
|
|
434
386
|
|
|
435
387
|
// The `patterns` below still read the whole text, where the surrounding sentence is what they are judging.
|
|
436
388
|
const prose = withoutCode(text);
|
|
437
|
-
for (const word of words) {
|
|
389
|
+
for (const word of listed ? words : []) {
|
|
438
390
|
const m = prose.match(bounded(word));
|
|
439
391
|
if (m) add("word", word, m[0]);
|
|
440
392
|
}
|
|
441
|
-
for (const phrase of phrases) {
|
|
393
|
+
for (const phrase of listed ? phrases : []) {
|
|
442
394
|
// 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.
|
|
443
395
|
|
|
444
396
|
// Every phrase here is whole words.
|
|
@@ -456,19 +408,24 @@ export function auditSlop(draft, { code = false } = {}) {
|
|
|
456
408
|
prose: code ? copyStrings(text) : prose,
|
|
457
409
|
};
|
|
458
410
|
for (const pattern of patterns) {
|
|
459
|
-
|
|
460
|
-
|
|
411
|
+
if (!listed && !pattern.anyLanguage) continue;
|
|
412
|
+
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));
|
|
461
418
|
}
|
|
462
419
|
for (const artifact of artifacts) {
|
|
463
|
-
const m =
|
|
420
|
+
const m = source.match(artifact.test);
|
|
464
421
|
if (m) add("artifact", artifact.id, m[0].slice(0, 90));
|
|
465
422
|
}
|
|
466
|
-
for (const finding of auditStructure(text)) findings.push(finding);
|
|
423
|
+
for (const finding of auditStructure(text, language)) findings.push(finding);
|
|
467
424
|
for (const m of text.matchAll(/[—–]/g)) {
|
|
468
|
-
add("dash", "em-or-en-dash",
|
|
425
|
+
add("dash", "em-or-en-dash", source.slice(Math.max(0, m.index - 30), m.index + 30));
|
|
469
426
|
}
|
|
470
427
|
for (const m of text.matchAll(EMOJI)) {
|
|
471
|
-
add("emoji", "emoji",
|
|
428
|
+
add("emoji", "emoji", source.slice(Math.max(0, m.index - 30), m.index + 30));
|
|
472
429
|
}
|
|
473
430
|
for (const m of withoutCode(text).matchAll(HASHTAG)) {
|
|
474
431
|
add("hashtag", "hashtag", m[0]);
|
|
@@ -476,7 +433,6 @@ export function auditSlop(draft, { code = false } = {}) {
|
|
|
476
433
|
|
|
477
434
|
const ledgerText = code ? copyStrings(text) : text;
|
|
478
435
|
const count = (re) => (ledgerText.match(re) ?? []).length;
|
|
479
|
-
const language = detectLanguage(text);
|
|
480
436
|
// Only the languages with pronoun sets are graded.
|
|
481
437
|
|
|
482
438
|
// Japanese marks the same distinction with particles and by leaving the subject out, so a regex over `we` and `you` says nothing about a Japanese draft.
|
|
@@ -489,13 +445,13 @@ export function auditSlop(draft, { code = false } = {}) {
|
|
|
489
445
|
add("ledger", "selfish-framing", `first ${first}, second ${second}`);
|
|
490
446
|
|
|
491
447
|
const review = [];
|
|
492
|
-
for (const grep of PIVOT_GREPS) {
|
|
448
|
+
for (const grep of listed ? PIVOT_GREPS : []) {
|
|
493
449
|
for (const m of text.matchAll(grep)) {
|
|
494
450
|
const from = Math.max(0, m.index - 45);
|
|
495
451
|
review.push({
|
|
496
452
|
kind: "review-pivot",
|
|
497
453
|
id: m[0].toLowerCase(),
|
|
498
|
-
detail: `...${
|
|
454
|
+
detail: `...${source.slice(from, m.index + 55)}...`,
|
|
499
455
|
});
|
|
500
456
|
}
|
|
501
457
|
}
|
|
@@ -537,11 +493,11 @@ export function auditSlop(draft, { code = false } = {}) {
|
|
|
537
493
|
*/
|
|
538
494
|
export function slopGate(
|
|
539
495
|
raw,
|
|
540
|
-
{ markup = false, code = false, normalizeSpaces = true, register } = {},
|
|
496
|
+
{ markup = false, code = false, normalizeSpaces = true, register, language } = {},
|
|
541
497
|
) {
|
|
542
498
|
const source = markup ? stripMarkup(raw) : raw;
|
|
543
499
|
const cleaned = stripInvisibles(source, { normalizeSpaces });
|
|
544
|
-
const audit = auditSlop(cleaned.text, { code });
|
|
500
|
+
const audit = auditSlop(cleaned.text, { code, language });
|
|
545
501
|
// 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,
|
|
546
502
|
|
|
547
503
|
// because the register was written and the delivery was spoken. `register.js` carries why.
|