@svelte-vitals/core 0.4.0 → 0.5.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/dist/index.d.ts +12 -1
- package/dist/index.js +93 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -247,6 +247,17 @@ declare function formatJsonReport(results: Result[], config: Config, meta: {
|
|
|
247
247
|
/** Render failing findings as an agent-actionable Markdown remediation document (issue #18). */
|
|
248
248
|
declare function formatAgentReport(results: Result[], config: Config): string;
|
|
249
249
|
|
|
250
|
+
/** Render penalized findings as a SARIF 2.1.0 log string (issue #18, design slice 5). */
|
|
251
|
+
declare function formatSarifReport(results: Result[], config: Config, meta: {
|
|
252
|
+
version: string;
|
|
253
|
+
}): string;
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Render penalized findings as GitHub Actions workflow commands (issue #18, design slice 5).
|
|
257
|
+
* GitHub turns these into inline PR annotations and run-annotation entries. Returns '' when clean.
|
|
258
|
+
*/
|
|
259
|
+
declare function formatGithubReport(results: Result[], config: Config): string;
|
|
260
|
+
|
|
250
261
|
/** Drop rules disabled via config (design §6). */
|
|
251
262
|
declare function selectRules(rules: Rule[], config: Config): Rule[];
|
|
252
263
|
/** Apply per-rule severity overrides to results (design §6). */
|
|
@@ -268,4 +279,4 @@ interface ScoreOptions {
|
|
|
268
279
|
/** Compute the headline score and its breakdown (design §12). */
|
|
269
280
|
declare function computeScore(results: Result[], config: Config, options?: ScoreOptions): ScoreResult;
|
|
270
281
|
|
|
271
|
-
export { type Category, type Classification, type Config, type ConsoleReportOptions, type Detection, type Fix, type HeadProvider, type HeadTag, type Presence, type Project, ROBOTS_SOURCE_PATHS, type ResolvedHead, type Result, type Rule, type RuleContext, type RuleSetting, type Runtime, SITEMAP_SOURCE_PATHS, type Scope, type ScoreModel, type ScoreOptions, type ScoreResult, type Severity, type Summary, type TreatDynamicAs, type Value, allRules, applyRuleSeverities, classify, computeScore, defaultConfig, defaultProject, defineConfig, effectiveSeverity, formatAgentReport, formatConsoleReport, formatJsonReport, hasFailureAtOrAbove, headTagRule, isPenalized, runRules, selectRules, seo001Title, seo002Description, seo003Canonical, seo004OgImage, seo005OgTitle, seo006Robots, seo007Sitemap, seo008JsonLd, seo009HtmlLang, summarize };
|
|
282
|
+
export { type Category, type Classification, type Config, type ConsoleReportOptions, type Detection, type Fix, type HeadProvider, type HeadTag, type Presence, type Project, ROBOTS_SOURCE_PATHS, type ResolvedHead, type Result, type Rule, type RuleContext, type RuleSetting, type Runtime, SITEMAP_SOURCE_PATHS, type Scope, type ScoreModel, type ScoreOptions, type ScoreResult, type Severity, type Summary, type TreatDynamicAs, type Value, allRules, applyRuleSeverities, classify, computeScore, defaultConfig, defaultProject, defineConfig, effectiveSeverity, formatAgentReport, formatConsoleReport, formatGithubReport, formatJsonReport, formatSarifReport, hasFailureAtOrAbove, headTagRule, isPenalized, runRules, selectRules, seo001Title, seo002Description, seo003Canonical, seo004OgImage, seo005OgTitle, seo006Robots, seo007Sitemap, seo008JsonLd, seo009HtmlLang, summarize };
|
package/dist/index.js
CHANGED
|
@@ -499,6 +499,97 @@ function formatAgentReport(results, config) {
|
|
|
499
499
|
return lines.join("\n").replace(/\n+$/, "\n");
|
|
500
500
|
}
|
|
501
501
|
|
|
502
|
+
// src/reporter/shared.ts
|
|
503
|
+
function severityToSarifLevel(sev) {
|
|
504
|
+
return sev === "critical" ? "error" : sev === "warning" ? "warning" : "note";
|
|
505
|
+
}
|
|
506
|
+
function severityToGithubLevel(sev) {
|
|
507
|
+
return sev === "critical" ? "error" : sev === "warning" ? "warning" : "notice";
|
|
508
|
+
}
|
|
509
|
+
function messageText(result) {
|
|
510
|
+
return result.recommendation ? `${result.message} ${result.recommendation}` : result.message;
|
|
511
|
+
}
|
|
512
|
+
function docsUrlFor(id) {
|
|
513
|
+
return `https://svelte-vitals.dev/rules/${id}`;
|
|
514
|
+
}
|
|
515
|
+
var RULE_META = new Map(
|
|
516
|
+
allRules.map((r) => [r.id, { title: r.title, severity: r.severity, docsUrl: docsUrlFor(r.id) }])
|
|
517
|
+
);
|
|
518
|
+
function ruleMetaById(id) {
|
|
519
|
+
return RULE_META.get(id);
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
// src/reporter/sarif.ts
|
|
523
|
+
function formatSarifReport(results, config, meta) {
|
|
524
|
+
const penalized = results.filter((r) => isPenalized(r.detection, config.treatDynamicAs));
|
|
525
|
+
const rules = [];
|
|
526
|
+
const ruleIndex = /* @__PURE__ */ new Map();
|
|
527
|
+
const sarifResults = penalized.map((r) => {
|
|
528
|
+
if (!ruleIndex.has(r.id)) {
|
|
529
|
+
const m = ruleMetaById(r.id);
|
|
530
|
+
const name = m?.title ?? r.id;
|
|
531
|
+
ruleIndex.set(r.id, rules.length);
|
|
532
|
+
rules.push({
|
|
533
|
+
id: r.id,
|
|
534
|
+
name,
|
|
535
|
+
shortDescription: { text: name },
|
|
536
|
+
helpUri: r.docsUrl ?? m?.docsUrl ?? docsUrlFor(r.id),
|
|
537
|
+
defaultConfiguration: { level: severityToSarifLevel(m?.severity ?? r.severity) }
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
const result = {
|
|
541
|
+
ruleId: r.id,
|
|
542
|
+
ruleIndex: ruleIndex.get(r.id),
|
|
543
|
+
level: severityToSarifLevel(effectiveSeverity(r, config)),
|
|
544
|
+
message: { text: messageText(r) },
|
|
545
|
+
partialFingerprints: { "svelteVitals/v1": `${r.id}:${r.route ?? "project"}` }
|
|
546
|
+
};
|
|
547
|
+
if (r.location) {
|
|
548
|
+
result.locations = [{ physicalLocation: { artifactLocation: { uri: r.location } } }];
|
|
549
|
+
}
|
|
550
|
+
return result;
|
|
551
|
+
});
|
|
552
|
+
const log = {
|
|
553
|
+
$schema: "https://json.schemastore.org/sarif-2.1.0.json",
|
|
554
|
+
version: "2.1.0",
|
|
555
|
+
runs: [
|
|
556
|
+
{
|
|
557
|
+
tool: {
|
|
558
|
+
driver: {
|
|
559
|
+
name: "svelte-vitals",
|
|
560
|
+
informationUri: "https://svelte-vitals.dev",
|
|
561
|
+
version: meta.version,
|
|
562
|
+
rules
|
|
563
|
+
}
|
|
564
|
+
},
|
|
565
|
+
results: sarifResults
|
|
566
|
+
}
|
|
567
|
+
]
|
|
568
|
+
};
|
|
569
|
+
return JSON.stringify(log, null, 2);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
// src/reporter/github.ts
|
|
573
|
+
function escapeData(s) {
|
|
574
|
+
return s.replace(/%/g, "%25").replace(/\r/g, "%0D").replace(/\n/g, "%0A");
|
|
575
|
+
}
|
|
576
|
+
function escapeProp(s) {
|
|
577
|
+
return escapeData(s).replace(/:/g, "%3A").replace(/,/g, "%2C");
|
|
578
|
+
}
|
|
579
|
+
function formatGithubReport(results, config) {
|
|
580
|
+
const penalized = results.filter((r) => isPenalized(r.detection, config.treatDynamicAs));
|
|
581
|
+
const lines = penalized.map((r) => {
|
|
582
|
+
const level = severityToGithubLevel(effectiveSeverity(r, config));
|
|
583
|
+
const meta = ruleMetaById(r.id);
|
|
584
|
+
const title = meta ? `${r.id}: ${meta.title}` : r.id;
|
|
585
|
+
const props = [];
|
|
586
|
+
if (r.location) props.push(`file=${escapeProp(r.location)}`);
|
|
587
|
+
props.push(`title=${escapeProp(title)}`);
|
|
588
|
+
return `::${level} ${props.join(",")}::${escapeData(messageText(r))}`;
|
|
589
|
+
});
|
|
590
|
+
return lines.join("\n");
|
|
591
|
+
}
|
|
592
|
+
|
|
502
593
|
// src/config-apply.ts
|
|
503
594
|
function selectRules(rules, config) {
|
|
504
595
|
return rules.filter((rule) => config.rules[rule.id] !== "off");
|
|
@@ -522,7 +613,9 @@ export {
|
|
|
522
613
|
effectiveSeverity,
|
|
523
614
|
formatAgentReport,
|
|
524
615
|
formatConsoleReport,
|
|
616
|
+
formatGithubReport,
|
|
525
617
|
formatJsonReport,
|
|
618
|
+
formatSarifReport,
|
|
526
619
|
hasFailureAtOrAbove,
|
|
527
620
|
headTagRule,
|
|
528
621
|
isPenalized,
|