dart-decimate 0.0.7 → 0.0.8
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/Cargo.lock +1 -1
- package/Cargo.toml +1 -1
- package/README.md +35 -48
- package/package.json +2 -1
- package/src/output/html/assets.rs +164 -0
- package/src/output/html/tests.rs +410 -0
- package/src/output/html.rs +176 -241
package/Cargo.lock
CHANGED
package/Cargo.toml
CHANGED
package/README.md
CHANGED
|
@@ -44,6 +44,21 @@ dependencies, duplicated code, complex functions, dependency hygiene,
|
|
|
44
44
|
architecture drift, Flutter graph issues, security candidates, and PR-risk
|
|
45
45
|
signals.
|
|
46
46
|
|
|
47
|
+
To open the same report in your browser:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
npx --yes dart-decimate html .
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
To review only files changed from another branch or ref:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
npx --yes dart-decimate html . --compare origin/main
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
`--compare REF` aliases `--changed-since REF`. If the ref is not found,
|
|
60
|
+
Dart Decimate suggests similar local or remote branches.
|
|
61
|
+
|
|
47
62
|
For JSON output that agents and CI can parse:
|
|
48
63
|
|
|
49
64
|
```bash
|
|
@@ -76,7 +91,7 @@ Add this to `package.json` if you want a short project command:
|
|
|
76
91
|
"dart-decimate": "dart-decimate json ."
|
|
77
92
|
},
|
|
78
93
|
"devDependencies": {
|
|
79
|
-
"dart-decimate": "^0.0.
|
|
94
|
+
"dart-decimate": "^0.0.8"
|
|
80
95
|
}
|
|
81
96
|
}
|
|
82
97
|
```
|
|
@@ -149,6 +164,10 @@ The `html` shortcut opens the report by default. On report commands, use
|
|
|
149
164
|
`--format html` to print static HTML or `--open` to write a private temporary
|
|
150
165
|
file and open it in the default browser.
|
|
151
166
|
|
|
167
|
+
Generated finding reports group issues by type in numbered, collapsible
|
|
168
|
+
sections. Search narrows visible findings, and type filters open the selected
|
|
169
|
+
group.
|
|
170
|
+
|
|
152
171
|
Human terminal reports strip control characters from user-derived paths and
|
|
153
172
|
messages; HTML reports escape user-derived content.
|
|
154
173
|
|
|
@@ -558,49 +577,8 @@ dart-decimate schema --format json | jq .issue_types
|
|
|
558
577
|
|
|
559
578
|
Current issue types:
|
|
560
579
|
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
unused-export
|
|
564
|
-
unused-type
|
|
565
|
-
private-type-leak
|
|
566
|
-
unused-enum-member
|
|
567
|
-
unused-class-member
|
|
568
|
-
duplicate-export
|
|
569
|
-
route-collision
|
|
570
|
-
private-widget-class
|
|
571
|
-
widget-top-level-function-boundary
|
|
572
|
-
unused-widget-param
|
|
573
|
-
unrendered-widget
|
|
574
|
-
missing-context-mounted-after-await
|
|
575
|
-
missing-entry-point
|
|
576
|
-
circular-dependency
|
|
577
|
-
re-export-cycle
|
|
578
|
-
boundary-violation
|
|
579
|
-
boundary-coverage
|
|
580
|
-
boundary-call-violation
|
|
581
|
-
policy-violation
|
|
582
|
-
unresolved-dependency
|
|
583
|
-
part-of-violation
|
|
584
|
-
unused-dependency
|
|
585
|
-
unused-dev-dependency
|
|
586
|
-
test-only-dependency
|
|
587
|
-
unused-dependency-override
|
|
588
|
-
misconfigured-dependency-override
|
|
589
|
-
unlisted-dependency
|
|
590
|
-
private-src-import
|
|
591
|
-
code-duplication
|
|
592
|
-
high-cyclomatic-complexity
|
|
593
|
-
high-cognitive-complexity
|
|
594
|
-
high-complexity
|
|
595
|
-
coverage-gap
|
|
596
|
-
high-crap-score
|
|
597
|
-
health-hotspot
|
|
598
|
-
refactoring-target
|
|
599
|
-
feature-flag
|
|
600
|
-
security-candidate
|
|
601
|
-
stale-suppression
|
|
602
|
-
missing-suppression-reason
|
|
603
|
-
```
|
|
580
|
+
See [docs/issue-types.md](docs/issue-types.md). Prefer the schema command when
|
|
581
|
+
you need the installed binary's exact list.
|
|
604
582
|
|
|
605
583
|
## CI
|
|
606
584
|
|
|
@@ -636,7 +614,9 @@ This repository already runs:
|
|
|
636
614
|
- Rust format, clippy, and tests
|
|
637
615
|
- npm package checks
|
|
638
616
|
- version sync between `Cargo.toml` and `package.json`
|
|
639
|
-
- a
|
|
617
|
+
- a PR version-bump gate requiring both package files to increase to an
|
|
618
|
+
unpublished version
|
|
619
|
+
- release guards that reject reused npm versions or tags on different commits
|
|
640
620
|
- migration checks that block previous package, command, schema, and MCP names
|
|
641
621
|
- Dependabot and weekly dependency/security audits
|
|
642
622
|
|
|
@@ -680,6 +660,7 @@ cargo fmt --check
|
|
|
680
660
|
cargo clippy --all-targets -- -D warnings
|
|
681
661
|
cargo test --all-targets
|
|
682
662
|
npm run version:check
|
|
663
|
+
npm run version:bump:check -- origin/main
|
|
683
664
|
npm run release:check
|
|
684
665
|
npm run migration:check
|
|
685
666
|
npm run pack:check
|
|
@@ -689,19 +670,25 @@ This repository forbids `unsafe_code`.
|
|
|
689
670
|
|
|
690
671
|
## Release Flow
|
|
691
672
|
|
|
692
|
-
Current version: `0.0.
|
|
673
|
+
Current version: `0.0.8`.
|
|
693
674
|
|
|
694
|
-
After the first public release, changes should go through pull requests.
|
|
675
|
+
After the first public release, changes should go through pull requests. Every
|
|
676
|
+
PR to `main` must bump both `Cargo.toml` and `package.json` above the base
|
|
677
|
+
branch and to an unpublished npm version.
|
|
695
678
|
|
|
696
679
|
To release a new version:
|
|
697
680
|
|
|
698
|
-
1. Update both `Cargo.toml` and `package.json
|
|
681
|
+
1. Update both `Cargo.toml` and `package.json` to the same unpublished version.
|
|
699
682
|
2. Open a PR.
|
|
700
683
|
3. Let CI pass.
|
|
701
684
|
4. Merge to `main`.
|
|
702
685
|
5. GitHub Actions publishes `dart-decimate` to npm, creates tag `vX.Y.Z`, and
|
|
703
686
|
creates the GitHub release.
|
|
704
687
|
|
|
688
|
+
Release reruns for the same commit may update GitHub release assets. If the npm
|
|
689
|
+
package already exists for that commit, the publish step is skipped; a reused tag
|
|
690
|
+
or npm version from another commit fails.
|
|
691
|
+
|
|
705
692
|
Local hooks block stale package names, mismatched versions, reused npm versions,
|
|
706
693
|
and direct pushes to `main`.
|
|
707
694
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dart-decimate",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "Rust-native codebase intelligence for Dart and Flutter module graphs.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"scripts": {
|
|
29
29
|
"postinstall": "node npm/scripts/postinstall.js",
|
|
30
30
|
"version:check": "node scripts/check-version-sync.mjs",
|
|
31
|
+
"version:bump:check": "node scripts/check-pr-version-bump.mjs",
|
|
31
32
|
"release:check": "node scripts/check-release-version.mjs",
|
|
32
33
|
"migration:check": "node scripts/check-dart-decimate-migration.mjs",
|
|
33
34
|
"pack:check": "npm pack --dry-run",
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/// Report UI tokens, layout, and static progressive-enhancement behavior.
|
|
2
|
+
pub(super) fn render_style(html: &mut String) {
|
|
3
|
+
html.push_str(
|
|
4
|
+
r#"<style>
|
|
5
|
+
:root {
|
|
6
|
+
color-scheme: dark;
|
|
7
|
+
--bg: #090909;
|
|
8
|
+
--surface: #121212;
|
|
9
|
+
--surface-raised: #181818;
|
|
10
|
+
--line: #2d2d2f;
|
|
11
|
+
--line-strong: #3a3a3d;
|
|
12
|
+
--text: #f4f4f5;
|
|
13
|
+
--muted: #ababaf;
|
|
14
|
+
--accent: #8fdcff;
|
|
15
|
+
--focus: #c7f0ff;
|
|
16
|
+
--error: #ff6b6b;
|
|
17
|
+
--warn: #ffd166;
|
|
18
|
+
--pass: #64d98a;
|
|
19
|
+
}
|
|
20
|
+
* { box-sizing: border-box; }
|
|
21
|
+
[hidden] { display: none !important; }
|
|
22
|
+
body {
|
|
23
|
+
margin: 0;
|
|
24
|
+
background: var(--bg);
|
|
25
|
+
color: var(--text);
|
|
26
|
+
font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
27
|
+
}
|
|
28
|
+
main { max-width: 1120px; margin: 0 auto; padding: 32px 24px 52px; }
|
|
29
|
+
h1, h2, h3, p { margin: 0; }
|
|
30
|
+
h1 { font-size: 2rem; letter-spacing: 0; line-height: 1.15; }
|
|
31
|
+
h2 { margin-top: 30px; font-size: 1.25rem; }
|
|
32
|
+
.topline { color: var(--muted); margin-bottom: 8px; text-transform: uppercase; letter-spacing: .08em; font-size: 12px; }
|
|
33
|
+
.hero { border-bottom: 1px solid var(--line); padding-bottom: 22px; }
|
|
34
|
+
.verdict { display: inline-flex; align-items: center; gap: 8px; margin-top: 14px; padding: 6px 9px; border: 1px solid var(--line); border-radius: 6px; }
|
|
35
|
+
.pass { color: var(--pass); }
|
|
36
|
+
.fail, .error { color: var(--error); }
|
|
37
|
+
.warning { color: var(--warn); }
|
|
38
|
+
.metrics, .groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px 18px; margin-top: 22px; }
|
|
39
|
+
.metric { border-top: 1px solid var(--line); padding-top: 10px; }
|
|
40
|
+
.group, .step { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
|
|
41
|
+
.metric span, .group span, .label { color: var(--muted); display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
|
|
42
|
+
.metric strong { display: block; margin-top: 4px; font-size: 1.35rem; }
|
|
43
|
+
.group p { margin-top: 8px; color: var(--text); }
|
|
44
|
+
.finding-tools { display: grid; gap: 12px; margin-top: 14px; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
|
|
45
|
+
.finding-tools label, .filter-label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
|
|
46
|
+
.finding-tools input { width: 100%; min-height: 44px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--bg); color: var(--text); font: inherit; padding: 8px 10px; }
|
|
47
|
+
.finding-tools input:focus { outline: 2px solid var(--focus); outline-offset: 2px; }
|
|
48
|
+
.filter-set { display: grid; gap: 8px; }
|
|
49
|
+
.filter-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
|
|
50
|
+
.type-filter { min-height: 44px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--bg); color: var(--text); cursor: pointer; font: inherit; padding: 8px 10px; text-align: left; }
|
|
51
|
+
.type-filter:hover { border-color: var(--muted); }
|
|
52
|
+
.type-filter:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
|
|
53
|
+
.type-filter[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); background: #10232b; }
|
|
54
|
+
.finding-status, .empty-results { grid-column: 1 / -1; color: var(--muted); font-size: 13px; }
|
|
55
|
+
.finding-groups { display: grid; gap: 12px; margin-top: 14px; }
|
|
56
|
+
.finding-group { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
|
|
57
|
+
.finding-group > summary { display: flex; align-items: center; justify-content: space-between; gap: 16px; cursor: pointer; list-style: none; padding: 14px 16px; }
|
|
58
|
+
.finding-group > summary::-webkit-details-marker { display: none; }
|
|
59
|
+
.finding-group > summary:hover { background: var(--surface-raised); }
|
|
60
|
+
.finding-group > summary:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
|
|
61
|
+
.finding-group[open] > summary { border-bottom: 1px solid var(--line); }
|
|
62
|
+
.summary-title { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; align-items: start; }
|
|
63
|
+
.summary-text { display: grid; gap: 3px; min-width: 0; }
|
|
64
|
+
.group-number { color: var(--muted); font-variant-numeric: tabular-nums; }
|
|
65
|
+
.summary-title strong { font-size: 1rem; }
|
|
66
|
+
.summary-right { display: inline-flex; align-items: center; gap: 12px; }
|
|
67
|
+
.summary-meta { color: var(--muted); font-size: 13px; text-align: right; }
|
|
68
|
+
.chevron { width: 9px; height: 9px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transform-origin: center; }
|
|
69
|
+
.finding-group[open] .chevron { transform: rotate(225deg); }
|
|
70
|
+
.findings { display: grid; gap: 12px; margin-top: 14px; }
|
|
71
|
+
.finding-group .findings { margin-top: 0; padding: 12px; }
|
|
72
|
+
.finding { background: var(--surface-raised); border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
|
|
73
|
+
.finding header { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
|
|
74
|
+
.finding h3 { font-size: 1rem; }
|
|
75
|
+
.rule, .location, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
|
|
76
|
+
.rule { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
|
|
77
|
+
.section { margin-top: 10px; }
|
|
78
|
+
.section p { margin-top: 3px; overflow-wrap: anywhere; }
|
|
79
|
+
.evidence { margin: 8px 0 0; padding-left: 18px; color: var(--text); }
|
|
80
|
+
.evidence li { margin: 3px 0; overflow-wrap: anywhere; }
|
|
81
|
+
.command { overflow-wrap: anywhere; color: var(--accent); }
|
|
82
|
+
a { color: var(--accent); text-decoration: none; }
|
|
83
|
+
a:hover { text-decoration: underline; }
|
|
84
|
+
@media (max-width: 720px) {
|
|
85
|
+
main { padding: 24px 16px 44px; }
|
|
86
|
+
h1 { font-size: 1.65rem; }
|
|
87
|
+
.finding-group > summary { align-items: flex-start; flex-direction: column; }
|
|
88
|
+
.summary-right { justify-content: space-between; width: 100%; }
|
|
89
|
+
.summary-meta { text-align: left; }
|
|
90
|
+
}
|
|
91
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
92
|
+
.finding-group > summary, .finding-tools input, .type-filter { transition: background-color .16s ease, border-color .16s ease, color .16s ease; }
|
|
93
|
+
.chevron { transition: transform .16s ease; }
|
|
94
|
+
}
|
|
95
|
+
</style>
|
|
96
|
+
"#,
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
pub(super) fn render_interaction_script(html: &mut String) {
|
|
101
|
+
html.push_str(
|
|
102
|
+
r#"<script>
|
|
103
|
+
(() => {
|
|
104
|
+
const controls = document.querySelector("[data-finding-controls]");
|
|
105
|
+
if (!controls) return;
|
|
106
|
+
const searchInput = controls.querySelector("[data-finding-search]");
|
|
107
|
+
const filterButtons = Array.from(controls.querySelectorAll("[data-finding-filter]"));
|
|
108
|
+
const status = controls.querySelector("[data-finding-status]");
|
|
109
|
+
const emptyResults = document.querySelector("[data-empty-results]");
|
|
110
|
+
const groups = Array.from(document.querySelectorAll("[data-finding-group]"));
|
|
111
|
+
if (!searchInput || filterButtons.length === 0 || !status || groups.length === 0) return;
|
|
112
|
+
const totalFindings = Number(status.dataset.total || 0);
|
|
113
|
+
let selectedType = "";
|
|
114
|
+
|
|
115
|
+
const syncButtons = () => {
|
|
116
|
+
for (const button of filterButtons) {
|
|
117
|
+
button.setAttribute("aria-pressed", button.dataset.kind === selectedType ? "true" : "false");
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const update = () => {
|
|
122
|
+
const query = searchInput.value.trim().toLowerCase();
|
|
123
|
+
let visibleFindings = 0;
|
|
124
|
+
let visibleGroups = 0;
|
|
125
|
+
|
|
126
|
+
for (const group of groups) {
|
|
127
|
+
const typeMatches = !selectedType || group.dataset.kind === selectedType;
|
|
128
|
+
let groupMatches = 0;
|
|
129
|
+
const findings = Array.from(group.querySelectorAll("[data-finding]"));
|
|
130
|
+
|
|
131
|
+
for (const finding of findings) {
|
|
132
|
+
const textMatches = !query || finding.textContent.toLowerCase().includes(query);
|
|
133
|
+
const visible = typeMatches && textMatches;
|
|
134
|
+
finding.hidden = !visible;
|
|
135
|
+
if (visible) groupMatches += 1;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
group.hidden = groupMatches === 0;
|
|
139
|
+
if (groupMatches > 0) {
|
|
140
|
+
visibleGroups += 1;
|
|
141
|
+
visibleFindings += groupMatches;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
status.textContent = `Showing ${visibleFindings} of ${totalFindings} findings in ${visibleGroups} ${visibleGroups === 1 ? "type" : "types"}.`;
|
|
146
|
+
if (emptyResults) emptyResults.hidden = visibleFindings !== 0;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
searchInput.addEventListener("input", update);
|
|
150
|
+
for (const button of filterButtons) {
|
|
151
|
+
button.addEventListener("click", () => {
|
|
152
|
+
selectedType = button.dataset.kind || "";
|
|
153
|
+
syncButtons();
|
|
154
|
+
if (selectedType) {
|
|
155
|
+
for (const group of groups) group.open = group.dataset.kind === selectedType;
|
|
156
|
+
}
|
|
157
|
+
update();
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
})();
|
|
161
|
+
</script>
|
|
162
|
+
"#,
|
|
163
|
+
);
|
|
164
|
+
}
|
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
use super::*;
|
|
2
|
+
use crate::output::{FindingAction, FindingEdge, NextStep, ReportCommand, ReportSummary};
|
|
3
|
+
|
|
4
|
+
#[test]
|
|
5
|
+
fn renders_browser_ready_report_with_escaped_evidence() {
|
|
6
|
+
let report = JsonReport {
|
|
7
|
+
schema_version: "dart-decimate.report.v1".to_owned(),
|
|
8
|
+
kind: "combined".to_owned(),
|
|
9
|
+
tool: "dart-decimate".to_owned(),
|
|
10
|
+
command: ReportCommand::Check,
|
|
11
|
+
verdict: Verdict::Fail,
|
|
12
|
+
summary: ReportSummary {
|
|
13
|
+
files: 3,
|
|
14
|
+
edges: 2,
|
|
15
|
+
findings: 1,
|
|
16
|
+
cycles: 1,
|
|
17
|
+
..ReportSummary::default()
|
|
18
|
+
},
|
|
19
|
+
findings: vec![Finding {
|
|
20
|
+
rule_id: "dart-decimate/circular-dependency".to_owned(),
|
|
21
|
+
fingerprint: Some("cycle:<unsafe>".to_owned()),
|
|
22
|
+
kind: FindingKind::CircularDependency,
|
|
23
|
+
severity: Severity::Error,
|
|
24
|
+
message: "Circular dependency spans 3 Dart files".to_owned(),
|
|
25
|
+
path: "lib/a.dart".to_owned(),
|
|
26
|
+
line: 1,
|
|
27
|
+
column: 0,
|
|
28
|
+
safe_to_delete: false,
|
|
29
|
+
files: vec![
|
|
30
|
+
"lib/a.dart".to_owned(),
|
|
31
|
+
"lib/b.dart".to_owned(),
|
|
32
|
+
"lib/c.dart".to_owned(),
|
|
33
|
+
],
|
|
34
|
+
edge: None,
|
|
35
|
+
actions: vec![
|
|
36
|
+
FindingAction::new(
|
|
37
|
+
"break-cycle",
|
|
38
|
+
"Move shared dependencies inward or invert one import edge",
|
|
39
|
+
false,
|
|
40
|
+
)
|
|
41
|
+
.with_dart_decimate_args([
|
|
42
|
+
"inspect",
|
|
43
|
+
"--format",
|
|
44
|
+
"json",
|
|
45
|
+
"--file",
|
|
46
|
+
"lib/a.dart",
|
|
47
|
+
]),
|
|
48
|
+
],
|
|
49
|
+
}],
|
|
50
|
+
clone_groups: Vec::new(),
|
|
51
|
+
complexity: Vec::new(),
|
|
52
|
+
file_scores: Vec::new(),
|
|
53
|
+
hotspots: Vec::new(),
|
|
54
|
+
refactoring_targets: Vec::new(),
|
|
55
|
+
threshold_overrides: Vec::new(),
|
|
56
|
+
feature_flags: Vec::new(),
|
|
57
|
+
security_candidates: Vec::new(),
|
|
58
|
+
attack_surface: Vec::new(),
|
|
59
|
+
runtime_coverage: None,
|
|
60
|
+
next_steps: Vec::new(),
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
let rendered = render_html_report(&report);
|
|
64
|
+
|
|
65
|
+
assert!(rendered.starts_with("<!doctype html>"));
|
|
66
|
+
assert!(rendered.contains("<h1>check report</h1>"));
|
|
67
|
+
assert!(rendered.contains("Architecture"));
|
|
68
|
+
assert!(rendered.contains("1 circular dependency"));
|
|
69
|
+
assert!(rendered.contains("Why"));
|
|
70
|
+
assert!(rendered.contains("cycle:<unsafe>"));
|
|
71
|
+
assert!(rendered.contains("lib/a.dart -> lib/b.dart -> lib/c.dart -> lib/a.dart"));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
#[test]
|
|
75
|
+
fn groups_findings_by_type_with_search_and_type_controls() {
|
|
76
|
+
let report = JsonReport {
|
|
77
|
+
schema_version: "dart-decimate.report.v1".to_owned(),
|
|
78
|
+
kind: "combined".to_owned(),
|
|
79
|
+
tool: "dart-decimate".to_owned(),
|
|
80
|
+
command: ReportCommand::Check,
|
|
81
|
+
verdict: Verdict::Fail,
|
|
82
|
+
summary: ReportSummary {
|
|
83
|
+
files: 4,
|
|
84
|
+
edges: 3,
|
|
85
|
+
findings: 3,
|
|
86
|
+
unresolved_dependencies: 2,
|
|
87
|
+
unused_widget_params: 1,
|
|
88
|
+
..ReportSummary::default()
|
|
89
|
+
},
|
|
90
|
+
findings: vec![
|
|
91
|
+
finding(
|
|
92
|
+
FindingKind::UnresolvedDependency,
|
|
93
|
+
"dart-decimate/unresolved-dependency",
|
|
94
|
+
"Missing local import lib/missing_a.dart",
|
|
95
|
+
"lib/a.dart",
|
|
96
|
+
),
|
|
97
|
+
finding(
|
|
98
|
+
FindingKind::UnresolvedDependency,
|
|
99
|
+
"dart-decimate/unresolved-dependency",
|
|
100
|
+
"Missing local import lib/missing_b.dart",
|
|
101
|
+
"lib/b.dart",
|
|
102
|
+
),
|
|
103
|
+
finding(
|
|
104
|
+
FindingKind::UnusedWidgetParam,
|
|
105
|
+
"dart-decimate/unused-widget-param",
|
|
106
|
+
"Widget constructor parameter is never read",
|
|
107
|
+
"lib/widget.dart",
|
|
108
|
+
),
|
|
109
|
+
],
|
|
110
|
+
clone_groups: Vec::new(),
|
|
111
|
+
complexity: Vec::new(),
|
|
112
|
+
file_scores: Vec::new(),
|
|
113
|
+
hotspots: Vec::new(),
|
|
114
|
+
refactoring_targets: Vec::new(),
|
|
115
|
+
threshold_overrides: Vec::new(),
|
|
116
|
+
feature_flags: Vec::new(),
|
|
117
|
+
security_candidates: Vec::new(),
|
|
118
|
+
attack_surface: Vec::new(),
|
|
119
|
+
runtime_coverage: None,
|
|
120
|
+
next_steps: Vec::new(),
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
let rendered = render_html_report(&report);
|
|
124
|
+
|
|
125
|
+
assert!(rendered.contains("data-finding-search"));
|
|
126
|
+
assert!(!rendered.contains("data-finding-type"));
|
|
127
|
+
assert!(rendered.contains(
|
|
128
|
+
"<button class=\"type-filter\" type=\"button\" data-finding-filter data-kind=\"Unused widget parameter\" aria-pressed=\"false\">2. Unused widget parameter (1)</button>"
|
|
129
|
+
));
|
|
130
|
+
assert!(!rendered.contains("if (query || selectedType) group.open = true;"));
|
|
131
|
+
assert!(rendered.contains("<details class=\"finding-group\" data-finding-group data-kind=\"Unresolved dependency\" open>"));
|
|
132
|
+
assert!(rendered.contains(
|
|
133
|
+
"<details class=\"finding-group\" data-finding-group data-kind=\"Unused widget parameter\">"
|
|
134
|
+
));
|
|
135
|
+
assert!(rendered.contains("<span class=\"group-number\">2.</span>"));
|
|
136
|
+
assert!(rendered.contains("<span class=\"chevron\" aria-hidden=\"true\"></span>"));
|
|
137
|
+
assert!(rendered.contains("2 findings | 2 errors"));
|
|
138
|
+
assert!(rendered.contains("1 finding | 1 error"));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
#[test]
|
|
142
|
+
fn group_headers_render_unique_rule_ids_only_when_concise() {
|
|
143
|
+
let report = JsonReport {
|
|
144
|
+
schema_version: "dart-decimate.report.v1".to_owned(),
|
|
145
|
+
kind: "combined".to_owned(),
|
|
146
|
+
tool: "dart-decimate".to_owned(),
|
|
147
|
+
command: ReportCommand::Check,
|
|
148
|
+
verdict: Verdict::Fail,
|
|
149
|
+
summary: ReportSummary {
|
|
150
|
+
files: 6,
|
|
151
|
+
findings: 6,
|
|
152
|
+
policy_violations: 2,
|
|
153
|
+
security_candidates: 4,
|
|
154
|
+
..ReportSummary::default()
|
|
155
|
+
},
|
|
156
|
+
findings: vec![
|
|
157
|
+
finding(
|
|
158
|
+
FindingKind::PolicyViolation,
|
|
159
|
+
"dart-decimate/policy/mobile/no-dart-io",
|
|
160
|
+
"dart:io is not allowed",
|
|
161
|
+
"lib/io.dart",
|
|
162
|
+
),
|
|
163
|
+
finding(
|
|
164
|
+
FindingKind::PolicyViolation,
|
|
165
|
+
"dart-decimate/policy/mobile/no-process",
|
|
166
|
+
"Process APIs are not allowed",
|
|
167
|
+
"lib/process.dart",
|
|
168
|
+
),
|
|
169
|
+
finding(
|
|
170
|
+
FindingKind::SecurityCandidate,
|
|
171
|
+
"dart-decimate/security/hardcoded-secret",
|
|
172
|
+
"Hardcoded secret candidate",
|
|
173
|
+
"lib/secret.dart",
|
|
174
|
+
),
|
|
175
|
+
finding(
|
|
176
|
+
FindingKind::SecurityCandidate,
|
|
177
|
+
"dart-decimate/security/tls-bypass",
|
|
178
|
+
"TLS bypass candidate",
|
|
179
|
+
"lib/tls.dart",
|
|
180
|
+
),
|
|
181
|
+
finding(
|
|
182
|
+
FindingKind::SecurityCandidate,
|
|
183
|
+
"dart-decimate/security/raw-sql",
|
|
184
|
+
"Raw SQL candidate",
|
|
185
|
+
"lib/sql.dart",
|
|
186
|
+
),
|
|
187
|
+
finding(
|
|
188
|
+
FindingKind::SecurityCandidate,
|
|
189
|
+
"dart-decimate/security/webview-javascript",
|
|
190
|
+
"WebView JavaScript bridge candidate",
|
|
191
|
+
"lib/webview.dart",
|
|
192
|
+
),
|
|
193
|
+
],
|
|
194
|
+
clone_groups: Vec::new(),
|
|
195
|
+
complexity: Vec::new(),
|
|
196
|
+
file_scores: Vec::new(),
|
|
197
|
+
hotspots: Vec::new(),
|
|
198
|
+
refactoring_targets: Vec::new(),
|
|
199
|
+
threshold_overrides: Vec::new(),
|
|
200
|
+
feature_flags: Vec::new(),
|
|
201
|
+
security_candidates: Vec::new(),
|
|
202
|
+
attack_surface: Vec::new(),
|
|
203
|
+
runtime_coverage: None,
|
|
204
|
+
next_steps: Vec::new(),
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
let rendered = render_html_report(&report);
|
|
208
|
+
|
|
209
|
+
assert!(rendered.contains(
|
|
210
|
+
"<span class=\"summary-text\"><strong>Policy violation</strong><span class=\"rule\">dart-decimate/policy/mobile/no-dart-io, dart-decimate/policy/mobile/no-process</span></span>"
|
|
211
|
+
));
|
|
212
|
+
assert!(
|
|
213
|
+
rendered
|
|
214
|
+
.contains("<span class=\"summary-text\"><strong>Security candidate</strong></span>")
|
|
215
|
+
);
|
|
216
|
+
assert!(!rendered.contains(
|
|
217
|
+
"<strong>Security candidate</strong><span class=\"rule\">dart-decimate/security/hardcoded-secret</span>"
|
|
218
|
+
));
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
#[test]
|
|
222
|
+
fn grouped_findings_preserves_first_seen_order_for_repeated_types() {
|
|
223
|
+
let findings = vec![
|
|
224
|
+
finding(
|
|
225
|
+
FindingKind::UnresolvedDependency,
|
|
226
|
+
"dart-decimate/unresolved-dependency",
|
|
227
|
+
"Missing local import lib/missing_a.dart",
|
|
228
|
+
"lib/a.dart",
|
|
229
|
+
),
|
|
230
|
+
finding(
|
|
231
|
+
FindingKind::UnusedWidgetParam,
|
|
232
|
+
"dart-decimate/unused-widget-param",
|
|
233
|
+
"Widget constructor parameter is never read",
|
|
234
|
+
"lib/widget.dart",
|
|
235
|
+
),
|
|
236
|
+
finding(
|
|
237
|
+
FindingKind::UnresolvedDependency,
|
|
238
|
+
"dart-decimate/unresolved-dependency",
|
|
239
|
+
"Missing local import lib/missing_b.dart",
|
|
240
|
+
"lib/b.dart",
|
|
241
|
+
),
|
|
242
|
+
finding(
|
|
243
|
+
FindingKind::PolicyViolation,
|
|
244
|
+
"dart-decimate/policy/mobile/no-dart-io",
|
|
245
|
+
"dart:io is not allowed",
|
|
246
|
+
"lib/io.dart",
|
|
247
|
+
),
|
|
248
|
+
finding(
|
|
249
|
+
FindingKind::UnusedWidgetParam,
|
|
250
|
+
"dart-decimate/unused-widget-param",
|
|
251
|
+
"Second widget constructor parameter is never read",
|
|
252
|
+
"lib/second_widget.dart",
|
|
253
|
+
),
|
|
254
|
+
];
|
|
255
|
+
|
|
256
|
+
let groups = grouped_findings(&findings);
|
|
257
|
+
|
|
258
|
+
assert_eq!(groups.len(), 3);
|
|
259
|
+
assert_eq!(groups[0].kind, FindingKind::UnresolvedDependency);
|
|
260
|
+
assert_eq!(
|
|
261
|
+
groups[0]
|
|
262
|
+
.entries
|
|
263
|
+
.iter()
|
|
264
|
+
.map(|(index, _)| *index)
|
|
265
|
+
.collect::<Vec<_>>(),
|
|
266
|
+
vec![1, 3]
|
|
267
|
+
);
|
|
268
|
+
assert_eq!(groups[1].kind, FindingKind::UnusedWidgetParam);
|
|
269
|
+
assert_eq!(
|
|
270
|
+
groups[1]
|
|
271
|
+
.entries
|
|
272
|
+
.iter()
|
|
273
|
+
.map(|(index, _)| *index)
|
|
274
|
+
.collect::<Vec<_>>(),
|
|
275
|
+
vec![2, 5]
|
|
276
|
+
);
|
|
277
|
+
assert_eq!(groups[2].kind, FindingKind::PolicyViolation);
|
|
278
|
+
assert_eq!(
|
|
279
|
+
groups[2]
|
|
280
|
+
.entries
|
|
281
|
+
.iter()
|
|
282
|
+
.map(|(index, _)| *index)
|
|
283
|
+
.collect::<Vec<_>>(),
|
|
284
|
+
vec![4]
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
#[test]
|
|
289
|
+
fn escapes_control_characters_from_user_values() {
|
|
290
|
+
let report = JsonReport {
|
|
291
|
+
schema_version: "dart-decimate.report.v1".to_owned(),
|
|
292
|
+
kind: "combined".to_owned(),
|
|
293
|
+
tool: "dart-decimate".to_owned(),
|
|
294
|
+
command: ReportCommand::Check,
|
|
295
|
+
verdict: Verdict::Fail,
|
|
296
|
+
summary: ReportSummary {
|
|
297
|
+
files: 2,
|
|
298
|
+
edges: 1,
|
|
299
|
+
findings: 1,
|
|
300
|
+
cycles: 1,
|
|
301
|
+
..ReportSummary::default()
|
|
302
|
+
},
|
|
303
|
+
findings: vec![Finding {
|
|
304
|
+
rule_id: "dart-decimate/circular-dependency".to_owned(),
|
|
305
|
+
fingerprint: Some("cycle:\x1bunsafe".to_owned()),
|
|
306
|
+
kind: FindingKind::CircularDependency,
|
|
307
|
+
severity: Severity::Error,
|
|
308
|
+
message: "Circular dependency includes \x07bell".to_owned(),
|
|
309
|
+
path: "lib/\x1b[31mbad.dart".to_owned(),
|
|
310
|
+
line: 1,
|
|
311
|
+
column: 0,
|
|
312
|
+
safe_to_delete: false,
|
|
313
|
+
files: vec![
|
|
314
|
+
"lib/\x1b[31mbad.dart".to_owned(),
|
|
315
|
+
"lib/\x07bell.dart".to_owned(),
|
|
316
|
+
],
|
|
317
|
+
edge: Some(FindingEdge {
|
|
318
|
+
from: "lib/\x1b[31mbad.dart".to_owned(),
|
|
319
|
+
to: "lib/\x07bell.dart".to_owned(),
|
|
320
|
+
specifier: "package:app/\x1bbad.dart".to_owned(),
|
|
321
|
+
kind: "import".to_owned(),
|
|
322
|
+
}),
|
|
323
|
+
actions: vec![
|
|
324
|
+
FindingAction::new("inspect-control", "Inspect \x07bell", false)
|
|
325
|
+
.with_dart_decimate_args([
|
|
326
|
+
"inspect",
|
|
327
|
+
"--format",
|
|
328
|
+
"json",
|
|
329
|
+
"--file",
|
|
330
|
+
"lib/\x1b[31mbad.dart",
|
|
331
|
+
]),
|
|
332
|
+
],
|
|
333
|
+
}],
|
|
334
|
+
clone_groups: Vec::new(),
|
|
335
|
+
complexity: Vec::new(),
|
|
336
|
+
file_scores: Vec::new(),
|
|
337
|
+
hotspots: Vec::new(),
|
|
338
|
+
refactoring_targets: Vec::new(),
|
|
339
|
+
threshold_overrides: Vec::new(),
|
|
340
|
+
feature_flags: Vec::new(),
|
|
341
|
+
security_candidates: Vec::new(),
|
|
342
|
+
attack_surface: Vec::new(),
|
|
343
|
+
runtime_coverage: None,
|
|
344
|
+
next_steps: vec![NextStep {
|
|
345
|
+
id: "inspect-control".to_owned(),
|
|
346
|
+
command: "dart-decimate inspect --file lib/\x1b[31mbad.dart".to_owned(),
|
|
347
|
+
reason: "Review \x07bell evidence".to_owned(),
|
|
348
|
+
}],
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
let rendered = render_html_report(&report);
|
|
352
|
+
|
|
353
|
+
assert!(!rendered.contains('\x1b'));
|
|
354
|
+
assert!(!rendered.contains('\x07'));
|
|
355
|
+
assert!(rendered.contains("lib/[31mbad.dart"));
|
|
356
|
+
assert!(rendered.contains("bell"));
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
#[test]
|
|
360
|
+
fn renders_omitted_details_for_summary_only_failures() {
|
|
361
|
+
let mut report = JsonReport {
|
|
362
|
+
schema_version: "dart-decimate.report.v1".to_owned(),
|
|
363
|
+
kind: "combined".to_owned(),
|
|
364
|
+
tool: "dart-decimate".to_owned(),
|
|
365
|
+
command: ReportCommand::Security,
|
|
366
|
+
verdict: Verdict::Fail,
|
|
367
|
+
summary: ReportSummary {
|
|
368
|
+
files: 1,
|
|
369
|
+
findings: 2,
|
|
370
|
+
security_candidates: 2,
|
|
371
|
+
..ReportSummary::default()
|
|
372
|
+
},
|
|
373
|
+
findings: Vec::new(),
|
|
374
|
+
clone_groups: Vec::new(),
|
|
375
|
+
complexity: Vec::new(),
|
|
376
|
+
file_scores: Vec::new(),
|
|
377
|
+
hotspots: Vec::new(),
|
|
378
|
+
refactoring_targets: Vec::new(),
|
|
379
|
+
threshold_overrides: Vec::new(),
|
|
380
|
+
feature_flags: Vec::new(),
|
|
381
|
+
security_candidates: Vec::new(),
|
|
382
|
+
attack_surface: Vec::new(),
|
|
383
|
+
runtime_coverage: None,
|
|
384
|
+
next_steps: Vec::new(),
|
|
385
|
+
};
|
|
386
|
+
report.findings.clear();
|
|
387
|
+
|
|
388
|
+
let rendered = render_html_report(&report);
|
|
389
|
+
|
|
390
|
+
assert!(rendered.contains("<h1>security report</h1>"));
|
|
391
|
+
assert!(rendered.contains("2 findings were omitted from this summary output."));
|
|
392
|
+
assert!(!rendered.contains("No findings. The selected Dart graph checks passed."));
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
fn finding(kind: FindingKind, rule_id: &str, message: &str, path: &str) -> Finding {
|
|
396
|
+
Finding {
|
|
397
|
+
rule_id: rule_id.to_owned(),
|
|
398
|
+
fingerprint: None,
|
|
399
|
+
kind,
|
|
400
|
+
severity: Severity::Error,
|
|
401
|
+
message: message.to_owned(),
|
|
402
|
+
path: path.to_owned(),
|
|
403
|
+
line: 1,
|
|
404
|
+
column: 0,
|
|
405
|
+
safe_to_delete: false,
|
|
406
|
+
files: Vec::new(),
|
|
407
|
+
edge: None,
|
|
408
|
+
actions: Vec::new(),
|
|
409
|
+
}
|
|
410
|
+
}
|
package/src/output/html.rs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
use std::fmt::Write as _;
|
|
1
|
+
use std::{collections::HashMap, fmt::Write as _, mem};
|
|
2
2
|
|
|
3
3
|
use crate::decision_surface::{
|
|
4
4
|
DecisionSurfaceCategory, DecisionSurfaceDecision, DecisionSurfaceReport,
|
|
@@ -11,9 +11,14 @@ use super::{
|
|
|
11
11
|
types::{Finding, FindingEdge, FindingKind, JsonReport, Severity, Verdict},
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
+
mod assets;
|
|
15
|
+
|
|
16
|
+
use assets::{render_interaction_script, render_style};
|
|
17
|
+
|
|
14
18
|
const MAX_RELATED_FILES: usize = 12;
|
|
19
|
+
const MAX_GROUP_RULE_IDS: usize = 3;
|
|
15
20
|
|
|
16
|
-
/// Render a browser-ready static report
|
|
21
|
+
/// Render a browser-ready static report with grouped finding navigation.
|
|
17
22
|
#[must_use]
|
|
18
23
|
pub fn render_html_report(report: &JsonReport) -> String {
|
|
19
24
|
let mut html = String::new();
|
|
@@ -74,60 +79,6 @@ fn render_decision_surface_document_start(html: &mut String, report: &DecisionSu
|
|
|
74
79
|
let _ = writeln!(html, "<body>");
|
|
75
80
|
}
|
|
76
81
|
|
|
77
|
-
fn render_style(html: &mut String) {
|
|
78
|
-
let _ = writeln!(
|
|
79
|
-
html,
|
|
80
|
-
"<style>
|
|
81
|
-
:root {{
|
|
82
|
-
color-scheme: dark;
|
|
83
|
-
--bg: #070707;
|
|
84
|
-
--panel: #111111;
|
|
85
|
-
--line: #2b2b2b;
|
|
86
|
-
--text: #f1f1f1;
|
|
87
|
-
--muted: #a6a6a6;
|
|
88
|
-
--accent: #8fdcff;
|
|
89
|
-
--error: #ff5c5c;
|
|
90
|
-
--warn: #ffd166;
|
|
91
|
-
--pass: #5ee091;
|
|
92
|
-
}}
|
|
93
|
-
* {{ box-sizing: border-box; }}
|
|
94
|
-
body {{
|
|
95
|
-
margin: 0;
|
|
96
|
-
background: var(--bg);
|
|
97
|
-
color: var(--text);
|
|
98
|
-
font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif;
|
|
99
|
-
}}
|
|
100
|
-
main {{ max-width: 1180px; margin: 0 auto; padding: 40px 24px 56px; }}
|
|
101
|
-
h1, h2, h3, p {{ margin: 0; }}
|
|
102
|
-
h1 {{ font-size: clamp(32px, 5vw, 60px); letter-spacing: 0; line-height: 1; }}
|
|
103
|
-
h2 {{ margin-top: 36px; font-size: 22px; }}
|
|
104
|
-
.topline {{ color: var(--muted); margin-bottom: 10px; text-transform: uppercase; letter-spacing: .08em; font-size: 12px; }}
|
|
105
|
-
.hero {{ border-bottom: 1px solid var(--line); padding-bottom: 28px; }}
|
|
106
|
-
.verdict {{ display: inline-flex; align-items: center; gap: 8px; margin-top: 18px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; }}
|
|
107
|
-
.pass {{ color: var(--pass); }}
|
|
108
|
-
.fail, .error {{ color: var(--error); }}
|
|
109
|
-
.warning {{ color: var(--warn); }}
|
|
110
|
-
.metrics, .groups {{ display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-top: 24px; }}
|
|
111
|
-
.metric, .group, .finding, .step {{ background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 16px; }}
|
|
112
|
-
.metric span, .group span, .label {{ color: var(--muted); display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }}
|
|
113
|
-
.metric strong, .group strong {{ display: block; margin-top: 4px; font-size: 24px; }}
|
|
114
|
-
.group p {{ margin-top: 8px; color: var(--text); }}
|
|
115
|
-
.findings {{ display: grid; gap: 14px; margin-top: 14px; }}
|
|
116
|
-
.finding header {{ display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 14px; }}
|
|
117
|
-
.finding h3 {{ font-size: 18px; }}
|
|
118
|
-
.rule, .location, .mono {{ font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }}
|
|
119
|
-
.rule {{ color: var(--muted); font-size: 13px; }}
|
|
120
|
-
.section {{ margin-top: 12px; }}
|
|
121
|
-
.section p {{ margin-top: 3px; }}
|
|
122
|
-
.evidence {{ margin: 8px 0 0; padding-left: 18px; color: var(--text); }}
|
|
123
|
-
.evidence li {{ margin: 3px 0; }}
|
|
124
|
-
.command {{ overflow-wrap: anywhere; color: var(--accent); }}
|
|
125
|
-
a {{ color: var(--accent); text-decoration: none; }}
|
|
126
|
-
a:hover {{ text-decoration: underline; }}
|
|
127
|
-
</style>"
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
82
|
fn render_summary(html: &mut String, report: &JsonReport) {
|
|
132
83
|
let verdict_class = match report.verdict {
|
|
133
84
|
Verdict::Pass => "pass",
|
|
@@ -286,17 +237,176 @@ fn render_findings(html: &mut String, report: &JsonReport) {
|
|
|
286
237
|
return;
|
|
287
238
|
}
|
|
288
239
|
|
|
289
|
-
let
|
|
290
|
-
|
|
291
|
-
|
|
240
|
+
let groups = grouped_findings(&report.findings);
|
|
241
|
+
render_finding_controls(html, &groups);
|
|
242
|
+
let _ = writeln!(
|
|
243
|
+
html,
|
|
244
|
+
"<p class=\"empty-results\" data-empty-results hidden>No findings match the current filters.</p>"
|
|
245
|
+
);
|
|
246
|
+
let _ = writeln!(html, "<div class=\"finding-groups\">");
|
|
247
|
+
for (group_index, group) in groups.iter().enumerate() {
|
|
248
|
+
render_finding_group(html, group_index, group);
|
|
292
249
|
}
|
|
293
250
|
let _ = writeln!(html, "</div>");
|
|
294
251
|
let _ = writeln!(html, "</section>");
|
|
295
252
|
}
|
|
296
253
|
|
|
254
|
+
struct FindingGroup<'a> {
|
|
255
|
+
kind: FindingKind,
|
|
256
|
+
rule_ids: Vec<&'a str>,
|
|
257
|
+
entries: Vec<(usize, &'a Finding)>,
|
|
258
|
+
error_count: usize,
|
|
259
|
+
warning_count: usize,
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
fn grouped_findings(findings: &[Finding]) -> Vec<FindingGroup<'_>> {
|
|
263
|
+
let mut groups: Vec<FindingGroup<'_>> = Vec::new();
|
|
264
|
+
let mut group_indices = HashMap::<mem::Discriminant<FindingKind>, usize>::new();
|
|
265
|
+
for (index, finding) in findings.iter().enumerate() {
|
|
266
|
+
let kind_key = mem::discriminant(&finding.kind);
|
|
267
|
+
if let Some(group_index) = group_indices.get(&kind_key).copied() {
|
|
268
|
+
let group = &mut groups[group_index];
|
|
269
|
+
group.push(index + 1, finding);
|
|
270
|
+
} else {
|
|
271
|
+
group_indices.insert(kind_key, groups.len());
|
|
272
|
+
groups.push(FindingGroup::new(index + 1, finding));
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
groups
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
impl<'a> FindingGroup<'a> {
|
|
279
|
+
fn new(index: usize, finding: &'a Finding) -> Self {
|
|
280
|
+
let mut group = Self {
|
|
281
|
+
kind: finding.kind,
|
|
282
|
+
rule_ids: Vec::new(),
|
|
283
|
+
entries: Vec::new(),
|
|
284
|
+
error_count: 0,
|
|
285
|
+
warning_count: 0,
|
|
286
|
+
};
|
|
287
|
+
group.push(index, finding);
|
|
288
|
+
group
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
fn push(&mut self, index: usize, finding: &'a Finding) {
|
|
292
|
+
match finding.severity {
|
|
293
|
+
Severity::Error => self.error_count += 1,
|
|
294
|
+
Severity::Warning => self.warning_count += 1,
|
|
295
|
+
}
|
|
296
|
+
let rule_id = finding.rule_id.as_str();
|
|
297
|
+
if !self.rule_ids.contains(&rule_id) {
|
|
298
|
+
self.rule_ids.push(rule_id);
|
|
299
|
+
}
|
|
300
|
+
self.entries.push((index, finding));
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
fn render_finding_controls(html: &mut String, groups: &[FindingGroup<'_>]) {
|
|
305
|
+
let total = groups
|
|
306
|
+
.iter()
|
|
307
|
+
.map(|group| group.entries.len())
|
|
308
|
+
.sum::<usize>();
|
|
309
|
+
let _ = writeln!(html, "<div class=\"finding-tools\" data-finding-controls>");
|
|
310
|
+
let _ = writeln!(
|
|
311
|
+
html,
|
|
312
|
+
"<label>Search<input type=\"search\" placeholder=\"Path, message, rule, evidence\" data-finding-search></label>"
|
|
313
|
+
);
|
|
314
|
+
let _ = writeln!(
|
|
315
|
+
html,
|
|
316
|
+
"<div class=\"filter-set\" role=\"group\" aria-label=\"Filter findings by type\">"
|
|
317
|
+
);
|
|
318
|
+
let _ = writeln!(html, "<span class=\"filter-label\">Type</span>");
|
|
319
|
+
let _ = writeln!(html, "<div class=\"filter-buttons\">");
|
|
320
|
+
let _ = writeln!(
|
|
321
|
+
html,
|
|
322
|
+
"<button class=\"type-filter\" type=\"button\" data-finding-filter data-kind=\"\" aria-pressed=\"true\">All types</button>"
|
|
323
|
+
);
|
|
324
|
+
for (index, group) in groups.iter().enumerate() {
|
|
325
|
+
let label = kind_label(group.kind);
|
|
326
|
+
let _ = writeln!(
|
|
327
|
+
html,
|
|
328
|
+
"<button class=\"type-filter\" type=\"button\" data-finding-filter data-kind=\"{}\" aria-pressed=\"false\">{}. {} ({})</button>",
|
|
329
|
+
escape(label),
|
|
330
|
+
index + 1,
|
|
331
|
+
escape(label),
|
|
332
|
+
group.entries.len()
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
let _ = writeln!(html, "</div></div>");
|
|
336
|
+
let _ = writeln!(
|
|
337
|
+
html,
|
|
338
|
+
"<p class=\"finding-status\" data-finding-status data-total=\"{total}\" aria-live=\"polite\">Showing {total} of {total} findings in {} {}.</p>",
|
|
339
|
+
groups.len(),
|
|
340
|
+
plural(groups.len(), "type", "types")
|
|
341
|
+
);
|
|
342
|
+
let _ = writeln!(html, "</div>");
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
fn render_finding_group(html: &mut String, group_index: usize, group: &FindingGroup<'_>) {
|
|
346
|
+
let label = kind_label(group.kind);
|
|
347
|
+
let open = if group_index == 0 { " open" } else { "" };
|
|
348
|
+
let _ = writeln!(
|
|
349
|
+
html,
|
|
350
|
+
"<details class=\"finding-group\" data-finding-group data-kind=\"{}\"{}>",
|
|
351
|
+
escape(label),
|
|
352
|
+
open
|
|
353
|
+
);
|
|
354
|
+
let _ = writeln!(html, "<summary>");
|
|
355
|
+
let rule_summary = group_rule_summary(group);
|
|
356
|
+
let rule_html = rule_summary.map_or_else(String::new, |rule_ids| {
|
|
357
|
+
format!("<span class=\"rule\">{}</span>", escape(&rule_ids))
|
|
358
|
+
});
|
|
359
|
+
let _ = writeln!(
|
|
360
|
+
html,
|
|
361
|
+
"<span class=\"summary-title\"><span class=\"group-number\">{}.</span><span class=\"summary-text\"><strong>{}</strong>{}</span></span>",
|
|
362
|
+
group_index + 1,
|
|
363
|
+
escape(label),
|
|
364
|
+
rule_html
|
|
365
|
+
);
|
|
366
|
+
let _ = writeln!(
|
|
367
|
+
html,
|
|
368
|
+
"<span class=\"summary-right\"><span class=\"summary-meta\">{}</span><span class=\"chevron\" aria-hidden=\"true\"></span></span>",
|
|
369
|
+
escape(&group_summary(group))
|
|
370
|
+
);
|
|
371
|
+
let _ = writeln!(html, "</summary>");
|
|
372
|
+
let _ = writeln!(html, "<div class=\"findings\">");
|
|
373
|
+
for (index, finding) in &group.entries {
|
|
374
|
+
render_finding(html, *index, finding);
|
|
375
|
+
}
|
|
376
|
+
let _ = writeln!(html, "</div>");
|
|
377
|
+
let _ = writeln!(html, "</details>");
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
fn group_rule_summary(group: &FindingGroup<'_>) -> Option<String> {
|
|
381
|
+
if group.rule_ids.is_empty() || group.rule_ids.len() > MAX_GROUP_RULE_IDS {
|
|
382
|
+
return None;
|
|
383
|
+
}
|
|
384
|
+
Some(group.rule_ids.join(", "))
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
fn group_summary(group: &FindingGroup<'_>) -> String {
|
|
388
|
+
let total = group.entries.len();
|
|
389
|
+
let mut parts = vec![format!("{total} {}", plural(total, "finding", "findings"))];
|
|
390
|
+
if group.error_count > 0 {
|
|
391
|
+
parts.push(format!(
|
|
392
|
+
"{} {}",
|
|
393
|
+
group.error_count,
|
|
394
|
+
plural(group.error_count, "error", "errors")
|
|
395
|
+
));
|
|
396
|
+
}
|
|
397
|
+
if group.warning_count > 0 {
|
|
398
|
+
parts.push(format!(
|
|
399
|
+
"{} {}",
|
|
400
|
+
group.warning_count,
|
|
401
|
+
plural(group.warning_count, "warning", "warnings")
|
|
402
|
+
));
|
|
403
|
+
}
|
|
404
|
+
parts.join(" | ")
|
|
405
|
+
}
|
|
406
|
+
|
|
297
407
|
fn render_finding(html: &mut String, index: usize, finding: &Finding) {
|
|
298
408
|
let severity_class = severity_class(finding.severity);
|
|
299
|
-
let _ = writeln!(html, "<article class=\"finding\">");
|
|
409
|
+
let _ = writeln!(html, "<article class=\"finding\" data-finding>");
|
|
300
410
|
let _ = writeln!(html, "<header>");
|
|
301
411
|
let _ = writeln!(
|
|
302
412
|
html,
|
|
@@ -394,6 +504,7 @@ fn render_next_steps(html: &mut String, report: &JsonReport) {
|
|
|
394
504
|
|
|
395
505
|
fn render_document_end(html: &mut String) {
|
|
396
506
|
let _ = writeln!(html, "</main>");
|
|
507
|
+
render_interaction_script(html);
|
|
397
508
|
let _ = writeln!(html, "</body>");
|
|
398
509
|
let _ = writeln!(html, "</html>");
|
|
399
510
|
}
|
|
@@ -489,6 +600,10 @@ fn related_files_preview(files: &[String]) -> String {
|
|
|
489
600
|
visible.join(", ")
|
|
490
601
|
}
|
|
491
602
|
|
|
603
|
+
const fn plural<'a>(count: usize, singular: &'a str, plural: &'a str) -> &'a str {
|
|
604
|
+
if count == 1 { singular } else { plural }
|
|
605
|
+
}
|
|
606
|
+
|
|
492
607
|
fn escape(value: &str) -> String {
|
|
493
608
|
let mut escaped = String::with_capacity(value.len());
|
|
494
609
|
for character in value.chars() {
|
|
@@ -508,184 +623,4 @@ fn escape(value: &str) -> String {
|
|
|
508
623
|
}
|
|
509
624
|
|
|
510
625
|
#[cfg(test)]
|
|
511
|
-
mod tests
|
|
512
|
-
use super::*;
|
|
513
|
-
use crate::output::{FindingAction, FindingEdge, NextStep, ReportCommand, ReportSummary};
|
|
514
|
-
|
|
515
|
-
#[test]
|
|
516
|
-
fn renders_browser_ready_report_with_escaped_evidence() {
|
|
517
|
-
let report = JsonReport {
|
|
518
|
-
schema_version: "dart-decimate.report.v1".to_owned(),
|
|
519
|
-
kind: "combined".to_owned(),
|
|
520
|
-
tool: "dart-decimate".to_owned(),
|
|
521
|
-
command: ReportCommand::Check,
|
|
522
|
-
verdict: Verdict::Fail,
|
|
523
|
-
summary: ReportSummary {
|
|
524
|
-
files: 3,
|
|
525
|
-
edges: 2,
|
|
526
|
-
findings: 1,
|
|
527
|
-
cycles: 1,
|
|
528
|
-
..ReportSummary::default()
|
|
529
|
-
},
|
|
530
|
-
findings: vec![Finding {
|
|
531
|
-
rule_id: "dart-decimate/circular-dependency".to_owned(),
|
|
532
|
-
fingerprint: Some("cycle:<unsafe>".to_owned()),
|
|
533
|
-
kind: FindingKind::CircularDependency,
|
|
534
|
-
severity: Severity::Error,
|
|
535
|
-
message: "Circular dependency spans 3 Dart files".to_owned(),
|
|
536
|
-
path: "lib/a.dart".to_owned(),
|
|
537
|
-
line: 1,
|
|
538
|
-
column: 0,
|
|
539
|
-
safe_to_delete: false,
|
|
540
|
-
files: vec![
|
|
541
|
-
"lib/a.dart".to_owned(),
|
|
542
|
-
"lib/b.dart".to_owned(),
|
|
543
|
-
"lib/c.dart".to_owned(),
|
|
544
|
-
],
|
|
545
|
-
edge: None,
|
|
546
|
-
actions: vec![
|
|
547
|
-
FindingAction::new(
|
|
548
|
-
"break-cycle",
|
|
549
|
-
"Move shared dependencies inward or invert one import edge",
|
|
550
|
-
false,
|
|
551
|
-
)
|
|
552
|
-
.with_dart_decimate_args([
|
|
553
|
-
"inspect",
|
|
554
|
-
"--format",
|
|
555
|
-
"json",
|
|
556
|
-
"--file",
|
|
557
|
-
"lib/a.dart",
|
|
558
|
-
]),
|
|
559
|
-
],
|
|
560
|
-
}],
|
|
561
|
-
clone_groups: Vec::new(),
|
|
562
|
-
complexity: Vec::new(),
|
|
563
|
-
file_scores: Vec::new(),
|
|
564
|
-
hotspots: Vec::new(),
|
|
565
|
-
refactoring_targets: Vec::new(),
|
|
566
|
-
threshold_overrides: Vec::new(),
|
|
567
|
-
feature_flags: Vec::new(),
|
|
568
|
-
security_candidates: Vec::new(),
|
|
569
|
-
attack_surface: Vec::new(),
|
|
570
|
-
runtime_coverage: None,
|
|
571
|
-
next_steps: Vec::new(),
|
|
572
|
-
};
|
|
573
|
-
|
|
574
|
-
let rendered = render_html_report(&report);
|
|
575
|
-
|
|
576
|
-
assert!(rendered.starts_with("<!doctype html>"));
|
|
577
|
-
assert!(rendered.contains("<h1>check report</h1>"));
|
|
578
|
-
assert!(rendered.contains("Architecture"));
|
|
579
|
-
assert!(rendered.contains("1 circular dependency"));
|
|
580
|
-
assert!(rendered.contains("Why"));
|
|
581
|
-
assert!(rendered.contains("cycle:<unsafe>"));
|
|
582
|
-
assert!(rendered.contains("lib/a.dart -> lib/b.dart -> lib/c.dart -> lib/a.dart"));
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
#[test]
|
|
586
|
-
fn escapes_control_characters_from_user_values() {
|
|
587
|
-
let report = JsonReport {
|
|
588
|
-
schema_version: "dart-decimate.report.v1".to_owned(),
|
|
589
|
-
kind: "combined".to_owned(),
|
|
590
|
-
tool: "dart-decimate".to_owned(),
|
|
591
|
-
command: ReportCommand::Check,
|
|
592
|
-
verdict: Verdict::Fail,
|
|
593
|
-
summary: ReportSummary {
|
|
594
|
-
files: 2,
|
|
595
|
-
edges: 1,
|
|
596
|
-
findings: 1,
|
|
597
|
-
cycles: 1,
|
|
598
|
-
..ReportSummary::default()
|
|
599
|
-
},
|
|
600
|
-
findings: vec![Finding {
|
|
601
|
-
rule_id: "dart-decimate/circular-dependency".to_owned(),
|
|
602
|
-
fingerprint: Some("cycle:\x1bunsafe".to_owned()),
|
|
603
|
-
kind: FindingKind::CircularDependency,
|
|
604
|
-
severity: Severity::Error,
|
|
605
|
-
message: "Circular dependency includes \x07bell".to_owned(),
|
|
606
|
-
path: "lib/\x1b[31mbad.dart".to_owned(),
|
|
607
|
-
line: 1,
|
|
608
|
-
column: 0,
|
|
609
|
-
safe_to_delete: false,
|
|
610
|
-
files: vec![
|
|
611
|
-
"lib/\x1b[31mbad.dart".to_owned(),
|
|
612
|
-
"lib/\x07bell.dart".to_owned(),
|
|
613
|
-
],
|
|
614
|
-
edge: Some(FindingEdge {
|
|
615
|
-
from: "lib/\x1b[31mbad.dart".to_owned(),
|
|
616
|
-
to: "lib/\x07bell.dart".to_owned(),
|
|
617
|
-
specifier: "package:app/\x1bbad.dart".to_owned(),
|
|
618
|
-
kind: "import".to_owned(),
|
|
619
|
-
}),
|
|
620
|
-
actions: vec![
|
|
621
|
-
FindingAction::new("inspect-control", "Inspect \x07bell", false)
|
|
622
|
-
.with_dart_decimate_args([
|
|
623
|
-
"inspect",
|
|
624
|
-
"--format",
|
|
625
|
-
"json",
|
|
626
|
-
"--file",
|
|
627
|
-
"lib/\x1b[31mbad.dart",
|
|
628
|
-
]),
|
|
629
|
-
],
|
|
630
|
-
}],
|
|
631
|
-
clone_groups: Vec::new(),
|
|
632
|
-
complexity: Vec::new(),
|
|
633
|
-
file_scores: Vec::new(),
|
|
634
|
-
hotspots: Vec::new(),
|
|
635
|
-
refactoring_targets: Vec::new(),
|
|
636
|
-
threshold_overrides: Vec::new(),
|
|
637
|
-
feature_flags: Vec::new(),
|
|
638
|
-
security_candidates: Vec::new(),
|
|
639
|
-
attack_surface: Vec::new(),
|
|
640
|
-
runtime_coverage: None,
|
|
641
|
-
next_steps: vec![NextStep {
|
|
642
|
-
id: "inspect-control".to_owned(),
|
|
643
|
-
command: "dart-decimate inspect --file lib/\x1b[31mbad.dart".to_owned(),
|
|
644
|
-
reason: "Review \x07bell evidence".to_owned(),
|
|
645
|
-
}],
|
|
646
|
-
};
|
|
647
|
-
|
|
648
|
-
let rendered = render_html_report(&report);
|
|
649
|
-
|
|
650
|
-
assert!(!rendered.contains('\x1b'));
|
|
651
|
-
assert!(!rendered.contains('\x07'));
|
|
652
|
-
assert!(rendered.contains("lib/[31mbad.dart"));
|
|
653
|
-
assert!(rendered.contains("bell"));
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
#[test]
|
|
657
|
-
fn renders_omitted_details_for_summary_only_failures() {
|
|
658
|
-
let mut report = JsonReport {
|
|
659
|
-
schema_version: "dart-decimate.report.v1".to_owned(),
|
|
660
|
-
kind: "combined".to_owned(),
|
|
661
|
-
tool: "dart-decimate".to_owned(),
|
|
662
|
-
command: ReportCommand::Security,
|
|
663
|
-
verdict: Verdict::Fail,
|
|
664
|
-
summary: ReportSummary {
|
|
665
|
-
files: 1,
|
|
666
|
-
findings: 2,
|
|
667
|
-
security_candidates: 2,
|
|
668
|
-
..ReportSummary::default()
|
|
669
|
-
},
|
|
670
|
-
findings: Vec::new(),
|
|
671
|
-
clone_groups: Vec::new(),
|
|
672
|
-
complexity: Vec::new(),
|
|
673
|
-
file_scores: Vec::new(),
|
|
674
|
-
hotspots: Vec::new(),
|
|
675
|
-
refactoring_targets: Vec::new(),
|
|
676
|
-
threshold_overrides: Vec::new(),
|
|
677
|
-
feature_flags: Vec::new(),
|
|
678
|
-
security_candidates: Vec::new(),
|
|
679
|
-
attack_surface: Vec::new(),
|
|
680
|
-
runtime_coverage: None,
|
|
681
|
-
next_steps: Vec::new(),
|
|
682
|
-
};
|
|
683
|
-
report.findings.clear();
|
|
684
|
-
|
|
685
|
-
let rendered = render_html_report(&report);
|
|
686
|
-
|
|
687
|
-
assert!(rendered.contains("<h1>security report</h1>"));
|
|
688
|
-
assert!(rendered.contains("2 findings were omitted from this summary output."));
|
|
689
|
-
assert!(!rendered.contains("No findings. The selected Dart graph checks passed."));
|
|
690
|
-
}
|
|
691
|
-
}
|
|
626
|
+
mod tests;
|