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,462 @@
1
+ use std::path::Path;
2
+
3
+ use crate::config::{filter_ignored_dependencies, filter_ignored_dependency_overrides};
4
+ use crate::output::{AnalysisResults, ReportCommand};
5
+ use crate::scan::ScannedProject;
6
+ use crate::{
7
+ SymbolAnalysisOptions, analyze_dependency_hygiene, analyze_health, analyze_security,
8
+ analyze_widgets, check_architecture_boundaries, detect_boundary_call_violations,
9
+ detect_boundary_coverage, detect_cycles, detect_duplicates, detect_feature_flags,
10
+ detect_policy_violations, detect_re_export_cycles, detect_route_collisions, find_dead_code,
11
+ load_policy_pack, missing_suppression_reasons_enabled,
12
+ };
13
+
14
+ use super::entry_points::{entry_points_for_check, entry_points_for_dead_code};
15
+ use super::{CliError, CommandRequest};
16
+
17
+ pub(super) fn analyze_project(
18
+ project: &ScannedProject,
19
+ request: &CommandRequest,
20
+ ) -> Result<AnalysisResults, CliError> {
21
+ let dead_code = analyze_project_dead_code(project, request)?;
22
+
23
+ Ok(AnalysisResults {
24
+ command: request.command,
25
+ symbols: analyze_project_symbols(project, request, dead_code.as_ref()),
26
+ cycles: analyze_project_cycles(project, request.command),
27
+ re_export_cycles: analyze_project_re_export_cycles(project, request.command),
28
+ boundary_violations: analyze_project_boundaries(project, request),
29
+ boundary_coverage: analyze_project_boundary_coverage(project, request),
30
+ boundary_call_violations: analyze_project_boundary_calls(project, request)?,
31
+ policy_violations: analyze_project_policy(project, request)?,
32
+ dependency_hygiene: analyze_project_dependencies(project, request)?,
33
+ duplicates: analyze_project_duplicates(project, request)?,
34
+ health: analyze_project_health(project, request)?,
35
+ feature_flags: analyze_project_flags(project, request)?,
36
+ security: analyze_project_security(project, request, dead_code.as_ref())?,
37
+ routes: analyze_project_routes(project, request.command),
38
+ widgets: analyze_project_widgets(project, request.command, dead_code.as_ref())?,
39
+ file_scope: None,
40
+ require_suppression_reasons: missing_suppression_reasons_enabled(&request.rules),
41
+ dead_code,
42
+ })
43
+ }
44
+
45
+ fn analyze_project_dead_code(
46
+ project: &ScannedProject,
47
+ request: &CommandRequest,
48
+ ) -> Result<Option<crate::DeadCodeReport>, CliError> {
49
+ match request.command {
50
+ ReportCommand::Check | ReportCommand::Audit => {
51
+ let entries =
52
+ entry_points_for_check(project, &request.entry_points, request.entry_point_mode());
53
+ Ok((!entries.is_empty()).then(|| find_project_dead_code(project, entries, request)))
54
+ }
55
+ ReportCommand::DeadCode => {
56
+ let entries = entry_points_for_dead_code(
57
+ project,
58
+ &request.entry_points,
59
+ request.entry_point_mode(),
60
+ )?;
61
+ Ok(Some(find_project_dead_code(project, entries, request)))
62
+ }
63
+ ReportCommand::Cycles
64
+ | ReportCommand::Dupes
65
+ | ReportCommand::Health
66
+ | ReportCommand::Flags
67
+ | ReportCommand::Security => Ok(None),
68
+ ReportCommand::TraceFile
69
+ | ReportCommand::TraceSymbol
70
+ | ReportCommand::TraceDependency
71
+ | ReportCommand::TraceClone
72
+ | ReportCommand::Inspect => unreachable!("trace commands do not use AnalysisResults"),
73
+ }
74
+ }
75
+
76
+ fn analyze_project_symbols(
77
+ project: &ScannedProject,
78
+ request: &CommandRequest,
79
+ dead_code: Option<&crate::DeadCodeReport>,
80
+ ) -> Option<crate::SymbolReport> {
81
+ match request.command {
82
+ ReportCommand::Check | ReportCommand::Audit | ReportCommand::DeadCode => {
83
+ Some(crate::analyze_symbols_with_options(
84
+ project,
85
+ dead_code,
86
+ SymbolAnalysisOptions {
87
+ include_entry_exports: request.symbol_options.include_entry_exports,
88
+ private_type_leaks: request.symbol_options.private_type_leaks,
89
+ },
90
+ ))
91
+ }
92
+ ReportCommand::Cycles
93
+ | ReportCommand::Dupes
94
+ | ReportCommand::Health
95
+ | ReportCommand::Flags
96
+ | ReportCommand::Security => None,
97
+ ReportCommand::TraceFile
98
+ | ReportCommand::TraceSymbol
99
+ | ReportCommand::TraceDependency
100
+ | ReportCommand::TraceClone
101
+ | ReportCommand::Inspect => unreachable!("trace commands do not use AnalysisResults"),
102
+ }
103
+ }
104
+
105
+ fn analyze_project_cycles(
106
+ project: &ScannedProject,
107
+ command: ReportCommand,
108
+ ) -> Vec<crate::DependencyCycle> {
109
+ match command {
110
+ ReportCommand::Check | ReportCommand::Audit | ReportCommand::Cycles => {
111
+ detect_project_cycles(project)
112
+ }
113
+ ReportCommand::DeadCode
114
+ | ReportCommand::Dupes
115
+ | ReportCommand::Health
116
+ | ReportCommand::Flags
117
+ | ReportCommand::Security => Vec::new(),
118
+ ReportCommand::TraceFile
119
+ | ReportCommand::TraceSymbol
120
+ | ReportCommand::TraceDependency
121
+ | ReportCommand::TraceClone
122
+ | ReportCommand::Inspect => unreachable!("trace commands do not use AnalysisResults"),
123
+ }
124
+ }
125
+
126
+ fn analyze_project_re_export_cycles(
127
+ project: &ScannedProject,
128
+ command: ReportCommand,
129
+ ) -> Vec<crate::ReExportCycle> {
130
+ match command {
131
+ ReportCommand::Check | ReportCommand::Audit | ReportCommand::Cycles => {
132
+ detect_project_re_export_cycles(project)
133
+ }
134
+ ReportCommand::DeadCode
135
+ | ReportCommand::Dupes
136
+ | ReportCommand::Health
137
+ | ReportCommand::Flags
138
+ | ReportCommand::Security => Vec::new(),
139
+ ReportCommand::TraceFile
140
+ | ReportCommand::TraceSymbol
141
+ | ReportCommand::TraceDependency
142
+ | ReportCommand::TraceClone
143
+ | ReportCommand::Inspect => unreachable!("trace commands do not use AnalysisResults"),
144
+ }
145
+ }
146
+
147
+ fn analyze_project_boundaries(
148
+ project: &ScannedProject,
149
+ request: &CommandRequest,
150
+ ) -> Vec<crate::BoundaryViolation> {
151
+ match request.command {
152
+ ReportCommand::Check | ReportCommand::Audit => {
153
+ check_architecture_boundaries(&project.graph, &request.boundaries)
154
+ }
155
+ ReportCommand::DeadCode
156
+ | ReportCommand::Cycles
157
+ | ReportCommand::Dupes
158
+ | ReportCommand::Health
159
+ | ReportCommand::Flags
160
+ | ReportCommand::Security => Vec::new(),
161
+ ReportCommand::TraceFile
162
+ | ReportCommand::TraceSymbol
163
+ | ReportCommand::TraceDependency
164
+ | ReportCommand::TraceClone
165
+ | ReportCommand::Inspect => unreachable!("trace commands do not use AnalysisResults"),
166
+ }
167
+ }
168
+
169
+ fn analyze_project_boundary_coverage(
170
+ project: &ScannedProject,
171
+ request: &CommandRequest,
172
+ ) -> Vec<crate::BoundaryCoverageGap> {
173
+ match request.command {
174
+ ReportCommand::Check | ReportCommand::Audit if request.boundary_coverage => {
175
+ detect_boundary_coverage(
176
+ project,
177
+ &request.boundaries,
178
+ &request.boundary_allow_unmatched,
179
+ )
180
+ }
181
+ ReportCommand::Check
182
+ | ReportCommand::Audit
183
+ | ReportCommand::DeadCode
184
+ | ReportCommand::Cycles
185
+ | ReportCommand::Dupes
186
+ | ReportCommand::Health
187
+ | ReportCommand::Flags
188
+ | ReportCommand::Security => Vec::new(),
189
+ ReportCommand::TraceFile
190
+ | ReportCommand::TraceSymbol
191
+ | ReportCommand::TraceDependency
192
+ | ReportCommand::TraceClone
193
+ | ReportCommand::Inspect => unreachable!("trace commands do not use AnalysisResults"),
194
+ }
195
+ }
196
+
197
+ fn analyze_project_boundary_calls(
198
+ project: &ScannedProject,
199
+ request: &CommandRequest,
200
+ ) -> Result<Vec<crate::BoundaryCallViolation>, CliError> {
201
+ match request.command {
202
+ ReportCommand::Check | ReportCommand::Audit => Ok(detect_boundary_call_violations(
203
+ project,
204
+ &request.boundary_calls,
205
+ )?),
206
+ ReportCommand::DeadCode
207
+ | ReportCommand::Cycles
208
+ | ReportCommand::Dupes
209
+ | ReportCommand::Health
210
+ | ReportCommand::Flags
211
+ | ReportCommand::Security => Ok(Vec::new()),
212
+ ReportCommand::TraceFile
213
+ | ReportCommand::TraceSymbol
214
+ | ReportCommand::TraceDependency
215
+ | ReportCommand::TraceClone
216
+ | ReportCommand::Inspect => unreachable!("trace commands do not use AnalysisResults"),
217
+ }
218
+ }
219
+
220
+ fn analyze_project_policy(
221
+ project: &ScannedProject,
222
+ request: &CommandRequest,
223
+ ) -> Result<Vec<crate::PolicyViolation>, CliError> {
224
+ match request.command {
225
+ ReportCommand::Check | ReportCommand::Audit => {
226
+ let packs = request
227
+ .policy_packs
228
+ .iter()
229
+ .map(|path| load_policy_pack(&project.root, path))
230
+ .collect::<Result<Vec<_>, _>>()?;
231
+ Ok(detect_policy_violations(project, &packs)?)
232
+ }
233
+ ReportCommand::DeadCode
234
+ | ReportCommand::Cycles
235
+ | ReportCommand::Dupes
236
+ | ReportCommand::Health
237
+ | ReportCommand::Flags
238
+ | ReportCommand::Security => Ok(Vec::new()),
239
+ ReportCommand::TraceFile
240
+ | ReportCommand::TraceSymbol
241
+ | ReportCommand::TraceDependency
242
+ | ReportCommand::TraceClone
243
+ | ReportCommand::Inspect => unreachable!("trace commands do not use AnalysisResults"),
244
+ }
245
+ }
246
+
247
+ fn analyze_project_dependencies(
248
+ project: &ScannedProject,
249
+ request: &CommandRequest,
250
+ ) -> Result<Option<crate::DependencyHygieneReport>, CliError> {
251
+ match request.command {
252
+ ReportCommand::Check | ReportCommand::Audit | ReportCommand::DeadCode => {
253
+ let mut report = analyze_dependency_hygiene(project)?;
254
+ filter_ignored_dependencies(&mut report, &request.ignore_dependencies);
255
+ filter_ignored_dependency_overrides(&mut report, &request.ignore_dependency_overrides);
256
+ Ok(Some(report))
257
+ }
258
+ ReportCommand::Cycles
259
+ | ReportCommand::Dupes
260
+ | ReportCommand::Health
261
+ | ReportCommand::Flags
262
+ | ReportCommand::Security => Ok(None),
263
+ ReportCommand::TraceFile
264
+ | ReportCommand::TraceSymbol
265
+ | ReportCommand::TraceDependency
266
+ | ReportCommand::TraceClone
267
+ | ReportCommand::Inspect => unreachable!("trace commands do not use AnalysisResults"),
268
+ }
269
+ }
270
+
271
+ fn analyze_project_duplicates(
272
+ project: &ScannedProject,
273
+ request: &CommandRequest,
274
+ ) -> Result<Option<crate::DuplicateCodeReport>, CliError> {
275
+ match request.command {
276
+ ReportCommand::Check | ReportCommand::Audit | ReportCommand::Dupes => Ok(Some(
277
+ detect_duplicates(project, &request.duplicate_options)?,
278
+ )),
279
+ ReportCommand::DeadCode
280
+ | ReportCommand::Cycles
281
+ | ReportCommand::Health
282
+ | ReportCommand::Flags
283
+ | ReportCommand::Security => Ok(None),
284
+ ReportCommand::TraceFile
285
+ | ReportCommand::TraceSymbol
286
+ | ReportCommand::TraceDependency
287
+ | ReportCommand::TraceClone
288
+ | ReportCommand::Inspect => unreachable!("trace commands do not use AnalysisResults"),
289
+ }
290
+ }
291
+
292
+ fn analyze_project_health(
293
+ project: &ScannedProject,
294
+ request: &CommandRequest,
295
+ ) -> Result<Option<crate::HealthReport>, CliError> {
296
+ match request.command {
297
+ ReportCommand::Check | ReportCommand::Audit | ReportCommand::Health => {
298
+ Ok(Some(analyze_health(project, &request.health_options)?))
299
+ }
300
+ ReportCommand::DeadCode
301
+ | ReportCommand::Cycles
302
+ | ReportCommand::Dupes
303
+ | ReportCommand::Flags
304
+ | ReportCommand::Security => Ok(None),
305
+ ReportCommand::TraceFile
306
+ | ReportCommand::TraceSymbol
307
+ | ReportCommand::TraceDependency
308
+ | ReportCommand::TraceClone
309
+ | ReportCommand::Inspect => unreachable!("trace commands do not use AnalysisResults"),
310
+ }
311
+ }
312
+
313
+ fn analyze_project_flags(
314
+ project: &ScannedProject,
315
+ request: &CommandRequest,
316
+ ) -> Result<Option<crate::FeatureFlagReport>, CliError> {
317
+ match request.command {
318
+ ReportCommand::Check | ReportCommand::Audit | ReportCommand::Flags => Ok(Some(
319
+ detect_feature_flags(project, &request.feature_flag_options)?,
320
+ )),
321
+ ReportCommand::DeadCode
322
+ | ReportCommand::Cycles
323
+ | ReportCommand::Dupes
324
+ | ReportCommand::Health
325
+ | ReportCommand::Security => Ok(None),
326
+ ReportCommand::TraceFile
327
+ | ReportCommand::TraceSymbol
328
+ | ReportCommand::TraceDependency
329
+ | ReportCommand::TraceClone
330
+ | ReportCommand::Inspect => unreachable!("trace commands do not use AnalysisResults"),
331
+ }
332
+ }
333
+
334
+ fn analyze_project_security(
335
+ project: &ScannedProject,
336
+ request: &CommandRequest,
337
+ dead_code: Option<&crate::DeadCodeReport>,
338
+ ) -> Result<Option<crate::SecurityReport>, CliError> {
339
+ match request.command {
340
+ ReportCommand::Check | ReportCommand::Audit => Ok(Some(analyze_security(
341
+ project,
342
+ &request.security_options,
343
+ dead_code,
344
+ )?)),
345
+ ReportCommand::Security => {
346
+ let entries =
347
+ entry_points_for_check(project, &request.entry_points, request.entry_point_mode());
348
+ let reachability =
349
+ (!entries.is_empty()).then(|| find_project_dead_code(project, entries, request));
350
+ Ok(Some(analyze_security(
351
+ project,
352
+ &request.security_options,
353
+ reachability.as_ref(),
354
+ )?))
355
+ }
356
+ ReportCommand::DeadCode
357
+ | ReportCommand::Cycles
358
+ | ReportCommand::Dupes
359
+ | ReportCommand::Health
360
+ | ReportCommand::Flags => Ok(None),
361
+ ReportCommand::TraceFile
362
+ | ReportCommand::TraceSymbol
363
+ | ReportCommand::TraceDependency
364
+ | ReportCommand::TraceClone
365
+ | ReportCommand::Inspect => unreachable!("trace commands do not use AnalysisResults"),
366
+ }
367
+ }
368
+
369
+ fn analyze_project_routes(
370
+ project: &ScannedProject,
371
+ command: ReportCommand,
372
+ ) -> Option<crate::RouteCollisionReport> {
373
+ match command {
374
+ ReportCommand::Check | ReportCommand::Audit => Some(detect_route_collisions(project)),
375
+ ReportCommand::DeadCode
376
+ | ReportCommand::Cycles
377
+ | ReportCommand::Dupes
378
+ | ReportCommand::Health
379
+ | ReportCommand::Flags
380
+ | ReportCommand::Security => None,
381
+ ReportCommand::TraceFile
382
+ | ReportCommand::TraceSymbol
383
+ | ReportCommand::TraceDependency
384
+ | ReportCommand::TraceClone
385
+ | ReportCommand::Inspect => unreachable!("trace commands do not use AnalysisResults"),
386
+ }
387
+ }
388
+
389
+ fn analyze_project_widgets(
390
+ project: &ScannedProject,
391
+ command: ReportCommand,
392
+ dead_code: Option<&crate::DeadCodeReport>,
393
+ ) -> Result<Option<crate::WidgetReport>, CliError> {
394
+ match command {
395
+ ReportCommand::Check | ReportCommand::Audit => {
396
+ Ok(Some(analyze_widgets(project, dead_code)?))
397
+ }
398
+ ReportCommand::DeadCode
399
+ | ReportCommand::Cycles
400
+ | ReportCommand::Dupes
401
+ | ReportCommand::Health
402
+ | ReportCommand::Flags
403
+ | ReportCommand::Security => Ok(None),
404
+ ReportCommand::TraceFile
405
+ | ReportCommand::TraceSymbol
406
+ | ReportCommand::TraceDependency
407
+ | ReportCommand::TraceClone
408
+ | ReportCommand::Inspect => unreachable!("trace commands do not use AnalysisResults"),
409
+ }
410
+ }
411
+
412
+ fn find_project_dead_code<I, P>(
413
+ project: &ScannedProject,
414
+ entry_points: I,
415
+ request: &CommandRequest,
416
+ ) -> crate::DeadCodeReport
417
+ where
418
+ I: IntoIterator<Item = P>,
419
+ P: AsRef<Path>,
420
+ {
421
+ let mut report = find_dead_code(&project.graph, entry_points);
422
+ report
423
+ .dead_files
424
+ .retain(|dead_file| is_project_path(project, &dead_file.path));
425
+ report
426
+ .reachable_files
427
+ .retain(|path| is_project_path(project, path));
428
+ if request.production {
429
+ for dead_file in &mut report.dead_files {
430
+ dead_file.safe_to_delete = false;
431
+ }
432
+ }
433
+ report
434
+ }
435
+
436
+ fn detect_project_cycles(project: &ScannedProject) -> Vec<crate::DependencyCycle> {
437
+ detect_cycles(&project.graph)
438
+ .into_iter()
439
+ .filter(|cycle| {
440
+ cycle
441
+ .files
442
+ .iter()
443
+ .any(|path| is_project_path(project, path))
444
+ })
445
+ .collect()
446
+ }
447
+
448
+ fn detect_project_re_export_cycles(project: &ScannedProject) -> Vec<crate::ReExportCycle> {
449
+ detect_re_export_cycles(&project.graph)
450
+ .into_iter()
451
+ .filter(|cycle| {
452
+ cycle
453
+ .files
454
+ .iter()
455
+ .any(|path| is_project_path(project, path))
456
+ })
457
+ .collect()
458
+ }
459
+
460
+ fn is_project_path(project: &ScannedProject, path: &Path) -> bool {
461
+ path.starts_with(&project.root)
462
+ }
@@ -0,0 +1,82 @@
1
+ use clap::ArgMatches;
2
+
3
+ use crate::config::DartDecimateConfig;
4
+ use crate::output::ReportCommand;
5
+ use crate::{DuplicateOptions, FeatureFlagOptions, HealthOptions, SecurityOptions};
6
+
7
+ use super::CliError;
8
+ use super::dupes_args::duplicate_options_with_defaults;
9
+ use super::flags_args::feature_flag_options_with_defaults;
10
+ use super::health_args::health_options_with_defaults;
11
+ use super::security_args::security_options_with_defaults;
12
+
13
+ pub(super) fn duplicate_options_for(
14
+ command: ReportCommand,
15
+ subcommand: &ArgMatches,
16
+ config: &DartDecimateConfig,
17
+ ) -> Result<DuplicateOptions, CliError> {
18
+ if matches!(
19
+ command,
20
+ ReportCommand::Check
21
+ | ReportCommand::Audit
22
+ | ReportCommand::Dupes
23
+ | ReportCommand::TraceClone
24
+ ) {
25
+ duplicate_options_with_defaults(subcommand, config.duplicate_options())
26
+ } else if command == ReportCommand::Inspect {
27
+ Ok(config.duplicate_options())
28
+ } else {
29
+ Ok(DuplicateOptions::default())
30
+ }
31
+ }
32
+
33
+ pub(super) fn health_options_for(
34
+ command: ReportCommand,
35
+ subcommand: &ArgMatches,
36
+ config: &DartDecimateConfig,
37
+ ) -> HealthOptions {
38
+ if matches!(
39
+ command,
40
+ ReportCommand::Check | ReportCommand::Audit | ReportCommand::Health
41
+ ) {
42
+ health_options_with_defaults(subcommand, config.health_options())
43
+ } else if command == ReportCommand::Inspect {
44
+ config.health_options()
45
+ } else {
46
+ HealthOptions::default()
47
+ }
48
+ }
49
+
50
+ pub(super) fn feature_flag_options_for(
51
+ command: ReportCommand,
52
+ subcommand: &ArgMatches,
53
+ config: &DartDecimateConfig,
54
+ ) -> FeatureFlagOptions {
55
+ if command == ReportCommand::Flags {
56
+ feature_flag_options_with_defaults(subcommand, config.feature_flag_options())
57
+ } else if matches!(
58
+ command,
59
+ ReportCommand::Check | ReportCommand::Audit | ReportCommand::Inspect
60
+ ) {
61
+ config.feature_flag_options()
62
+ } else {
63
+ FeatureFlagOptions::default()
64
+ }
65
+ }
66
+
67
+ pub(super) fn security_options_for(
68
+ command: ReportCommand,
69
+ subcommand: &ArgMatches,
70
+ config: &DartDecimateConfig,
71
+ ) -> SecurityOptions {
72
+ if command == ReportCommand::Security {
73
+ security_options_with_defaults(subcommand, config.security_options())
74
+ } else if matches!(
75
+ command,
76
+ ReportCommand::Check | ReportCommand::Audit | ReportCommand::Inspect
77
+ ) {
78
+ config.security_options()
79
+ } else {
80
+ SecurityOptions::default()
81
+ }
82
+ }