@blundergoat/gruff-ts 0.4.0 → 0.6.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/CHANGELOG.md +123 -1
- package/CONTRIBUTING.md +32 -25
- package/README.md +55 -46
- package/SECURITY.md +18 -30
- package/UPGRADING.md +101 -0
- package/bin/gruff-ts +3 -0
- package/docs/README.md +11 -13
- package/docs/agent-hook.md +33 -24
- package/docs/ci-integration.md +38 -24
- package/docs/configuration.md +173 -71
- package/docs/dashboard.md +12 -13
- package/docs/output-formats.md +100 -25
- package/docs/philosophy.md +2 -2
- package/docs/reports-and-ci.md +14 -157
- package/docs/rules.md +140 -106
- package/package.json +10 -8
- package/src/analyser.ts +886 -282
- package/src/baseline-file.ts +867 -0
- package/src/baseline-identity.ts +463 -0
- package/src/baseline-options.ts +139 -34
- package/src/baseline.ts +85 -55
- package/src/blocks.ts +579 -364
- package/src/changed-regions.ts +414 -65
- package/src/check-ignore.ts +28 -13
- package/src/class-rules.ts +461 -302
- package/src/cli-program.ts +956 -166
- package/src/cli.ts +9 -2
- package/src/comment-rules.ts +277 -414
- package/src/comment-scanner.ts +363 -44
- package/src/complexity-metrics.ts +320 -0
- package/src/config-load-error.ts +17 -8
- package/src/config-parse.ts +291 -98
- package/src/config-preservation.ts +81 -26
- package/src/config.ts +778 -210
- package/src/constants.ts +7 -6
- package/src/context-doc-rules.ts +188 -61
- package/src/dashboard.ts +88 -23
- package/src/dead-code-rules.ts +153 -74
- package/src/discovery.ts +521 -148
- package/src/doc-rules.ts +592 -147
- package/src/duplicate-test-group-rules.ts +359 -0
- package/src/findings-helpers.ts +240 -89
- package/src/findings.ts +48 -24
- package/src/fixture-purpose-rules.ts +226 -48
- package/src/github-actions-event-guards.ts +331 -0
- package/src/github-actions-rules.ts +336 -106
- package/src/hook-contract.ts +708 -211
- package/src/init-config.ts +169 -114
- package/src/inline-suppressions.ts +340 -0
- package/src/limit-band.ts +56 -0
- package/src/line-rules.ts +331 -419
- package/src/migrate-config.ts +670 -0
- package/src/naming-pushers.ts +33 -107
- package/src/parsed-script.ts +1206 -0
- package/src/pillar-summary.ts +56 -40
- package/src/profiles.ts +97 -71
- package/src/project-config-rules.ts +335 -146
- package/src/project-rules.ts +237 -115
- package/src/public-exports.ts +284 -0
- package/src/report-html.ts +217 -85
- package/src/report-renderers.ts +864 -195
- package/src/rule-list.ts +166 -46
- package/src/rules.ts +100 -104
- package/src/safety-rules.ts +191 -132
- package/src/scoring.ts +255 -52
- package/src/security-flow-rules.ts +930 -109
- package/src/selectors.ts +169 -0
- package/src/sensitive-data-rules.ts +502 -375
- package/src/sensitive-exclusions.ts +435 -0
- package/src/source-text.ts +380 -148
- package/src/static-analysis-redundant-rules.ts +298 -41
- package/src/test-block-rules.ts +422 -228
- package/src/text-scans.ts +67 -9
- package/src/types.ts +222 -71
- package/tsconfig.json +2 -1
- package/src/process-exec-metadata.ts +0 -153
- package/src/test-fixtures.ts +0 -668
package/src/report-html.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// HTML
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
1
|
+
// Renders standalone HTML reports (`analyse --format html`, `report --format html`) and the local dashboard shell.
|
|
2
|
+
//
|
|
3
|
+
// Shares pillar rows and grade helpers with `report-renderers.ts` so terminal, Markdown, HTML, and dashboard views stay consistent.
|
|
4
|
+
// Kept separate from `report-renderers.ts` to keep both renderer modules cleanly below the file-length threshold.
|
|
5
5
|
import type { AnalysisReport, Finding, Severity } from "./types.ts";
|
|
6
6
|
import { buildPillarRows, grade } from "./pillar-summary.ts";
|
|
7
7
|
import { severityGradeBreakdown } from "./scoring.ts";
|
|
@@ -21,10 +21,13 @@ interface DashboardRenderContext {
|
|
|
21
21
|
scanPath: string;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
24
|
+
/**
|
|
25
|
+
* Renders a self-contained report with inline CSS so it can be archived or emailed.
|
|
26
|
+
* Finding locations carry the stable data-path attribute.
|
|
27
|
+
*
|
|
28
|
+
* @param report - analysis results supplying the document's scores, diagnostics and findings
|
|
29
|
+
* @param dashboardContext - local project root and scan path, omitted when the dashboard context section is unnecessary
|
|
30
|
+
* @returns Complete HTML document for the scan, with n/a in the title when the report has no grade
|
|
28
31
|
*/
|
|
29
32
|
function renderHtml(report: AnalysisReport, dashboardContext?: DashboardRenderContext): string {
|
|
30
33
|
const bodySections = [
|
|
@@ -43,7 +46,7 @@ function renderHtml(report: AnalysisReport, dashboardContext?: DashboardRenderCo
|
|
|
43
46
|
<head>
|
|
44
47
|
<meta charset="utf-8">
|
|
45
48
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
46
|
-
<title>gruff-ts report - ${escapeHtml(report.score.grade)}</title>
|
|
49
|
+
<title>gruff-ts report - ${escapeHtml(report.score.grade ?? "n/a")}</title>
|
|
47
50
|
<style>${htmlReportCss(report.diagnostics.length > 0)}</style>
|
|
48
51
|
</head>
|
|
49
52
|
<body>
|
|
@@ -54,23 +57,38 @@ ${bodySections}
|
|
|
54
57
|
</html>`;
|
|
55
58
|
}
|
|
56
59
|
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
/**
|
|
61
|
+
* Renders the report header showing the analysed file count, output format, failure threshold, schema, and tool version.
|
|
62
|
+
* Zero analysed files display "." in the paths row; the schema identifies the report shape.
|
|
63
|
+
*
|
|
64
|
+
* @param report - analysis report supplying path counts, run settings, schemaVersion, and tool version
|
|
65
|
+
* @returns HTML header element for the report masthead
|
|
66
|
+
*/
|
|
59
67
|
function htmlMasthead(report: AnalysisReport): string {
|
|
60
68
|
const paths = report.paths.analysedFiles === 0 ? "." : `${report.paths.analysedFiles} analysed ${report.paths.analysedFiles === 1 ? "file" : "files"}`;
|
|
61
69
|
return `<header class="masthead"><div class="brand"><div class="wordmark">gruff</div><div class="tagline">ts/js code - inspected for human sign-off</div></div><div class="meta">${htmlMetaRow("paths", paths)}${htmlMetaRow("format", report.run.format)}${htmlMetaRow("fail", report.run.failOn)}${htmlMetaRow("schema", report.schemaVersion)}<div class="inspection-id">gruff-ts ${escapeHtml(report.tool.version)}</div></div></header>`;
|
|
62
70
|
}
|
|
63
71
|
|
|
64
|
-
|
|
65
|
-
|
|
72
|
+
/**
|
|
73
|
+
* Renders a metadata row and escapes both strings so metadata cannot inject HTML.
|
|
74
|
+
*
|
|
75
|
+
* @param label - field name displayed in the row label span
|
|
76
|
+
* @param metaValue - value displayed beside the label after HTML escaping
|
|
77
|
+
* @returns HTML div containing the escaped label and value spans
|
|
78
|
+
*/
|
|
66
79
|
function htmlMetaRow(label: string, metaValue: string): string {
|
|
67
80
|
const escapedLabel = escapeHtml(label);
|
|
68
81
|
const escapedValue = escapeHtml(metaValue);
|
|
69
82
|
return `<div><span class="label">${escapedLabel}</span><span class="val">${escapedValue}</span></div>`;
|
|
70
83
|
}
|
|
71
84
|
|
|
72
|
-
|
|
73
|
-
|
|
85
|
+
/**
|
|
86
|
+
* Renders the report's run diagnostics before scores in the stable HTML order because scan limits and failures
|
|
87
|
+
* can affect how readers interpret the results.
|
|
88
|
+
*
|
|
89
|
+
* @param report - analysis report supplying run diagnostic entries
|
|
90
|
+
* @returns HTML diagnostics section, or empty text when report.diagnostics is empty
|
|
91
|
+
*/
|
|
74
92
|
function htmlDiagnostics(report: AnalysisReport): string {
|
|
75
93
|
if (report.diagnostics.length === 0) {
|
|
76
94
|
return "";
|
|
@@ -79,9 +97,13 @@ function htmlDiagnostics(report: AnalysisReport): string {
|
|
|
79
97
|
return `<section class="diagnostics"><h2 class="section-head">diagnostics <span class="aside">run messages</span></h2><div class="diagnostic-list">${diagnostics}</div></section>`;
|
|
80
98
|
}
|
|
81
99
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
100
|
+
/**
|
|
101
|
+
* Formats a run diagnostic using the stable diagnostic-type, diagnostic-message, and diagnostic-location classes.
|
|
102
|
+
* With no file path, the entry has no location span; with a path and no line, the location shows the path alone.
|
|
103
|
+
*
|
|
104
|
+
* @param diagnostic - run diagnostic record with type, message, and optional filePath and line
|
|
105
|
+
* @returns HTML div element for the escaped diagnostic entry
|
|
106
|
+
*/
|
|
85
107
|
function htmlDiagnosticEntry(diagnostic: AnalysisReport["diagnostics"][number]): string {
|
|
86
108
|
const lineSuffix = diagnostic.line ? `:${diagnostic.line}` : "";
|
|
87
109
|
const location = diagnostic.filePath
|
|
@@ -90,22 +112,31 @@ function htmlDiagnosticEntry(diagnostic: AnalysisReport["diagnostics"][number]):
|
|
|
90
112
|
return `<div class="diagnostic"><span class="diagnostic-type">${escapeHtml(diagnostic.diagnosticType)}</span><span class="diagnostic-message">${escapeHtml(diagnostic.message)}</span>${location}</div>`;
|
|
91
113
|
}
|
|
92
114
|
|
|
93
|
-
|
|
94
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Renders the dashboard-only banner for the requested or default project root and scan path.
|
|
117
|
+
* Escapes both values because callers can override them through query parameters.
|
|
118
|
+
*
|
|
119
|
+
* @param context - dashboard render context holding the projectRoot and scanPath values
|
|
120
|
+
* @returns HTML section element displaying the escaped project root and scan path
|
|
121
|
+
*/
|
|
95
122
|
function htmlDashboardContext(context: DashboardRenderContext): string {
|
|
96
123
|
const escapedProjectRoot = escapeHtml(context.projectRoot);
|
|
97
124
|
const escapedScanPath = escapeHtml(context.scanPath);
|
|
98
125
|
return `<section class="dashboard-context"><h2 class="section-head">dashboard scan <span class="aside">local run</span></h2><div class="dashboard-context-grid"><div><span class="label">Project root</span><span class="val">${escapedProjectRoot}</span></div><div><span class="label">Path</span><span class="val">${escapedScanPath}</span></div></div></section>`;
|
|
99
126
|
}
|
|
100
127
|
|
|
101
|
-
|
|
102
|
-
*
|
|
103
|
-
*
|
|
128
|
+
/**
|
|
129
|
+
* Renders the analysis report's grade, verdict summary, severity pills, and finding totals as HTML.
|
|
130
|
+
* The stable visual contract keeps dashboard and static report verdicts consistent.
|
|
131
|
+
*
|
|
132
|
+
* @param report - scored or unscored analysis result to summarize
|
|
133
|
+
* @returns the HTML verdict section for the shared report renderer
|
|
104
134
|
*/
|
|
105
135
|
function htmlVerdict(report: AnalysisReport): string {
|
|
106
|
-
|
|
107
|
-
const
|
|
108
|
-
const
|
|
136
|
+
// A missing grade displays n/a. A missing composite displays not evaluated / 100 so an unscored scan cannot look perfect.
|
|
137
|
+
const gradeCssClass = gradeClass(report.score.grade ?? "n/a");
|
|
138
|
+
const escapedGrade = escapeHtml(report.score.grade ?? "n/a");
|
|
139
|
+
const scoreText = report.score.composite === null ? "not evaluated" : report.score.composite.toFixed(1);
|
|
109
140
|
const escapedSummary = escapeHtml(verdictSummary(report));
|
|
110
141
|
const breakdown = severityGradeBreakdown(report.findings);
|
|
111
142
|
const severityPills = htmlSeverityPills(breakdown);
|
|
@@ -113,15 +144,25 @@ function htmlVerdict(report: AnalysisReport): string {
|
|
|
113
144
|
return `<section class="verdict"><div class="grade-stamp ${gradeCssClass}"><div class="grade-letter">${escapedGrade}</div><div class="grade-score">${scoreText} / 100</div></div><div class="verdict-body"><div class="verdict-headline">Inspection complete.<br><em>${escapedSummary}</em></div>${severityPills}<div class="verdict-stats">${stats}</div></div></section>`;
|
|
114
145
|
}
|
|
115
146
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
147
|
+
/**
|
|
148
|
+
* Renders three labeled grade pills (Errors, Warnings, Advisory) directly under the verdict headline.
|
|
149
|
+
* Uses the breakdown's grade and count for each severity because the composite grade can hide what drove it.
|
|
150
|
+
*
|
|
151
|
+
* @param breakdown - per-severity grade and finding count buckets for error, warning, and advisory
|
|
152
|
+
* @returns HTML container div holding the three severity grade pills
|
|
153
|
+
*/
|
|
119
154
|
function htmlSeverityPills(breakdown: ReturnType<typeof severityGradeBreakdown>): string {
|
|
120
155
|
return `<div class="severity-grades">${htmlSeverityPill("Errors", breakdown.error)}${htmlSeverityPill("Warnings", breakdown.warning)}${htmlSeverityPill("Advisory", breakdown.advisory)}</div>`;
|
|
121
156
|
}
|
|
122
157
|
|
|
123
|
-
|
|
124
|
-
|
|
158
|
+
/**
|
|
159
|
+
* Renders an HTML grade pill and escapes displayed values to avoid markup injection.
|
|
160
|
+
* Uses gradeClass for a fixed CSS class, falling back to n for an unrecognized or absent initial.
|
|
161
|
+
*
|
|
162
|
+
* @param label - severity heading displayed before the pill
|
|
163
|
+
* @param bucket - grade letter and finding count for that severity
|
|
164
|
+
* @returns HTML span element for the labeled severity grade pill and count
|
|
165
|
+
*/
|
|
125
166
|
function htmlSeverityPill(label: string, bucket: { grade: string; count: number }): string {
|
|
126
167
|
const cssClass = gradeClass(bucket.grade);
|
|
127
168
|
const escapedLabel = escapeHtml(label);
|
|
@@ -130,8 +171,13 @@ function htmlSeverityPill(label: string, bucket: { grade: string; count: number
|
|
|
130
171
|
return `<span class="severity-grade">${escapedLabel} <span class="grade-pill ${cssClass}">${escapedGradeLetter}</span> <span class="severity-count">(${escapedCount})</span></span>`;
|
|
131
172
|
}
|
|
132
173
|
|
|
133
|
-
|
|
134
|
-
|
|
174
|
+
/**
|
|
175
|
+
* Builds the verdict headline sentence counting only warning and error findings.
|
|
176
|
+
* Advisories are intentionally excluded from the verdict text because they are below the stable "needs attention" threshold.
|
|
177
|
+
*
|
|
178
|
+
* @param report - analysis report supplying summary counts and findings
|
|
179
|
+
* @returns Plain-text verdict sentence summarizing warning and error findings across pillars
|
|
180
|
+
*/
|
|
135
181
|
function verdictSummary(report: AnalysisReport): string {
|
|
136
182
|
const thresholdFindings = report.summary.warning + report.summary.error;
|
|
137
183
|
if (thresholdFindings === 0) {
|
|
@@ -141,8 +187,14 @@ function verdictSummary(report: AnalysisReport): string {
|
|
|
141
187
|
return `${thresholdFindings} ${thresholdFindings === 1 ? "finding" : "findings"} at warning or error severity across ${pillars.size} ${pillars.size === 1 ? "pillar" : "pillars"}.`;
|
|
142
188
|
}
|
|
143
189
|
|
|
144
|
-
|
|
145
|
-
|
|
190
|
+
/**
|
|
191
|
+
* Renders a stat card and escapes all three strings before embedding them in HTML.
|
|
192
|
+
*
|
|
193
|
+
* @param number - formatted count text displayed at the top of the card
|
|
194
|
+
* @param label - caption displayed below the count
|
|
195
|
+
* @param className - CSS modifier class selecting the number's visual style
|
|
196
|
+
* @returns HTML div element containing the escaped stat number and label
|
|
197
|
+
*/
|
|
146
198
|
function htmlStat(number: string, label: string, className: string): string {
|
|
147
199
|
const escapedClassName = escapeHtml(className);
|
|
148
200
|
const escapedNumber = escapeHtml(number);
|
|
@@ -150,12 +202,12 @@ function htmlStat(number: string, label: string, className: string): string {
|
|
|
150
202
|
return `<div class="stat"><div class="num ${escapedClassName}">${escapedNumber}</div><div class="lbl">${escapedLabel}</div></div>`;
|
|
151
203
|
}
|
|
152
204
|
|
|
153
|
-
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
205
|
+
/**
|
|
206
|
+
* Uses shared pillar rows so that HTML follows the stable summary order, findings DESC then pillar ASC.
|
|
207
|
+
* The HTML contract keeps the pillar-grid anchor and columns for pillar, grade, score, findings, advisory, warning and error.
|
|
208
|
+
*
|
|
209
|
+
* @param report - analysis results supplying pillar scores and findings by severity
|
|
210
|
+
* @returns HTML section containing the pillar summary table
|
|
159
211
|
*/
|
|
160
212
|
function htmlPillars(report: AnalysisReport): string {
|
|
161
213
|
const rows = buildPillarRows(report);
|
|
@@ -165,15 +217,20 @@ function htmlPillars(report: AnalysisReport): string {
|
|
|
165
217
|
: rows
|
|
166
218
|
.map((row) => {
|
|
167
219
|
const letter = row.grade;
|
|
168
|
-
|
|
220
|
+
const scoreCell = row.score === null ? "n/a" : row.score.toFixed(2);
|
|
221
|
+
return `<tr><td class="pillar-name">${escapeHtml(row.pillar)}</td><td class="num"><span class="grade-pill ${gradeClass(letter)}">${escapeHtml(letter)}</span></td><td class="num">${scoreCell}</td><td class="num">${row.findings}</td><td class="num">${row.advisory}</td><td class="num">${row.warning}</td><td class="num">${row.error}</td></tr>`;
|
|
169
222
|
})
|
|
170
223
|
.join("");
|
|
171
224
|
return `<section class="pillars"><h2 class="section-head">Pillars <span class="aside">grade, score, findings by severity</span></h2><div class="pillar-grid"><table class="pillar-table"><thead><tr><th scope="col">pillar</th><th scope="col" class="num">grade</th><th scope="col" class="num">score</th><th scope="col" class="num">findings</th><th scope="col" class="num">advisory</th><th scope="col" class="num">warning</th><th scope="col" class="num">error</th></tr></thead><tbody>${body}</tbody></table></div></section>`;
|
|
172
225
|
}
|
|
173
226
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
227
|
+
/**
|
|
228
|
+
* Renders the worst-first offender table capped at 10 rows so that the layout stays stable.
|
|
229
|
+
* An empty list shows No offenders found, and an unavailable score shows n/a for both the score and grade.
|
|
230
|
+
*
|
|
231
|
+
* @param report - analysis report supplying the topOffenders list
|
|
232
|
+
* @returns HTML section element containing the top offenders table
|
|
233
|
+
*/
|
|
177
234
|
function htmlOffenders(report: AnalysisReport): string {
|
|
178
235
|
const rows =
|
|
179
236
|
report.score.topOffenders.length === 0
|
|
@@ -181,16 +238,19 @@ function htmlOffenders(report: AnalysisReport): string {
|
|
|
181
238
|
: report.score.topOffenders
|
|
182
239
|
.slice(0, 10)
|
|
183
240
|
.map((file) => {
|
|
184
|
-
const letter = grade(file.score);
|
|
185
|
-
|
|
241
|
+
const letter = file.score === null ? "n/a" : grade(file.score);
|
|
242
|
+
const scoreCell = file.score === null ? "n/a" : file.score.toFixed(1);
|
|
243
|
+
return `<tr><td class="file-path">${htmlLocation(file.filePath)}</td><td class="num">${scoreCell}</td><td class="num">${file.findings}</td><td class="num"><span class="grade-pill ${gradeClass(letter)}">${letter}</span></td></tr>`;
|
|
186
244
|
})
|
|
187
245
|
.join("");
|
|
188
246
|
return `<section class="offenders"><h2 class="section-head">top offenders <span class="aside">sorted by score</span></h2><table class="offender-list"><thead><tr><th scope="col">file</th><th scope="col" class="num">score</th><th scope="col" class="num">findings</th><th scope="col" class="num">grade</th></tr></thead><tbody>${rows}</tbody></table></section>`;
|
|
189
247
|
}
|
|
190
248
|
|
|
191
|
-
|
|
192
|
-
*
|
|
193
|
-
*
|
|
249
|
+
/**
|
|
250
|
+
* Renders the cyclomatic-complexity histogram so that the stable bucket layout stays visible even when no findings qualify.
|
|
251
|
+
*
|
|
252
|
+
* @param report - analysis results supplying the cyclomatic findings to chart
|
|
253
|
+
* @returns HTML chart section with a summary and bucket counts, including zero counts on minimum-height bars
|
|
194
254
|
*/
|
|
195
255
|
function htmlDistribution(report: AnalysisReport): string {
|
|
196
256
|
const distribution = cyclomaticDistribution(report);
|
|
@@ -208,9 +268,11 @@ function htmlDistribution(report: AnalysisReport): string {
|
|
|
208
268
|
return `<section class="chart-section"><h2 class="section-head">distribution <span class="aside">cyclomatic complexity</span></h2><p class="chart-summary">${escapeHtml(cyclomaticSummary(distribution))}</p><div class="chart-card"><div class="title">cyclomatic complexity - flagged functions</div><div class="histogram">${bars}</div><div class="histogram-axis">${axis}</div></div></section>`;
|
|
209
269
|
}
|
|
210
270
|
|
|
211
|
-
|
|
212
|
-
*
|
|
213
|
-
*
|
|
271
|
+
/**
|
|
272
|
+
* Counts cyclomatic findings for the HTML histogram. Findings that cannot be assigned a bucket are skipped.
|
|
273
|
+
*
|
|
274
|
+
* @param report - analysis report supplying the findings to count
|
|
275
|
+
* @returns Counts in stable chart order, with zero retained for each empty bucket
|
|
214
276
|
*/
|
|
215
277
|
function cyclomaticDistribution(report: AnalysisReport): Record<string, number> {
|
|
216
278
|
const distribution: Record<string, number> = { "1-5": 0, "6-10": 0, "11-15": 0, "16-20": 0, "21+": 0 };
|
|
@@ -223,9 +285,13 @@ function cyclomaticDistribution(report: AnalysisReport): Record<string, number>
|
|
|
223
285
|
return distribution;
|
|
224
286
|
}
|
|
225
287
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
288
|
+
/**
|
|
289
|
+
* Maps a cyclomatic complexity finding to its histogram bucket, or leaves non-matching findings out of the chart.
|
|
290
|
+
* Reads the complexity count from the message because the stable rule format supplies the value used by the chart.
|
|
291
|
+
*
|
|
292
|
+
* @param finding - finding inspected for ruleId complexity.cyclomatic and its numeric complexity
|
|
293
|
+
* @returns Histogram bucket label for the finding's complexity, or undefined when not applicable
|
|
294
|
+
*/
|
|
229
295
|
function cyclomaticFindingBucket(finding: Finding): string | undefined {
|
|
230
296
|
if (finding.ruleId !== "complexity.cyclomatic") {
|
|
231
297
|
return undefined;
|
|
@@ -235,8 +301,12 @@ function cyclomaticFindingBucket(finding: Finding): string | undefined {
|
|
|
235
301
|
return complexityValue === undefined ? undefined : cyclomaticBucket(complexityValue);
|
|
236
302
|
}
|
|
237
303
|
|
|
238
|
-
|
|
239
|
-
|
|
304
|
+
/**
|
|
305
|
+
* Selects the highest-minimum histogram bucket label using descending minima in CYCLOMATIC_BUCKETS.
|
|
306
|
+
*
|
|
307
|
+
* @param complexityValue - parsed cyclomatic complexity score to classify
|
|
308
|
+
* @returns Matching bucket label, or undefined when the value falls below all bucket minima
|
|
309
|
+
*/
|
|
240
310
|
function cyclomaticBucket(complexityValue: number): string | undefined {
|
|
241
311
|
for (const bucket of CYCLOMATIC_BUCKETS) {
|
|
242
312
|
if (complexityValue >= bucket.minimum) {
|
|
@@ -246,8 +316,13 @@ function cyclomaticBucket(complexityValue: number): string | undefined {
|
|
|
246
316
|
return undefined;
|
|
247
317
|
}
|
|
248
318
|
|
|
249
|
-
|
|
250
|
-
|
|
319
|
+
/**
|
|
320
|
+
* Formats a singular or plural caption for functions above CC 10.
|
|
321
|
+
* Missing 11-15, 16-20, or 21+ counts contribute zero.
|
|
322
|
+
*
|
|
323
|
+
* @param distribution - cyclomatic histogram counts keyed by bucket label
|
|
324
|
+
* @returns Summary caption breaking down functions exceeding CC 10 across the upper three buckets
|
|
325
|
+
*/
|
|
251
326
|
function cyclomaticSummary(distribution: Record<string, number>): string {
|
|
252
327
|
const moderate = distribution["11-15"] ?? 0;
|
|
253
328
|
const high = distribution["16-20"] ?? 0;
|
|
@@ -256,8 +331,13 @@ function cyclomaticSummary(distribution: Record<string, number>): string {
|
|
|
256
331
|
return `${exceeds} ${exceeds === 1 ? "function" : "functions"} ${exceeds === 1 ? "exceeds" : "exceed"} CC 10 (${moderate} in 11-15, ${high} in 16-20, ${severe} at 21+).`;
|
|
257
332
|
}
|
|
258
333
|
|
|
259
|
-
|
|
260
|
-
|
|
334
|
+
/**
|
|
335
|
+
* Renders the HTML findings section, showing No findings when empty and applying the stable 250-entry cap.
|
|
336
|
+
* The heading shows first 250 of N when the list is capped so long lists stay easier to scan.
|
|
337
|
+
*
|
|
338
|
+
* @param report - analysis report supplying the findings array to display
|
|
339
|
+
* @returns HTML section element listing up to 250 flagged findings
|
|
340
|
+
*/
|
|
261
341
|
function htmlFindings(report: AnalysisReport): string {
|
|
262
342
|
const findings =
|
|
263
343
|
report.findings.length === 0
|
|
@@ -273,9 +353,12 @@ function htmlFindings(report: AnalysisReport): string {
|
|
|
273
353
|
return `<section class="findings"><h2 class="section-head">flagged findings${capped}</h2><div class="findings-list">${findings}</div></section>`;
|
|
274
354
|
}
|
|
275
355
|
|
|
276
|
-
|
|
277
|
-
*
|
|
278
|
-
*
|
|
356
|
+
/**
|
|
357
|
+
* Renders the report footer with the tool version and schema string.
|
|
358
|
+
* These stable identifiers tell reviewers which release and output contract produced the report.
|
|
359
|
+
*
|
|
360
|
+
* @param report - analysis report supplying tool.version and schemaVersion
|
|
361
|
+
* @returns HTML footer element containing the escaped tool version and schema identifier
|
|
279
362
|
*/
|
|
280
363
|
function htmlFooter(report: AnalysisReport): string {
|
|
281
364
|
const escapedVersion = escapeHtml(report.tool.version);
|
|
@@ -283,29 +366,48 @@ function htmlFooter(report: AnalysisReport): string {
|
|
|
283
366
|
return `<footer class="footer"><div class="left">gruff-ts - v${escapedVersion}</div><div class="center">strong opinions, opinionated defaults</div><div class="right">schema - ${escapedSchemaVersion}</div></footer>`;
|
|
284
367
|
}
|
|
285
368
|
|
|
286
|
-
|
|
287
|
-
|
|
369
|
+
/**
|
|
370
|
+
* Renders a keyboard-focusable location span, HTML-escaping both the displayed text and data-path attribute.
|
|
371
|
+
* An absent line leaves only the path.
|
|
372
|
+
*
|
|
373
|
+
* @param filePath - source file path to display and store in data-path
|
|
374
|
+
* @param line - optional 1-based line number appended after a colon when defined
|
|
375
|
+
* @returns HTML span element for the formatted location
|
|
376
|
+
*/
|
|
288
377
|
function htmlLocation(filePath: string, line?: number): string {
|
|
289
378
|
const text = line === undefined ? filePath : `${filePath}:${line}`;
|
|
290
379
|
return `<span class="loc-link" tabindex="0" data-path="${escapeHtml(text)}">${escapeHtml(text)}</span>`;
|
|
291
380
|
}
|
|
292
381
|
|
|
293
|
-
|
|
294
|
-
|
|
382
|
+
/**
|
|
383
|
+
* Maps a finding severity to a fixed badge CSS suffix that can be interpolated into markup without HTML escaping.
|
|
384
|
+
*
|
|
385
|
+
* @param severity - finding severity level ("error", "warning", or "advisory")
|
|
386
|
+
* @returns CSS suffix: "fail" for error, "warn" for warning, or "note" otherwise
|
|
387
|
+
*/
|
|
295
388
|
function severityClass(severity: Severity): string {
|
|
296
389
|
return severity === "error" ? "fail" : severity === "warning" ? "warn" : "note";
|
|
297
390
|
}
|
|
298
391
|
|
|
299
|
-
|
|
300
|
-
|
|
392
|
+
/**
|
|
393
|
+
* Derives a CSS suffix from the grade's first letter, ignoring case.
|
|
394
|
+
* Empty grades and initials outside a, b, c, d, and f use the neutral suffix n.
|
|
395
|
+
*
|
|
396
|
+
* @param gradeValue - grade text whose leading character selects the color class
|
|
397
|
+
* @returns Lowercase letter "a", "b", "c", "d", "f", or "n"
|
|
398
|
+
*/
|
|
301
399
|
function gradeClass(gradeValue: string): string {
|
|
302
400
|
const letter = gradeValue[0]?.toLowerCase() ?? "n";
|
|
303
401
|
return ["a", "b", "c", "d", "f"].includes(letter) ? letter : "n";
|
|
304
402
|
}
|
|
305
403
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
404
|
+
/**
|
|
405
|
+
* Builds the inline stylesheet shared by static HTML reports and dashboard scan reports.
|
|
406
|
+
* Omitting diagnostic rules keeps reports without diagnostics smaller.
|
|
407
|
+
*
|
|
408
|
+
* @param shouldIncludeDiagnostics - whether to append CSS rules for the diagnostics section
|
|
409
|
+
* @returns Minified CSS text for embedding in the report style tag
|
|
410
|
+
*/
|
|
309
411
|
function htmlReportCss(shouldIncludeDiagnostics: boolean): string {
|
|
310
412
|
const baseCss = `:root{--ink:#0d0c0a;--ink-2:#161412;--ink-3:#1f1c19;--paper:#f3e9d2;--paper-dim:#b5ab94;--paper-mute:#7d735f;--rule:#2a2622;--forge:#e85d04;--grade-a:#7fa15a;--grade-b:#b8b450;--grade-c:#d08c36;--grade-d:#c2552b;--grade-f:#8b2828;--advisory:#b5ab94;--serif:Georgia,'Iowan Old Style',serif;--mono:'JetBrains Mono','IBM Plex Mono',ui-monospace,monospace}*{box-sizing:border-box;margin:0;padding:0}html{background:var(--ink);scrollbar-gutter:stable}body{font-family:var(--mono);color:var(--paper);background:var(--ink);min-height:100vh;line-height:1.5;font-size:14px;padding:48px 32px}.paper{max-width:1180px;margin:0 auto 24px;background:var(--ink-2);border:1px solid var(--rule);position:relative;padding:56px 64px 48px;scrollbar-gutter:stable}.corner-tr,.corner-bl,.paper:before,.paper:after{content:'';position:absolute;width:22px;height:22px;border:1px solid var(--forge)}.paper:before{top:12px;left:12px;border-right:0;border-bottom:0}.paper:after{bottom:12px;right:12px;border-left:0;border-top:0}.corner-tr{top:12px;right:12px;border-left:0;border-bottom:0}.corner-bl{bottom:12px;left:12px;border-right:0;border-top:0}.masthead{display:grid;grid-template-columns:1fr auto;gap:32px;padding-bottom:28px;border-bottom:1px solid var(--rule);align-items:end}.wordmark{font-family:var(--serif);font-weight:900;font-size:96px;line-height:.85;color:var(--paper);font-style:italic}.wordmark:after{content:'-ts';color:var(--forge);font-style:normal;font-size:.45em;margin-left:.15em;vertical-align:super}.tagline{margin-top:12px;font-size:11px;letter-spacing:0;color:var(--paper-mute);text-transform:uppercase}.meta{text-align:right;font-size:11px;color:var(--paper-dim);line-height:1.9}.label{color:var(--paper-mute);text-transform:uppercase;letter-spacing:0;margin-right:8px}.val{color:var(--paper)}.inspection-id{margin-top:10px;color:var(--forge);font-weight:700;font-size:12px;letter-spacing:0}.section-head{font-size:11px;letter-spacing:0;color:var(--paper-mute);text-transform:uppercase;padding-bottom:16px;margin-bottom:20px;border-bottom:1px solid var(--rule);display:flex;justify-content:space-between;align-items:baseline;font-family:var(--mono);font-weight:500;line-height:1.5}.section-head:before{content:'>';margin-right:10px;color:var(--forge);font-family:var(--serif);font-size:14px;font-style:italic}.aside{color:var(--paper-mute);font-size:10px;letter-spacing:0}.verdict{display:grid;grid-template-columns:auto 1fr;gap:56px;padding:48px 0;border-bottom:1px solid var(--rule);align-items:center}.grade-stamp{width:220px;height:220px;border:3px solid currentColor;color:var(--grade-b);display:flex;flex-direction:column;align-items:center;justify-content:center;transform:rotate(-4deg)}.grade-stamp.a,.grade.a,.grade-pill.a{color:var(--grade-a)}.grade-stamp.b,.grade.b,.grade-pill.b{color:var(--grade-b)}.grade-stamp.c,.grade.c,.grade-pill.c{color:var(--grade-c)}.grade-stamp.d,.grade.d,.grade-pill.d{color:var(--grade-d)}.grade-stamp.f,.grade.f,.grade-pill.f{color:var(--grade-f)}.grade-letter{font-family:var(--serif);font-style:italic;font-weight:900;font-size:112px;line-height:1}.grade-score{font-size:13px;letter-spacing:0}.verdict-body{display:flex;flex-direction:column;gap:18px}.verdict-headline{font-family:var(--serif);font-style:italic;font-weight:600;font-size:38px;line-height:1.15}.verdict-headline em{color:var(--forge)}.verdict-stats{display:grid;grid-template-columns:repeat(4,1fr);border-top:1px solid var(--rule);padding-top:20px}.stat{border-right:1px solid var(--rule);padding:0 18px}.stat:first-child{padding-left:0}.stat:last-child{border-right:0}.verdict-stats .num{font-family:var(--serif);font-weight:800;font-size:32px;line-height:1}.verdict-stats .num.warn{color:var(--grade-c)}.verdict-stats .num.fail{color:var(--grade-f)}.verdict-stats .num.note{color:var(--advisory)}.lbl{font-size:10px;text-transform:uppercase;letter-spacing:0;color:var(--paper-mute);margin-top:8px}.pillars,.offenders,.chart-section{padding:48px 0;border-bottom:1px solid var(--rule)}.pillar-grid{background:var(--ink-2)}.pillar-table{width:100%;border-collapse:collapse}.pillar-table .pillar-name{color:var(--paper);font-weight:500;text-transform:uppercase;letter-spacing:0;font-size:11px}.pillar-table .grade-pill{font-size:14px;padding:2px 8px;min-width:30px}table{width:100%;border-collapse:collapse;font-size:13px;table-layout:auto;font-family:var(--mono)}th{text-align:left;font-size:10px;text-transform:uppercase;letter-spacing:0;color:var(--paper-mute);font-weight:500;padding:12px 14px 12px 0;border-bottom:1px solid var(--rule)}th:last-child,td:last-child{padding-right:0}th.num,td.num{text-align:right;padding-left:18px}td{padding:14px 14px 14px 0;border-bottom:1px solid var(--ink-3);color:var(--paper-dim);font-size:13px;font-family:var(--mono);font-weight:500;line-height:1.4}td.num{color:var(--paper);font-variant-numeric:tabular-nums}.file-path{color:var(--paper);font-weight:500}.grade-pill{display:inline-block;font-family:var(--serif);font-style:italic;font-weight:800;font-size:18px;line-height:1;padding:4px 10px;border:1.5px solid currentColor;min-width:36px;text-align:center}.chart-summary{color:var(--paper-dim);font-size:12px;margin:-6px 0 18px}.chart-card{border:1px solid var(--rule);padding:24px;background:var(--ink-3)}.title{font-size:10px;text-transform:uppercase;letter-spacing:0;color:var(--paper-mute);margin-bottom:24px}.histogram{display:flex;align-items:flex-end;gap:6px;height:180px;padding-bottom:20px;border-bottom:1px solid var(--rule)}.bar{flex:1;background:var(--forge);position:relative;min-height:4px}.bar.warn{background:var(--grade-c)}.bar.fail{background:var(--grade-f)}.bar .count{position:absolute;top:-22px;left:50%;transform:translateX(-50%);font-size:11px}.histogram-axis{display:flex;gap:6px;margin-top:8px;font-size:10px;color:var(--paper-mute)}.histogram-axis span{flex:1;text-align:center}.findings{padding:48px 0}.finding{display:grid;grid-template-columns:auto 1fr auto;gap:24px;padding:18px 0;border-bottom:1px solid var(--ink-3);align-items:start}.severity{font-size:9px;text-transform:uppercase;letter-spacing:0;padding:4px 10px;border:1px solid currentColor;margin-top:2px;min-width:76px;text-align:center}.severity.fail{color:var(--grade-f)}.severity.warn{color:var(--grade-c)}.severity.note{color:var(--paper-mute)}.rule{font-size:10px;color:var(--forge);text-transform:uppercase;letter-spacing:0;margin-bottom:6px;font-family:var(--mono);font-weight:700;line-height:1.5}.msg{font-family:var(--serif);font-weight:500;font-size:17px;color:var(--paper);line-height:1.4}.loc{font-size:11px;color:var(--paper-mute);margin-top:8px}.loc code{color:var(--paper-dim);background:var(--ink-3);padding:1px 6px;border:1px solid var(--rule)}.loc-link{color:inherit;text-decoration:none}.loc-link:focus-visible{outline:2px solid var(--forge);outline-offset:3px}.points{font-size:10px;color:var(--paper-mute);text-align:right;letter-spacing:0;min-width:96px;padding-left:12px}.empty{color:var(--paper-dim);font-size:12px}.footer{margin-top:48px;padding-top:24px;border-top:1px solid var(--rule);display:grid;grid-template-columns:1fr auto 1fr;gap:24px;align-items:center;font-size:10px;color:var(--paper-mute);letter-spacing:0;text-transform:uppercase}.center{font-family:var(--serif);font-style:italic;font-size:13px;color:var(--paper-dim);text-transform:none;letter-spacing:0}.right{text-align:right}@media(max-width:900px){body{padding:16px}.paper{padding:28px 20px}.wordmark{font-size:64px}.masthead,.verdict{grid-template-columns:1fr}.meta{text-align:left}.grade-stamp{margin:0 auto}.verdict-stats{grid-template-columns:repeat(2,1fr);gap:16px}.stat{border-right:0;padding:0}.verdict-headline{font-size:28px}.footer{grid-template-columns:1fr}.center,.right{text-align:left}}@media(max-width:560px){.pillar-table thead{display:none}.pillar-table,.pillar-table tbody,.pillar-table tr,.pillar-table td{display:block;width:100%}.pillar-table tr{border-bottom:1px solid var(--ink-3);padding:10px 0}.pillar-table td{border-bottom:0;padding:6px 0}.pillar-table td.num{text-align:left;padding-left:0}.finding{grid-template-columns:1fr}.points{text-align:left;padding-left:0}.verdict-stats{grid-template-columns:1fr}.histogram{height:140px}}`;
|
|
311
413
|
const reportCss = `${baseCss}.dashboard-context{padding:28px 0;border-bottom:1px solid var(--rule)}.dashboard-context-grid{display:grid;grid-template-columns:1fr 1fr;gap:12px}.dashboard-context-grid>div{border:1px solid var(--rule);background:var(--ink-3);padding:12px 14px}.dashboard-context .label{display:block;margin:0 0 6px}.dashboard-context .val{overflow-wrap:anywhere}@media(max-width:700px){.dashboard-context-grid{grid-template-columns:1fr}}@media(max-width:560px){.offender-list thead{display:none}.offender-list,.offender-list tbody,.offender-list tr,.offender-list td{display:block;width:100%}.offender-list tr{border-bottom:1px solid var(--ink-3);padding:10px 0}.offender-list td{border-bottom:0;padding:6px 0}.offender-list td.num{text-align:left;padding-left:0}}`;
|
|
@@ -315,8 +417,13 @@ function htmlReportCss(shouldIncludeDiagnostics: boolean): string {
|
|
|
315
417
|
return `${reportCss}.diagnostics{padding:28px 0 0}.diagnostic-list{display:grid;gap:10px}.diagnostic{display:grid;grid-template-columns:auto 1fr;gap:10px 14px;border:1px solid var(--rule);background:var(--ink-3);padding:12px 14px;color:var(--paper-dim);font-size:12px}.diagnostic-type{text-transform:uppercase;letter-spacing:0;color:var(--forge);font-size:10px}.diagnostic-location{grid-column:2;color:var(--paper-mute);font-size:11px}`;
|
|
316
418
|
}
|
|
317
419
|
|
|
318
|
-
|
|
319
|
-
|
|
420
|
+
/**
|
|
421
|
+
* Renders the dashboard shell with an iframe and control panel so scans can reload without losing form state.
|
|
422
|
+
*
|
|
423
|
+
* @param projectRoot - initial project root directory populating the form input and scan URL
|
|
424
|
+
* @param scanPath - initial scan path populating the form input and scan URL
|
|
425
|
+
* @returns Complete HTML document for the dashboard home page
|
|
426
|
+
*/
|
|
320
427
|
function dashboardHomeHtml(projectRoot: string, scanPath: string): string {
|
|
321
428
|
const initialScan = dashboardScanUrl(projectRoot, scanPath);
|
|
322
429
|
return `<!doctype html>
|
|
@@ -350,14 +457,26 @@ function dashboardHomeHtml(projectRoot: string, scanPath: string): string {
|
|
|
350
457
|
</html>`;
|
|
351
458
|
}
|
|
352
459
|
|
|
353
|
-
|
|
460
|
+
/**
|
|
461
|
+
* Builds the /scan request URL encoded as form query parameters with spaces written as +.
|
|
462
|
+
*
|
|
463
|
+
* @param projectRoot - project root directory serialized as the projectRoot query parameter
|
|
464
|
+
* @param scanPath - target scan path serialized as the path query parameter
|
|
465
|
+
* @returns Relative /scan URL with encoded projectRoot and path query parameters
|
|
466
|
+
*/
|
|
354
467
|
function dashboardScanUrl(projectRoot: string, scanPath: string): string {
|
|
355
468
|
const params = new URLSearchParams({ projectRoot, path: scanPath });
|
|
356
469
|
return `/scan?${params.toString()}`;
|
|
357
470
|
}
|
|
358
471
|
|
|
359
|
-
|
|
360
|
-
|
|
472
|
+
/**
|
|
473
|
+
* Renders the dashboard failure page and escapes all three values because error text and paths can contain repository-controlled content.
|
|
474
|
+
*
|
|
475
|
+
* @param message - failure reason displayed in the error body
|
|
476
|
+
* @param projectRoot - project root directory identifying the failed scan
|
|
477
|
+
* @param scanPath - target scan path identifying the failed scan
|
|
478
|
+
* @returns Complete HTML document for the dashboard scan error page
|
|
479
|
+
*/
|
|
361
480
|
function dashboardErrorHtml(message: string, projectRoot: string, scanPath: string): string {
|
|
362
481
|
const escapedMessage = escapeHtml(message);
|
|
363
482
|
const escapedProjectRoot = escapeHtml(projectRoot);
|
|
@@ -383,20 +502,33 @@ function dashboardErrorHtml(message: string, projectRoot: string, scanPath: stri
|
|
|
383
502
|
</html>`;
|
|
384
503
|
}
|
|
385
504
|
|
|
386
|
-
|
|
387
|
-
|
|
505
|
+
/**
|
|
506
|
+
* Provides the stylesheet shared by the dashboard shell and its error page.
|
|
507
|
+
* Inlined rather than linked so the dashboard stays self-contained without separate asset routes for offline use.
|
|
508
|
+
*
|
|
509
|
+
* @returns Minified CSS text for the dashboard shell and error page
|
|
510
|
+
*/
|
|
388
511
|
function dashboardCss(): string {
|
|
389
512
|
return `:root{color-scheme:dark;--ink:#0d0c0a;--ink-2:#161412;--panel:#1f1c19;--paper:#f3e9d2;--paper-dim:#b5ab94;--paper-mute:#7d735f;--rule:#2a2622;--forge:#e85d04;--forge-dark:#b94402;--mono:'JetBrains Mono','IBM Plex Mono',ui-monospace,monospace}*{box-sizing:border-box}html,body{height:100%;margin:0;background:var(--ink);color:var(--paper);font-family:var(--mono);font-size:14px;line-height:1.5}.report-frame{position:fixed;inset:0;width:100%;height:100%;border:0;background:var(--ink)}.controls-toggle{position:fixed;top:18px;right:18px;z-index:3;width:44px;height:44px;border:1px solid rgba(232,93,4,.75);border-radius:8px;background:var(--forge);color:#170b05;font:700 22px/1 var(--mono);display:grid;place-items:center;cursor:pointer;box-shadow:0 16px 36px rgba(0,0,0,.38)}.controls-toggle:hover,.controls-toggle:focus-visible{background:#ff7a1a;outline:2px solid rgba(243,233,210,.75);outline-offset:3px}.controls-panel{position:fixed;z-index:2;top:74px;right:18px;width:min(420px,calc(100vw - 36px));max-height:calc(100vh - 92px);overflow:auto;background:rgba(31,28,25,.98);border:1px solid var(--rule);border-radius:8px;padding:20px;box-shadow:0 24px 70px rgba(0,0,0,.5)}[hidden]{display:none!important}.controls-head{border-bottom:1px solid var(--rule);padding-bottom:14px;margin-bottom:16px}.controls-head h1{margin:0;font-size:18px;font-weight:800}.controls-head p{margin:4px 0 0;color:var(--paper-mute);font-size:12px;text-transform:uppercase}.scan-form{display:grid;gap:14px}.scan-form label{display:grid;gap:6px;color:var(--paper-dim);font-size:12px;text-transform:uppercase}.scan-form input{width:100%;font:inherit;color:var(--paper);background:var(--ink-2);border:1px solid var(--rule);border-radius:6px;padding:10px 11px;min-width:0}.scan-form input:focus{outline:2px solid var(--forge);outline-offset:2px}.scan-state{display:flex;justify-content:space-between;gap:12px;border:1px solid var(--rule);background:var(--ink-2);border-radius:6px;padding:10px 11px;color:var(--paper-mute)}.scan-state strong{color:var(--paper);font-weight:700;text-align:right}.actions{display:grid;grid-template-columns:1fr 1fr;gap:10px}.actions button{font:inherit;border:1px solid var(--forge);border-radius:6px;padding:10px 12px;background:var(--forge);color:#170b05;font-weight:800;cursor:pointer}.actions button.secondary{background:transparent;color:var(--paper);border-color:var(--rule)}.actions button:disabled{opacity:.6;cursor:wait}.scan-error{max-width:720px;margin:8vh auto;padding:48px;background:var(--panel);border:1px solid var(--rule);color:var(--paper)}.scan-error h1{margin:0 0 16px;font-size:28px}.scan-error p{color:var(--paper-dim);overflow-wrap:anywhere}.scan-error dl{display:grid;grid-template-columns:auto 1fr;gap:8px 16px;margin:24px 0 0}.scan-error dt{color:var(--paper-mute);text-transform:uppercase}.scan-error dd{margin:0;overflow-wrap:anywhere}@media(max-width:560px){.controls-toggle{top:12px;right:12px}.controls-panel{top:64px;right:12px;width:calc(100vw - 24px);max-height:calc(100vh - 76px);padding:16px}.actions{grid-template-columns:1fr}.scan-error{margin:0;min-height:100vh;padding:28px 20px}.scan-error dl{grid-template-columns:1fr}}`;
|
|
390
513
|
}
|
|
391
514
|
|
|
392
|
-
|
|
393
|
-
|
|
515
|
+
/**
|
|
516
|
+
* Provides the inline script served with the dashboard shell.
|
|
517
|
+
* Updates the URL via history.replaceState so a maintainer can copy and reproduce the current scan without re-typing controls.
|
|
518
|
+
*
|
|
519
|
+
* @returns Minified client-side JavaScript controlling the panel toggle, scan form, and iframe state
|
|
520
|
+
*/
|
|
394
521
|
function dashboardJs(): string {
|
|
395
522
|
return `const form=document.querySelector("[data-scan-form]");const frame=document.querySelector(".report-frame");const toggle=document.querySelector(".controls-toggle");const panel=document.querySelector(".controls-panel");const refresh=document.querySelector("[data-refresh]");const status=document.querySelector("[data-scan-status]");function setOpen(open){panel.hidden=!open;toggle.setAttribute("aria-expanded",String(open));if(open){const input=form.querySelector("input");if(input){input.focus();}}}function params(){return new URLSearchParams(new FormData(form));}function runScan(){const query=params();status.textContent="Scanning";refresh.disabled=true;form.querySelector("button[type=submit]").disabled=true;frame.src="/scan?"+query.toString();history.replaceState(null,"","/?"+query.toString());}toggle.addEventListener("click",()=>setOpen(panel.hidden));document.addEventListener("keydown",(event)=>{if(event.key==="Escape"){setOpen(false);}});form.addEventListener("submit",(event)=>{event.preventDefault();runScan();});refresh.addEventListener("click",runScan);frame.addEventListener("load",()=>{status.textContent="Ready";refresh.disabled=false;form.querySelector("button[type=submit]").disabled=false;});`;
|
|
396
523
|
}
|
|
397
524
|
|
|
398
|
-
|
|
399
|
-
|
|
525
|
+
/**
|
|
526
|
+
* Escapes &, <, >, and double quotes for report text and double-quoted attributes.
|
|
527
|
+
* Escapes & first so that the entities inserted by the other replacements stay intact.
|
|
528
|
+
*
|
|
529
|
+
* @param htmlText - raw text to sanitize before embedding in HTML content or double-quoted attributes
|
|
530
|
+
* @returns Escaped text safe for HTML text nodes and double-quoted attribute values
|
|
531
|
+
*/
|
|
400
532
|
function escapeHtml(htmlText: string): string {
|
|
401
533
|
return htmlText.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """);
|
|
402
534
|
}
|