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,636 @@
1
+ use std::path::PathBuf;
2
+
3
+ use serde::{Deserialize, Serialize};
4
+ use thiserror::Error;
5
+
6
+ use crate::Location;
7
+
8
+ use super::runtime_intelligence::{
9
+ RuntimeBlastRadius, RuntimeCoverageIntelligence, RuntimeImportance,
10
+ };
11
+ use super::threshold_types::{
12
+ EffectiveThresholds, HealthThresholdOverride, HealthThresholdOverrideReport, ThresholdSource,
13
+ };
14
+
15
+ /// Complexity detector options.
16
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
17
+ pub struct HealthOptions {
18
+ /// Maximum cyclomatic complexity before reporting.
19
+ pub max_cyclomatic: usize,
20
+ /// Maximum cognitive complexity before reporting.
21
+ pub max_cognitive: usize,
22
+ /// Limit output to the N highest complexity findings.
23
+ pub top: Option<usize>,
24
+ /// Include per-decision-point contribution records.
25
+ pub complexity_breakdown: HealthToggle,
26
+ /// LCOV file used for coverage-aware health checks.
27
+ pub coverage_path: Option<PathBuf>,
28
+ /// Report source files with no covered executable lines.
29
+ pub coverage_gaps: HealthToggle,
30
+ /// Maximum CRAP score before reporting.
31
+ pub max_crap: Option<usize>,
32
+ /// Runtime coverage JSON file or directory.
33
+ pub runtime_coverage_path: Option<PathBuf>,
34
+ /// Minimum runtime invocations before a file is a hot path.
35
+ pub min_invocations_hot: usize,
36
+ /// Minimum total runtime observations for high-confidence cleanup signals.
37
+ pub min_observation_volume: usize,
38
+ /// Fraction of total runtime traffic considered low traffic.
39
+ pub low_traffic_threshold: LowTrafficThreshold,
40
+ /// Include per-file health scores.
41
+ pub file_scores: HealthToggle,
42
+ /// Report low-scoring complexity hotspots.
43
+ pub hotspots: HealthToggle,
44
+ /// Report prioritized refactoring targets.
45
+ pub targets: HealthToggle,
46
+ /// Attach CODEOWNERS ownership metadata to health inventories.
47
+ pub ownership: HealthToggle,
48
+ /// Minimum file health score before hotspot reporting.
49
+ pub min_score: usize,
50
+ /// Per-file/function local complexity ceilings.
51
+ pub threshold_overrides: Vec<HealthThresholdOverride>,
52
+ }
53
+
54
+ impl Default for HealthOptions {
55
+ fn default() -> Self {
56
+ Self {
57
+ max_cyclomatic: 20,
58
+ max_cognitive: 15,
59
+ top: None,
60
+ complexity_breakdown: HealthToggle::Off,
61
+ coverage_path: None,
62
+ coverage_gaps: HealthToggle::Off,
63
+ max_crap: None,
64
+ runtime_coverage_path: None,
65
+ min_invocations_hot: 100,
66
+ min_observation_volume: 5_000,
67
+ low_traffic_threshold: LowTrafficThreshold::default(),
68
+ file_scores: HealthToggle::Off,
69
+ hotspots: HealthToggle::Off,
70
+ targets: HealthToggle::Off,
71
+ ownership: HealthToggle::Off,
72
+ min_score: 70,
73
+ threshold_overrides: Vec::new(),
74
+ }
75
+ }
76
+ }
77
+
78
+ /// Fraction of runtime observations considered low traffic.
79
+ #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
80
+ pub struct LowTrafficThreshold(u32);
81
+
82
+ impl LowTrafficThreshold {
83
+ const SCALE: u32 = 1_000_000;
84
+
85
+ /// Build a threshold from a ratio in the inclusive range `0.0..=1.0`.
86
+ #[must_use]
87
+ pub fn from_ratio(value: f64) -> Self {
88
+ if !value.is_finite() || value <= 0.0 {
89
+ return Self(0);
90
+ }
91
+ if value >= 1.0 {
92
+ return Self(Self::SCALE);
93
+ }
94
+ let scaled = (value * f64::from(Self::SCALE)).round();
95
+ let micros = format!("{scaled:.0}").parse::<u32>().unwrap_or(Self::SCALE);
96
+ Self(micros)
97
+ }
98
+
99
+ /// Return the threshold as a ratio.
100
+ #[must_use]
101
+ pub fn ratio(self) -> f64 {
102
+ f64::from(self.0) / f64::from(Self::SCALE)
103
+ }
104
+
105
+ /// Build a threshold from an integer fraction.
106
+ #[must_use]
107
+ pub fn from_fraction(numerator: usize, denominator: usize) -> Self {
108
+ if denominator == 0 || numerator == 0 {
109
+ return Self(0);
110
+ }
111
+ let numerator = u64::try_from(numerator).unwrap_or(u64::MAX);
112
+ let denominator = u64::try_from(denominator).unwrap_or(u64::MAX);
113
+ let scaled =
114
+ u128::from(numerator).saturating_mul(u128::from(Self::SCALE)) / u128::from(denominator);
115
+ Self(u32::try_from(scaled).unwrap_or(Self::SCALE))
116
+ }
117
+ }
118
+
119
+ impl Default for LowTrafficThreshold {
120
+ fn default() -> Self {
121
+ Self::from_ratio(0.001)
122
+ }
123
+ }
124
+
125
+ impl Serialize for LowTrafficThreshold {
126
+ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
127
+ where
128
+ S: serde::Serializer,
129
+ {
130
+ serializer.serialize_f64(self.ratio())
131
+ }
132
+ }
133
+
134
+ impl<'de> Deserialize<'de> for LowTrafficThreshold {
135
+ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
136
+ where
137
+ D: serde::Deserializer<'de>,
138
+ {
139
+ f64::deserialize(deserializer).map(Self::from_ratio)
140
+ }
141
+ }
142
+
143
+ /// Boolean health-analysis toggle.
144
+ #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
145
+ pub enum HealthToggle {
146
+ /// Toggle disabled.
147
+ #[default]
148
+ Off,
149
+ /// Toggle enabled.
150
+ On,
151
+ }
152
+
153
+ impl HealthToggle {
154
+ /// Whether this toggle is enabled.
155
+ #[must_use]
156
+ pub const fn is_enabled(self) -> bool {
157
+ matches!(self, Self::On)
158
+ }
159
+ }
160
+
161
+ impl From<bool> for HealthToggle {
162
+ fn from(value: bool) -> Self {
163
+ if value { Self::On } else { Self::Off }
164
+ }
165
+ }
166
+
167
+ impl Serialize for HealthToggle {
168
+ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
169
+ where
170
+ S: serde::Serializer,
171
+ {
172
+ serializer.serialize_bool(self.is_enabled())
173
+ }
174
+ }
175
+
176
+ impl<'de> Deserialize<'de> for HealthToggle {
177
+ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
178
+ where
179
+ D: serde::Deserializer<'de>,
180
+ {
181
+ bool::deserialize(deserializer).map(Self::from)
182
+ }
183
+ }
184
+
185
+ /// Dart code health report.
186
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
187
+ pub struct HealthReport {
188
+ /// Options used to compute this report.
189
+ pub options: HealthOptions,
190
+ /// Aggregate 0-100 project health score; higher is healthier.
191
+ pub quality_score: usize,
192
+ /// Number of source files included in health analysis.
193
+ pub analyzed_files: usize,
194
+ /// Number of function-like declarations scored.
195
+ pub functions: usize,
196
+ /// Highest cyclomatic complexity found.
197
+ pub max_cyclomatic_complexity: usize,
198
+ /// Highest cognitive complexity found.
199
+ pub max_cognitive_complexity: usize,
200
+ /// Number of files represented in the loaded LCOV report.
201
+ pub coverage_files: usize,
202
+ /// Highest CRAP score found from complexity and coverage data.
203
+ pub max_crap_score: usize,
204
+ /// Functions exceeding configured thresholds.
205
+ pub complexity: Vec<ComplexityFinding>,
206
+ /// Source files with no covered executable lines.
207
+ pub coverage_gaps: Vec<CoverageGapFinding>,
208
+ /// Functions exceeding configured CRAP threshold.
209
+ pub crap: Vec<CrapFinding>,
210
+ /// Configured threshold override statuses.
211
+ pub threshold_overrides: Vec<HealthThresholdOverrideReport>,
212
+ /// Runtime coverage evidence, when requested.
213
+ pub runtime_coverage: Option<RuntimeCoverageReport>,
214
+ /// Per-file health scores.
215
+ pub file_scores: Vec<FileHealthScore>,
216
+ /// Low-scoring files selected as hotspots.
217
+ pub hotspots: Vec<HealthHotspot>,
218
+ /// Files selected as refactoring targets.
219
+ pub refactoring_targets: Vec<RefactoringTarget>,
220
+ }
221
+
222
+ /// Runtime coverage report derived from local V8 or Istanbul coverage.
223
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
224
+ pub struct RuntimeCoverageReport {
225
+ /// Runtime coverage input path.
226
+ pub source_path: PathBuf,
227
+ /// Runtime coverage source format.
228
+ pub source_format: RuntimeCoverageFormat,
229
+ /// Stable hash of the coverage input payload.
230
+ pub source_hash: String,
231
+ /// Files observed in runtime coverage.
232
+ pub observed_files: usize,
233
+ /// Total observed runtime invocations.
234
+ pub total_invocations: usize,
235
+ /// Hot path threshold used for this run.
236
+ pub min_invocations_hot: usize,
237
+ /// Observation volume threshold used for this run.
238
+ pub min_observation_volume: usize,
239
+ /// Low-traffic threshold used for this run.
240
+ pub low_traffic_threshold: LowTrafficThreshold,
241
+ /// Files meeting the hot path threshold.
242
+ pub hot_paths: Vec<RuntimeHotPath>,
243
+ /// Runtime-derived cleanup/review signals.
244
+ pub findings: Vec<RuntimeCoverageFinding>,
245
+ /// Static/runtime recommendations for agent review.
246
+ pub coverage_intelligence: Vec<RuntimeCoverageIntelligence>,
247
+ /// Caller blast-radius rows for hot runtime paths.
248
+ pub blast_radius: Vec<RuntimeBlastRadius>,
249
+ /// Runtime-weighted production importance rows.
250
+ pub importance: Vec<RuntimeImportance>,
251
+ /// Non-fatal parsing or mapping warnings.
252
+ pub warnings: Vec<String>,
253
+ }
254
+
255
+ /// Runtime coverage source format.
256
+ #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
257
+ #[serde(rename_all = "kebab-case")]
258
+ pub enum RuntimeCoverageFormat {
259
+ /// Istanbul `coverage-final.json` coverage map.
260
+ Istanbul,
261
+ /// V8 coverage JSON file or directory.
262
+ V8,
263
+ /// Mixed coverage directory containing more than one supported format.
264
+ Mixed,
265
+ }
266
+
267
+ /// Runtime hot path.
268
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
269
+ pub struct RuntimeHotPath {
270
+ /// Dart file path.
271
+ pub path: PathBuf,
272
+ /// 1-based line when the coverage input exposes one.
273
+ pub line: Option<usize>,
274
+ /// Optional function name from runtime coverage.
275
+ pub symbol: Option<String>,
276
+ /// Observed runtime invocations.
277
+ pub invocations: usize,
278
+ /// Source map confidence.
279
+ pub source_map_confidence: SourceMapConfidence,
280
+ }
281
+
282
+ /// Runtime cleanup or review signal.
283
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
284
+ pub struct RuntimeCoverageFinding {
285
+ /// Dart file path.
286
+ pub path: PathBuf,
287
+ /// Runtime coverage finding kind.
288
+ pub kind: RuntimeCoverageFindingKind,
289
+ /// 1-based line.
290
+ pub line: usize,
291
+ /// Observed runtime invocations.
292
+ pub invocations: usize,
293
+ /// Fraction of all runtime observations.
294
+ pub traffic_fraction: LowTrafficThreshold,
295
+ /// Whether graph plus runtime evidence supports deletion.
296
+ pub safe_to_delete: bool,
297
+ /// Whether a human or agent should review before changing.
298
+ pub review_required: bool,
299
+ /// Runtime confidence for the signal.
300
+ pub confidence: RuntimeCoverageConfidence,
301
+ /// Agent-readable reason.
302
+ pub reason: String,
303
+ }
304
+
305
+ /// Runtime coverage signal kind.
306
+ #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
307
+ #[serde(rename_all = "kebab-case")]
308
+ pub enum RuntimeCoverageFindingKind {
309
+ /// File had runtime coverage below the low-traffic threshold.
310
+ LowTraffic,
311
+ /// File was part of the scanned project but absent from runtime coverage.
312
+ CoverageUnavailable,
313
+ }
314
+
315
+ /// Runtime coverage confidence.
316
+ #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
317
+ #[serde(rename_all = "kebab-case")]
318
+ pub enum RuntimeCoverageConfidence {
319
+ /// Enough runtime observations to trust aggregate signals.
320
+ High,
321
+ /// Runtime evidence exists but volume is below the high-confidence threshold.
322
+ Medium,
323
+ /// Runtime evidence was absent or unmapped.
324
+ Low,
325
+ }
326
+
327
+ /// Confidence that a runtime coverage entry maps to the reported source path.
328
+ #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
329
+ #[serde(rename_all = "kebab-case")]
330
+ pub enum SourceMapConfidence {
331
+ /// Path resolved to a local Dart source file.
332
+ Resolved,
333
+ /// Path was normalized but not found under the scanned project.
334
+ Fallback,
335
+ /// Path could not be mapped.
336
+ Unresolved,
337
+ }
338
+
339
+ /// One function-like Dart declaration exceeding health thresholds.
340
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
341
+ pub struct ComplexityFinding {
342
+ /// Dart file path.
343
+ pub path: PathBuf,
344
+ /// Function, method, getter, setter, constructor, or anonymous closure name.
345
+ pub symbol: String,
346
+ /// Function-like declaration kind.
347
+ pub kind: ComplexityFunctionKind,
348
+ /// Location of the function-like declaration.
349
+ pub location: Location,
350
+ /// Cyclomatic complexity score.
351
+ pub cyclomatic_complexity: usize,
352
+ /// Cognitive complexity score.
353
+ pub cognitive_complexity: usize,
354
+ /// Rule represented by this finding.
355
+ pub rule: ComplexityRule,
356
+ /// Effective thresholds used when a local override matched.
357
+ pub effective_thresholds: Option<EffectiveThresholds>,
358
+ /// Source of the effective thresholds when not global defaults.
359
+ pub threshold_source: Option<ThresholdSource>,
360
+ /// Configured reason for the threshold override.
361
+ pub threshold_reason: Option<String>,
362
+ /// Optional decision-point breakdown.
363
+ pub contributions: Vec<ComplexityContribution>,
364
+ }
365
+
366
+ /// One Dart file with no observed covered executable lines.
367
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
368
+ pub struct CoverageGapFinding {
369
+ /// Dart file path.
370
+ pub path: PathBuf,
371
+ /// Location used for the file-level finding.
372
+ pub location: Location,
373
+ /// Why the file is considered a coverage gap.
374
+ pub reason: CoverageGapReason,
375
+ /// Covered executable lines in LCOV.
376
+ pub covered_lines: usize,
377
+ /// Executable lines in LCOV.
378
+ pub executable_lines: usize,
379
+ }
380
+
381
+ /// Coverage-gap reason.
382
+ #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
383
+ #[serde(rename_all = "kebab-case")]
384
+ pub enum CoverageGapReason {
385
+ /// LCOV had no record for the Dart file.
386
+ MissingFromCoverage,
387
+ /// LCOV had a file record but no executable lines.
388
+ NoExecutableLines,
389
+ /// LCOV had executable lines, none of which were covered.
390
+ ZeroCoveredLines,
391
+ }
392
+
393
+ /// One function-like declaration exceeding the configured CRAP threshold.
394
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
395
+ pub struct CrapFinding {
396
+ /// Dart file path.
397
+ pub path: PathBuf,
398
+ /// Function, method, getter, setter, constructor, or closure name.
399
+ pub symbol: String,
400
+ /// Function-like declaration kind.
401
+ pub kind: ComplexityFunctionKind,
402
+ /// Location of the function-like declaration.
403
+ pub location: Location,
404
+ /// Cyclomatic complexity score.
405
+ pub cyclomatic_complexity: usize,
406
+ /// Cognitive complexity score.
407
+ pub cognitive_complexity: usize,
408
+ /// Covered executable lines in the function range.
409
+ pub covered_lines: usize,
410
+ /// Executable lines in the function range.
411
+ pub executable_lines: usize,
412
+ /// Rounded line coverage percentage for the function range.
413
+ pub line_coverage_percent: usize,
414
+ /// CRAP score, rounded up for stable thresholds.
415
+ pub crap_score: usize,
416
+ /// Effective thresholds used when a local override matched.
417
+ pub effective_thresholds: Option<EffectiveThresholds>,
418
+ /// Source of the effective thresholds when not global defaults.
419
+ pub threshold_source: Option<ThresholdSource>,
420
+ /// Configured reason for the threshold override.
421
+ pub threshold_reason: Option<String>,
422
+ }
423
+
424
+ /// One file-level health score.
425
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
426
+ pub struct FileHealthScore {
427
+ /// Dart file path.
428
+ pub path: PathBuf,
429
+ /// 0-100 health score; higher is healthier.
430
+ pub score: usize,
431
+ /// Function-like declarations in the file.
432
+ pub functions: usize,
433
+ /// Functions exceeding static complexity or CRAP thresholds.
434
+ pub complex_functions: usize,
435
+ /// Highest cyclomatic complexity in the file.
436
+ pub max_cyclomatic_complexity: usize,
437
+ /// Highest cognitive complexity in the file.
438
+ pub max_cognitive_complexity: usize,
439
+ /// Highest CRAP score in the file.
440
+ pub max_crap_score: usize,
441
+ /// Coverage status for the file.
442
+ pub coverage_status: FileCoverageStatus,
443
+ /// Covered executable lines when LCOV has data.
444
+ pub covered_lines: Option<usize>,
445
+ /// Executable lines when LCOV has data.
446
+ pub executable_lines: Option<usize>,
447
+ /// Rounded line coverage percentage when LCOV has executable lines.
448
+ pub line_coverage_percent: Option<usize>,
449
+ /// Agent-readable reasons contributing to the score.
450
+ pub reasons: Vec<String>,
451
+ /// Owners matched from CODEOWNERS, when requested.
452
+ pub owners: Vec<String>,
453
+ /// CODEOWNERS file used for this owner match.
454
+ pub owner_source: Option<String>,
455
+ /// GitLab CODEOWNERS section, when present.
456
+ pub owner_section: Option<String>,
457
+ }
458
+
459
+ /// File-level coverage status.
460
+ #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
461
+ #[serde(rename_all = "kebab-case")]
462
+ pub enum FileCoverageStatus {
463
+ /// Coverage was not requested for this run.
464
+ NotRequested,
465
+ /// Coverage was requested but this file had no LCOV record.
466
+ Missing,
467
+ /// LCOV had no executable lines for this file.
468
+ NoExecutableLines,
469
+ /// LCOV had executable lines but none were covered.
470
+ Uncovered,
471
+ /// LCOV had at least one covered executable line.
472
+ Covered,
473
+ }
474
+
475
+ /// Low-scoring file-level hotspot.
476
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
477
+ pub struct HealthHotspot {
478
+ /// Dart file path.
479
+ pub path: PathBuf,
480
+ /// Location used for the file-level finding.
481
+ pub location: Location,
482
+ /// 0-100 health score.
483
+ pub score: usize,
484
+ /// Reasons contributing to hotspot selection.
485
+ pub reasons: Vec<String>,
486
+ /// Owners matched from CODEOWNERS, when requested.
487
+ pub owners: Vec<String>,
488
+ /// CODEOWNERS file used for this owner match.
489
+ pub owner_source: Option<String>,
490
+ /// GitLab CODEOWNERS section, when present.
491
+ pub owner_section: Option<String>,
492
+ }
493
+
494
+ /// Ranked refactoring target.
495
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
496
+ pub struct RefactoringTarget {
497
+ /// Dart file path.
498
+ pub path: PathBuf,
499
+ /// Location used for the file-level finding.
500
+ pub location: Location,
501
+ /// 0-100 health score.
502
+ pub score: usize,
503
+ /// Priority score used for deterministic target ordering.
504
+ pub priority: usize,
505
+ /// Reasons contributing to target selection.
506
+ pub reasons: Vec<String>,
507
+ /// Owners matched from CODEOWNERS, when requested.
508
+ pub owners: Vec<String>,
509
+ /// CODEOWNERS file used for this owner match.
510
+ pub owner_source: Option<String>,
511
+ /// GitLab CODEOWNERS section, when present.
512
+ pub owner_section: Option<String>,
513
+ }
514
+
515
+ /// Function-like declaration kind.
516
+ #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
517
+ #[serde(rename_all = "kebab-case")]
518
+ pub enum ComplexityFunctionKind {
519
+ /// Top-level function.
520
+ Function,
521
+ /// Getter declaration.
522
+ Getter,
523
+ /// Setter declaration.
524
+ Setter,
525
+ /// Class, mixin, extension, or enum method.
526
+ Method,
527
+ /// Constructor or factory constructor.
528
+ Constructor,
529
+ /// Operator overload.
530
+ Operator,
531
+ /// Anonymous function expression.
532
+ Closure,
533
+ }
534
+
535
+ /// Complexity threshold rule exceeded by a function.
536
+ #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
537
+ #[serde(rename_all = "kebab-case")]
538
+ pub enum ComplexityRule {
539
+ /// Cyclomatic threshold only.
540
+ HighCyclomaticComplexity,
541
+ /// Cognitive threshold only.
542
+ HighCognitiveComplexity,
543
+ /// Both cyclomatic and cognitive thresholds.
544
+ HighComplexity,
545
+ }
546
+
547
+ impl ComplexityRule {
548
+ /// Rule identifier used by JSON findings.
549
+ #[must_use]
550
+ pub const fn rule_id(self) -> &'static str {
551
+ match self {
552
+ Self::HighCyclomaticComplexity => "dart-decimate/high-cyclomatic-complexity",
553
+ Self::HighCognitiveComplexity => "dart-decimate/high-cognitive-complexity",
554
+ Self::HighComplexity => "dart-decimate/high-complexity",
555
+ }
556
+ }
557
+ }
558
+
559
+ /// One decision point contributing to complexity.
560
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
561
+ pub struct ComplexityContribution {
562
+ /// Source location of the decision point.
563
+ pub location: Location,
564
+ /// Decision-point kind.
565
+ pub kind: String,
566
+ /// Cyclomatic score added by this point.
567
+ pub cyclomatic: usize,
568
+ /// Cognitive score added by this point.
569
+ pub cognitive: usize,
570
+ /// Nesting depth at the decision point.
571
+ pub nesting: usize,
572
+ }
573
+
574
+ /// Errors returned while computing health metrics.
575
+ #[derive(Debug, Error)]
576
+ pub enum HealthError {
577
+ /// A Dart file could not be read.
578
+ #[error("failed to read Dart file {path}: {source}")]
579
+ ReadFile {
580
+ /// File path.
581
+ path: PathBuf,
582
+ /// Underlying IO error.
583
+ source: std::io::Error,
584
+ },
585
+ /// Tree-Sitter rejected the Dart grammar.
586
+ #[error("failed to load Dart grammar: {0}")]
587
+ Language(#[from] tree_sitter::LanguageError),
588
+ /// Tree-Sitter did not produce a parse tree.
589
+ #[error("tree-sitter did not return a parse tree for {path}")]
590
+ ParseCancelled {
591
+ /// Path being parsed.
592
+ path: PathBuf,
593
+ },
594
+ /// Coverage-aware health was requested without an LCOV file.
595
+ #[error(
596
+ "coverage data not found under {root}; pass --coverage PATH or create coverage/lcov.info"
597
+ )]
598
+ MissingCoverageData {
599
+ /// Project root.
600
+ root: PathBuf,
601
+ },
602
+ /// LCOV file could not be read.
603
+ #[error("failed to read coverage file {path}: {source}")]
604
+ ReadCoverage {
605
+ /// LCOV path.
606
+ path: PathBuf,
607
+ /// Underlying IO error.
608
+ source: std::io::Error,
609
+ },
610
+ /// LCOV file could not be parsed.
611
+ #[error("failed to parse coverage file {path} at line {line}: {message}")]
612
+ ParseCoverage {
613
+ /// LCOV path.
614
+ path: PathBuf,
615
+ /// 1-based line number.
616
+ line: usize,
617
+ /// Parse failure details.
618
+ message: String,
619
+ },
620
+ /// Runtime coverage file could not be read.
621
+ #[error("failed to read runtime coverage {path}: {source}")]
622
+ ReadRuntimeCoverage {
623
+ /// Runtime coverage path.
624
+ path: PathBuf,
625
+ /// Underlying IO error.
626
+ source: std::io::Error,
627
+ },
628
+ /// Runtime coverage JSON could not be parsed.
629
+ #[error("failed to parse runtime coverage {path}: {message}")]
630
+ ParseRuntimeCoverage {
631
+ /// Runtime coverage path.
632
+ path: PathBuf,
633
+ /// Parse failure details.
634
+ message: String,
635
+ },
636
+ }