dart-decimate 0.0.5 → 0.0.7

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.
@@ -0,0 +1,449 @@
1
+ use super::types::{Finding, FindingAction, FindingKind, ReportSummary, Verdict};
2
+
3
+ pub(super) fn summary_groups(summary: &ReportSummary) -> [(&'static str, Vec<String>); 6] {
4
+ [
5
+ ("Architecture", architecture_items(summary)),
6
+ ("Dependency Hygiene", dependency_items(summary)),
7
+ ("Cleanup", cleanup_items(summary)),
8
+ ("Quality", quality_items(summary)),
9
+ ("Flutter", flutter_items(summary)),
10
+ ("Security", security_items(summary)),
11
+ ]
12
+ }
13
+
14
+ pub(super) fn omitted_findings_message(summary: &ReportSummary, verdict: Verdict) -> String {
15
+ match summary.findings {
16
+ 1 => "1 finding was omitted from this summary output. Re-run without --summary to inspect it."
17
+ .to_owned(),
18
+ count if count > 1 => format!(
19
+ "{count} findings were omitted from this summary output. Re-run without --summary to inspect them."
20
+ ),
21
+ _ if verdict == Verdict::Fail => {
22
+ "Finding details were omitted from this failing report. Re-run without --summary to inspect them."
23
+ .to_owned()
24
+ }
25
+ _ => "Finding details were omitted from this report. Re-run without --summary to inspect them."
26
+ .to_owned(),
27
+ }
28
+ }
29
+
30
+ fn architecture_items(summary: &ReportSummary) -> Vec<String> {
31
+ let mut items = Vec::new();
32
+ push_count(
33
+ &mut items,
34
+ summary.cycles,
35
+ "circular dependency",
36
+ "circular dependencies",
37
+ );
38
+ push_count(
39
+ &mut items,
40
+ summary.re_export_cycles,
41
+ "re-export cycle",
42
+ "re-export cycles",
43
+ );
44
+ push_count(
45
+ &mut items,
46
+ summary.boundary_violations,
47
+ "boundary violation",
48
+ "boundary violations",
49
+ );
50
+ push_count(
51
+ &mut items,
52
+ summary.boundary_coverage,
53
+ "boundary coverage gap",
54
+ "boundary coverage gaps",
55
+ );
56
+ push_count(
57
+ &mut items,
58
+ summary.boundary_call_violations,
59
+ "boundary call violation",
60
+ "boundary call violations",
61
+ );
62
+ push_count(
63
+ &mut items,
64
+ summary.policy_violations,
65
+ "policy violation",
66
+ "policy violations",
67
+ );
68
+ push_count(
69
+ &mut items,
70
+ summary.route_collisions,
71
+ "route collision",
72
+ "route collisions",
73
+ );
74
+ push_count(
75
+ &mut items,
76
+ summary.part_of_violations,
77
+ "part-of violation",
78
+ "part-of violations",
79
+ );
80
+ push_count(
81
+ &mut items,
82
+ summary.unresolved_dependencies,
83
+ "unresolved local dependency",
84
+ "unresolved local dependencies",
85
+ );
86
+ items
87
+ }
88
+
89
+ fn dependency_items(summary: &ReportSummary) -> Vec<String> {
90
+ let mut items = Vec::new();
91
+ push_count(
92
+ &mut items,
93
+ summary.unused_dependencies,
94
+ "unused dependency",
95
+ "unused dependencies",
96
+ );
97
+ push_count(
98
+ &mut items,
99
+ summary.unused_dev_dependencies,
100
+ "unused dev dependency",
101
+ "unused dev dependencies",
102
+ );
103
+ push_count(
104
+ &mut items,
105
+ summary.test_only_dependencies,
106
+ "test-only production dependency",
107
+ "test-only production dependencies",
108
+ );
109
+ push_count(
110
+ &mut items,
111
+ summary.unlisted_dependencies,
112
+ "unlisted dependency",
113
+ "unlisted dependencies",
114
+ );
115
+ push_count(
116
+ &mut items,
117
+ summary.private_src_imports,
118
+ "private lib/src import",
119
+ "private lib/src imports",
120
+ );
121
+ push_count(
122
+ &mut items,
123
+ summary.dependency_overrides,
124
+ "dependency override issue",
125
+ "dependency override issues",
126
+ );
127
+ items
128
+ }
129
+
130
+ fn cleanup_items(summary: &ReportSummary) -> Vec<String> {
131
+ let mut items = Vec::new();
132
+ push_count(&mut items, summary.dead_files, "dead file", "dead files");
133
+ push_count(
134
+ &mut items,
135
+ summary.unused_exports,
136
+ "unused export",
137
+ "unused exports",
138
+ );
139
+ push_count(
140
+ &mut items,
141
+ summary.unused_types,
142
+ "unused type",
143
+ "unused types",
144
+ );
145
+ push_count(
146
+ &mut items,
147
+ summary.unused_enum_members,
148
+ "unused enum member",
149
+ "unused enum members",
150
+ );
151
+ push_count(
152
+ &mut items,
153
+ summary.unused_class_members,
154
+ "unused class member",
155
+ "unused class members",
156
+ );
157
+ push_count(
158
+ &mut items,
159
+ summary.duplicate_exports,
160
+ "duplicate export",
161
+ "duplicate exports",
162
+ );
163
+ push_count(
164
+ &mut items,
165
+ summary.missing_suppression_reasons,
166
+ "suppression without reason",
167
+ "suppressions without reasons",
168
+ );
169
+ items
170
+ }
171
+
172
+ fn quality_items(summary: &ReportSummary) -> Vec<String> {
173
+ let mut items = Vec::new();
174
+ if summary.code_duplications > 0 {
175
+ items.push(format!(
176
+ "{} duplicate {} covering {} {} ({})",
177
+ summary.code_duplications,
178
+ plural(summary.code_duplications, "group", "groups"),
179
+ summary.duplicated_lines,
180
+ plural(summary.duplicated_lines, "line", "lines"),
181
+ format_basis_points(summary.duplication_percentage_basis_points)
182
+ ));
183
+ }
184
+ push_count(
185
+ &mut items,
186
+ summary.complex_functions,
187
+ "complex function",
188
+ "complex functions",
189
+ );
190
+ push_count(
191
+ &mut items,
192
+ summary.coverage_gaps,
193
+ "coverage gap",
194
+ "coverage gaps",
195
+ );
196
+ push_count(
197
+ &mut items,
198
+ summary.crap_functions,
199
+ "high CRAP function",
200
+ "high CRAP functions",
201
+ );
202
+ push_count(&mut items, summary.hotspots, "hotspot", "hotspots");
203
+ push_count(
204
+ &mut items,
205
+ summary.refactoring_targets,
206
+ "refactoring target",
207
+ "refactoring targets",
208
+ );
209
+ items
210
+ }
211
+
212
+ fn flutter_items(summary: &ReportSummary) -> Vec<String> {
213
+ let mut items = Vec::new();
214
+ push_count(
215
+ &mut items,
216
+ summary.private_widget_classes,
217
+ "private widget class",
218
+ "private widget classes",
219
+ );
220
+ push_count(
221
+ &mut items,
222
+ summary.widget_top_level_functions,
223
+ "top-level widget helper",
224
+ "top-level widget helpers",
225
+ );
226
+ push_count(
227
+ &mut items,
228
+ summary.unused_widget_params,
229
+ "unused widget parameter",
230
+ "unused widget parameters",
231
+ );
232
+ push_count(
233
+ &mut items,
234
+ summary.unrendered_widgets,
235
+ "unrendered widget",
236
+ "unrendered widgets",
237
+ );
238
+ push_count(
239
+ &mut items,
240
+ summary.missing_context_mounted_after_await,
241
+ "missing context.mounted guard",
242
+ "missing context.mounted guards",
243
+ );
244
+ items
245
+ }
246
+
247
+ fn security_items(summary: &ReportSummary) -> Vec<String> {
248
+ let mut items = Vec::new();
249
+ push_count(
250
+ &mut items,
251
+ summary.security_candidates,
252
+ "security candidate",
253
+ "security candidates",
254
+ );
255
+ push_count(
256
+ &mut items,
257
+ summary.feature_flags,
258
+ "feature flag",
259
+ "feature flags",
260
+ );
261
+ items
262
+ }
263
+
264
+ fn push_count(items: &mut Vec<String>, count: usize, singular: &str, plural_label: &str) {
265
+ if count > 0 {
266
+ items.push(format!("{count} {}", plural(count, singular, plural_label)));
267
+ }
268
+ }
269
+
270
+ const fn plural<'a>(count: usize, singular: &'a str, plural: &'a str) -> &'a str {
271
+ if count == 1 { singular } else { plural }
272
+ }
273
+
274
+ fn format_basis_points(points: u32) -> String {
275
+ let whole = points / 100;
276
+ let fraction = points % 100;
277
+ if fraction == 0 {
278
+ return format!("{whole}%");
279
+ }
280
+ format!("{whole}.{fraction:02}%")
281
+ }
282
+
283
+ pub(super) const fn kind_label(kind: FindingKind) -> &'static str {
284
+ match kind {
285
+ FindingKind::DeadFile => "Dead file",
286
+ FindingKind::UnusedExport => "Unused export",
287
+ FindingKind::UnusedType => "Unused type",
288
+ FindingKind::PrivateTypeLeak => "Private type leak",
289
+ FindingKind::UnusedEnumMember => "Unused enum member",
290
+ FindingKind::UnusedClassMember => "Unused class member",
291
+ FindingKind::DuplicateExport => "Duplicate export",
292
+ FindingKind::RouteCollision => "Route collision",
293
+ FindingKind::PrivateWidgetClass => "Private widget class",
294
+ FindingKind::WidgetTopLevelFunctionBoundary => "Top-level widget helper",
295
+ FindingKind::UnusedWidgetParam => "Unused widget parameter",
296
+ FindingKind::UnrenderedWidget => "Unrendered widget",
297
+ FindingKind::MissingContextMountedAfterAwait => "Missing context.mounted guard",
298
+ FindingKind::MissingEntryPoint => "Missing entry point",
299
+ FindingKind::CircularDependency => "Circular dependency",
300
+ FindingKind::ReExportCycle => "Re-export cycle",
301
+ FindingKind::BoundaryViolation => "Boundary violation",
302
+ FindingKind::BoundaryCoverage => "Boundary coverage gap",
303
+ FindingKind::BoundaryCallViolation => "Boundary call violation",
304
+ FindingKind::PolicyViolation => "Policy violation",
305
+ FindingKind::UnresolvedDependency => "Unresolved dependency",
306
+ FindingKind::PartOfViolation => "Part-of violation",
307
+ FindingKind::UnusedDependency => "Unused dependency",
308
+ FindingKind::UnusedDevDependency => "Unused dev dependency",
309
+ FindingKind::TestOnlyDependency => "Test-only production dependency",
310
+ FindingKind::UnusedDependencyOverride => "Unused dependency override",
311
+ FindingKind::MisconfiguredDependencyOverride => "Misconfigured dependency override",
312
+ FindingKind::UnlistedDependency => "Unlisted dependency",
313
+ FindingKind::PrivateSrcImport => "Private lib/src import",
314
+ FindingKind::CodeDuplication => "Code duplication",
315
+ FindingKind::HighCyclomaticComplexity => "High cyclomatic complexity",
316
+ FindingKind::HighCognitiveComplexity => "High cognitive complexity",
317
+ FindingKind::HighComplexity => "High complexity",
318
+ FindingKind::CoverageGap => "Coverage gap",
319
+ FindingKind::HighCrapScore => "High CRAP score",
320
+ FindingKind::HealthHotspot => "Health hotspot",
321
+ FindingKind::RefactoringTarget => "Refactoring target",
322
+ FindingKind::FeatureFlag => "Feature flag",
323
+ FindingKind::SecurityCandidate => "Security candidate",
324
+ FindingKind::StaleSuppression => "Stale suppression",
325
+ FindingKind::MissingSuppressionReason => "Missing suppression reason",
326
+ }
327
+ }
328
+
329
+ pub(super) const fn why_text(kind: FindingKind) -> &'static str {
330
+ match kind {
331
+ FindingKind::CircularDependency => {
332
+ "These files import or export each other in a loop. That couples builds, tests, ownership, and refactors across the whole component."
333
+ }
334
+ FindingKind::ReExportCycle => {
335
+ "Barrel exports loop back into each other, so public API propagation is hard to reason about and can expose symbols accidentally."
336
+ }
337
+ FindingKind::BoundaryViolation => {
338
+ "A file depends on a layer or module that the configured architecture boundary disallows."
339
+ }
340
+ FindingKind::BoundaryCoverage => {
341
+ "A Dart file is outside every configured architecture zone, so boundary checks cannot prove who owns it."
342
+ }
343
+ FindingKind::BoundaryCallViolation => {
344
+ "Code in a configured zone directly calls an API pattern that should sit behind an allowed boundary."
345
+ }
346
+ FindingKind::PolicyViolation => {
347
+ "A declarative rule pack matched this file, import, export, or call pattern."
348
+ }
349
+ FindingKind::DeadFile => {
350
+ "No configured entry point reaches this Dart file through imports, exports, parts, or augmentation edges."
351
+ }
352
+ FindingKind::MissingEntryPoint => {
353
+ "The configured entry path was not found in the parsed Dart module graph."
354
+ }
355
+ FindingKind::UnresolvedDependency => {
356
+ "A local import, export, part, or augmentation URI points at a Dart file that Dart Decimate could not resolve."
357
+ }
358
+ FindingKind::PartOfViolation => {
359
+ "A Dart part file and its owning library disagree, or one side of the part relationship is missing."
360
+ }
361
+ FindingKind::UnusedDependency
362
+ | FindingKind::UnusedDevDependency
363
+ | FindingKind::TestOnlyDependency
364
+ | FindingKind::UnusedDependencyOverride
365
+ | FindingKind::MisconfiguredDependencyOverride
366
+ | FindingKind::UnlistedDependency => {
367
+ "The pubspec dependency graph and the Dart import graph do not agree."
368
+ }
369
+ FindingKind::PrivateSrcImport => {
370
+ "The import reaches into another package's private lib/src implementation surface."
371
+ }
372
+ FindingKind::UnusedExport | FindingKind::UnusedType => {
373
+ "The public declaration is not referenced from reachable Dart files in the current graph."
374
+ }
375
+ FindingKind::UnusedEnumMember | FindingKind::UnusedClassMember => {
376
+ "The member is not referenced from reachable Dart files in the current graph."
377
+ }
378
+ FindingKind::DuplicateExport => {
379
+ "One public API entry exposes more than one declaration with the same name."
380
+ }
381
+ FindingKind::RouteCollision => {
382
+ "Two typed route declarations resolve to the same route name or path."
383
+ }
384
+ FindingKind::CodeDuplication => {
385
+ "The same token sequence appears in multiple Dart locations, increasing maintenance cost when behavior changes."
386
+ }
387
+ FindingKind::HighCyclomaticComplexity
388
+ | FindingKind::HighCognitiveComplexity
389
+ | FindingKind::HighComplexity => {
390
+ "The function has enough branch or nesting decisions to raise review and change risk."
391
+ }
392
+ FindingKind::CoverageGap => {
393
+ "Runtime coverage data found no covered executable lines for this Dart file."
394
+ }
395
+ FindingKind::HighCrapScore => {
396
+ "The function combines high branching complexity with low test coverage."
397
+ }
398
+ FindingKind::HealthHotspot | FindingKind::RefactoringTarget => {
399
+ "Size, complexity, duplication, coupling, coverage, or ownership signals make this file expensive to change."
400
+ }
401
+ FindingKind::FeatureFlag => {
402
+ "Feature flag usage is present and should be traceable before cleanup or rollout work."
403
+ }
404
+ FindingKind::SecurityCandidate => {
405
+ "Static graph evidence found code that deserves security review before changing or trusting it."
406
+ }
407
+ FindingKind::PrivateTypeLeak => {
408
+ "A public API exposes a private Dart library type, making the public contract harder to consume safely."
409
+ }
410
+ FindingKind::PrivateWidgetClass
411
+ | FindingKind::WidgetTopLevelFunctionBoundary
412
+ | FindingKind::UnusedWidgetParam
413
+ | FindingKind::UnrenderedWidget
414
+ | FindingKind::MissingContextMountedAfterAwait => {
415
+ "Flutter-specific graph evidence found code whose structure can drift from reachable UI behavior."
416
+ }
417
+ FindingKind::StaleSuppression => {
418
+ "A suppression comment no longer matches an active finding."
419
+ }
420
+ FindingKind::MissingSuppressionReason => {
421
+ "A suppression comment exists without the required reason text."
422
+ }
423
+ }
424
+ }
425
+
426
+ pub(super) fn best_text(finding: &Finding, action: &FindingAction) -> String {
427
+ match finding.kind {
428
+ FindingKind::CircularDependency => {
429
+ "Break one import/export edge first. Move shared code inward, invert the dependency, or remove an unnecessary barrel hop.".to_owned()
430
+ }
431
+ FindingKind::ReExportCycle => {
432
+ "Break one export edge first. Prefer a single public barrel that points outward without looping back.".to_owned()
433
+ }
434
+ FindingKind::CodeDuplication => {
435
+ "Trace the clone group, then extract shared code only if the duplicated blocks should change together.".to_owned()
436
+ }
437
+ _ if finding.safe_to_delete || action.auto_fixable => {
438
+ format!("{} This is marked safe-to-delete from graph evidence, but still review generated and dynamic entry points.", action.description)
439
+ }
440
+ _ => action.description.clone(),
441
+ }
442
+ }
443
+
444
+ pub(super) fn fallback_best(kind: FindingKind) -> String {
445
+ format!(
446
+ "Run `dart-decimate inspect --format json` for this {} before editing.",
447
+ kind_label(kind).to_ascii_lowercase()
448
+ )
449
+ }
@@ -88,5 +88,16 @@ pub(super) fn next_steps(root: &Path, results: &AnalysisResults) -> Vec<NextStep
88
88
  }
89
89
  }
90
90
 
91
+ if results.security.as_ref().is_some_and(|report| {
92
+ report.total_occurrences > report.candidates.len() && !report.candidates.is_empty()
93
+ }) {
94
+ steps.push(NextStep {
95
+ id: "review-security-surface".to_owned(),
96
+ command: "dart-decimate security . --format json --surface".to_owned(),
97
+ reason: "List all security candidate occurrences behind representative findings"
98
+ .to_owned(),
99
+ });
100
+ }
101
+
91
102
  steps
92
103
  }
@@ -333,6 +333,7 @@ fn trace_steps(
333
333
  const fn cwe_ids(category: SecurityCategory) -> &'static [&'static str] {
334
334
  match category {
335
335
  SecurityCategory::HardcodedSecret => &["CWE-798"],
336
+ SecurityCategory::FirebaseApiKey => &["CWE-200"],
336
337
  SecurityCategory::InsecureTransport => &["CWE-319"],
337
338
  SecurityCategory::TlsBypass => &["CWE-295"],
338
339
  SecurityCategory::WebViewRisk => &["CWE-749"],
@@ -345,6 +346,7 @@ const fn cwe_ids(category: SecurityCategory) -> &'static [&'static str] {
345
346
  const fn source_label(category: SecurityCategory) -> &'static str {
346
347
  match category {
347
348
  SecurityCategory::HardcodedSecret => "source-code-literal",
349
+ SecurityCategory::FirebaseApiKey => "firebase-options-api-key",
348
350
  SecurityCategory::InsecureTransport => "http-url-literal",
349
351
  SecurityCategory::TlsBypass => "tls-callback-or-context",
350
352
  SecurityCategory::WebViewRisk => "webview-configuration",
@@ -357,6 +359,7 @@ const fn source_label(category: SecurityCategory) -> &'static str {
357
359
  const fn boundary_label(category: SecurityCategory) -> &'static str {
358
360
  match category {
359
361
  SecurityCategory::HardcodedSecret => "source-control",
362
+ SecurityCategory::FirebaseApiKey => "firebase-client-config",
360
363
  SecurityCategory::InsecureTransport => "network-transport",
361
364
  SecurityCategory::TlsBypass => "tls-validation",
362
365
  SecurityCategory::WebViewRisk => "embedded-webview",
@@ -368,7 +371,7 @@ const fn boundary_label(category: SecurityCategory) -> &'static str {
368
371
 
369
372
  const fn trace_role(category: SecurityCategory) -> &'static str {
370
373
  match category {
371
- SecurityCategory::HardcodedSecret => "source",
374
+ SecurityCategory::HardcodedSecret | SecurityCategory::FirebaseApiKey => "source",
372
375
  SecurityCategory::TlsBypass | SecurityCategory::WebViewRisk => "boundary",
373
376
  SecurityCategory::InsecureTransport
374
377
  | SecurityCategory::ProcessExecution
@@ -380,6 +383,7 @@ const fn trace_role(category: SecurityCategory) -> &'static str {
380
383
  const fn category_name(category: SecurityCategory) -> &'static str {
381
384
  match category {
382
385
  SecurityCategory::HardcodedSecret => "hardcoded secret",
386
+ SecurityCategory::FirebaseApiKey => "Firebase API key",
383
387
  SecurityCategory::InsecureTransport => "insecure transport",
384
388
  SecurityCategory::TlsBypass => "TLS bypass",
385
389
  SecurityCategory::WebViewRisk => "WebView risk",
@@ -168,6 +168,13 @@ pub struct JsonReport {
168
168
  pub next_steps: Vec<NextStep>,
169
169
  }
170
170
 
171
+ impl JsonReport {
172
+ pub(crate) fn has_hidden_security_candidate_occurrences(&self) -> bool {
173
+ !self.security_candidates.is_empty()
174
+ && self.summary.security_candidate_occurrences > self.security_candidates.len()
175
+ }
176
+ }
177
+
171
178
  /// Report summary.
172
179
  #[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
173
180
  pub struct ReportSummary {
package/src/output.rs CHANGED
@@ -7,7 +7,9 @@ mod feature_flag_findings;
7
7
  mod format;
8
8
  mod graph_findings;
9
9
  mod health_findings;
10
+ mod html;
10
11
  mod human;
12
+ mod human_details;
11
13
  mod next_steps;
12
14
  mod route_findings;
13
15
  mod runtime_coverage;
@@ -44,6 +46,7 @@ use health_findings::{
44
46
  add_health_findings, json_complexity, json_file_scores, json_hotspots,
45
47
  json_refactoring_targets, json_threshold_overrides,
46
48
  };
49
+ pub use html::{render_decision_surface_html_report, render_html_report};
47
50
  pub use human::render_human_report;
48
51
  use next_steps::next_steps;
49
52
  use route_findings::add_route_findings;
@@ -358,6 +358,7 @@ fn security_category_schema() -> Value {
358
358
  "type": "string",
359
359
  "enum": [
360
360
  "hardcoded-secret",
361
+ "firebase-api-key",
361
362
  "insecure-transport",
362
363
  "tls-bypass",
363
364
  "web-view-risk",