@heyramzi/lint 2.14.0 → 2.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/jev-core.js +3 -2
- package/package.json +2 -1
- package/rules/no-inline-svg.js +1 -1
- package/slop-clean.js +99 -33
- package/slop-views.js +4 -1
- package/svelte-template.js +1 -44
- package/template-braces.js +63 -0
package/jev-core.js
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
PARAGRAPH_SHAPES,
|
|
12
12
|
SHAPES,
|
|
13
13
|
} from "#lint/data/jev-shapes.js";
|
|
14
|
+
import { withoutTemplateCode } from "#lint/slop-clean.js";
|
|
14
15
|
|
|
15
16
|
// The questions live in data/jev-shapes.js; callers keep importing them from here.
|
|
16
17
|
export {
|
|
@@ -73,8 +74,8 @@ export function sentences(text) {
|
|
|
73
74
|
|
|
74
75
|
/** Markup as Jev reads it: a block ends a paragraph, and link text says it's a link. */
|
|
75
76
|
export function proseOf(html) {
|
|
76
|
-
|
|
77
|
-
|
|
77
|
+
// A Svelte page's `{...}` is code, and the model read it as the writer's sentences.
|
|
78
|
+
return withoutTemplateCode(html.replace(/<(script|style)[\s\S]*?<\/\1>|<!--[\s\S]*?-->/gi, " "))
|
|
78
79
|
.replace(/<a\b[^>]*>([\s\S]*?)<\/a>/gi, "\n\nLink: $1\n\n")
|
|
79
80
|
.replace(/<\/(p|li|h[1-6]|div|td|blockquote)>|<br\s*\/?>/gi, "\n\n")
|
|
80
81
|
.replace(/<[^>]+>/g, " ")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heyramzi/lint",
|
|
3
|
-
"version": "2.14.
|
|
3
|
+
"version": "2.14.1",
|
|
4
4
|
"description": "Shared oxlint rules, base config and gates for Studio projects",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"ui-rules-markup.js",
|
|
53
53
|
"svelte-markup.js",
|
|
54
54
|
"svelte-template.js",
|
|
55
|
+
"template-braces.js",
|
|
55
56
|
"register.js",
|
|
56
57
|
"register.d.ts",
|
|
57
58
|
"repo-rules.js",
|
package/rules/no-inline-svg.js
CHANGED
|
@@ -22,7 +22,7 @@ export default {
|
|
|
22
22
|
},
|
|
23
23
|
messages: {
|
|
24
24
|
noInlineSvg:
|
|
25
|
-
"Inline <svg> at line {{ line }}. Use an icon component (e.g. phosphor-svelte) or
|
|
25
|
+
"Inline <svg> at line {{ line }}. Use an icon component (e.g. phosphor-svelte), or put the SVG component under components/icons/ or a logos/ folder: only those paths may hold inline <svg>.",
|
|
26
26
|
},
|
|
27
27
|
schema: [],
|
|
28
28
|
},
|
package/slop-clean.js
CHANGED
|
@@ -15,6 +15,8 @@ import {
|
|
|
15
15
|
isInvisible,
|
|
16
16
|
} from "#lint/data/invisibles.js";
|
|
17
17
|
import { hitLines } from "#lint/slop-lines.js";
|
|
18
|
+
import { looksLikeCopy } from "#lint/slop-views.js";
|
|
19
|
+
import { braceEnd, skipBraces, skipString, skipTemplate } from "#lint/template-braces.js";
|
|
18
20
|
|
|
19
21
|
/**
|
|
20
22
|
* HTML in, prose out, so an email body and a markdown draft audit the same way.
|
|
@@ -27,54 +29,118 @@ export function stripMarkup(raw, { keepLines = false } = {}) {
|
|
|
27
29
|
// `keepLines` leaves each removed block's line breaks behind, so a hit's line is the file's line.
|
|
28
30
|
// The audit itself reads the collapsed text, whose matches every gate run has agreed with.
|
|
29
31
|
const gap = keepLines ? (m) => ` ${m.replace(/[^\n]/g, "")}` : " ";
|
|
30
|
-
const text =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
const text = withoutTemplateCode(
|
|
33
|
+
raw
|
|
34
|
+
.replace(/<(script|style)[\s\S]*?<\/\1>/gi, gap)
|
|
35
|
+
// A markup comment is a note to the next developer, not copy.
|
|
36
|
+
|
|
37
|
+
// 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.
|
|
38
|
+
.replace(/<!--[\s\S]*?-->/g, gap),
|
|
39
|
+
{ keepLines },
|
|
40
|
+
)
|
|
36
41
|
.replace(/&[a-z]+;|&#\d+;/gi, " ")
|
|
37
42
|
.replace(/<[^>]+>/g, gap);
|
|
38
|
-
|
|
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, " ");
|
|
43
|
+
const prose = text.replace(/[ \t]+/g, " ");
|
|
44
44
|
return keepLines ? prose : prose.trim();
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
|
-
* Drops every
|
|
48
|
+
* Drops the code of every Svelte or Vue `{...}` from markup, keeping only the copy strings of a plain interpolation.
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
/*
|
|
52
|
+
* Code read as prose fails the gate. `{#each items as row, i (row)}` counted `i` as a first-person pronoun on 3 pages, a JSON-LD object inside `{@html}` failed
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
/*
|
|
56
|
+
* `comma-run` on a CBAM news page (27 Oct 2026), and `Classer {les(reste, "ligne restante", "lignes restantes")}` failed it on Locameublé (16 Nov 2026).
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
/*
|
|
60
|
+
* It runs before tags go, so `onclick={() => a > b}` no longer ends its tag at the arrow. A block (`{#`, `{:`, `{/`, `{@`) and anything inside a tag go whole.
|
|
49
61
|
*/
|
|
50
62
|
|
|
51
63
|
/*
|
|
52
|
-
* A `
|
|
64
|
+
* A plain `{value}` in text becomes `0`, so "Code sent to {email}" keeps an object and doesn't end on its preposition. Glued to a word, as in `ligne{s(n)}`,
|
|
53
65
|
*/
|
|
54
|
-
|
|
66
|
+
|
|
67
|
+
/*
|
|
68
|
+
* it's a suffix and leaves nothing. Its literals of 2+ words wait for the end of the line, each on a line of their own, so arguments never join a sentence.
|
|
69
|
+
*/
|
|
70
|
+
export function withoutTemplateCode(text, { keepLines = false } = {}) {
|
|
55
71
|
let out = "";
|
|
56
|
-
let
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
72
|
+
let waiting = [];
|
|
73
|
+
let inTag = false;
|
|
74
|
+
for (let i = 0; i < text.length; i++) {
|
|
75
|
+
const c = text[i];
|
|
76
|
+
if (c === "\n" && waiting.length) {
|
|
77
|
+
out += `\n${waiting.join("\n")}`;
|
|
78
|
+
waiting = [];
|
|
79
|
+
}
|
|
80
|
+
const end = c === "{" ? braceEnd(text, i) : -1;
|
|
81
|
+
if (end < 0) {
|
|
82
|
+
if (c === "<" && /[A-Za-z/]/.test(text[i + 1] ?? "")) inTag = true;
|
|
83
|
+
else if (c === ">") inTag = false;
|
|
84
|
+
out += c;
|
|
60
85
|
continue;
|
|
61
86
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
87
|
+
const code = text.slice(i, end + 1);
|
|
88
|
+
if (inTag || "#:/@".includes(code[1])) out += ` ${keepLines ? newlinesIn(code) : ""}`;
|
|
89
|
+
else {
|
|
90
|
+
const copy = copyLiterals(code);
|
|
91
|
+
out += placeholder(text[i - 1]);
|
|
92
|
+
if (keepLines) out += keptLines(code, copy);
|
|
93
|
+
else waiting.push(...copy.map((l) => l.text));
|
|
94
|
+
}
|
|
95
|
+
i = end;
|
|
96
|
+
}
|
|
97
|
+
return waiting.length ? `${out}\n${waiting.join("\n")}` : out;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** What a value stands in for in a sentence: `0`, or nothing when it is a word's ending. */
|
|
101
|
+
const placeholder = (before = "") => (/\p{L}/u.test(before) ? "" : "x");
|
|
102
|
+
|
|
103
|
+
const newlinesIn = (code) => code.replace(/[^\n]/g, "");
|
|
104
|
+
|
|
105
|
+
/** An expression's literals where they sit, between the line breaks it spanned, so a hit's line is the file's. */
|
|
106
|
+
function keptLines(code, copy) {
|
|
107
|
+
let out = "";
|
|
108
|
+
let from = 0;
|
|
109
|
+
for (const l of copy) {
|
|
110
|
+
out += `${newlinesIn(code.slice(from, Math.max(from, l.index)))} ${l.text} `;
|
|
111
|
+
from = Math.max(from, l.end);
|
|
112
|
+
}
|
|
113
|
+
return out + newlinesIn(code.slice(from));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* The string literals of an expression that read as copy, each with where it sits in `code`.
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
/*
|
|
121
|
+
* A template literal's `${...}` reads as a value does in markup, and the literals inside it count on their own.
|
|
122
|
+
*/
|
|
123
|
+
function copyLiterals(code) {
|
|
124
|
+
const found = [];
|
|
125
|
+
for (let i = 0; i < code.length; i++) {
|
|
126
|
+
const q = code[i];
|
|
127
|
+
if (q !== '"' && q !== "'" && q !== "`") continue;
|
|
128
|
+
const end = q === "`" ? skipTemplate(code, i) : skipString(code, i, q);
|
|
129
|
+
let text = "";
|
|
130
|
+
for (let j = i + 1; j < end; j++) {
|
|
131
|
+
if (code[j] === "\\") text += code[++j] ?? "";
|
|
132
|
+
else if (q === "`" && code[j] === "$" && code[j + 1] === "{") {
|
|
133
|
+
const close = skipBraces(code, j + 1) - 1;
|
|
134
|
+
const inner = copyLiterals(code.slice(j + 1, close + 1));
|
|
135
|
+
found.push(...inner.map((l) => ({ ...l, index: l.index + j + 1, end: l.end + j + 1 })));
|
|
136
|
+
text += placeholder(code[j - 1]);
|
|
137
|
+
j = close;
|
|
138
|
+
} else text += code[j];
|
|
73
139
|
}
|
|
74
|
-
|
|
75
|
-
i =
|
|
140
|
+
if (looksLikeCopy(text)) found.push({ text: text.trim(), index: i, end: end + 1 });
|
|
141
|
+
i = end;
|
|
76
142
|
}
|
|
77
|
-
return
|
|
143
|
+
return found.toSorted((a, b) => a.index - b.index);
|
|
78
144
|
}
|
|
79
145
|
|
|
80
146
|
const isPictographic = (ch) => /\p{Extended_Pictographic}/u.test(ch);
|
package/slop-views.js
CHANGED
|
@@ -41,9 +41,12 @@ export function withoutComments(text) {
|
|
|
41
41
|
export function copyStrings(text) {
|
|
42
42
|
const literals =
|
|
43
43
|
withoutComments(text).match(/"(?:[^"\\\n]|\\.)*"|`(?:[^`\\]|\\.)*`|'(?:[^'\\\n]|\\.)*'/g) ?? [];
|
|
44
|
-
return literals.filter(
|
|
44
|
+
return literals.filter(looksLikeCopy).join("\n");
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
/** A string of 2 words or more. A lone word is a key, a class or a flag, not a sentence anyone wrote. */
|
|
48
|
+
export const looksLikeCopy = (s) => /\p{L}{2,}\s+\p{L}{2,}/u.test(s);
|
|
49
|
+
|
|
47
50
|
/**
|
|
48
51
|
* A string literal's first sentence is sentence-initial, and every anchored pattern used to miss it.
|
|
49
52
|
*/
|
package/svelte-template.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import { readFileSync } from "node:fs";
|
|
14
|
+
import { skipBraces } from "#lint/template-braces.js";
|
|
14
15
|
|
|
15
16
|
export const VOID_ELEMENTS = new Set([
|
|
16
17
|
"area",
|
|
@@ -46,50 +47,6 @@ export const MATHML_ELEMENTS = new Set(
|
|
|
46
47
|
|
|
47
48
|
const RAW_TEXT = new Set(["script", "style"]);
|
|
48
49
|
|
|
49
|
-
/** The index just past the `}` that closes the `{` at `start`, honouring strings and comments. */
|
|
50
|
-
function skipBraces(source, start) {
|
|
51
|
-
let depth = 0;
|
|
52
|
-
for (let i = start; i < source.length; i++) {
|
|
53
|
-
const c = source[i];
|
|
54
|
-
if (c === "'" || c === '"') {
|
|
55
|
-
i = skipString(source, i, c);
|
|
56
|
-
} else if (c === "`") {
|
|
57
|
-
i = skipTemplate(source, i);
|
|
58
|
-
} else if (c === "/" && source[i + 1] === "*") {
|
|
59
|
-
const end = source.indexOf("*/", i + 2);
|
|
60
|
-
if (end === -1) return source.length;
|
|
61
|
-
i = end + 1;
|
|
62
|
-
} else if (c === "/" && source[i + 1] === "/" && source[i - 1] !== ":") {
|
|
63
|
-
const end = source.indexOf("\n", i);
|
|
64
|
-
if (end === -1) return source.length;
|
|
65
|
-
i = end;
|
|
66
|
-
} else if (c === "{") {
|
|
67
|
-
depth++;
|
|
68
|
-
} else if (c === "}") {
|
|
69
|
-
depth--;
|
|
70
|
-
if (depth === 0) return i + 1;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return source.length;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function skipString(source, start, quote) {
|
|
77
|
-
for (let i = start + 1; i < source.length; i++) {
|
|
78
|
-
if (source[i] === "\\") i++;
|
|
79
|
-
else if (source[i] === quote || source[i] === "\n") return i;
|
|
80
|
-
}
|
|
81
|
-
return source.length;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function skipTemplate(source, start) {
|
|
85
|
-
for (let i = start + 1; i < source.length; i++) {
|
|
86
|
-
if (source[i] === "\\") i++;
|
|
87
|
-
else if (source[i] === "`") return i;
|
|
88
|
-
else if (source[i] === "$" && source[i + 1] === "{") i = skipBraces(source, i + 1) - 1;
|
|
89
|
-
}
|
|
90
|
-
return source.length;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
50
|
/**
|
|
94
51
|
* Scan a whole .svelte source.
|
|
95
52
|
* @returns {{ tags: Tag[], expressions: Expression[], blocks: Block[] }}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a Svelte or Vue `{...}` ends, honouring strings, template literals and comments. No Node import, so `jev-core` can use it in a Worker.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* A flat scan that treats a backtick as a quote ends a template literal at the first nested one: `${a ? `b` : "c"}` lost the rest of a
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* Locameublé page to one `{@render}` that never closed, so no copy after it was read (16 Nov 2026).
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** The index of the `}` that closes the `{` at `start`, or -1 when nothing balances it. */
|
|
14
|
+
export function braceEnd(source, start) {
|
|
15
|
+
let depth = 0;
|
|
16
|
+
for (let i = start; i < source.length; i++) {
|
|
17
|
+
const c = source[i];
|
|
18
|
+
if (c === "'" || c === '"') {
|
|
19
|
+
i = skipString(source, i, c);
|
|
20
|
+
} else if (c === "`") {
|
|
21
|
+
i = skipTemplate(source, i);
|
|
22
|
+
} else if (c === "/" && source[i + 1] === "*") {
|
|
23
|
+
const end = source.indexOf("*/", i + 2);
|
|
24
|
+
if (end === -1) return -1;
|
|
25
|
+
i = end + 1;
|
|
26
|
+
} else if (c === "/" && source[i + 1] === "/" && source[i - 1] !== ":") {
|
|
27
|
+
const end = source.indexOf("\n", i);
|
|
28
|
+
if (end === -1) return -1;
|
|
29
|
+
i = end;
|
|
30
|
+
} else if (c === "{") {
|
|
31
|
+
depth++;
|
|
32
|
+
} else if (c === "}") {
|
|
33
|
+
depth--;
|
|
34
|
+
if (depth === 0) return i;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return -1;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The index just past the `}` that closes the `{` at `start`, or the source's length. */
|
|
41
|
+
export function skipBraces(source, start) {
|
|
42
|
+
const end = braceEnd(source, start);
|
|
43
|
+
return end < 0 ? source.length : end + 1;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The index of the quote closing the string at `start`. A line break ends an unclosed one. */
|
|
47
|
+
export function skipString(source, start, quote) {
|
|
48
|
+
for (let i = start + 1; i < source.length; i++) {
|
|
49
|
+
if (source[i] === "\\") i++;
|
|
50
|
+
else if (source[i] === quote || source[i] === "\n") return i;
|
|
51
|
+
}
|
|
52
|
+
return source.length;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The index of the backtick closing the template literal at `start`, past every `${...}`. */
|
|
56
|
+
export function skipTemplate(source, start) {
|
|
57
|
+
for (let i = start + 1; i < source.length; i++) {
|
|
58
|
+
if (source[i] === "\\") i++;
|
|
59
|
+
else if (source[i] === "`") return i;
|
|
60
|
+
else if (source[i] === "$" && source[i + 1] === "{") i = skipBraces(source, i + 1) - 1;
|
|
61
|
+
}
|
|
62
|
+
return source.length;
|
|
63
|
+
}
|