@svelte-vitals/core 0.43.0 → 0.44.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 +12 -1
- package/dist/chunk-2N7E4JFX.js +30 -0
- package/dist/index-CWWQEu8q.d.ts +1138 -0
- package/dist/index.d.ts +1 -1953
- package/dist/index.js +5 -8477
- package/dist/internal.d.ts +883 -0
- package/dist/internal.js +8642 -0
- package/package.json +10 -5
|
@@ -0,0 +1,1138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core type definitions shared across modes. This module is pure: no I/O, no
|
|
3
|
+
* `node:` imports, no runtime-specific globals (design §8).
|
|
4
|
+
*/
|
|
5
|
+
type Severity = 'critical' | 'warning' | 'info';
|
|
6
|
+
/** Where a head tag is set, relative to the route being evaluated (design §4). */
|
|
7
|
+
type Presence = 'own' | 'inherited' | 'none';
|
|
8
|
+
/** How a tag's value is determined (design §4). */
|
|
9
|
+
type Value = 'static' | 'dynamic' | 'absent';
|
|
10
|
+
/**
|
|
11
|
+
* Two-axis detection result. Kept independent so combinations such as
|
|
12
|
+
* "inherited + dynamic" remain expressible (design §4).
|
|
13
|
+
*/
|
|
14
|
+
interface Detection {
|
|
15
|
+
presence: Presence;
|
|
16
|
+
value: Value;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* One compiled SvelteKit alias entry, in the order Kit builds them (`get_config_aliases` in
|
|
20
|
+
* `@sveltejs/kit/src/exports/vite/utils.js`): `$lib` first, then `kit.alias` in declaration
|
|
21
|
+
* order. Resolution takes the FIRST matching entry, exactly as Vite's alias plugin does, so
|
|
22
|
+
* **position is precedence** — the list is never sorted and a longer `find` never wins on
|
|
23
|
+
* length alone.
|
|
24
|
+
*/
|
|
25
|
+
interface KitAlias {
|
|
26
|
+
/** The alias key, with any trailing `/*` removed. */
|
|
27
|
+
find: string;
|
|
28
|
+
/**
|
|
29
|
+
* The project-relative target: posixified, with any trailing `/*` and any trailing slashes
|
|
30
|
+
* removed. `null` when the config's value is not a string literal — such an entry still
|
|
31
|
+
* matches (holding its position and its mode) but resolves to undefined, so a specifier we
|
|
32
|
+
* cannot resolve stays unresolved instead of falling through to a later entry.
|
|
33
|
+
*/
|
|
34
|
+
replacement: string | null;
|
|
35
|
+
/**
|
|
36
|
+
* How `find` matches a specifier, mirroring Kit's three compiled entry shapes:
|
|
37
|
+
* - `prefix` — `spec === find` or `spec.startsWith(find + '/')`; a plain key.
|
|
38
|
+
* - `contents` — `spec.startsWith(find + '/')` only; from a `key/*` key, which Kit
|
|
39
|
+
* documents as matching "the contents of a directory, not the directory itself".
|
|
40
|
+
* - `exact` — `spec === find` only; a plain key whose `key/*` form is ALSO declared, which
|
|
41
|
+
* is how Kit stops the plain key from swallowing the nested specifiers.
|
|
42
|
+
*/
|
|
43
|
+
match: 'prefix' | 'contents' | 'exact';
|
|
44
|
+
}
|
|
45
|
+
/** Project-wide facts precomputed by the runtime layer for project-scope rules (design §10). */
|
|
46
|
+
interface Project {
|
|
47
|
+
hasRobotsTxt: boolean;
|
|
48
|
+
hasSitemap: boolean;
|
|
49
|
+
/** <html lang> from app.html: presence 'own' when the attribute exists ('none' otherwise); value 'static' if non-empty, 'absent' if empty. */
|
|
50
|
+
htmlLang: Detection;
|
|
51
|
+
/** Whether the static static/robots.txt references a sitemap (`Sitemap:` line). Undefined for a +server endpoint / absent / unreadable. */
|
|
52
|
+
robotsReferencesSitemap?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Set when the Vite config disables minification for production builds (performance/minify-disabled).
|
|
55
|
+
* `file` is the config path relative to the analyzed root (posix, may start with `../`
|
|
56
|
+
* in monorepos); unset for inline programmatic configs. `line` is 1-based and set only
|
|
57
|
+
* when the literal `minify: false` was located in that file; unset when the value was
|
|
58
|
+
* resolved at build time (plugin/conditional config).
|
|
59
|
+
*/
|
|
60
|
+
viteMinifyDisabled?: {
|
|
61
|
+
file?: string;
|
|
62
|
+
line?: number;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Set when the project configures a non-empty `kit.paths.base` — read from the `sveltekit()`
|
|
66
|
+
* Vite plugin config, else `svelte.config.{js,ts}` (correctness/base-path-navigation).
|
|
67
|
+
* `value` is the literal base when statically resolvable, unset when the config computes it
|
|
68
|
+
* (e.g. `dev ? '' : '/repo'`). `file` is the config path relative to the analyzed root (posix).
|
|
69
|
+
* Absent means the app is served at the root — the rule stays silent.
|
|
70
|
+
*/
|
|
71
|
+
kitPathsBase?: {
|
|
72
|
+
value?: string;
|
|
73
|
+
file: string;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* The project's compiled SvelteKit alias entries, in Kit's own order (`$lib` first), read from
|
|
77
|
+
* `svelte.config.{js,ts}`. Absent means no config was read — resolution then falls back to
|
|
78
|
+
* `$lib` → `src/lib`, which is what this analyzer assumed unconditionally before. A collected
|
|
79
|
+
* list is never empty: `$lib` is always prepended.
|
|
80
|
+
*/
|
|
81
|
+
kitAliases?: KitAlias[];
|
|
82
|
+
/**
|
|
83
|
+
* Whether `src/app.html` opens with `<!doctype html>` (a11y/doctype). Set from the same read
|
|
84
|
+
* as `htmlLang`; absent when the file wasn't read (missing or unreadable) — the rule stays
|
|
85
|
+
* silent then, like `viteMinifyDisabled`'s absent convention.
|
|
86
|
+
*/
|
|
87
|
+
appHtmlDoctype?: boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Literal `id` attributes in `src/app.html`, from the same read as `htmlLang`. The shell is part
|
|
90
|
+
* of every rendered document, so its ids satisfy a route's id references (a11y/no-missing-id-ref);
|
|
91
|
+
* absent when the file wasn't read.
|
|
92
|
+
*/
|
|
93
|
+
appHtmlIds?: string[];
|
|
94
|
+
}
|
|
95
|
+
declare const defaultProject: Project;
|
|
96
|
+
/** A concrete, agent-actionable remediation for a finding (design §10, issue #18). */
|
|
97
|
+
interface Fix {
|
|
98
|
+
/** One-line imperative instruction, e.g. 'Add a <meta name="description"> inside <svelte:head>.' */
|
|
99
|
+
description: string;
|
|
100
|
+
/** Concrete code to insert or a file's contents to create. */
|
|
101
|
+
snippet?: string;
|
|
102
|
+
/** Markdown fenced-code language for `snippet` (default 'svelte'). */
|
|
103
|
+
lang?: string;
|
|
104
|
+
}
|
|
105
|
+
/** A single rule finding for one route (or the whole project). */
|
|
106
|
+
interface Result {
|
|
107
|
+
/** Rule id, e.g. 'seo/title-presence'. */
|
|
108
|
+
id: string;
|
|
109
|
+
severity: Severity;
|
|
110
|
+
detection: Detection;
|
|
111
|
+
/** Route path, e.g. '/blog/[slug]'. Omitted for project-scoped rules. */
|
|
112
|
+
route?: string;
|
|
113
|
+
/** Source location, e.g. 'src/routes/blog/[slug]/+page.svelte'. */
|
|
114
|
+
location?: string;
|
|
115
|
+
message: string;
|
|
116
|
+
recommendation?: string;
|
|
117
|
+
docsUrl?: string;
|
|
118
|
+
/** Agent-actionable remediation (issue #18). */
|
|
119
|
+
fix?: Fix;
|
|
120
|
+
/** Vitals category this finding belongs to (default 'seo' when absent). */
|
|
121
|
+
category?: Category;
|
|
122
|
+
/** 1-based source line for element-level findings (e.g. a specific <img>). */
|
|
123
|
+
line?: number;
|
|
124
|
+
}
|
|
125
|
+
type Scope = 'route' | 'project' | 'component';
|
|
126
|
+
type Category = 'seo' | 'performance' | 'correctness' | 'security' | 'architecture' | 'a11y';
|
|
127
|
+
/**
|
|
128
|
+
* Every category, as a runtime list — for validating a user-supplied category
|
|
129
|
+
* name and naming the known ones in the error. One definition so a category
|
|
130
|
+
* added to `Category` can't be accepted by one validator and rejected by
|
|
131
|
+
* another. Not an ordering: reporters keep their own display order.
|
|
132
|
+
*/
|
|
133
|
+
declare const CATEGORIES: readonly Category[];
|
|
134
|
+
/** How dynamic (`{data.title}`) values are treated by scoring (design §4, §12). */
|
|
135
|
+
type TreatDynamicAs = 'pass' | 'warn' | 'fail';
|
|
136
|
+
/** Resolved option values handed to a rule at check time. */
|
|
137
|
+
type RuleOptions = Record<string, unknown>;
|
|
138
|
+
/**
|
|
139
|
+
* Object form of a rule setting. `severity` omitted keeps the rule's built-in
|
|
140
|
+
* severity — the common case when only a threshold is being moved.
|
|
141
|
+
* `{ severity: 'off', … }` disables the rule and any `options` beside it are
|
|
142
|
+
* inert (equivalent to the bare `'off'` string, not an error).
|
|
143
|
+
*/
|
|
144
|
+
interface RuleSettingObject {
|
|
145
|
+
severity?: Severity | 'off';
|
|
146
|
+
options?: RuleOptions;
|
|
147
|
+
}
|
|
148
|
+
/** Per-rule override: disable, change severity, and/or set options. */
|
|
149
|
+
type RuleSetting = 'off' | Severity | RuleSettingObject;
|
|
150
|
+
/**
|
|
151
|
+
* Scoped rule override (design 2026-07-18), applied to results after analysis.
|
|
152
|
+
* An entry matches a finding when any `route` glob matches its route id or any
|
|
153
|
+
* `files` glob matches its source location; at least one of the two must be
|
|
154
|
+
* set. Glob syntax: `*` matches within a segment, `**` across segments, a
|
|
155
|
+
* trailing `/**` also matches the bare prefix, and all other characters
|
|
156
|
+
* (including SvelteKit's `(`, `)`, `[`, `]`) are literal.
|
|
157
|
+
*/
|
|
158
|
+
interface RuleOverride {
|
|
159
|
+
/**
|
|
160
|
+
* Route-id glob(s), e.g. '/admin/**'. Note route ids drop `(group)` segments
|
|
161
|
+
* (`src/routes/(app)/dashboard` reports as '/dashboard') — target a group
|
|
162
|
+
* via `files` instead.
|
|
163
|
+
*/
|
|
164
|
+
route?: string | string[];
|
|
165
|
+
/** Source-path glob(s) matched against a finding's location, e.g. 'src/routes/(app)/**'. */
|
|
166
|
+
files?: string | string[];
|
|
167
|
+
/** Keys are rule ids ('seo/title-presence') or category names ('seo'). Rule id beats category within an entry. */
|
|
168
|
+
rules: Record<string, RuleSetting>;
|
|
169
|
+
}
|
|
170
|
+
interface Config {
|
|
171
|
+
treatDynamicAs: TreatDynamicAs;
|
|
172
|
+
/** Component names treated as meta sources of unknown content (design §11 layer 4). */
|
|
173
|
+
metaComponents: string[];
|
|
174
|
+
/** Per-rule overrides keyed by rule id (design §6). */
|
|
175
|
+
rules: Record<string, RuleSetting>;
|
|
176
|
+
/** Minimum severity that fails the run / CI (design §6). */
|
|
177
|
+
failOn: Severity;
|
|
178
|
+
/** Per-category weights for the combined Health score (default: equal, 1 each) (#10). */
|
|
179
|
+
weights?: Partial<Record<Category, number>>;
|
|
180
|
+
/** Route-/file-scoped rule overrides, applied to results after analysis (later entries win). */
|
|
181
|
+
overrides?: RuleOverride[];
|
|
182
|
+
}
|
|
183
|
+
declare const defaultConfig: Config;
|
|
184
|
+
/** Merge user config over defaults. Identity helper for config files (design §6). */
|
|
185
|
+
declare function defineConfig(config?: Partial<Config>): Config;
|
|
186
|
+
|
|
187
|
+
interface Summary {
|
|
188
|
+
critical: number;
|
|
189
|
+
warning: number;
|
|
190
|
+
info: number;
|
|
191
|
+
/** Passed (not penalized), including dynamic. */
|
|
192
|
+
passed: number;
|
|
193
|
+
/** Subset of passed that resolved dynamically (↯). */
|
|
194
|
+
dynamic: number;
|
|
195
|
+
}
|
|
196
|
+
/** Classify a single result for display/scoring (design §7, §12). */
|
|
197
|
+
type Classification = 'fail' | 'pass' | 'dynamic';
|
|
198
|
+
declare function classify(result: Result, config: Config): Classification;
|
|
199
|
+
/** A penalized dynamic finding is a warning under treatDynamicAs 'warn'; otherwise the rule's severity. */
|
|
200
|
+
declare function effectiveSeverity(result: Result, config: Config): Severity;
|
|
201
|
+
declare function summarize(results: Result[], config: Config): Summary;
|
|
202
|
+
/** Whether the run should fail the build/CI per the minimum failing severity. */
|
|
203
|
+
declare function hasFailureAtOrAbove(summary: Summary, min: Severity): boolean;
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Runtime abstraction (design §8). Core defines only the interface; concrete
|
|
207
|
+
* adapters (Node / Deno / Bun) live in the CLI package and are the only place
|
|
208
|
+
* allowed to touch runtime-specific I/O APIs. Providers and rules use this
|
|
209
|
+
* interface exclusively, which keeps them runtime-agnostic and lets tests inject
|
|
210
|
+
* an in-memory implementation.
|
|
211
|
+
*/
|
|
212
|
+
interface Runtime {
|
|
213
|
+
/** Read a UTF-8 text file. Rejects if the file does not exist. */
|
|
214
|
+
readFile(path: string): Promise<string>;
|
|
215
|
+
/** Whether a path exists. */
|
|
216
|
+
exists(path: string): Promise<boolean>;
|
|
217
|
+
/**
|
|
218
|
+
* Paths matching `pattern`, relative to `cwd`.
|
|
219
|
+
*
|
|
220
|
+
* **Dot files and dot directories are excluded**, and an adapter must keep it that way: the
|
|
221
|
+
* directory-shaped Architecture rules derive their directory set from these paths, and one of them
|
|
222
|
+
* enumerates a parent's children exhaustively, so a `.server/` appearing here would be reported as
|
|
223
|
+
* an undeclared name. Both shipped adapters pass `dot: false`.
|
|
224
|
+
*
|
|
225
|
+
* **Every returned path is a file, never a directory**, and an adapter must keep that true too:
|
|
226
|
+
* `architecture/reserved-directory-names`' unit test takes a directory's immediate children from
|
|
227
|
+
* this same inventory and asks whether one of them is a file named after the directory, so an
|
|
228
|
+
* adapter that let a directory through here would let a bare `Card/Card` satisfy that test as if it
|
|
229
|
+
* were an entry file. Both shipped adapters get this for free from their glob library's default,
|
|
230
|
+
* which returns files only unless asked to include directories.
|
|
231
|
+
*/
|
|
232
|
+
glob(pattern: string, cwd: string): Promise<string[]>;
|
|
233
|
+
/** Join path segments without depending on `node:path`. */
|
|
234
|
+
join(...parts: string[]): string;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* How many file reads may be in flight at once. Analysis reads every `.svelte` file in a project
|
|
238
|
+
* in parallel, which on a large project opens more descriptors than the process is allowed: at
|
|
239
|
+
* `ulimit -n 1024` — a common container default — a 1 681-route project raised `EMFILE`, and
|
|
240
|
+
* because a failed read lands in the same `catch` as a malformed component, 682 files were dropped
|
|
241
|
+
* and the run still reported a normal score. The cap is what keeps the analysis whole.
|
|
242
|
+
*
|
|
243
|
+
* 64 is chosen to sit well under the stock 256 on macOS while leaving descriptors for everything
|
|
244
|
+
* else the process holds open. It is not a throughput knob: reads are a few percent of the work.
|
|
245
|
+
*/
|
|
246
|
+
declare const READ_CONCURRENCY = 64;
|
|
247
|
+
/**
|
|
248
|
+
* `readFile` with at most `limit` reads in flight. A plain counter plus a queue of waiters —
|
|
249
|
+
* deliberately not a dependency, and pure enough to live in core.
|
|
250
|
+
*/
|
|
251
|
+
declare function withReadLimit(readFile: (path: string) => Promise<string>, limit?: number): (path: string) => Promise<string>;
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* A normalized head tag. The mode-independent boundary (design §8): the static
|
|
255
|
+
* SourceHeadProvider (CLI, via the runtime-abstracted `HeadProvider` below) and
|
|
256
|
+
* the rendered collector (`@svelte-vitals/vite`, build-time Node) both emit
|
|
257
|
+
* these, so rules never need to know which mode produced them.
|
|
258
|
+
*/
|
|
259
|
+
interface HeadTag {
|
|
260
|
+
kind: 'title' | 'meta' | 'link' | 'jsonld' | 'script';
|
|
261
|
+
/** <meta name="...">. */
|
|
262
|
+
name?: string;
|
|
263
|
+
/** <meta property="..."> (e.g. og:image). */
|
|
264
|
+
property?: string;
|
|
265
|
+
/** <link rel="...">. */
|
|
266
|
+
rel?: string;
|
|
267
|
+
/** <link as="..."> keyword (e.g. 'font') when statically literal; undefined when absent or dynamically bound. */
|
|
268
|
+
as?: string;
|
|
269
|
+
/** True when a <link> has an `as` attribute at all (literal or dynamic). Distinguishes "no as" from "dynamic as". */
|
|
270
|
+
hasAs?: boolean;
|
|
271
|
+
/** True when a <link> has a `crossorigin` attribute (presence only; value is irrelevant to the checks). */
|
|
272
|
+
hasCrossorigin?: boolean;
|
|
273
|
+
/** True when a <meta name="robots"> literal content contains `noindex`/`none`. Undefined when dynamic or absent. */
|
|
274
|
+
noindex?: boolean;
|
|
275
|
+
/** Literal `<script type="application/ld+json">` content, set only when the script is static. Undefined when dynamic. */
|
|
276
|
+
jsonld?: string;
|
|
277
|
+
/** Literal visible text of a static <title> or <meta name="description"> content, set only when static. Undefined when dynamic. */
|
|
278
|
+
text?: string;
|
|
279
|
+
/** Literal `hreflang` of a `<link rel="alternate">` (e.g. 'en', 'en-US', 'x-default'). Undefined when dynamic/absent. */
|
|
280
|
+
hreflang?: string;
|
|
281
|
+
/** Literal href (link) / src (script) URL when static — used for third-party origin analysis (performance/preconnect). */
|
|
282
|
+
href?: string;
|
|
283
|
+
/** True for a render-blocking `<script src>` in <head> (no defer/async/module) (performance/render-blocking-script). */
|
|
284
|
+
blocking?: boolean;
|
|
285
|
+
/** Where this tag was set relative to the route. Never 'none' (absence = no tag). */
|
|
286
|
+
presence: Exclude<Presence, 'none'>;
|
|
287
|
+
/** Whether the tag's value is static/dynamic/absent (design §4). */
|
|
288
|
+
value: Value;
|
|
289
|
+
/** Source file the tag came from (static mode only). */
|
|
290
|
+
file?: string;
|
|
291
|
+
}
|
|
292
|
+
/** Resolved effective head for a single route (design §8). */
|
|
293
|
+
interface ResolvedHead {
|
|
294
|
+
/** Route path, e.g. '/blog/[slug]'. */
|
|
295
|
+
route: string;
|
|
296
|
+
/** Which provider produced this. */
|
|
297
|
+
source: 'static' | 'rendered';
|
|
298
|
+
/** Effective head tags after layout-chain composition. */
|
|
299
|
+
tags: HeadTag[];
|
|
300
|
+
/** Representative source file for the route (used for issue locations). */
|
|
301
|
+
file: string;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Supplies ResolvedHead[] for a project through the runtime abstraction. The
|
|
305
|
+
* static (CLI) mode implements this; rendered mode reads prerendered HTML at
|
|
306
|
+
* build time and emits the same ResolvedHead[] without the runtime indirection.
|
|
307
|
+
*/
|
|
308
|
+
interface HeadProvider {
|
|
309
|
+
mode: 'static' | 'rendered';
|
|
310
|
+
collect(rt: Runtime, cwd: string, config?: Config): Promise<ResolvedHead[]>;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* A normalized <img> occurrence — the mode-independent boundary for Performance
|
|
315
|
+
* rules (mirrors head.ts). Attribute presence only: a dynamically-bound attribute
|
|
316
|
+
* (width={w}) still counts as present, so dynamic values are never flagged.
|
|
317
|
+
*/
|
|
318
|
+
interface ImageInfo {
|
|
319
|
+
hasWidth: boolean;
|
|
320
|
+
hasHeight: boolean;
|
|
321
|
+
hasLoading: boolean;
|
|
322
|
+
/** True when the <img> has an `alt` attribute at all (incl. empty `alt=""` decorative; seo/image-alt). */
|
|
323
|
+
hasAlt: boolean;
|
|
324
|
+
/** True when the <img> has a literal `loading="lazy"` (performance/lcp-image). Dynamic/spread → false. */
|
|
325
|
+
lazy: boolean;
|
|
326
|
+
/** True when the <img> has a `srcset` attribute (performance/responsive-image). */
|
|
327
|
+
hasSrcset: boolean;
|
|
328
|
+
/** 1-based source line, or 0 if unknown. */
|
|
329
|
+
line: number;
|
|
330
|
+
/** Source file the <img> came from. */
|
|
331
|
+
file: string;
|
|
332
|
+
}
|
|
333
|
+
/** Resolved <img> elements for a single route (page + layout chain). */
|
|
334
|
+
interface ResolvedImages {
|
|
335
|
+
route: string;
|
|
336
|
+
images: ImageInfo[];
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* A normalized page-body heading occurrence — the mode-independent boundary for
|
|
341
|
+
* the heading-hierarchy rule (mirrors images.ts). Both providers collect these
|
|
342
|
+
* so seo/single-h1 never needs to know which mode produced them.
|
|
343
|
+
*/
|
|
344
|
+
interface HeadingInfo {
|
|
345
|
+
/** Heading level 1–6 (the `n` in <hn>). */
|
|
346
|
+
level: number;
|
|
347
|
+
/** 1-based source line, or 0 if unknown (rendered mode does not track lines). */
|
|
348
|
+
line: number;
|
|
349
|
+
/** Source file the heading came from. */
|
|
350
|
+
file: string;
|
|
351
|
+
}
|
|
352
|
+
/** Resolved page-body headings for a single route (page + layout chain). */
|
|
353
|
+
interface ResolvedHeadings {
|
|
354
|
+
route: string;
|
|
355
|
+
headings: HeadingInfo[];
|
|
356
|
+
/**
|
|
357
|
+
* Headings found in child components rendered (transitively) by this route's
|
|
358
|
+
* chain files — source mode only; absent in rendered mode. Kept separate from
|
|
359
|
+
* `headings` because their position in document order is unknown: safe for
|
|
360
|
+
* counting (seo/single-h1), unusable for outline order (seo/heading-level-skip).
|
|
361
|
+
*/
|
|
362
|
+
componentHeadings?: HeadingInfo[];
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/** One step of a template branch address: which exclusive block, and which arm of it. */
|
|
366
|
+
interface BranchStep {
|
|
367
|
+
/** index of the {#if}/{#await} block among its file's blocks (document order) */
|
|
368
|
+
group: number;
|
|
369
|
+
/** branch index within the group (if: 0..n consequent→else; await: 0=pending,1=then,2=catch) */
|
|
370
|
+
branch: number;
|
|
371
|
+
}
|
|
372
|
+
/** Where a folded occurrence sits, for the finding location. */
|
|
373
|
+
interface A11yOccurrenceInfo {
|
|
374
|
+
file: string;
|
|
375
|
+
line: number;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Route-scoped a11y facts, the mode-independent boundary for the landmark/id rules
|
|
379
|
+
* (mirrors headings.ts). Source mode composes the layout chain plus its resolved
|
|
380
|
+
* components; rendered mode reads the prerendered document.
|
|
381
|
+
*/
|
|
382
|
+
interface ResolvedA11y {
|
|
383
|
+
route: string;
|
|
384
|
+
/** representatives per landmark kind after the branch-aware fold ('main' | 'banner' | 'contentinfo' | 'complementary') */
|
|
385
|
+
landmarks: Record<string, A11yOccurrenceInfo[]>;
|
|
386
|
+
/** landmark occurrences nested inside another landmark after composition */
|
|
387
|
+
nestedLandmarks: {
|
|
388
|
+
kind: string;
|
|
389
|
+
within: string;
|
|
390
|
+
file: string;
|
|
391
|
+
line: number;
|
|
392
|
+
}[];
|
|
393
|
+
/** representatives per literal id */
|
|
394
|
+
ids: Record<string, A11yOccurrenceInfo[]>;
|
|
395
|
+
/** literal id references */
|
|
396
|
+
idRefs: {
|
|
397
|
+
id: string;
|
|
398
|
+
attr: string;
|
|
399
|
+
file: string;
|
|
400
|
+
line: number;
|
|
401
|
+
}[];
|
|
402
|
+
/** optimistic candidates: every literal id anywhere (all branches, each/snippet bodies, components, app.html) */
|
|
403
|
+
idCandidates: string[];
|
|
404
|
+
/** closed world holds: every component resolved, no depth truncation, no {@html}/spread, no dynamic id */
|
|
405
|
+
fullyResolved: boolean;
|
|
406
|
+
}
|
|
407
|
+
type Foldable = {
|
|
408
|
+
key: string;
|
|
409
|
+
path: BranchStep[];
|
|
410
|
+
repeatable: boolean;
|
|
411
|
+
};
|
|
412
|
+
/**
|
|
413
|
+
* Branch-aware occurrence fold (design "Control-flow semantics"): within a branch
|
|
414
|
+
* occurrences sum, across the arms of one exclusive block the arm with the most
|
|
415
|
+
* occurrences wins (tie → lowest branch index) and ITS occurrences are the group's
|
|
416
|
+
* representatives — so a caller's count is always `list.length`, with a location per
|
|
417
|
+
* representative. `{#each}`/`{#snippet}` occurrences render 0..N times and drop out.
|
|
418
|
+
* The max is per key: there is no scalar total to maximize.
|
|
419
|
+
*/
|
|
420
|
+
declare function foldOccurrences<T extends Foldable>(nodes: T[]): Map<string, T[]>;
|
|
421
|
+
/**
|
|
422
|
+
* Decode a fragment identifier the way navigation does before matching an element id
|
|
423
|
+
* (`href="#caf%C3%A9"` targets `id="café"`). Malformed escapes are kept verbatim —
|
|
424
|
+
* the browser would also fail to decode them, so the raw text is the comparable form.
|
|
425
|
+
*/
|
|
426
|
+
declare function decodeFragmentId(fragment: string): string;
|
|
427
|
+
/** Whitespace-split tokens of a (possibly undefined) literal attribute value. */
|
|
428
|
+
declare function splitTokens(value: string | undefined): string[];
|
|
429
|
+
/** Explicit `role` values that map to the landmark kinds the route rules inspect. */
|
|
430
|
+
declare const LANDMARK_ROLES: ReadonlySet<string>;
|
|
431
|
+
/** Attributes whose (whitespace-tokenized) values reference element ids. */
|
|
432
|
+
declare const IDREF_ATTRS: readonly string[];
|
|
433
|
+
/**
|
|
434
|
+
* Whether a decoded URL fragment is HTML's "top of the document" indicator: `#top` (ASCII
|
|
435
|
+
* case-insensitive) scrolls to the top when no element has that id, so it is never a missing
|
|
436
|
+
* reference. Compare AFTER percent-decoding — `#%74op` navigates identically to `#top`.
|
|
437
|
+
*/
|
|
438
|
+
declare function isTopFragment(id: string): boolean;
|
|
439
|
+
/**
|
|
440
|
+
* A fragment with its text directive removed. Everything from the first `:~:` on is user-agent
|
|
441
|
+
* instructions for finding text and names no element, while anything before it is still an
|
|
442
|
+
* ordinary element fragment — `#section:~:text=hi` targets `id="section"`, `#:~:text=hi` targets
|
|
443
|
+
* nothing. Returns an empty string when the fragment is a directive and nothing else.
|
|
444
|
+
*/
|
|
445
|
+
declare function stripTextDirective(fragment: string): string;
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Component-body facts for the Correctness category — the source-analysis boundary
|
|
449
|
+
* (mirrors images.ts / headings.ts). Collected by the static (CLI) provider only;
|
|
450
|
+
* the rendered provider can't see reactivity, so correctness rules no-op there.
|
|
451
|
+
*/
|
|
452
|
+
/** An `{#each}` block in a component template. */
|
|
453
|
+
interface EachBlockFact {
|
|
454
|
+
/** True when the block has a key, e.g. `{#each items as item (item.id)}`. */
|
|
455
|
+
hasKey: boolean;
|
|
456
|
+
/** 1-based source line, or 0 if unknown. */
|
|
457
|
+
line: number;
|
|
458
|
+
/** Set when the block's key expression is its index binding or a trivial coercion of it — `(i)`, `(String(i))`, `(Number(i))`, `` (`${i}`) ``, `(i.toString())`, `(i + '')` — correctness/each-index-key. */
|
|
459
|
+
indexKey?: boolean;
|
|
460
|
+
}
|
|
461
|
+
/** An `$effect(...)` / `$effect.pre(...)` call in a component's instance script. */
|
|
462
|
+
interface EffectFact {
|
|
463
|
+
/** 1-based source line, or 0 if unknown. */
|
|
464
|
+
line: number;
|
|
465
|
+
/** True when the effect body only assigns to `$state` variables (the "use $derived" smell). */
|
|
466
|
+
assignsOnlyState: boolean;
|
|
467
|
+
/** True when this $effect has a NON-EMPTY body that reads no reactive value and makes no bare call — it never re-runs, so it should be onMount (correctness/effect-as-onmount). */
|
|
468
|
+
mountOnly: boolean;
|
|
469
|
+
}
|
|
470
|
+
/** A `$effect` guaranteed to run outside component initialisation — it throws `effect_orphan` at runtime (correctness/orphan-effect). */
|
|
471
|
+
interface OrphanEffectFact {
|
|
472
|
+
/** 1-based source line, or 0 if unknown. For 'constructor-instantiated', the module-scope `new` site. */
|
|
473
|
+
line: number;
|
|
474
|
+
/** 'top-level' = runs at module evaluation; 'constructor-instantiated' = module-scope `new` of a same-file class whose constructor creates a bare effect. */
|
|
475
|
+
kind: 'top-level' | 'constructor-instantiated';
|
|
476
|
+
/** Class name when kind is 'constructor-instantiated' (used in the finding message). */
|
|
477
|
+
className?: string;
|
|
478
|
+
}
|
|
479
|
+
/** A svelte lifecycle/context call guaranteed to run outside component initialisation — it throws `lifecycle_outside_component` at runtime (correctness/orphan-lifecycle). */
|
|
480
|
+
interface OrphanLifecycleCallFact {
|
|
481
|
+
/** Canonical svelte export name (alias-resolved), e.g. 'onMount'. */
|
|
482
|
+
name: string;
|
|
483
|
+
/** 1-based source line, or 0 if unknown. For 'constructor-instantiated', the module-scope `new` site. */
|
|
484
|
+
line: number;
|
|
485
|
+
/** 'top-level' = runs at module evaluation; 'constructor-instantiated' = module-scope `new` of a same-file class whose constructor calls a tracked function. */
|
|
486
|
+
kind: 'top-level' | 'constructor-instantiated';
|
|
487
|
+
/** Class name when kind is 'constructor-instantiated' (used in the finding message). */
|
|
488
|
+
className?: string;
|
|
489
|
+
}
|
|
490
|
+
/** A browser-only global read in code that runs on the server — SSR crashes with "<name> is not defined" (correctness/server-browser-global, correctness/instance-browser-global). */
|
|
491
|
+
interface BrowserGlobalRefFact {
|
|
492
|
+
/** The global's name, e.g. 'window'. */
|
|
493
|
+
name: string;
|
|
494
|
+
/** 1-based source line, or 0 if unknown. */
|
|
495
|
+
line: number;
|
|
496
|
+
/** 'module' = module evaluation (script module / runes module — correctness/server-browser-global); 'instance' = component-init top level (runs on the server during SSR — correctness/instance-browser-global). */
|
|
497
|
+
context: 'module' | 'instance';
|
|
498
|
+
}
|
|
499
|
+
/** A flagged source position in a component (e.g. an `{@html}` tag or a `javascript:` URL). */
|
|
500
|
+
interface SourceSpan {
|
|
501
|
+
/** 1-based source line, or 0 if unknown. */
|
|
502
|
+
line: number;
|
|
503
|
+
}
|
|
504
|
+
/** An inline `svelte-vitals-disable-next-line` directive found in the component's source (issue #92). */
|
|
505
|
+
interface SuppressionDirective {
|
|
506
|
+
/** 1-based line the directive suppresses (the line immediately after the comment). */
|
|
507
|
+
line: number;
|
|
508
|
+
/** Rule ids suppressed on that line; undefined = suppress every rule on that line. */
|
|
509
|
+
ruleIds?: string[];
|
|
510
|
+
}
|
|
511
|
+
/** An `<input type="checkbox">` / `<input type="radio">` element carrying a `bind:value`
|
|
512
|
+
* directive — `bind:value` observes the DOM `value` property, which checkbox/radio
|
|
513
|
+
* interaction never changes, so the bound state silently never updates
|
|
514
|
+
* (correctness/checkable-bind-value). */
|
|
515
|
+
interface CheckableBindValueFact {
|
|
516
|
+
/** Which checkable input type was flagged — selects the message wording. */
|
|
517
|
+
kind: 'checkbox' | 'radio';
|
|
518
|
+
/** 1-based source line, or 0 if unknown. */
|
|
519
|
+
line: number;
|
|
520
|
+
}
|
|
521
|
+
/** A root-relative navigation literal — broken when the app is served under `kit.paths.base`
|
|
522
|
+
* (correctness/base-path-navigation). Shared by the component and Kit-module channels. */
|
|
523
|
+
interface BasePathLinkFact {
|
|
524
|
+
/** Which navigation surface it was written on — selects the message wording. */
|
|
525
|
+
kind: 'href' | 'goto' | 'redirect';
|
|
526
|
+
/** The literal path as written, e.g. '/about'. */
|
|
527
|
+
path: string;
|
|
528
|
+
/** 1-based source line, or 0 if unknown. */
|
|
529
|
+
line: number;
|
|
530
|
+
}
|
|
531
|
+
/** An interactive element (e.g. `<button>`) found nested inside another interactive
|
|
532
|
+
* container (e.g. `<a href>`) (a11y/interactive-nesting). */
|
|
533
|
+
interface InteractiveNestingFact {
|
|
534
|
+
containerTag: string;
|
|
535
|
+
/** The container's literal `role`, when that is what made it a container rather than its tag. */
|
|
536
|
+
containerRole?: string;
|
|
537
|
+
descendantTag: string;
|
|
538
|
+
/** 1-based source line of the descendant, or 0 if unknown. */
|
|
539
|
+
line: number;
|
|
540
|
+
}
|
|
541
|
+
/** A `button`/`a href`/`input type="image"` with no computable accessible name (a11y/accessible-name). */
|
|
542
|
+
interface UnnamedInteractiveFact {
|
|
543
|
+
tag: string;
|
|
544
|
+
/** 1-based source line, or 0 if unknown. */
|
|
545
|
+
line: number;
|
|
546
|
+
}
|
|
547
|
+
/** An element carrying a `role` and/or `aria-*` attribute(s) (a11y ARIA rules). */
|
|
548
|
+
interface AriaElementFact {
|
|
549
|
+
tag: string;
|
|
550
|
+
/** 1-based source line, or 0 if unknown. */
|
|
551
|
+
line: number;
|
|
552
|
+
/** literal role value; undefined = no role attr; { expression: true } = dynamic */
|
|
553
|
+
role?: {
|
|
554
|
+
literal?: string;
|
|
555
|
+
expression?: boolean;
|
|
556
|
+
};
|
|
557
|
+
/** every aria-* attribute on the element */
|
|
558
|
+
aria: {
|
|
559
|
+
name: string;
|
|
560
|
+
literal?: string;
|
|
561
|
+
expression?: boolean;
|
|
562
|
+
line: number;
|
|
563
|
+
}[];
|
|
564
|
+
/** literal `type` of an `<input>`, lowercased; undefined for non-inputs or a dynamic type */
|
|
565
|
+
inputType?: string;
|
|
566
|
+
/** Set when the element also carries a spread attribute — its full attribute set is
|
|
567
|
+
* unknowable, so required-prop presence checks must treat it as satisfied (a11y/required-aria-props). */
|
|
568
|
+
hasSpread?: true;
|
|
569
|
+
}
|
|
570
|
+
/** Reactivity/correctness + security + architecture facts parsed from one `.svelte` component. */
|
|
571
|
+
interface ComponentFacts {
|
|
572
|
+
/** Source file the component came from. */
|
|
573
|
+
file: string;
|
|
574
|
+
eachBlocks: EachBlockFact[];
|
|
575
|
+
effects: EffectFact[];
|
|
576
|
+
/** `{@html …}` occurrences — raw-HTML render surfaces (security/raw-html). */
|
|
577
|
+
htmlTags: SourceSpan[];
|
|
578
|
+
/** Element attributes with a literal `javascript:` URL (security/javascript-url). */
|
|
579
|
+
javascriptUrls: SourceSpan[];
|
|
580
|
+
/** Source line count of the component file (architecture/component-size). */
|
|
581
|
+
loc: number;
|
|
582
|
+
/** Named props destructured from `$props()`; 0 when unknowable (rest / non-destructured) (architecture/prop-count). */
|
|
583
|
+
propCount: number;
|
|
584
|
+
/** Module specifiers of every `import` in the instance + module scripts (performance/heavy-import). */
|
|
585
|
+
imports: string[];
|
|
586
|
+
/**
|
|
587
|
+
* Module specifiers of every `import`, each with its source line (performance/heavy-import,
|
|
588
|
+
* architecture/route-component-import). `type` marks a declaration that contributes **no runtime
|
|
589
|
+
* value binding** — either `import type …`, or one whose every specifier is inline-typed
|
|
590
|
+
* (`import { type A } from …`). A specifier-less side-effect import is not marked: it still loads
|
|
591
|
+
* the module. Optional, so existing external constructors of `ComponentFacts` are unaffected.
|
|
592
|
+
*/
|
|
593
|
+
importSpans: {
|
|
594
|
+
source: string;
|
|
595
|
+
line: number;
|
|
596
|
+
type?: true;
|
|
597
|
+
}[];
|
|
598
|
+
/** Value `import * as X from '<bare pkg>'` namespace imports (type-only excluded) — performance/namespace-import. */
|
|
599
|
+
namespaceImports: {
|
|
600
|
+
source: string;
|
|
601
|
+
line: number;
|
|
602
|
+
}[];
|
|
603
|
+
/** `$state` declarations never written or escaped anywhere in the component — candidates for const (correctness/unmutated-state). */
|
|
604
|
+
constableStates: {
|
|
605
|
+
name: string;
|
|
606
|
+
line: number;
|
|
607
|
+
}[];
|
|
608
|
+
/** Mutations of a non-`$bindable` prop from `$props()`, or a legacy `export let` prop — member writes, `delete`, or a mutating method call (correctness/prop-mutation). `legacy` distinguishes which mode the prop was declared in (absent/false: `$props()`), since the fix differs — optional so existing external constructors of `ComponentFacts` are unaffected. */
|
|
609
|
+
mutatedProps: {
|
|
610
|
+
name: string;
|
|
611
|
+
line: number;
|
|
612
|
+
legacy?: boolean;
|
|
613
|
+
}[];
|
|
614
|
+
/** Top-level const/let bindings computed from a $props() or legacy `export let` prop without $derived (or `$:`), never reassigned or escaped, and referenced (eagerly) in the template — frozen at init (correctness/stale-prop-derivation). `legacy` distinguishes which mode the prop was declared in, since the fix differs — optional so existing external constructors of `ComponentFacts` are unaffected. */
|
|
615
|
+
stalePropDerivations: {
|
|
616
|
+
name: string;
|
|
617
|
+
line: number;
|
|
618
|
+
legacy?: boolean;
|
|
619
|
+
}[];
|
|
620
|
+
/** Object/array-literal $state bindings reassigned at least once but never mutated, escaped, aliased, or item-edited — $state.raw candidates (performance/state-raw). */
|
|
621
|
+
rawableStates: {
|
|
622
|
+
name: string;
|
|
623
|
+
line: number;
|
|
624
|
+
}[];
|
|
625
|
+
/** Plain built-in instances (Map/Set/Date/URL/URLSearchParams) in $state whose type-specific mutations were observed inside functions, with no exempting reassignment — untracked by reactivity (correctness/nonreactive-builtin-state). */
|
|
626
|
+
nonreactiveBuiltinStates: {
|
|
627
|
+
name: string;
|
|
628
|
+
type: string;
|
|
629
|
+
line: number;
|
|
630
|
+
}[];
|
|
631
|
+
/** `<input type="checkbox">` / `<input type="radio">` elements bound with `bind:value`
|
|
632
|
+
* instead of `bind:checked`/`bind:group` (correctness/checkable-bind-value). */
|
|
633
|
+
checkableBindValues: CheckableBindValueFact[];
|
|
634
|
+
/** Root-relative `<a href>` and `goto()` literals in this component (correctness/base-path-navigation). */
|
|
635
|
+
basePathLinks: BasePathLinkFact[];
|
|
636
|
+
/** `$effect` calls guaranteed to run outside component initialisation — module scope in `.svelte.ts`/`.svelte.js` or `<script module>` (correctness/orphan-effect). */
|
|
637
|
+
orphanEffects: OrphanEffectFact[];
|
|
638
|
+
/** Svelte lifecycle/context calls guaranteed to run outside component initialisation — module scope in `.svelte.ts`/`.svelte.js` or `<script module>` (correctness/orphan-lifecycle). */
|
|
639
|
+
orphanLifecycleCalls: OrphanLifecycleCallFact[];
|
|
640
|
+
/** Browser-global reads in server-executed positions of this file (correctness/server-browser-global, correctness/instance-browser-global). */
|
|
641
|
+
browserGlobalRefs: BrowserGlobalRefFact[];
|
|
642
|
+
/** Module-scope `$state` declarations in a `.svelte.ts`/`.svelte.js` runes module — on a server, one instance shared by every request (security/shared-state-import). Always empty for `.svelte` files. */
|
|
643
|
+
moduleStateDecls: {
|
|
644
|
+
name: string;
|
|
645
|
+
line: number;
|
|
646
|
+
}[];
|
|
647
|
+
/** Inline `svelte-vitals-disable-next-line` directives found in this file's source — component-rule escape hatch (issue #92). Optional: absent is equivalent to no directives, so existing external constructors of `ComponentFacts` are unaffected. */
|
|
648
|
+
suppressions?: SuppressionDirective[];
|
|
649
|
+
/** Markdown links `[label](url)` appearing inside a comment (architecture/doc-link-target). */
|
|
650
|
+
commentLinks: {
|
|
651
|
+
url: string;
|
|
652
|
+
line: number;
|
|
653
|
+
}[];
|
|
654
|
+
/** Elements carrying a role or any aria-* attribute (a11y ARIA rules). */
|
|
655
|
+
ariaElements?: AriaElementFact[];
|
|
656
|
+
/** Interactive elements nested inside another interactive container (a11y/interactive-nesting). */
|
|
657
|
+
interactiveNestings?: InteractiveNestingFact[];
|
|
658
|
+
/** `button`/`a href`/`input type="image"` elements with no computable accessible name (a11y/accessible-name). */
|
|
659
|
+
unnamedInteractive?: UnnamedInteractiveFact[];
|
|
660
|
+
/** `<label>` elements with neither a `for` attribute nor a wrapped labelable descendant (a11y/label-has-control). */
|
|
661
|
+
unassociatedLabels?: {
|
|
662
|
+
line: number;
|
|
663
|
+
}[];
|
|
664
|
+
/** Text nodes whose trimmed content opens with a bullet character followed by whitespace, outside any `li` (a11y/use-list). */
|
|
665
|
+
bulletTexts?: {
|
|
666
|
+
line: number;
|
|
667
|
+
char: string;
|
|
668
|
+
}[];
|
|
669
|
+
/** `<select required>` (no `multiple`, display size absent or ≤ 1) whose first `option` element
|
|
670
|
+
* child is not a placeholder label option (a11y/placeholder-label-option). */
|
|
671
|
+
selectsMissingPlaceholder?: {
|
|
672
|
+
line: number;
|
|
673
|
+
}[];
|
|
674
|
+
/** `<time>` with no `datetime` attribute whose literal text content is not machine-readable (a11y/require-datetime). */
|
|
675
|
+
timesMissingDatetime?: {
|
|
676
|
+
line: number;
|
|
677
|
+
text: string;
|
|
678
|
+
}[];
|
|
679
|
+
/** Set when the file failed to read or parse and these facts are the empty fallback — the file was NOT analyzed. */
|
|
680
|
+
parseFailed?: true;
|
|
681
|
+
/** Set when the file could not be READ — an environment problem (permissions, a descriptor
|
|
682
|
+
* limit), not a malformed component. Reported separately so one does not masquerade as the other. */
|
|
683
|
+
readFailed?: true;
|
|
684
|
+
}
|
|
685
|
+
/**
|
|
686
|
+
* Warnings for files a collector could not read or parse: the file contributes empty facts, so any
|
|
687
|
+
* findings it would have produced are simply missing rather than reported as fixed. The two causes
|
|
688
|
+
* are reported separately — an unreadable file is an environment problem (permissions, a descriptor
|
|
689
|
+
* limit) and a malformed one is the author's, and sharing a message is how a descriptor limit once
|
|
690
|
+
* read as hundreds of broken components. Capped at 10 inline paths so one badly-broken directory
|
|
691
|
+
* cannot flood the terminal.
|
|
692
|
+
*/
|
|
693
|
+
declare function skippedFileWarnings(facts: readonly {
|
|
694
|
+
file: string;
|
|
695
|
+
parseFailed?: true;
|
|
696
|
+
readFailed?: true;
|
|
697
|
+
}[]): string[];
|
|
698
|
+
|
|
699
|
+
/**
|
|
700
|
+
* Facts parsed from one SvelteKit route/hooks file for the SSR shared-state rules
|
|
701
|
+
* (the security kit-module rules). Collected by `collectKitModuleFacts` (static/CLI + vite build mode).
|
|
702
|
+
*/
|
|
703
|
+
interface KitModuleFacts {
|
|
704
|
+
/** Repo-relative source file. */
|
|
705
|
+
file: string;
|
|
706
|
+
/** 'server' = runs only on the server (+*.server, +server, hooks.server); 'universal' = +page.ts/+layout.ts (still runs on the server during SSR). */
|
|
707
|
+
kind: 'server' | 'universal';
|
|
708
|
+
/** Module-scope let/var reassigned from inside a function (security/server-module-state). */
|
|
709
|
+
moduleStateReassignments: {
|
|
710
|
+
name: string;
|
|
711
|
+
line: number;
|
|
712
|
+
inHandler: boolean;
|
|
713
|
+
}[];
|
|
714
|
+
/** Writes to an imported binding from inside an exported handler (security/handler-state-write). */
|
|
715
|
+
importedStateWrites: {
|
|
716
|
+
name: string;
|
|
717
|
+
line: number;
|
|
718
|
+
via: 'assignment' | 'set-call';
|
|
719
|
+
}[];
|
|
720
|
+
/** Writes to an imported binding outside handlers — top level or helper functions (security/shared-state-import's write flavour). */
|
|
721
|
+
importedStateWritesOutsideHandlers: {
|
|
722
|
+
name: string;
|
|
723
|
+
line: number;
|
|
724
|
+
}[];
|
|
725
|
+
/**
|
|
726
|
+
* `.set()`/`.update()` in a handler on an import resolving under the `$lib` server root.
|
|
727
|
+
* The call shape alone cannot tell a persistence client (`db.set(…)`) from a hand-rolled
|
|
728
|
+
* in-memory store, so the decision needs the target module — which this pure parse cannot
|
|
729
|
+
* read. `collectKitModuleFacts` resolves each one and promotes the in-memory ones into
|
|
730
|
+
* `importedStateWrites`; a consumer that ignores this field sees the pre-arbitration
|
|
731
|
+
* behaviour, i.e. every one of these exempt.
|
|
732
|
+
*/
|
|
733
|
+
pendingServerStoreWrites: {
|
|
734
|
+
name: string;
|
|
735
|
+
imported: string;
|
|
736
|
+
resolved: string;
|
|
737
|
+
line: number;
|
|
738
|
+
}[];
|
|
739
|
+
/** Value imports whose specifier resolves to a repo-local `.svelte.ts`/`.svelte.js` runes module (security/shared-state-import). */
|
|
740
|
+
runesModuleImports: {
|
|
741
|
+
source: string;
|
|
742
|
+
resolved: string;
|
|
743
|
+
names: string[];
|
|
744
|
+
line: number;
|
|
745
|
+
}[];
|
|
746
|
+
/** Svelte lifecycle/context calls that run outside component initialisation — top level, handler bodies, or the `init` hook (correctness/orphan-lifecycle). */
|
|
747
|
+
lifecycleCalls: {
|
|
748
|
+
name: string;
|
|
749
|
+
line: number;
|
|
750
|
+
inHandler: boolean;
|
|
751
|
+
}[];
|
|
752
|
+
/** Browser-global reads in server-executed positions — top level, handler bodies, the `init` hook (correctness/server-browser-global). Empty when the file itself exports `ssr = false`. */
|
|
753
|
+
browserGlobalRefs: {
|
|
754
|
+
name: string;
|
|
755
|
+
line: number;
|
|
756
|
+
inHandler: boolean;
|
|
757
|
+
}[];
|
|
758
|
+
/** Root-relative `redirect()` literals in this Kit module (correctness/base-path-navigation). */
|
|
759
|
+
basePathLinks: BasePathLinkFact[];
|
|
760
|
+
/** Set when this file disables SSR via `export const ssr = false` (inline or same-file alias export) — the declaration's line (seo/ssr-disabled). */
|
|
761
|
+
ssrDisabled?: {
|
|
762
|
+
line: number;
|
|
763
|
+
};
|
|
764
|
+
/** Set when this file disables client-side rendering via `export const csr = false` (inline or same-file alias export). With no client runtime, a universal load only runs during SSR — performance/load-waterfall's browser-waterfall premise doesn't hold. */
|
|
765
|
+
csrDisabled?: {
|
|
766
|
+
line: number;
|
|
767
|
+
};
|
|
768
|
+
/** Sequential-await analysis of the exported `load` function (performance/load-waterfall, performance/sequential-awaits): 1-based lines of await sites that depend on an earlier await's result, and of sites independent of all earlier awaits. Set only when at least one list is non-empty. */
|
|
769
|
+
loadWaterfalls?: {
|
|
770
|
+
dependentLines: number[];
|
|
771
|
+
independentLines: number[];
|
|
772
|
+
};
|
|
773
|
+
/** Inline `svelte-vitals-disable-next-line` directives in this file. */
|
|
774
|
+
suppressions: SuppressionDirective[];
|
|
775
|
+
/** Set when the file failed to read or parse and these facts are the empty fallback — the file was NOT analyzed. */
|
|
776
|
+
parseFailed?: true;
|
|
777
|
+
/** Set when the file could not be READ — an environment problem, not a malformed module. */
|
|
778
|
+
readFailed?: true;
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
/** The severity a setting selects: `'off'`, an explicit severity, or undefined (leave the built-in). */
|
|
782
|
+
declare function settingSeverity(setting: RuleSetting | undefined): Severity | 'off' | undefined;
|
|
783
|
+
/** The options a setting carries, or undefined for the string forms. */
|
|
784
|
+
declare function settingOptions(setting: RuleSetting | undefined): RuleOptions | undefined;
|
|
785
|
+
/** Drop rules disabled via config (design §6). */
|
|
786
|
+
declare function selectRules(rules: Rule[], config: Config): Rule[];
|
|
787
|
+
/**
|
|
788
|
+
* `config` with `failedRuleIds` (from `runRules`' `failedRules`) forced `'off'`: a rule that threw
|
|
789
|
+
* examined nothing, so leaving it in the inventory would score it as if it had run clean, silently
|
|
790
|
+
* inflating Health. Reuses the exact mechanism a `rules: { id: 'off' }` config entry already gets —
|
|
791
|
+
* `selectRules`/`buildInventory` both drop an `'off'` id from the denominator — rather than adding a
|
|
792
|
+
* second, parallel notion of "not counted" for callers to keep in sync.
|
|
793
|
+
*/
|
|
794
|
+
declare function withFailedRulesOff(config: Config, failedRuleIds: readonly string[]): Config;
|
|
795
|
+
/** One-line "rule failed and was skipped" warning; capped to the message's first line so a stack trace can't flood a terminal. */
|
|
796
|
+
declare function formatFailedRuleWarning(f: {
|
|
797
|
+
id: string;
|
|
798
|
+
message: string;
|
|
799
|
+
}): string;
|
|
800
|
+
/** Apply per-rule severity overrides to results (design §6). */
|
|
801
|
+
declare function applyRuleSeverities(results: Result[], config: Config): Result[];
|
|
802
|
+
/** An override entry with its globs compiled once. Build with `compileOverrides`. */
|
|
803
|
+
interface CompiledOverride {
|
|
804
|
+
routes: RegExp[];
|
|
805
|
+
files: RegExp[];
|
|
806
|
+
rules: Record<string, RuleSetting>;
|
|
807
|
+
}
|
|
808
|
+
/**
|
|
809
|
+
* Compile every override entry's globs to RegExp, once. Callers that match many
|
|
810
|
+
* targets (every component, every route) must hoist this out of their loop.
|
|
811
|
+
*/
|
|
812
|
+
declare function compileOverrides(config: Config): CompiledOverride[];
|
|
813
|
+
/**
|
|
814
|
+
* Whether an override entry applies to a target. THE single definition of that
|
|
815
|
+
* question — the result post-pass and in-run option resolution both call it.
|
|
816
|
+
* Sharing this matcher is necessary but not sufficient for a severity override
|
|
817
|
+
* and an option override to select the same files: each caller must also pass
|
|
818
|
+
* the same `target` (route and, critically, `file`) the other path effectively
|
|
819
|
+
* matches against. See Finding 1, docs/superpowers/specs/2026-07-26-rule-options-design.md.
|
|
820
|
+
*/
|
|
821
|
+
declare function overrideMatches(o: CompiledOverride, target: {
|
|
822
|
+
route?: string;
|
|
823
|
+
file?: string;
|
|
824
|
+
}): boolean;
|
|
825
|
+
/**
|
|
826
|
+
* Apply route-/file-scoped overrides to results (design 2026-07-18). An entry
|
|
827
|
+
* matches when any `route` glob matches the finding's route id or any `files`
|
|
828
|
+
* glob matches its location (OR). `'off'` removes a matched result entirely —
|
|
829
|
+
* passing seeds included, so scoring and "checks passed" counts behave as if
|
|
830
|
+
* the rule never ran there. A severity value rewrites the result's severity.
|
|
831
|
+
* Entries are evaluated in order (later entries win); within one entry, a
|
|
832
|
+
* rule-id key beats a category key only when it specifies a `severity` — an
|
|
833
|
+
* options-only rule-id key (no `severity`) contributes its options but leaves
|
|
834
|
+
* the category key's severity in force, rather than shadowing it (design
|
|
835
|
+
* 2026-07-26, Finding 2 / second review Finding E).
|
|
836
|
+
*/
|
|
837
|
+
declare function applyOverrides(results: Result[], config: Config): Result[];
|
|
838
|
+
|
|
839
|
+
/**
|
|
840
|
+
* Per-rule options: their declaration, resolution, and validation (design
|
|
841
|
+
* 2026-07-26). Deliberately does not import `rule.ts` — `rule.ts` imports
|
|
842
|
+
* `RuleOptionsSpec` from here, so taking `Rule` as a parameter would cycle.
|
|
843
|
+
* Callers pass the id and the spec instead.
|
|
844
|
+
*/
|
|
845
|
+
|
|
846
|
+
/**
|
|
847
|
+
* One configurable option. `kind` decides the merge semantics, so no rule
|
|
848
|
+
* writes merge code of its own: `integer` replaces, and the two collection
|
|
849
|
+
* kinds ADD to the built-in default (never replace — see the design doc).
|
|
850
|
+
*/
|
|
851
|
+
type RuleOptionSpec = {
|
|
852
|
+
kind: 'integer';
|
|
853
|
+
default: number;
|
|
854
|
+
min?: number;
|
|
855
|
+
max?: number;
|
|
856
|
+
} | {
|
|
857
|
+
kind: 'string-list';
|
|
858
|
+
default: readonly string[];
|
|
859
|
+
} | {
|
|
860
|
+
kind: 'string-map';
|
|
861
|
+
default: Readonly<Record<string, string>>;
|
|
862
|
+
};
|
|
863
|
+
/** A rule's configurable options, keyed by option name. */
|
|
864
|
+
type RuleOptionsSpec = Record<string, RuleOptionSpec>;
|
|
865
|
+
/**
|
|
866
|
+
* Typed reads of a resolved options object. `RuleOptions` values are `unknown`
|
|
867
|
+
* (the map is open-ended by design), so without these every rule would carry
|
|
868
|
+
* its own `o.max as number` cast and the "resolution guarantees the declared
|
|
869
|
+
* kind" invariant would live in a dozen places instead of one. `resolveRuleOptions`
|
|
870
|
+
* always seeds every declared key from the spec default and validation rejects a
|
|
871
|
+
* wrongly-typed value up front, so a mismatch here means a rule read a key it
|
|
872
|
+
* never declared — the `fallback` keeps that a wrong number rather than a crash.
|
|
873
|
+
*/
|
|
874
|
+
declare function intOption(options: RuleOptions, key: string, fallback?: number): number;
|
|
875
|
+
/** As `intOption`, for a `string-list` option. */
|
|
876
|
+
declare function listOption(options: RuleOptions, key: string): string[];
|
|
877
|
+
/** As `intOption`, for a `string-map` option. */
|
|
878
|
+
declare function mapOption(options: RuleOptions, key: string): Record<string, string>;
|
|
879
|
+
/**
|
|
880
|
+
* Whether any config layer so much as mentions `ruleId` — its `rules` entry, or any `overrides`
|
|
881
|
+
* entry's.
|
|
882
|
+
*
|
|
883
|
+
* A rule that is inert until declared can return early on `false` instead of resolving options once
|
|
884
|
+
* per target and discarding the result. That waste is not hypothetical: the three directory-shaped
|
|
885
|
+
* Architecture rules resolve per directory, so an unconfigured project pays it for every directory
|
|
886
|
+
* under `src/` three times over, on every dev-server save. Measured 2026-07-30 over a synthetic tree
|
|
887
|
+
* of 1,523 directories: 5.4 ms per analysis, for rules that are off by default and therefore produce
|
|
888
|
+
* nothing.
|
|
889
|
+
*
|
|
890
|
+
* Deliberately conservative. It asks only whether the rule is *mentioned*, not whether the mention
|
|
891
|
+
* resolves to a non-empty value, so a `'off'` severity with no options still answers `true` and the
|
|
892
|
+
* caller does its normal work. A cheaper-but-wrong version of this would make a rule skip work it
|
|
893
|
+
* owed; this one can only ever fail to save time.
|
|
894
|
+
*/
|
|
895
|
+
declare function isMentionedAnywhere(config: Config, ruleId: string): boolean;
|
|
896
|
+
/**
|
|
897
|
+
* Effective options for a rule at a target: built-in defaults, then
|
|
898
|
+
* `config.rules[ruleId].options`, then every matching `config.overrides` entry
|
|
899
|
+
* in order. Integers take the last value; lists and maps accumulate.
|
|
900
|
+
*
|
|
901
|
+
* `target` omitted skips overrides entirely (project-scoped rules). Callers
|
|
902
|
+
* resolving many targets should hoist `compileOverrides(config)` and pass it as
|
|
903
|
+
* `compiled` — otherwise every call recompiles the globs.
|
|
904
|
+
*/
|
|
905
|
+
declare function resolveRuleOptions(ruleId: string, spec: RuleOptionsSpec | undefined, config: Config, target?: {
|
|
906
|
+
route?: string;
|
|
907
|
+
file?: string;
|
|
908
|
+
}, compiled?: CompiledOverride[]): RuleOptions;
|
|
909
|
+
/**
|
|
910
|
+
* Problems with a user-supplied options object, as human-readable sentences
|
|
911
|
+
* (empty = valid). Callers treat any result as fatal: a typo that silently
|
|
912
|
+
* leaves the config inert is the failure this exists to prevent.
|
|
913
|
+
*
|
|
914
|
+
* `baseline`, when given, is the already-resolved value this `options` layer
|
|
915
|
+
* is being merged onto — built-in defaults merged with any earlier layer(s)
|
|
916
|
+
* (e.g. the global `config.rules[id].options`, when `options` is an
|
|
917
|
+
* `overrides[]` entry). The min/max cross-check below compares against it
|
|
918
|
+
* instead of the spec's own default, so a layer that only sets one side of a
|
|
919
|
+
* range is checked against what it actually inherits (design 2026-07-26
|
|
920
|
+
* review, Finding A). Omit it to check `options` against the spec defaults
|
|
921
|
+
* alone, as when validating the global layer itself. A `baseline` that is
|
|
922
|
+
* only partially resolved (missing `min` or `max`) is treated as "can't
|
|
923
|
+
* determine that side" rather than silently comparing against `undefined` —
|
|
924
|
+
* see the `typeof` guard below.
|
|
925
|
+
*
|
|
926
|
+
* `skipRangeCheck`, when true, skips the min/max cross-check entirely
|
|
927
|
+
* regardless of `baseline`. A caller sets this when it statically cannot
|
|
928
|
+
* rule out that some *other* config layer narrows the opposite side of the
|
|
929
|
+
* range at the same target — see the CLI's and the Vite plugin's
|
|
930
|
+
* `overrides[]` validation (design 2026-07-26 review, Finding A, third
|
|
931
|
+
* pass).
|
|
932
|
+
*/
|
|
933
|
+
declare function validateRuleOptions(ruleId: string, spec: RuleOptionsSpec | undefined, options: RuleOptions, baseline?: RuleOptions, skipRangeCheck?: boolean): string[];
|
|
934
|
+
/**
|
|
935
|
+
* Whether `validateRuleOptions` should skip the min/max cross-check for
|
|
936
|
+
* `overrides[selfIndex].rules[key]` — the whole decision, so the CLI's
|
|
937
|
+
* config-file loader and the Vite plugin can't drift apart on it (they held
|
|
938
|
+
* line-for-line copies of it before).
|
|
939
|
+
*
|
|
940
|
+
* An entry that sets both sides, or neither, is judged against its baseline as
|
|
941
|
+
* usual. An entry that sets only one side is skipped when some *other* entry
|
|
942
|
+
* sets the opposite side, since the two may co-apply at a shared target and be
|
|
943
|
+
* valid there — see `otherOverrideNarrowsOppositeSide` for why that is
|
|
944
|
+
* conservative by necessity and what it lets through.
|
|
945
|
+
*/
|
|
946
|
+
declare function shouldSkipRangeCheck(overrides: readonly unknown[], selfIndex: number, key: string, setting: unknown): boolean;
|
|
947
|
+
/**
|
|
948
|
+
* Problems with one user-supplied rule setting — the bare severity string or the
|
|
949
|
+
* object form — as human-readable sentences prefixed with `label` (empty = valid).
|
|
950
|
+
* THE single definition of what a setting may look like: the CLI's config-file
|
|
951
|
+
* loader and the Vite plugin both funnel through it, so a config file and the
|
|
952
|
+
* equivalent plugin option are accepted or rejected identically. Callers treat any
|
|
953
|
+
* result as fatal, on the same reasoning as an unknown rule id — a typo that
|
|
954
|
+
* silently leaves the config inert is the failure being prevented.
|
|
955
|
+
*
|
|
956
|
+
* `label` names the setting in the message (e.g. `rules.seo/title-length`,
|
|
957
|
+
* `overrides[0].rules.architecture`); `ruleId` is the key options messages quote.
|
|
958
|
+
* `allowOptions` is false for a category key: a category may carry a severity, but
|
|
959
|
+
* options are rule-specific and meaningless there. `baseline` and `skipRangeCheck`
|
|
960
|
+
* are passed through to `validateRuleOptions`.
|
|
961
|
+
*/
|
|
962
|
+
declare function validateRuleSetting(label: string, ruleId: string, setting: unknown, spec: RuleOptionsSpec | undefined, opts: {
|
|
963
|
+
allowOptions: boolean;
|
|
964
|
+
baseline?: RuleOptions;
|
|
965
|
+
skipRangeCheck?: boolean;
|
|
966
|
+
}): string[];
|
|
967
|
+
|
|
968
|
+
/** Input given to every rule. Mode-independent: rules see only ResolvedHead[] (design §8, §10). */
|
|
969
|
+
interface RuleContext {
|
|
970
|
+
heads: ResolvedHead[];
|
|
971
|
+
/** Per-route <img> elements for Performance rules (absent in modes that don't collect them). */
|
|
972
|
+
images?: ResolvedImages[];
|
|
973
|
+
/** Per-route page-body headings for seo/single-h1 (absent in modes that don't collect them). */
|
|
974
|
+
headings?: ResolvedHeadings[];
|
|
975
|
+
/** Per-route composed landmark/id occurrences for the route-scoped a11y rules (absent in modes that don't collect them). */
|
|
976
|
+
a11y?: ResolvedA11y[];
|
|
977
|
+
/** Per-file component-body facts for Correctness rules (static/CLI mode only). */
|
|
978
|
+
components?: ComponentFacts[];
|
|
979
|
+
/** Per-file SvelteKit route/hooks facts for the SSR shared-state rules (static/CLI + vite build mode only). */
|
|
980
|
+
kitModules?: KitModuleFacts[];
|
|
981
|
+
/**
|
|
982
|
+
* Every file under `src/`, as project-relative paths, for directory-shaped Architecture rules
|
|
983
|
+
* (static/CLI + vite build mode only). Sorted — see `collectSourceFiles`, which is what both
|
|
984
|
+
* adapters use to build it.
|
|
985
|
+
*/
|
|
986
|
+
sourceFiles?: string[];
|
|
987
|
+
project: Project;
|
|
988
|
+
config: Config;
|
|
989
|
+
/**
|
|
990
|
+
* Report per-declaration counts of places this rule examined. The engine supplies it and keys the
|
|
991
|
+
* result by rule id; a rule that does not call it gets no entry, which is distinct from an entry of
|
|
992
|
+
* zeros. Absent in contexts a caller builds directly. Silent last-write-wins: calling it more than
|
|
993
|
+
* once keeps only the most recent map, with no merge and no error — call it once, with the complete
|
|
994
|
+
* counts, at the end of `check()`.
|
|
995
|
+
*/
|
|
996
|
+
recordExamined?: (counts: Record<string, number>) => void;
|
|
997
|
+
}
|
|
998
|
+
interface Rule {
|
|
999
|
+
id: string;
|
|
1000
|
+
title: string;
|
|
1001
|
+
category: Category;
|
|
1002
|
+
/** Default severity (overridable by config in later slices). */
|
|
1003
|
+
severity: Severity;
|
|
1004
|
+
/** 'route' = evaluated per route, 'project' = site-wide, 'component' = evaluated per source file (design §10, §12). */
|
|
1005
|
+
scope: Scope;
|
|
1006
|
+
/** Why this rule matters — one or two sentences, surfaced by `svelte-vitals explain` (issue #24). */
|
|
1007
|
+
rationale: string;
|
|
1008
|
+
/** Canonical remediation template, shared by findings and `svelte-vitals explain` (issue #24). */
|
|
1009
|
+
fix?: Fix;
|
|
1010
|
+
/** Configurable options for this rule; absent means the rule takes none. */
|
|
1011
|
+
options?: RuleOptionsSpec;
|
|
1012
|
+
/**
|
|
1013
|
+
* Evaluate the resolved heads. A single rule may return one Result per route,
|
|
1014
|
+
* so it always returns an array. Project-scoped rules return a single element.
|
|
1015
|
+
*/
|
|
1016
|
+
check(ctx: RuleContext): Promise<Result[]>;
|
|
1017
|
+
}
|
|
1018
|
+
/** Documentation URL for a rule id. Single source so no per-rule URL can drift (issue #24). */
|
|
1019
|
+
declare function docsUrlFor(id: string): string;
|
|
1020
|
+
/**
|
|
1021
|
+
* Whether a detection should be penalized by scoring (design §12). Shared by the
|
|
1022
|
+
* future Scorer and by the Slice 0 reporter so pass/fail is decided in one place.
|
|
1023
|
+
*
|
|
1024
|
+
* presence 'none' → penalized (nothing set anywhere)
|
|
1025
|
+
* value 'absent' → penalized (tag present but empty)
|
|
1026
|
+
* value 'dynamic' → penalized when treatDynamicAs is not 'pass' (warn or fail)
|
|
1027
|
+
* otherwise (static/inherited) → not penalized
|
|
1028
|
+
*/
|
|
1029
|
+
declare function isPenalized(detection: Detection, treatDynamicAs: TreatDynamicAs): boolean;
|
|
1030
|
+
|
|
1031
|
+
interface ScoreModel {
|
|
1032
|
+
routeAverage: number;
|
|
1033
|
+
sitePenalty: number;
|
|
1034
|
+
/** Headline cap value when it actually lowered the score, else null. */
|
|
1035
|
+
criticalCap: number | null;
|
|
1036
|
+
}
|
|
1037
|
+
interface ScoreResult {
|
|
1038
|
+
/** The score as displayed: `Math.floor(rawScore)`, so 100 means the deduction was exactly zero. */
|
|
1039
|
+
score: number;
|
|
1040
|
+
/**
|
|
1041
|
+
* The same score before flooring, after `sitePenalty` and the cap, clamped to `[0, 100]`. Exposed so
|
|
1042
|
+
* `computeHealth` can average unrounded values and floor once — averaging the displayed scores would
|
|
1043
|
+
* compose two roundings and move Health by up to two points.
|
|
1044
|
+
*/
|
|
1045
|
+
rawScore: number;
|
|
1046
|
+
scoreModel: ScoreModel;
|
|
1047
|
+
/** Keys this result set touched. */
|
|
1048
|
+
keys: number;
|
|
1049
|
+
/** Keys carrying at least one penalized finding. */
|
|
1050
|
+
affectedKeys: number;
|
|
1051
|
+
}
|
|
1052
|
+
interface ScoreOptions {
|
|
1053
|
+
applyCriticalCap?: boolean;
|
|
1054
|
+
/** The rules that ran. Defaults to the selected registry; supplied by tests and custom rule sets. */
|
|
1055
|
+
rules?: readonly Rule[];
|
|
1056
|
+
}
|
|
1057
|
+
/** Compute the headline score and its breakdown (design §12). */
|
|
1058
|
+
declare function computeScore(results: Result[], config: Config, options?: ScoreOptions): ScoreResult;
|
|
1059
|
+
/** Compute an independent score per category present in `results` (issue #10). */
|
|
1060
|
+
declare function scoresByCategory(results: Result[], config: Config, options?: ScoreOptions): Partial<Record<Category, ScoreResult>>;
|
|
1061
|
+
interface HealthResult {
|
|
1062
|
+
/** Weighted overall score across present categories (0–100). */
|
|
1063
|
+
health: number;
|
|
1064
|
+
categories: Partial<Record<Category, ScoreResult>>;
|
|
1065
|
+
/** Effective weight used per present category. */
|
|
1066
|
+
weights: Partial<Record<Category, number>>;
|
|
1067
|
+
}
|
|
1068
|
+
/** Combined weighted Health score over the categories present in `results` (#10). */
|
|
1069
|
+
declare function computeHealth(results: Result[], config: Config): HealthResult;
|
|
1070
|
+
|
|
1071
|
+
declare function issueOf(result: Result): {
|
|
1072
|
+
fix?: Fix | undefined;
|
|
1073
|
+
docsUrl?: string | undefined;
|
|
1074
|
+
recommendation: string | undefined;
|
|
1075
|
+
line?: number | undefined;
|
|
1076
|
+
id: string;
|
|
1077
|
+
category: Category;
|
|
1078
|
+
title: string;
|
|
1079
|
+
detection: Detection;
|
|
1080
|
+
location: string | undefined;
|
|
1081
|
+
};
|
|
1082
|
+
type JsonIssue = ReturnType<typeof issueOf> & {
|
|
1083
|
+
severity: ReturnType<typeof effectiveSeverity>;
|
|
1084
|
+
};
|
|
1085
|
+
/**
|
|
1086
|
+
* Per-rule counts. A rule present with `findings: 0` ran and reported nothing, and an absent rule was not
|
|
1087
|
+
* selected — but only when the caller supplied `ruleIds`. Without it the map is seeded from results alone,
|
|
1088
|
+
* so absence means "produced nothing" rather than "not selected".
|
|
1089
|
+
*/
|
|
1090
|
+
interface RuleEvidence {
|
|
1091
|
+
findings: number;
|
|
1092
|
+
passed: number;
|
|
1093
|
+
}
|
|
1094
|
+
interface JsonReport {
|
|
1095
|
+
version: string;
|
|
1096
|
+
score: number;
|
|
1097
|
+
weights: Partial<Record<Category, number>>;
|
|
1098
|
+
categories: Record<string, {
|
|
1099
|
+
score: number;
|
|
1100
|
+
scoreModel: ScoreModel;
|
|
1101
|
+
keys: number;
|
|
1102
|
+
affectedKeys: number;
|
|
1103
|
+
}>;
|
|
1104
|
+
summary: Summary;
|
|
1105
|
+
rules: Record<string, RuleEvidence>;
|
|
1106
|
+
routes: Array<{
|
|
1107
|
+
route: string;
|
|
1108
|
+
score: number;
|
|
1109
|
+
categories: Record<string, number>;
|
|
1110
|
+
issues: JsonIssue[];
|
|
1111
|
+
}>;
|
|
1112
|
+
siteIssues: JsonIssue[];
|
|
1113
|
+
/**
|
|
1114
|
+
* Floored severity weight per `"<category>::<scope>"` pair. Reproduces a `routes[].categories` entry
|
|
1115
|
+
* (`100 - 100 * failed / inventories[pair]`): a key is either a route id or a source file path, and
|
|
1116
|
+
* those two key spaces never overlap, so a category's results on one key always draw on a single scope.
|
|
1117
|
+
* It does not reproduce `routes[].score`: a route spanning more than one pair sums their *raw* weights
|
|
1118
|
+
* and floors that sum once, so adding this map's already-floored entries and re-dividing can disagree.
|
|
1119
|
+
*/
|
|
1120
|
+
inventories: Record<string, number>;
|
|
1121
|
+
/**
|
|
1122
|
+
* Per-rule, per-declaration counts of places examined. Unlike `rules`, this describes the analysis
|
|
1123
|
+
* rather than the report: `--diff`, `--baseline` and suppressions do not narrow it. Three states: a
|
|
1124
|
+
* rule that reports no counts has no entry; a rule that counts but whose configuration declares
|
|
1125
|
+
* nothing has an empty entry; a declaration that judged nothing has an entry of `0`.
|
|
1126
|
+
*/
|
|
1127
|
+
examined?: Record<string, Record<string, number>>;
|
|
1128
|
+
}
|
|
1129
|
+
/** Build the structured JSON report object (design §7). The shape the `json` reporter emits (issue #24). */
|
|
1130
|
+
declare function buildJsonReport(results: Result[], config: Config, meta: {
|
|
1131
|
+
version: string;
|
|
1132
|
+
}, ruleIds?: readonly string[], examined?: Record<string, Record<string, number>>): JsonReport;
|
|
1133
|
+
/** Render results as the documented JSON report string (design §7). */
|
|
1134
|
+
declare function formatJsonReport(results: Result[], config: Config, meta: {
|
|
1135
|
+
version: string;
|
|
1136
|
+
}, ruleIds?: readonly string[], examined?: Record<string, Record<string, number>>): string;
|
|
1137
|
+
|
|
1138
|
+
export { formatFailedRuleWarning as $, type A11yOccurrenceInfo as A, type BranchStep as B, type ComponentFacts as C, applyRuleSeverities as D, type EachBlockFact as E, type Fix as F, buildJsonReport as G, type HeadTag as H, type ImageInfo as I, type JsonReport as J, type KitAlias as K, LANDMARK_ROLES as L, classify as M, compileOverrides as N, type OrphanEffectFact as O, type Project as P, computeHealth as Q, type Runtime as R, type SuppressionDirective as S, computeScore as T, decodeFragmentId as U, type Value as V, defaultConfig as W, defaultProject as X, docsUrlFor as Y, effectiveSeverity as Z, foldOccurrences as _, type KitModuleFacts as a, formatJsonReport as a0, hasFailureAtOrAbove as a1, intOption as a2, isMentionedAnywhere as a3, isPenalized as a4, isTopFragment as a5, listOption as a6, mapOption as a7, overrideMatches as a8, resolveRuleOptions as a9, scoresByCategory as aa, selectRules as ab, settingOptions as ac, settingSeverity as ad, shouldSkipRangeCheck as ae, skippedFileWarnings as af, splitTokens as ag, stripTextDirective as ah, summarize as ai, validateRuleOptions as aj, validateRuleSetting as ak, withFailedRulesOff as al, withReadLimit as am, CATEGORIES as an, type Detection as ao, type Presence as ap, type RuleEvidence as aq, type RuleOptions as ar, type RuleOverride as as, type RuleSetting as at, type RuleSettingObject as au, type ScoreModel as av, type Summary as aw, type TreatDynamicAs as ax, defineConfig as ay, type Rule as b, type RuleContext as c, type Result as d, type Category as e, type Severity as f, type RuleOptionSpec as g, type ResolvedHead as h, type Config as i, type Classification as j, type CompiledOverride as k, type EffectFact as l, type HeadProvider as m, type HeadingInfo as n, type HealthResult as o, IDREF_ATTRS as p, READ_CONCURRENCY as q, type ResolvedA11y as r, type ResolvedHeadings as s, type ResolvedImages as t, type RuleOptionsSpec as u, type Scope as v, type ScoreOptions as w, type ScoreResult as x, type SourceSpan as y, applyOverrides as z };
|