dart-decimate 0.0.1

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.
Files changed (188) hide show
  1. package/Cargo.lock +572 -0
  2. package/Cargo.toml +41 -0
  3. package/LICENSE +21 -0
  4. package/README.md +617 -0
  5. package/assets/dart-decimate-banner.png +0 -0
  6. package/npm/bin/dart-decimate-mcp.js +48 -0
  7. package/npm/bin/dart-decimate.js +48 -0
  8. package/npm/scripts/postinstall.js +46 -0
  9. package/npm/scripts/test-npx-local.js +54 -0
  10. package/npm/scripts/test-npx-mcp-local.js +56 -0
  11. package/package.json +45 -0
  12. package/src/baseline.rs +643 -0
  13. package/src/bin/dart-decimate-mcp.rs +11 -0
  14. package/src/boundaries/tests.rs +60 -0
  15. package/src/boundaries.rs +317 -0
  16. package/src/changed_scope.rs +117 -0
  17. package/src/ci_template.rs +399 -0
  18. package/src/cli/analyze.rs +462 -0
  19. package/src/cli/analyzer_options.rs +82 -0
  20. package/src/cli/audit_run.rs +327 -0
  21. package/src/cli/boundary_args.rs +44 -0
  22. package/src/cli/ci_template_run.rs +196 -0
  23. package/src/cli/command_name.rs +20 -0
  24. package/src/cli/common_args.rs +167 -0
  25. package/src/cli/config_run.rs +78 -0
  26. package/src/cli/coverage_run.rs +393 -0
  27. package/src/cli/decision_surface_run.rs +99 -0
  28. package/src/cli/default_command.rs +69 -0
  29. package/src/cli/dupes_args.rs +150 -0
  30. package/src/cli/entry_points.rs +121 -0
  31. package/src/cli/error.rs +149 -0
  32. package/src/cli/error_output.rs +68 -0
  33. package/src/cli/explain_run.rs +72 -0
  34. package/src/cli/fix_run.rs +162 -0
  35. package/src/cli/flags_args.rs +23 -0
  36. package/src/cli/health_args.rs +200 -0
  37. package/src/cli/hooks_run.rs +191 -0
  38. package/src/cli/impact_run.rs +95 -0
  39. package/src/cli/init_run.rs +49 -0
  40. package/src/cli/inspect_args.rs +20 -0
  41. package/src/cli/inspect_run.rs +66 -0
  42. package/src/cli/issue_filter_args.rs +240 -0
  43. package/src/cli/list_run.rs +311 -0
  44. package/src/cli/mode_args.rs +72 -0
  45. package/src/cli/output_format.rs +62 -0
  46. package/src/cli/regression_args.rs +156 -0
  47. package/src/cli/request_args.rs +175 -0
  48. package/src/cli/schema_commands.rs +72 -0
  49. package/src/cli/scope_args.rs +174 -0
  50. package/src/cli/security_args.rs +175 -0
  51. package/src/cli/security_gate_run.rs +66 -0
  52. package/src/cli/security_summary_run.rs +43 -0
  53. package/src/cli/summary_args.rs +12 -0
  54. package/src/cli/tests.rs +516 -0
  55. package/src/cli/trace_args.rs +67 -0
  56. package/src/cli/trace_run.rs +131 -0
  57. package/src/cli/trace_tests.rs +235 -0
  58. package/src/cli/unsupported_run.rs +116 -0
  59. package/src/cli/watch_run.rs +153 -0
  60. package/src/cli.rs +603 -0
  61. package/src/config/boundary_config.rs +235 -0
  62. package/src/config/cache.rs +25 -0
  63. package/src/config/dependencies.rs +114 -0
  64. package/src/config/health.rs +237 -0
  65. package/src/config/jsonc.rs +66 -0
  66. package/src/config/policy.rs +91 -0
  67. package/src/config/rule_aliases.rs +487 -0
  68. package/src/config/rules.rs +339 -0
  69. package/src/config.rs +635 -0
  70. package/src/coverage.rs +469 -0
  71. package/src/dart_parser.rs +673 -0
  72. package/src/decision_surface.rs +405 -0
  73. package/src/dependencies/analyze.rs +218 -0
  74. package/src/dependencies/codegen.rs +118 -0
  75. package/src/dependencies/discovery.rs +60 -0
  76. package/src/dependencies/overrides.rs +76 -0
  77. package/src/dependencies/private_src_imports.rs +32 -0
  78. package/src/dependencies/pubspec_document.rs +86 -0
  79. package/src/dependencies/pubspec_entry.rs +96 -0
  80. package/src/dependencies/tests.rs +544 -0
  81. package/src/dependencies/usage.rs +33 -0
  82. package/src/dependencies.rs +553 -0
  83. package/src/dependency_scripts.rs +91 -0
  84. package/src/dupes/lex.rs +236 -0
  85. package/src/dupes/tests.rs +119 -0
  86. package/src/dupes.rs +625 -0
  87. package/src/explain.rs +692 -0
  88. package/src/extract/directives.rs +252 -0
  89. package/src/extract/error_tests.rs +25 -0
  90. package/src/extract/members.rs +210 -0
  91. package/src/extract/primary_constructors.rs +421 -0
  92. package/src/extract/references.rs +151 -0
  93. package/src/extract/routes.rs +691 -0
  94. package/src/extract/signatures.rs +266 -0
  95. package/src/extract/string_tests.rs +18 -0
  96. package/src/extract/strings.rs +107 -0
  97. package/src/extract/tests.rs +697 -0
  98. package/src/extract.rs +680 -0
  99. package/src/feature_flags/tests.rs +76 -0
  100. package/src/feature_flags.rs +453 -0
  101. package/src/finding_identity.rs +60 -0
  102. package/src/fix.rs +551 -0
  103. package/src/generated.rs +53 -0
  104. package/src/graph/augment_tests.rs +212 -0
  105. package/src/graph/conditionals.rs +74 -0
  106. package/src/graph/package_config_tests.rs +100 -0
  107. package/src/graph/parts.rs +248 -0
  108. package/src/graph/pubspec_tests.rs +119 -0
  109. package/src/graph/tests.rs +837 -0
  110. package/src/graph/uri_tests.rs +102 -0
  111. package/src/graph.rs +644 -0
  112. package/src/health/coverage.rs +309 -0
  113. package/src/health/ownership.rs +175 -0
  114. package/src/health/runtime_coverage.rs +616 -0
  115. package/src/health/runtime_intelligence.rs +511 -0
  116. package/src/health/scores.rs +296 -0
  117. package/src/health/tests.rs +240 -0
  118. package/src/health/threshold_types.rs +163 -0
  119. package/src/health/thresholds.rs +229 -0
  120. package/src/health/types.rs +636 -0
  121. package/src/health.rs +597 -0
  122. package/src/hooks/agent_settings.rs +175 -0
  123. package/src/hooks/templates.rs +51 -0
  124. package/src/hooks.rs +569 -0
  125. package/src/impact.rs +287 -0
  126. package/src/init.rs +237 -0
  127. package/src/inspect.rs +142 -0
  128. package/src/intelligence/tests.rs +232 -0
  129. package/src/intelligence.rs +305 -0
  130. package/src/lib.rs +198 -0
  131. package/src/main.rs +5 -0
  132. package/src/manifest/mcp.rs +565 -0
  133. package/src/manifest.rs +552 -0
  134. package/src/mcp/cli_args/value_args.rs +175 -0
  135. package/src/mcp/cli_args.rs +658 -0
  136. package/src/mcp/cli_args_tests.rs +522 -0
  137. package/src/mcp/code_execute.rs +671 -0
  138. package/src/mcp/tools.rs +660 -0
  139. package/src/mcp.rs +325 -0
  140. package/src/output/audit_risk.rs +135 -0
  141. package/src/output/dependency_findings.rs +327 -0
  142. package/src/output/duplication_findings.rs +114 -0
  143. package/src/output/feature_flag_findings.rs +122 -0
  144. package/src/output/format.rs +31 -0
  145. package/src/output/graph_findings.rs +461 -0
  146. package/src/output/health_findings.rs +612 -0
  147. package/src/output/human.rs +27 -0
  148. package/src/output/next_steps.rs +92 -0
  149. package/src/output/route_findings.rs +76 -0
  150. package/src/output/runtime_coverage.rs +515 -0
  151. package/src/output/scope.rs +183 -0
  152. package/src/output/security_findings.rs +390 -0
  153. package/src/output/security_sarif.rs +150 -0
  154. package/src/output/suppressions.rs +323 -0
  155. package/src/output/symbol_findings.rs +257 -0
  156. package/src/output/tests.rs +114 -0
  157. package/src/output/types.rs +604 -0
  158. package/src/output/widget_findings.rs +213 -0
  159. package/src/output.rs +682 -0
  160. package/src/package_map.rs +495 -0
  161. package/src/policy/packs.rs +232 -0
  162. package/src/policy/tests.rs +134 -0
  163. package/src/policy.rs +640 -0
  164. package/src/project_list.rs +376 -0
  165. package/src/report_schema/inventory.rs +418 -0
  166. package/src/report_schema.rs +488 -0
  167. package/src/routes.rs +354 -0
  168. package/src/scan/tests.rs +250 -0
  169. package/src/scan.rs +275 -0
  170. package/src/security/detect.rs +639 -0
  171. package/src/security/tests.rs +178 -0
  172. package/src/security.rs +373 -0
  173. package/src/security_gate.rs +555 -0
  174. package/src/symbols/path_filters.rs +27 -0
  175. package/src/symbols/private_type_leaks.rs +125 -0
  176. package/src/symbols/riverpod.rs +113 -0
  177. package/src/symbols/tests.rs +692 -0
  178. package/src/symbols.rs +693 -0
  179. package/src/trace/tests.rs +225 -0
  180. package/src/trace.rs +690 -0
  181. package/src/unsupported.rs +47 -0
  182. package/src/widgets/lifecycle.rs +484 -0
  183. package/src/widgets/params.rs +236 -0
  184. package/src/widgets/tests.rs +430 -0
  185. package/src/widgets/top_level.rs +110 -0
  186. package/src/widgets/unrendered.rs +374 -0
  187. package/src/widgets.rs +590 -0
  188. package/src/workspace_scope.rs +358 -0
@@ -0,0 +1,643 @@
1
+ use std::collections::{BTreeMap, BTreeSet};
2
+ use std::fs;
3
+ use std::path::{Path, PathBuf};
4
+
5
+ use serde::{Deserialize, Serialize};
6
+ use thiserror::Error;
7
+
8
+ use crate::finding_identity::finding_identity;
9
+ use crate::output::{Finding, FindingKind, JsonAttackSurfaceEntry, JsonReport, Severity, Verdict};
10
+ use crate::{JsonCloneGroup, JsonComplexityFinding, JsonFeatureFlag, JsonSecurityCandidate};
11
+
12
+ pub const BASELINE_SCHEMA_VERSION: &str = "dart-decimate.baseline.v1";
13
+ pub const REGRESSION_BASELINE_SCHEMA_VERSION: &str = "dart-decimate.regression-baseline.v1";
14
+
15
+ /// Identity-based finding baseline.
16
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
17
+ pub struct Baseline {
18
+ /// Baseline schema identifier.
19
+ pub schema_version: String,
20
+ /// Tool that created this baseline.
21
+ pub tool: String,
22
+ /// Stable finding identities captured by the baseline.
23
+ pub findings: Vec<BaselineFinding>,
24
+ }
25
+
26
+ /// One persisted finding identity.
27
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
28
+ pub struct BaselineFinding {
29
+ /// Stable identity string used for matching future findings.
30
+ pub identity: String,
31
+ /// Stable rule id.
32
+ pub rule_id: String,
33
+ /// Rule-provided fingerprint, when the finding exposes one.
34
+ pub fingerprint: Option<String>,
35
+ /// Finding category.
36
+ pub kind: FindingKind,
37
+ /// Root-relative finding path.
38
+ pub path: String,
39
+ }
40
+
41
+ /// Count-based regression baseline.
42
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
43
+ pub struct RegressionBaseline {
44
+ /// Baseline schema identifier.
45
+ pub schema_version: String,
46
+ /// Tool that created this baseline.
47
+ pub tool: String,
48
+ /// Command that produced the baseline.
49
+ pub command: String,
50
+ /// Per-rule and total finding counts.
51
+ pub counts: RegressionCounts,
52
+ }
53
+
54
+ /// Count snapshot used for regression comparison.
55
+ #[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
56
+ pub struct RegressionCounts {
57
+ /// Total visible finding count.
58
+ pub findings: usize,
59
+ /// Visible finding counts keyed by stable rule id.
60
+ pub rules: BTreeMap<String, usize>,
61
+ }
62
+
63
+ /// Allowed count increase before a regression is reported.
64
+ #[derive(Debug, Clone, Copy, PartialEq, Eq)]
65
+ pub enum RegressionTolerance {
66
+ /// Absolute issue-count increase.
67
+ Absolute(usize),
68
+ /// Percentage increase in basis points, where 10000 is 100%.
69
+ PercentBasisPoints(u32),
70
+ }
71
+
72
+ impl Default for RegressionTolerance {
73
+ fn default() -> Self {
74
+ Self::Absolute(0)
75
+ }
76
+ }
77
+
78
+ /// Count-based regression comparison.
79
+ #[derive(Debug, Clone, PartialEq, Eq)]
80
+ pub struct RegressionComparison {
81
+ /// Total finding-count change.
82
+ pub total: RegressionCountDelta,
83
+ /// Per-rule count changes.
84
+ pub rules: Vec<RegressionCountDelta>,
85
+ }
86
+
87
+ impl RegressionComparison {
88
+ /// Whether any count increased beyond tolerance.
89
+ #[must_use]
90
+ pub fn regressed(&self) -> bool {
91
+ self.total.regressed || self.rules.iter().any(|delta| delta.regressed)
92
+ }
93
+ }
94
+
95
+ /// One regression count delta.
96
+ #[derive(Debug, Clone, PartialEq, Eq)]
97
+ pub struct RegressionCountDelta {
98
+ /// Count name or rule id.
99
+ pub name: String,
100
+ /// Baseline count.
101
+ pub baseline: usize,
102
+ /// Current count.
103
+ pub current: usize,
104
+ /// Allowed increase.
105
+ pub allowed_increase: usize,
106
+ /// Whether current count exceeded baseline plus allowed increase.
107
+ pub regressed: bool,
108
+ }
109
+
110
+ /// Errors returned while loading or saving baselines.
111
+ #[derive(Debug, Error)]
112
+ pub enum BaselineError {
113
+ /// Baseline file could not be read.
114
+ #[error("failed to read baseline {path}: {source}")]
115
+ Read {
116
+ /// Baseline path.
117
+ path: PathBuf,
118
+ /// Underlying IO error.
119
+ source: std::io::Error,
120
+ },
121
+ /// Baseline file could not be parsed.
122
+ #[error("failed to parse baseline {path}: {source}")]
123
+ Parse {
124
+ /// Baseline path.
125
+ path: PathBuf,
126
+ /// JSON parse error.
127
+ source: serde_json::Error,
128
+ },
129
+ /// Baseline file had an unsupported schema.
130
+ #[error("unsupported baseline schema {schema_version:?} in {path}")]
131
+ Schema {
132
+ /// Baseline path.
133
+ path: PathBuf,
134
+ /// Unsupported schema version.
135
+ schema_version: String,
136
+ },
137
+ /// Baseline parent directory could not be created.
138
+ #[error("failed to create baseline directory {path}: {source}")]
139
+ CreateDir {
140
+ /// Directory path.
141
+ path: PathBuf,
142
+ /// Underlying IO error.
143
+ source: std::io::Error,
144
+ },
145
+ /// Baseline file could not be written.
146
+ #[error("failed to write baseline {path}: {source}")]
147
+ Write {
148
+ /// Baseline path.
149
+ path: PathBuf,
150
+ /// Underlying IO error.
151
+ source: std::io::Error,
152
+ },
153
+ /// Baseline JSON could not be serialized.
154
+ #[error("failed to render baseline {path}: {source}")]
155
+ Json {
156
+ /// Baseline path.
157
+ path: PathBuf,
158
+ /// JSON serialization error.
159
+ source: serde_json::Error,
160
+ },
161
+ }
162
+
163
+ /// Build a baseline from the visible findings in a report.
164
+ #[must_use]
165
+ pub fn baseline_from_report(report: &JsonReport) -> Baseline {
166
+ let mut findings = report
167
+ .findings
168
+ .iter()
169
+ .map(BaselineFinding::from)
170
+ .collect::<Vec<_>>();
171
+ findings.sort_by(|left, right| left.identity.cmp(&right.identity));
172
+ findings.dedup_by(|left, right| left.identity == right.identity);
173
+
174
+ Baseline {
175
+ schema_version: BASELINE_SCHEMA_VERSION.to_owned(),
176
+ tool: "dart-decimate".to_owned(),
177
+ findings,
178
+ }
179
+ }
180
+
181
+ /// Build a count-based regression baseline from the visible findings in a report.
182
+ #[must_use]
183
+ pub fn regression_baseline_from_report(report: &JsonReport) -> RegressionBaseline {
184
+ RegressionBaseline {
185
+ schema_version: REGRESSION_BASELINE_SCHEMA_VERSION.to_owned(),
186
+ tool: "dart-decimate".to_owned(),
187
+ command: report.command.as_str().to_owned(),
188
+ counts: regression_counts(report),
189
+ }
190
+ }
191
+
192
+ /// Load a baseline from disk.
193
+ ///
194
+ /// # Errors
195
+ ///
196
+ /// Returns [`BaselineError`] when the file is unreadable, malformed, or uses an
197
+ /// unsupported schema version.
198
+ pub fn load_baseline(path: impl AsRef<Path>) -> Result<Baseline, BaselineError> {
199
+ let path = path.as_ref();
200
+ let source = fs::read_to_string(path).map_err(|source| BaselineError::Read {
201
+ path: path.to_path_buf(),
202
+ source,
203
+ })?;
204
+ let baseline =
205
+ serde_json::from_str::<Baseline>(&source).map_err(|source| BaselineError::Parse {
206
+ path: path.to_path_buf(),
207
+ source,
208
+ })?;
209
+ if baseline.schema_version != BASELINE_SCHEMA_VERSION {
210
+ return Err(BaselineError::Schema {
211
+ path: path.to_path_buf(),
212
+ schema_version: baseline.schema_version,
213
+ });
214
+ }
215
+ Ok(baseline)
216
+ }
217
+
218
+ /// Load a count-based regression baseline from disk.
219
+ ///
220
+ /// # Errors
221
+ ///
222
+ /// Returns [`BaselineError`] when the file is unreadable, malformed, or uses an
223
+ /// unsupported schema version.
224
+ pub fn load_regression_baseline(
225
+ path: impl AsRef<Path>,
226
+ ) -> Result<RegressionBaseline, BaselineError> {
227
+ let path = path.as_ref();
228
+ let source = fs::read_to_string(path).map_err(|source| BaselineError::Read {
229
+ path: path.to_path_buf(),
230
+ source,
231
+ })?;
232
+ let baseline = serde_json::from_str::<RegressionBaseline>(&source).map_err(|source| {
233
+ BaselineError::Parse {
234
+ path: path.to_path_buf(),
235
+ source,
236
+ }
237
+ })?;
238
+ if baseline.schema_version != REGRESSION_BASELINE_SCHEMA_VERSION {
239
+ return Err(BaselineError::Schema {
240
+ path: path.to_path_buf(),
241
+ schema_version: baseline.schema_version,
242
+ });
243
+ }
244
+ Ok(baseline)
245
+ }
246
+
247
+ /// Save a baseline to disk.
248
+ ///
249
+ /// # Errors
250
+ ///
251
+ /// Returns [`BaselineError`] when the parent directory cannot be created or the
252
+ /// file cannot be written.
253
+ pub fn save_baseline(path: impl AsRef<Path>, baseline: &Baseline) -> Result<(), BaselineError> {
254
+ save_json(path, baseline)
255
+ }
256
+
257
+ /// Save a count-based regression baseline to disk.
258
+ ///
259
+ /// # Errors
260
+ ///
261
+ /// Returns [`BaselineError`] when the parent directory cannot be created or the
262
+ /// file cannot be written.
263
+ pub fn save_regression_baseline(
264
+ path: impl AsRef<Path>,
265
+ baseline: &RegressionBaseline,
266
+ ) -> Result<(), BaselineError> {
267
+ save_json(path, baseline)
268
+ }
269
+
270
+ fn save_json<T: Serialize>(path: impl AsRef<Path>, value: &T) -> Result<(), BaselineError> {
271
+ let path = path.as_ref();
272
+ if let Some(parent) = path.parent() {
273
+ if !parent.as_os_str().is_empty() {
274
+ fs::create_dir_all(parent).map_err(|source| BaselineError::CreateDir {
275
+ path: parent.to_path_buf(),
276
+ source,
277
+ })?;
278
+ }
279
+ }
280
+ let mut json = serde_json::to_string_pretty(value).map_err(|source| BaselineError::Json {
281
+ path: path.to_path_buf(),
282
+ source,
283
+ })?;
284
+ json.push('\n');
285
+ fs::write(path, json).map_err(|source| BaselineError::Write {
286
+ path: path.to_path_buf(),
287
+ source,
288
+ })
289
+ }
290
+
291
+ /// Compare visible report counts against a regression baseline.
292
+ #[must_use]
293
+ pub fn compare_regression_baseline(
294
+ report: &JsonReport,
295
+ baseline: &RegressionBaseline,
296
+ tolerance: RegressionTolerance,
297
+ ) -> RegressionComparison {
298
+ let current = regression_counts(report);
299
+ let mut rules = baseline
300
+ .counts
301
+ .rules
302
+ .keys()
303
+ .chain(current.rules.keys())
304
+ .collect::<BTreeSet<_>>()
305
+ .into_iter()
306
+ .map(|rule| {
307
+ regression_delta(
308
+ rule,
309
+ baseline.counts.rules.get(rule).copied().unwrap_or_default(),
310
+ current.rules.get(rule).copied().unwrap_or_default(),
311
+ tolerance,
312
+ )
313
+ })
314
+ .collect::<Vec<_>>();
315
+ rules.sort_by(|left, right| left.name.cmp(&right.name));
316
+
317
+ RegressionComparison {
318
+ total: regression_delta(
319
+ "findings",
320
+ baseline.counts.findings,
321
+ current.findings,
322
+ tolerance,
323
+ ),
324
+ rules,
325
+ }
326
+ }
327
+
328
+ fn regression_counts(report: &JsonReport) -> RegressionCounts {
329
+ let mut rules = BTreeMap::<String, usize>::new();
330
+ for finding in &report.findings {
331
+ *rules.entry(finding.rule_id.clone()).or_default() += 1;
332
+ }
333
+ RegressionCounts {
334
+ findings: report.findings.len(),
335
+ rules,
336
+ }
337
+ }
338
+
339
+ fn regression_delta(
340
+ name: &str,
341
+ baseline: usize,
342
+ current: usize,
343
+ tolerance: RegressionTolerance,
344
+ ) -> RegressionCountDelta {
345
+ let allowed_increase = allowed_increase(baseline, tolerance);
346
+ RegressionCountDelta {
347
+ name: name.to_owned(),
348
+ baseline,
349
+ current,
350
+ allowed_increase,
351
+ regressed: current > baseline.saturating_add(allowed_increase),
352
+ }
353
+ }
354
+
355
+ fn allowed_increase(baseline: usize, tolerance: RegressionTolerance) -> usize {
356
+ match tolerance {
357
+ RegressionTolerance::Absolute(value) => value,
358
+ RegressionTolerance::PercentBasisPoints(value) => {
359
+ let numerator = baseline.saturating_mul(value as usize);
360
+ numerator.saturating_add(9999) / 10000
361
+ }
362
+ }
363
+ }
364
+
365
+ /// Remove findings already present in `baseline` and recompute report verdicts.
366
+ pub fn apply_baseline_to_report(report: &mut JsonReport, baseline: &Baseline) {
367
+ let known = baseline
368
+ .findings
369
+ .iter()
370
+ .map(|finding| finding.identity.as_str())
371
+ .collect::<BTreeSet<_>>();
372
+ if known.is_empty() {
373
+ return;
374
+ }
375
+
376
+ report
377
+ .findings
378
+ .retain(|finding| !known.contains(finding_identity(finding).as_str()));
379
+ filter_detail_sections(report);
380
+ recompute_summary(report);
381
+ report.verdict = if report
382
+ .findings
383
+ .iter()
384
+ .any(|finding| finding.severity == Severity::Error)
385
+ {
386
+ Verdict::Fail
387
+ } else {
388
+ Verdict::Pass
389
+ };
390
+ }
391
+
392
+ impl From<&Finding> for BaselineFinding {
393
+ fn from(finding: &Finding) -> Self {
394
+ Self {
395
+ identity: finding_identity(finding),
396
+ rule_id: finding.rule_id.clone(),
397
+ fingerprint: finding.fingerprint.clone(),
398
+ kind: finding.kind,
399
+ path: finding.path.clone(),
400
+ }
401
+ }
402
+ }
403
+
404
+ fn filter_detail_sections(report: &mut JsonReport) {
405
+ let remaining = report
406
+ .findings
407
+ .iter()
408
+ .map(|finding| {
409
+ (
410
+ finding.kind,
411
+ finding.path.clone(),
412
+ finding.fingerprint.clone(),
413
+ )
414
+ })
415
+ .collect::<Vec<_>>();
416
+
417
+ report
418
+ .clone_groups
419
+ .retain(|group| clone_group_live(group, &remaining));
420
+ report
421
+ .complexity
422
+ .retain(|finding| complexity_live(finding, &remaining));
423
+ report
424
+ .hotspots
425
+ .retain(|hotspot| detail_path_live(FindingKind::HealthHotspot, &hotspot.path, &remaining));
426
+ report.refactoring_targets.retain(|target| {
427
+ detail_path_live(FindingKind::RefactoringTarget, &target.path, &remaining)
428
+ });
429
+ report
430
+ .feature_flags
431
+ .retain(|flag| feature_flag_live(flag, &remaining));
432
+ report
433
+ .security_candidates
434
+ .retain(|candidate| security_live(candidate, &remaining));
435
+ report
436
+ .attack_surface
437
+ .retain(|entry| attack_surface_live(entry, &report.security_candidates));
438
+ report
439
+ .next_steps
440
+ .retain(|step| next_step_live(&step.id, &remaining));
441
+ }
442
+
443
+ fn clone_group_live(
444
+ group: &JsonCloneGroup,
445
+ remaining: &[(FindingKind, String, Option<String>)],
446
+ ) -> bool {
447
+ remaining.iter().any(|(kind, _, fingerprint)| {
448
+ *kind == FindingKind::CodeDuplication && fingerprint.as_deref() == Some(&group.fingerprint)
449
+ })
450
+ }
451
+
452
+ fn complexity_live(
453
+ finding: &JsonComplexityFinding,
454
+ remaining: &[(FindingKind, String, Option<String>)],
455
+ ) -> bool {
456
+ remaining.iter().any(|(kind, path, _)| {
457
+ complexity_kind(*kind)
458
+ && path == &finding.path
459
+ && finding.rule_id.ends_with(kind_suffix(*kind))
460
+ })
461
+ }
462
+
463
+ fn detail_path_live(
464
+ expected: FindingKind,
465
+ detail_path: &str,
466
+ remaining: &[(FindingKind, String, Option<String>)],
467
+ ) -> bool {
468
+ remaining
469
+ .iter()
470
+ .any(|(kind, path, _)| *kind == expected && path == detail_path)
471
+ }
472
+
473
+ fn feature_flag_live(
474
+ flag: &JsonFeatureFlag,
475
+ remaining: &[(FindingKind, String, Option<String>)],
476
+ ) -> bool {
477
+ flag.occurrences.iter().any(|occurrence| {
478
+ remaining
479
+ .iter()
480
+ .any(|(kind, path, _)| *kind == FindingKind::FeatureFlag && path == &occurrence.path)
481
+ })
482
+ }
483
+
484
+ fn security_live(
485
+ candidate: &JsonSecurityCandidate,
486
+ remaining: &[(FindingKind, String, Option<String>)],
487
+ ) -> bool {
488
+ remaining.iter().any(|(kind, _, fingerprint)| {
489
+ *kind == FindingKind::SecurityCandidate
490
+ && fingerprint.as_deref() == Some(candidate.fingerprint.as_str())
491
+ })
492
+ }
493
+
494
+ fn attack_surface_live(
495
+ entry: &JsonAttackSurfaceEntry,
496
+ candidates: &[JsonSecurityCandidate],
497
+ ) -> bool {
498
+ candidates
499
+ .iter()
500
+ .any(|candidate| candidate.category == entry.category)
501
+ }
502
+
503
+ fn next_step_live(id: &str, remaining: &[(FindingKind, String, Option<String>)]) -> bool {
504
+ match id {
505
+ "trace-unused-export" => has_kind(remaining, FindingKind::UnusedExport),
506
+ "trace-unused-type" => has_kind(remaining, FindingKind::UnusedType),
507
+ "trace-unused-dependency" => remaining
508
+ .iter()
509
+ .any(|(kind, _, _)| is_dependency_hygiene_kind(*kind)),
510
+ "trace-code-duplication" => has_kind(remaining, FindingKind::CodeDuplication),
511
+ "complexity-breakdown" => remaining.iter().any(|(kind, _, _)| complexity_kind(*kind)),
512
+ _ => true,
513
+ }
514
+ }
515
+
516
+ fn has_kind(remaining: &[(FindingKind, String, Option<String>)], expected: FindingKind) -> bool {
517
+ remaining.iter().any(|(kind, _, _)| *kind == expected)
518
+ }
519
+
520
+ fn complexity_kind(kind: FindingKind) -> bool {
521
+ matches!(
522
+ kind,
523
+ FindingKind::HighCyclomaticComplexity
524
+ | FindingKind::HighCognitiveComplexity
525
+ | FindingKind::HighComplexity
526
+ | FindingKind::HighCrapScore
527
+ )
528
+ }
529
+ fn kind_suffix(kind: FindingKind) -> &'static str {
530
+ match kind {
531
+ FindingKind::HighCyclomaticComplexity => "high-cyclomatic-complexity",
532
+ FindingKind::HighCognitiveComplexity => "high-cognitive-complexity",
533
+ FindingKind::HighComplexity => "high-complexity",
534
+ FindingKind::HighCrapScore => "high-crap-score",
535
+ _ => "",
536
+ }
537
+ }
538
+ fn recompute_summary(report: &mut JsonReport) {
539
+ report.summary.unresolved_dependencies =
540
+ kind_count(&report.findings, FindingKind::UnresolvedDependency);
541
+ report.summary.part_of_violations = kind_count(&report.findings, FindingKind::PartOfViolation);
542
+ report.summary.unused_dependencies = dependency_count(&report.findings);
543
+ report.summary.unused_dev_dependencies =
544
+ kind_count(&report.findings, FindingKind::UnusedDevDependency);
545
+ report.summary.test_only_dependencies =
546
+ kind_count(&report.findings, FindingKind::TestOnlyDependency);
547
+ report.summary.dependency_overrides = dependency_override_count(&report.findings);
548
+ report.summary.unused_dependency_overrides =
549
+ kind_count(&report.findings, FindingKind::UnusedDependencyOverride);
550
+ report.summary.misconfigured_dependency_overrides = kind_count(
551
+ &report.findings,
552
+ FindingKind::MisconfiguredDependencyOverride,
553
+ );
554
+ report.summary.unlisted_dependencies =
555
+ kind_count(&report.findings, FindingKind::UnlistedDependency);
556
+ report.summary.private_src_imports =
557
+ kind_count(&report.findings, FindingKind::PrivateSrcImport);
558
+ report.summary.dead_files = kind_count(&report.findings, FindingKind::DeadFile);
559
+ report.summary.unused_exports = kind_count(&report.findings, FindingKind::UnusedExport);
560
+ report.summary.unused_types = kind_count(&report.findings, FindingKind::UnusedType);
561
+ report.summary.private_type_leaks = kind_count(&report.findings, FindingKind::PrivateTypeLeak);
562
+ report.summary.unused_enum_members =
563
+ kind_count(&report.findings, FindingKind::UnusedEnumMember);
564
+ report.summary.unused_class_members =
565
+ kind_count(&report.findings, FindingKind::UnusedClassMember);
566
+ report.summary.duplicate_exports = kind_count(&report.findings, FindingKind::DuplicateExport);
567
+ report.summary.route_collisions = kind_count(&report.findings, FindingKind::RouteCollision);
568
+ report.summary.private_widget_classes =
569
+ kind_count(&report.findings, FindingKind::PrivateWidgetClass);
570
+ report.summary.widget_top_level_functions = kind_count(
571
+ &report.findings,
572
+ FindingKind::WidgetTopLevelFunctionBoundary,
573
+ );
574
+ report.summary.unused_widget_params =
575
+ kind_count(&report.findings, FindingKind::UnusedWidgetParam);
576
+ report.summary.unrendered_widgets = kind_count(&report.findings, FindingKind::UnrenderedWidget);
577
+ report.summary.missing_context_mounted_after_await = kind_count(
578
+ &report.findings,
579
+ FindingKind::MissingContextMountedAfterAwait,
580
+ );
581
+ report.summary.code_duplications = report.clone_groups.len();
582
+ report.summary.complex_functions = report.complexity.len();
583
+ report.summary.coverage_gaps = kind_count(&report.findings, FindingKind::CoverageGap);
584
+ report.summary.crap_functions = kind_count(&report.findings, FindingKind::HighCrapScore);
585
+ report.summary.file_scores = report.file_scores.len();
586
+ report.summary.hotspots = report.hotspots.len();
587
+ report.summary.refactoring_targets = report.refactoring_targets.len();
588
+ report.summary.feature_flags = report.feature_flags.len();
589
+ report.summary.feature_flag_occurrences = report
590
+ .feature_flags
591
+ .iter()
592
+ .map(|flag| flag.occurrences.len())
593
+ .sum();
594
+ report.summary.security_candidates = report.security_candidates.len();
595
+ report.summary.security_candidate_occurrences = report
596
+ .security_candidates
597
+ .iter()
598
+ .map(|candidate| candidate.occurrences.len())
599
+ .sum();
600
+ report.summary.attack_surface = report.attack_surface.len();
601
+ report.summary.missing_entry_points =
602
+ kind_count(&report.findings, FindingKind::MissingEntryPoint);
603
+ report.summary.cycles = kind_count(&report.findings, FindingKind::CircularDependency);
604
+ report.summary.re_export_cycles = kind_count(&report.findings, FindingKind::ReExportCycle);
605
+ report.summary.boundary_violations =
606
+ kind_count(&report.findings, FindingKind::BoundaryViolation);
607
+ report.summary.boundary_coverage = kind_count(&report.findings, FindingKind::BoundaryCoverage);
608
+ report.summary.boundary_call_violations =
609
+ kind_count(&report.findings, FindingKind::BoundaryCallViolation);
610
+ report.summary.policy_violations = kind_count(&report.findings, FindingKind::PolicyViolation);
611
+ report.summary.missing_suppression_reasons =
612
+ kind_count(&report.findings, FindingKind::MissingSuppressionReason);
613
+ report.summary.findings = report.findings.len();
614
+ }
615
+
616
+ fn kind_count(findings: &[Finding], kind: FindingKind) -> usize {
617
+ findings
618
+ .iter()
619
+ .filter(|finding| finding.kind == kind)
620
+ .count()
621
+ }
622
+
623
+ fn dependency_count(findings: &[Finding]) -> usize {
624
+ findings
625
+ .iter()
626
+ .filter(|finding| is_dependency_hygiene_kind(finding.kind))
627
+ .count()
628
+ }
629
+
630
+ fn dependency_override_count(findings: &[Finding]) -> usize {
631
+ kind_count(findings, FindingKind::UnusedDependencyOverride)
632
+ + kind_count(findings, FindingKind::MisconfiguredDependencyOverride)
633
+ }
634
+
635
+ const fn is_dependency_hygiene_kind(kind: FindingKind) -> bool {
636
+ matches!(
637
+ kind,
638
+ FindingKind::UnusedDependency
639
+ | FindingKind::UnusedDevDependency
640
+ | FindingKind::TestOnlyDependency
641
+ | FindingKind::UnusedDependencyOverride
642
+ )
643
+ }
@@ -0,0 +1,11 @@
1
+ use std::process::ExitCode;
2
+
3
+ fn main() -> ExitCode {
4
+ match dart_decimate::mcp::run_stdio() {
5
+ Ok(()) => ExitCode::SUCCESS,
6
+ Err(error) => {
7
+ eprintln!("dart-decimate-mcp: {error}");
8
+ ExitCode::from(1)
9
+ }
10
+ }
11
+ }