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,461 @@
1
+ use super::format::{dependency_kind, display_path};
2
+ use super::{Finding, FindingAction, FindingEdge, FindingKind, Severity};
3
+ use crate::{
4
+ BoundaryCallViolation, BoundaryCoverageGap, BoundaryViolation, DeadCodeReport, DependencyCycle,
5
+ InvalidPartReason, InvalidPartRelationship, PolicySeverity, PolicyViolation, ReExportCycle,
6
+ UnresolvedDependency, scan::ScannedProject,
7
+ };
8
+
9
+ pub(super) fn add_dead_code_findings(
10
+ root: &std::path::Path,
11
+ dead_code: &DeadCodeReport,
12
+ findings: &mut Vec<Finding>,
13
+ ) {
14
+ for path in &dead_code.missing_entry_points {
15
+ let path = display_path(root, path);
16
+ findings.push(Finding {
17
+ rule_id: "dart-decimate/missing-entry-point".to_owned(),
18
+ fingerprint: None,
19
+ kind: FindingKind::MissingEntryPoint,
20
+ severity: Severity::Error,
21
+ message: format!("Entry point was not found in the module graph: {path}"),
22
+ path: path.clone(),
23
+ line: 1,
24
+ column: 0,
25
+ safe_to_delete: false,
26
+ files: Vec::new(),
27
+ edge: None,
28
+ actions: vec![
29
+ FindingAction::new(
30
+ "fix-entry-point",
31
+ "Pass an existing Dart entry point with --entry",
32
+ false,
33
+ )
34
+ .with_target_path(path.clone())
35
+ .with_config_key("entry")
36
+ .with_value_schema("array of Dart entry point paths"),
37
+ ],
38
+ });
39
+ }
40
+
41
+ for dead_file in &dead_code.dead_files {
42
+ let path = display_path(root, &dead_file.path);
43
+ findings.push(Finding {
44
+ rule_id: "dart-decimate/dead-file".to_owned(),
45
+ fingerprint: None,
46
+ kind: FindingKind::DeadFile,
47
+ severity: Severity::Error,
48
+ message: format!("Dart file is unreachable from the configured entry points: {path}"),
49
+ path: path.clone(),
50
+ line: 1,
51
+ column: 0,
52
+ safe_to_delete: dead_file.safe_to_delete,
53
+ files: Vec::new(),
54
+ edge: None,
55
+ actions: vec![
56
+ FindingAction::new(
57
+ "delete-file",
58
+ "Delete the unreachable Dart file after confirming no dynamic entry point uses it",
59
+ dead_file.safe_to_delete,
60
+ )
61
+ .with_target_path(path.clone())
62
+ .with_dart_decimate_args(["inspect", "--format", "json", "--file", path.as_str()]),
63
+ ],
64
+ });
65
+ }
66
+ }
67
+
68
+ pub(super) fn add_cycle_findings(
69
+ root: &std::path::Path,
70
+ cycles: &[DependencyCycle],
71
+ findings: &mut Vec<Finding>,
72
+ ) {
73
+ for cycle in cycles {
74
+ let files = cycle
75
+ .files
76
+ .iter()
77
+ .map(|path| display_path(root, path))
78
+ .collect::<Vec<_>>();
79
+ let path = files.first().cloned().unwrap_or_default();
80
+ findings.push(Finding {
81
+ rule_id: "dart-decimate/circular-dependency".to_owned(),
82
+ fingerprint: None,
83
+ kind: FindingKind::CircularDependency,
84
+ severity: Severity::Error,
85
+ message: format!("Circular dependency spans {} Dart files", files.len()),
86
+ path: path.clone(),
87
+ line: 1,
88
+ column: 0,
89
+ safe_to_delete: false,
90
+ files,
91
+ edge: None,
92
+ actions: vec![
93
+ FindingAction::new(
94
+ "break-cycle",
95
+ "Move shared dependencies inward or invert one import edge",
96
+ false,
97
+ )
98
+ .with_target_path(path.clone())
99
+ .with_dart_decimate_args([
100
+ "inspect",
101
+ "--format",
102
+ "json",
103
+ "--file",
104
+ path.as_str(),
105
+ ]),
106
+ ],
107
+ });
108
+ }
109
+ }
110
+
111
+ pub(super) fn add_re_export_cycle_findings(
112
+ root: &std::path::Path,
113
+ cycles: &[ReExportCycle],
114
+ findings: &mut Vec<Finding>,
115
+ ) {
116
+ for cycle in cycles {
117
+ let files = cycle
118
+ .files
119
+ .iter()
120
+ .map(|path| display_path(root, path))
121
+ .collect::<Vec<_>>();
122
+ let path = files.first().cloned().unwrap_or_default();
123
+ findings.push(Finding {
124
+ rule_id: "dart-decimate/re-export-cycle".to_owned(),
125
+ fingerprint: None,
126
+ kind: FindingKind::ReExportCycle,
127
+ severity: Severity::Error,
128
+ message: format!("Re-export cycle spans {} Dart files", files.len()),
129
+ path: path.clone(),
130
+ line: 1,
131
+ column: 0,
132
+ safe_to_delete: false,
133
+ files,
134
+ edge: None,
135
+ actions: vec![
136
+ FindingAction::new(
137
+ "break-re-export-cycle",
138
+ "Remove or redirect one barrel export so public API propagation is acyclic",
139
+ false,
140
+ )
141
+ .with_target_path(path.clone())
142
+ .with_dart_decimate_args([
143
+ "inspect",
144
+ "--format",
145
+ "json",
146
+ "--file",
147
+ path.as_str(),
148
+ ]),
149
+ ],
150
+ });
151
+ }
152
+ }
153
+
154
+ pub(super) fn add_boundary_findings(
155
+ root: &std::path::Path,
156
+ violations: &[BoundaryViolation],
157
+ findings: &mut Vec<Finding>,
158
+ ) {
159
+ for violation in violations {
160
+ let from = display_path(root, &violation.from_path);
161
+ let to = display_path(root, &violation.to_path);
162
+ findings.push(Finding {
163
+ rule_id: "dart-decimate/boundary-violation".to_owned(),
164
+ fingerprint: None,
165
+ kind: FindingKind::BoundaryViolation,
166
+ severity: Severity::Error,
167
+ message: format!("{from} must not depend on {to}"),
168
+ path: from.clone(),
169
+ line: violation.location.line,
170
+ column: violation.location.column,
171
+ safe_to_delete: false,
172
+ files: vec![from.clone(), to.clone()],
173
+ edge: Some(FindingEdge {
174
+ from: from.clone(),
175
+ to,
176
+ specifier: violation.specifier.clone(),
177
+ kind: dependency_kind(violation.kind),
178
+ }),
179
+ actions: vec![
180
+ FindingAction::new(
181
+ "repair-boundary",
182
+ "Move the dependency behind an allowed boundary or invert the ownership",
183
+ false,
184
+ )
185
+ .with_target_path(from.clone())
186
+ .with_dart_decimate_args(["inspect", "--format", "json", "--file", from.as_str()])
187
+ .with_suppression_comment("// dart-decimate-ignore-next-line boundary-violation"),
188
+ ],
189
+ });
190
+ }
191
+ }
192
+
193
+ pub(super) fn add_boundary_coverage_findings(
194
+ root: &std::path::Path,
195
+ gaps: &[BoundaryCoverageGap],
196
+ findings: &mut Vec<Finding>,
197
+ ) {
198
+ for gap in gaps {
199
+ let path = display_path(root, &gap.path);
200
+ let zones = gap
201
+ .configured_boundaries
202
+ .iter()
203
+ .map(|boundary| display_path(root, boundary))
204
+ .collect::<Vec<_>>();
205
+ findings.push(Finding {
206
+ rule_id: "dart-decimate/boundary-violation".to_owned(),
207
+ fingerprint: None,
208
+ kind: FindingKind::BoundaryCoverage,
209
+ severity: Severity::Error,
210
+ message: format!("{path} is not covered by any configured architecture boundary"),
211
+ path: path.clone(),
212
+ line: gap.location.line,
213
+ column: gap.location.column,
214
+ safe_to_delete: false,
215
+ files: zones,
216
+ edge: None,
217
+ actions: vec![
218
+ FindingAction::new(
219
+ "assign-boundary",
220
+ "Move the file into a configured boundary or add an intentional boundary zone",
221
+ false,
222
+ )
223
+ .with_target_path(path.clone())
224
+ .with_config_key("boundary")
225
+ .with_value_schema("array of FROM:DISALLOW architecture boundary rules")
226
+ .with_suppression_comment("// dart-decimate-ignore-next-line boundary-violation"),
227
+ ],
228
+ });
229
+ }
230
+ }
231
+
232
+ pub(super) fn add_boundary_call_findings(
233
+ root: &std::path::Path,
234
+ violations: &[BoundaryCallViolation],
235
+ findings: &mut Vec<Finding>,
236
+ ) {
237
+ for violation in violations {
238
+ let path = display_path(root, &violation.path);
239
+ findings.push(Finding {
240
+ rule_id: "dart-decimate/boundary-violation".to_owned(),
241
+ fingerprint: None,
242
+ kind: FindingKind::BoundaryCallViolation,
243
+ severity: Severity::Error,
244
+ message: format!(
245
+ "{path} calls {} matching forbidden boundary pattern {}",
246
+ violation.callee, violation.pattern
247
+ ),
248
+ path: path.clone(),
249
+ line: violation.location.line,
250
+ column: violation.location.column,
251
+ safe_to_delete: false,
252
+ files: vec![display_path(root, &violation.from_boundary)],
253
+ edge: None,
254
+ actions: vec![
255
+ FindingAction::new(
256
+ "repair-boundary-call",
257
+ "Move the call behind an allowed boundary or replace it with an owned abstraction",
258
+ false,
259
+ )
260
+ .with_target_path(path.clone())
261
+ .with_config_key("boundary_calls")
262
+ .with_value_schema("array of FROM:PATTERN forbidden direct call rules")
263
+ .with_suppression_comment("// dart-decimate-ignore-next-line boundary-call-violation"),
264
+ ],
265
+ });
266
+ }
267
+ }
268
+
269
+ pub(super) fn add_policy_findings(
270
+ root: &std::path::Path,
271
+ violations: &[PolicyViolation],
272
+ findings: &mut Vec<Finding>,
273
+ ) {
274
+ for violation in violations {
275
+ let path = display_path(root, &violation.path);
276
+ let message = violation.message.clone().unwrap_or_else(|| {
277
+ format!(
278
+ "{} matches policy pattern {}",
279
+ violation.target, violation.pattern
280
+ )
281
+ });
282
+ findings.push(Finding {
283
+ rule_id: violation.rule_id.clone(),
284
+ fingerprint: None,
285
+ kind: FindingKind::PolicyViolation,
286
+ severity: policy_severity(violation.severity),
287
+ message,
288
+ path: path.clone(),
289
+ line: violation.location.line,
290
+ column: violation.location.column,
291
+ safe_to_delete: false,
292
+ files: Vec::new(),
293
+ edge: None,
294
+ actions: vec![
295
+ FindingAction::new(
296
+ "repair-policy-violation",
297
+ "Change the import or call so it complies with the owning rule pack",
298
+ false,
299
+ )
300
+ .with_target_path(path.clone())
301
+ .with_config_key("rulePacks")
302
+ .with_value_schema("array of declarative policy pack paths")
303
+ .with_suppression_comment(format!(
304
+ "// dart-decimate-ignore-next-line policy-violation {}",
305
+ violation.rule_id
306
+ )),
307
+ ],
308
+ });
309
+ }
310
+ }
311
+
312
+ const fn policy_severity(severity: Option<PolicySeverity>) -> Severity {
313
+ match severity {
314
+ Some(PolicySeverity::Error) => Severity::Error,
315
+ Some(PolicySeverity::Warn) | None => Severity::Warning,
316
+ }
317
+ }
318
+
319
+ pub(super) fn add_unresolved_findings(project: &ScannedProject, findings: &mut Vec<Finding>) {
320
+ for dependency in project.graph.unresolved() {
321
+ if dependency.from_path.starts_with(&project.root) {
322
+ findings.push(unresolved_finding(&project.root, dependency));
323
+ }
324
+ }
325
+ }
326
+
327
+ pub(super) fn add_part_of_findings(project: &ScannedProject, findings: &mut Vec<Finding>) {
328
+ for relationship in project.graph.invalid_part_relationships() {
329
+ if relationship.part_path.starts_with(&project.root) {
330
+ findings.push(part_of_finding(&project.root, relationship));
331
+ }
332
+ }
333
+ }
334
+
335
+ pub(super) fn project_unresolved_count(project: &ScannedProject) -> usize {
336
+ project
337
+ .graph
338
+ .unresolved()
339
+ .iter()
340
+ .filter(|dependency| dependency.from_path.starts_with(&project.root))
341
+ .count()
342
+ }
343
+
344
+ pub(super) fn project_part_of_violation_count(project: &ScannedProject) -> usize {
345
+ project
346
+ .graph
347
+ .invalid_part_relationships()
348
+ .iter()
349
+ .filter(|relationship| relationship.part_path.starts_with(&project.root))
350
+ .count()
351
+ }
352
+
353
+ fn unresolved_finding(root: &std::path::Path, dependency: &UnresolvedDependency) -> Finding {
354
+ let from = display_path(root, &dependency.from_path);
355
+ let attempted = display_path(root, &dependency.attempted_path);
356
+ Finding {
357
+ rule_id: "dart-decimate/unresolved-dependency".to_owned(),
358
+ fingerprint: None,
359
+ kind: FindingKind::UnresolvedDependency,
360
+ severity: Severity::Error,
361
+ message: format!(
362
+ "Local dependency target was not found: {}",
363
+ dependency.specifier
364
+ ),
365
+ path: from.clone(),
366
+ line: dependency.location.line,
367
+ column: dependency.location.column,
368
+ safe_to_delete: false,
369
+ files: vec![from.clone(), attempted.clone()],
370
+ edge: Some(FindingEdge {
371
+ from: from.clone(),
372
+ to: attempted,
373
+ specifier: dependency.specifier.clone(),
374
+ kind: dependency_kind(dependency.kind),
375
+ }),
376
+ actions: vec![
377
+ FindingAction::new(
378
+ "fix-import",
379
+ "Update the dependency URI or add the missing Dart file",
380
+ false,
381
+ )
382
+ .with_target_path(from.clone())
383
+ .with_dart_decimate_args(["inspect", "--format", "json", "--file", from.as_str()])
384
+ .with_suppression_comment("// dart-decimate-ignore-next-line unresolved-dependency"),
385
+ ],
386
+ }
387
+ }
388
+
389
+ fn part_of_finding(root: &std::path::Path, relationship: &InvalidPartRelationship) -> Finding {
390
+ let part = display_path(root, &relationship.part_path);
391
+ let library = relationship
392
+ .library_path
393
+ .as_ref()
394
+ .map(|path| display_path(root, path));
395
+ let files = library
396
+ .iter()
397
+ .cloned()
398
+ .chain(std::iter::once(part.clone()))
399
+ .collect::<Vec<_>>();
400
+ Finding {
401
+ rule_id: "dart-decimate/part-of-violation".to_owned(),
402
+ fingerprint: None,
403
+ kind: FindingKind::PartOfViolation,
404
+ severity: Severity::Error,
405
+ message: part_of_message(root, relationship),
406
+ path: part.clone(),
407
+ line: relationship.location.line,
408
+ column: relationship.location.column,
409
+ safe_to_delete: false,
410
+ files,
411
+ edge: library.map(|library| FindingEdge {
412
+ from: library,
413
+ to: part.clone(),
414
+ specifier: relationship.specifier.clone(),
415
+ kind: "part".to_owned(),
416
+ }),
417
+ actions: vec![
418
+ FindingAction::new(
419
+ "repair-part-of",
420
+ "Update the library part directive or the part file's part of directive",
421
+ false,
422
+ )
423
+ .with_target_path(part.clone())
424
+ .with_dart_decimate_args(["inspect", "--format", "json", "--file", part.as_str()])
425
+ .with_suppression_comment("// dart-decimate-ignore-next-line part-of-violation"),
426
+ ],
427
+ }
428
+ }
429
+
430
+ fn part_of_message(root: &std::path::Path, relationship: &InvalidPartRelationship) -> String {
431
+ match &relationship.reason {
432
+ InvalidPartReason::MissingPartOf => {
433
+ "Dart part file is missing a matching part of directive".to_owned()
434
+ }
435
+ InvalidPartReason::EmptyPartOf => {
436
+ "Dart part file has an empty part of directive".to_owned()
437
+ }
438
+ InvalidPartReason::OrphanPartOf { .. } => {
439
+ "Dart part file has no owning library part directive".to_owned()
440
+ }
441
+ InvalidPartReason::DuplicatePartOwner {
442
+ existing_library_path,
443
+ } => format!(
444
+ "Dart part file is already owned by another library: {}",
445
+ display_path(root, existing_library_path)
446
+ ),
447
+ InvalidPartReason::PartOfUriUnresolved { actual_specifier } => {
448
+ format!("Dart part of URI could not be resolved: {actual_specifier}")
449
+ }
450
+ InvalidPartReason::PartOfUriMismatch {
451
+ actual_specifier, ..
452
+ } => format!("Dart part of URI points at a different library: {actual_specifier}"),
453
+ InvalidPartReason::PartOfNameMismatch {
454
+ expected_name,
455
+ actual_name,
456
+ } => format!(
457
+ "Dart part of library name mismatch: expected {}, found {actual_name}",
458
+ expected_name.as_deref().unwrap_or("<unnamed library>")
459
+ ),
460
+ }
461
+ }