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.
- package/Cargo.lock +572 -0
- package/Cargo.toml +41 -0
- package/LICENSE +21 -0
- package/README.md +617 -0
- package/assets/dart-decimate-banner.png +0 -0
- package/npm/bin/dart-decimate-mcp.js +48 -0
- package/npm/bin/dart-decimate.js +48 -0
- package/npm/scripts/postinstall.js +46 -0
- package/npm/scripts/test-npx-local.js +54 -0
- package/npm/scripts/test-npx-mcp-local.js +56 -0
- package/package.json +45 -0
- package/src/baseline.rs +643 -0
- package/src/bin/dart-decimate-mcp.rs +11 -0
- package/src/boundaries/tests.rs +60 -0
- package/src/boundaries.rs +317 -0
- package/src/changed_scope.rs +117 -0
- package/src/ci_template.rs +399 -0
- package/src/cli/analyze.rs +462 -0
- package/src/cli/analyzer_options.rs +82 -0
- package/src/cli/audit_run.rs +327 -0
- package/src/cli/boundary_args.rs +44 -0
- package/src/cli/ci_template_run.rs +196 -0
- package/src/cli/command_name.rs +20 -0
- package/src/cli/common_args.rs +167 -0
- package/src/cli/config_run.rs +78 -0
- package/src/cli/coverage_run.rs +393 -0
- package/src/cli/decision_surface_run.rs +99 -0
- package/src/cli/default_command.rs +69 -0
- package/src/cli/dupes_args.rs +150 -0
- package/src/cli/entry_points.rs +121 -0
- package/src/cli/error.rs +149 -0
- package/src/cli/error_output.rs +68 -0
- package/src/cli/explain_run.rs +72 -0
- package/src/cli/fix_run.rs +162 -0
- package/src/cli/flags_args.rs +23 -0
- package/src/cli/health_args.rs +200 -0
- package/src/cli/hooks_run.rs +191 -0
- package/src/cli/impact_run.rs +95 -0
- package/src/cli/init_run.rs +49 -0
- package/src/cli/inspect_args.rs +20 -0
- package/src/cli/inspect_run.rs +66 -0
- package/src/cli/issue_filter_args.rs +240 -0
- package/src/cli/list_run.rs +311 -0
- package/src/cli/mode_args.rs +72 -0
- package/src/cli/output_format.rs +62 -0
- package/src/cli/regression_args.rs +156 -0
- package/src/cli/request_args.rs +175 -0
- package/src/cli/schema_commands.rs +72 -0
- package/src/cli/scope_args.rs +174 -0
- package/src/cli/security_args.rs +175 -0
- package/src/cli/security_gate_run.rs +66 -0
- package/src/cli/security_summary_run.rs +43 -0
- package/src/cli/summary_args.rs +12 -0
- package/src/cli/tests.rs +516 -0
- package/src/cli/trace_args.rs +67 -0
- package/src/cli/trace_run.rs +131 -0
- package/src/cli/trace_tests.rs +235 -0
- package/src/cli/unsupported_run.rs +116 -0
- package/src/cli/watch_run.rs +153 -0
- package/src/cli.rs +603 -0
- package/src/config/boundary_config.rs +235 -0
- package/src/config/cache.rs +25 -0
- package/src/config/dependencies.rs +114 -0
- package/src/config/health.rs +237 -0
- package/src/config/jsonc.rs +66 -0
- package/src/config/policy.rs +91 -0
- package/src/config/rule_aliases.rs +487 -0
- package/src/config/rules.rs +339 -0
- package/src/config.rs +635 -0
- package/src/coverage.rs +469 -0
- package/src/dart_parser.rs +673 -0
- package/src/decision_surface.rs +405 -0
- package/src/dependencies/analyze.rs +218 -0
- package/src/dependencies/codegen.rs +118 -0
- package/src/dependencies/discovery.rs +60 -0
- package/src/dependencies/overrides.rs +76 -0
- package/src/dependencies/private_src_imports.rs +32 -0
- package/src/dependencies/pubspec_document.rs +86 -0
- package/src/dependencies/pubspec_entry.rs +96 -0
- package/src/dependencies/tests.rs +544 -0
- package/src/dependencies/usage.rs +33 -0
- package/src/dependencies.rs +553 -0
- package/src/dependency_scripts.rs +91 -0
- package/src/dupes/lex.rs +236 -0
- package/src/dupes/tests.rs +119 -0
- package/src/dupes.rs +625 -0
- package/src/explain.rs +692 -0
- package/src/extract/directives.rs +252 -0
- package/src/extract/error_tests.rs +25 -0
- package/src/extract/members.rs +210 -0
- package/src/extract/primary_constructors.rs +421 -0
- package/src/extract/references.rs +151 -0
- package/src/extract/routes.rs +691 -0
- package/src/extract/signatures.rs +266 -0
- package/src/extract/string_tests.rs +18 -0
- package/src/extract/strings.rs +107 -0
- package/src/extract/tests.rs +697 -0
- package/src/extract.rs +680 -0
- package/src/feature_flags/tests.rs +76 -0
- package/src/feature_flags.rs +453 -0
- package/src/finding_identity.rs +60 -0
- package/src/fix.rs +551 -0
- package/src/generated.rs +53 -0
- package/src/graph/augment_tests.rs +212 -0
- package/src/graph/conditionals.rs +74 -0
- package/src/graph/package_config_tests.rs +100 -0
- package/src/graph/parts.rs +248 -0
- package/src/graph/pubspec_tests.rs +119 -0
- package/src/graph/tests.rs +837 -0
- package/src/graph/uri_tests.rs +102 -0
- package/src/graph.rs +644 -0
- package/src/health/coverage.rs +309 -0
- package/src/health/ownership.rs +175 -0
- package/src/health/runtime_coverage.rs +616 -0
- package/src/health/runtime_intelligence.rs +511 -0
- package/src/health/scores.rs +296 -0
- package/src/health/tests.rs +240 -0
- package/src/health/threshold_types.rs +163 -0
- package/src/health/thresholds.rs +229 -0
- package/src/health/types.rs +636 -0
- package/src/health.rs +597 -0
- package/src/hooks/agent_settings.rs +175 -0
- package/src/hooks/templates.rs +51 -0
- package/src/hooks.rs +569 -0
- package/src/impact.rs +287 -0
- package/src/init.rs +237 -0
- package/src/inspect.rs +142 -0
- package/src/intelligence/tests.rs +232 -0
- package/src/intelligence.rs +305 -0
- package/src/lib.rs +198 -0
- package/src/main.rs +5 -0
- package/src/manifest/mcp.rs +565 -0
- package/src/manifest.rs +552 -0
- package/src/mcp/cli_args/value_args.rs +175 -0
- package/src/mcp/cli_args.rs +658 -0
- package/src/mcp/cli_args_tests.rs +522 -0
- package/src/mcp/code_execute.rs +671 -0
- package/src/mcp/tools.rs +660 -0
- package/src/mcp.rs +325 -0
- package/src/output/audit_risk.rs +135 -0
- package/src/output/dependency_findings.rs +327 -0
- package/src/output/duplication_findings.rs +114 -0
- package/src/output/feature_flag_findings.rs +122 -0
- package/src/output/format.rs +31 -0
- package/src/output/graph_findings.rs +461 -0
- package/src/output/health_findings.rs +612 -0
- package/src/output/human.rs +27 -0
- package/src/output/next_steps.rs +92 -0
- package/src/output/route_findings.rs +76 -0
- package/src/output/runtime_coverage.rs +515 -0
- package/src/output/scope.rs +183 -0
- package/src/output/security_findings.rs +390 -0
- package/src/output/security_sarif.rs +150 -0
- package/src/output/suppressions.rs +323 -0
- package/src/output/symbol_findings.rs +257 -0
- package/src/output/tests.rs +114 -0
- package/src/output/types.rs +604 -0
- package/src/output/widget_findings.rs +213 -0
- package/src/output.rs +682 -0
- package/src/package_map.rs +495 -0
- package/src/policy/packs.rs +232 -0
- package/src/policy/tests.rs +134 -0
- package/src/policy.rs +640 -0
- package/src/project_list.rs +376 -0
- package/src/report_schema/inventory.rs +418 -0
- package/src/report_schema.rs +488 -0
- package/src/routes.rs +354 -0
- package/src/scan/tests.rs +250 -0
- package/src/scan.rs +275 -0
- package/src/security/detect.rs +639 -0
- package/src/security/tests.rs +178 -0
- package/src/security.rs +373 -0
- package/src/security_gate.rs +555 -0
- package/src/symbols/path_filters.rs +27 -0
- package/src/symbols/private_type_leaks.rs +125 -0
- package/src/symbols/riverpod.rs +113 -0
- package/src/symbols/tests.rs +692 -0
- package/src/symbols.rs +693 -0
- package/src/trace/tests.rs +225 -0
- package/src/trace.rs +690 -0
- package/src/unsupported.rs +47 -0
- package/src/widgets/lifecycle.rs +484 -0
- package/src/widgets/params.rs +236 -0
- package/src/widgets/tests.rs +430 -0
- package/src/widgets/top_level.rs +110 -0
- package/src/widgets/unrendered.rs +374 -0
- package/src/widgets.rs +590 -0
- package/src/workspace_scope.rs +358 -0
package/src/cli.rs
ADDED
|
@@ -0,0 +1,603 @@
|
|
|
1
|
+
use std::ffi::OsString;
|
|
2
|
+
use std::fs::File;
|
|
3
|
+
use std::io::Write;
|
|
4
|
+
use std::path::{Path, PathBuf};
|
|
5
|
+
|
|
6
|
+
use clap::{Arg, ArgAction, ArgMatches, Command, parser::ValueSource};
|
|
7
|
+
|
|
8
|
+
use crate::baseline::{
|
|
9
|
+
RegressionTolerance, apply_baseline_to_report, baseline_from_report,
|
|
10
|
+
compare_regression_baseline, load_baseline, load_regression_baseline,
|
|
11
|
+
regression_baseline_from_report, save_baseline as write_baseline,
|
|
12
|
+
save_regression_baseline as write_regression_baseline,
|
|
13
|
+
};
|
|
14
|
+
use crate::config::{
|
|
15
|
+
ConfigError, DartDecimateConfig, IgnoreDependencyOverrideRule, RuleConfig,
|
|
16
|
+
apply_rules_to_report, load_dart_decimate_config,
|
|
17
|
+
};
|
|
18
|
+
use crate::output::{
|
|
19
|
+
ReportCommand, Verdict, build_json_report, filter_report_findings, render_human_report,
|
|
20
|
+
render_sarif_report,
|
|
21
|
+
};
|
|
22
|
+
use crate::scan::{ScanOptions, scan_project_with_options};
|
|
23
|
+
use crate::{
|
|
24
|
+
BoundaryCallRule, BoundaryRule, DuplicateOptions, FeatureFlagOptions, HealthOptions,
|
|
25
|
+
SecurityOptions,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
mod analyze;
|
|
29
|
+
mod analyzer_options;
|
|
30
|
+
mod audit_run;
|
|
31
|
+
mod boundary_args;
|
|
32
|
+
mod ci_template_run;
|
|
33
|
+
mod command_name;
|
|
34
|
+
mod common_args;
|
|
35
|
+
mod config_run;
|
|
36
|
+
mod coverage_run;
|
|
37
|
+
mod decision_surface_run;
|
|
38
|
+
mod default_command;
|
|
39
|
+
mod dupes_args;
|
|
40
|
+
mod entry_points;
|
|
41
|
+
mod error;
|
|
42
|
+
mod error_output;
|
|
43
|
+
mod explain_run;
|
|
44
|
+
mod fix_run;
|
|
45
|
+
mod flags_args;
|
|
46
|
+
mod health_args;
|
|
47
|
+
mod hooks_run;
|
|
48
|
+
mod impact_run;
|
|
49
|
+
mod init_run;
|
|
50
|
+
mod inspect_args;
|
|
51
|
+
mod inspect_run;
|
|
52
|
+
mod issue_filter_args;
|
|
53
|
+
mod list_run;
|
|
54
|
+
mod mode_args;
|
|
55
|
+
mod output_format;
|
|
56
|
+
mod regression_args;
|
|
57
|
+
mod request_args;
|
|
58
|
+
mod schema_commands;
|
|
59
|
+
mod scope_args;
|
|
60
|
+
mod security_args;
|
|
61
|
+
mod security_gate_run;
|
|
62
|
+
mod security_summary_run;
|
|
63
|
+
mod summary_args;
|
|
64
|
+
mod trace_args;
|
|
65
|
+
mod trace_run;
|
|
66
|
+
mod unsupported_run;
|
|
67
|
+
mod watch_run;
|
|
68
|
+
use crate::security_gate::{SecurityDiffSource, SecurityGateMode};
|
|
69
|
+
use analyze::analyze_project;
|
|
70
|
+
use analyzer_options::{
|
|
71
|
+
duplicate_options_for, feature_flag_options_for, health_options_for, security_options_for,
|
|
72
|
+
};
|
|
73
|
+
use boundary_args::boundary_command;
|
|
74
|
+
use ci_template_run::{ci_command, ci_template_command, run_ci, run_ci_template};
|
|
75
|
+
use command_name::report_command_from_name;
|
|
76
|
+
use common_args::{
|
|
77
|
+
audit_baseline_arg, baseline_command, report_command, root_path, scan_command,
|
|
78
|
+
symbol_options_command,
|
|
79
|
+
};
|
|
80
|
+
use config_run::{config_command, run_config};
|
|
81
|
+
use coverage_run::{coverage_command, run_coverage};
|
|
82
|
+
use decision_surface_run::{
|
|
83
|
+
decision_surface_command, max_decisions_arg, review_command, run_decision_surface,
|
|
84
|
+
};
|
|
85
|
+
use dupes_args::{dupes_command, trace_clone_command};
|
|
86
|
+
pub use error::CliError;
|
|
87
|
+
pub use error_output::run_from_env;
|
|
88
|
+
use explain_run::{explain_command, run_explain};
|
|
89
|
+
use fix_run::{fix_command, run_fix};
|
|
90
|
+
use flags_args::flags_command;
|
|
91
|
+
use health_args::{health_command, health_command_without_top};
|
|
92
|
+
use hooks_run::{hooks_command, run_hooks, run_setup_hooks, setup_hooks_command};
|
|
93
|
+
use impact_run::{impact_command, run_impact};
|
|
94
|
+
use init_run::{init_command, run_init};
|
|
95
|
+
use inspect_args::inspect_command;
|
|
96
|
+
use inspect_run::run_inspect_request;
|
|
97
|
+
use issue_filter_args::{check_issue_filter_command, dead_code_issue_filter_command};
|
|
98
|
+
use list_run::{list_command, run_list, run_workspaces, workspaces_command};
|
|
99
|
+
use output_format::{
|
|
100
|
+
OutputFormat, ReportOutputFormat, output_format, output_format_value, report_output_format,
|
|
101
|
+
};
|
|
102
|
+
use regression_args::{
|
|
103
|
+
regression_baseline_path, regression_request_args, save_regression_baseline_path,
|
|
104
|
+
};
|
|
105
|
+
use request_args::{boundary_rules, trace_request_args};
|
|
106
|
+
use schema_commands::{
|
|
107
|
+
config_schema_command, manifest_command, report_schema_command, rule_pack_schema_command,
|
|
108
|
+
run_config_schema, run_manifest, run_report_schema, run_rule_pack_schema,
|
|
109
|
+
};
|
|
110
|
+
use security_args::{
|
|
111
|
+
SecurityCliOptions, SecurityIssueMode, SecuritySummaryMode, security_cli_options,
|
|
112
|
+
security_command,
|
|
113
|
+
};
|
|
114
|
+
use security_gate_run::apply_security_gate;
|
|
115
|
+
use trace_args::{
|
|
116
|
+
trace_command, trace_dependency_command, trace_file_command, trace_symbol_command,
|
|
117
|
+
};
|
|
118
|
+
use trace_run::run_trace_request;
|
|
119
|
+
use unsupported_run::{
|
|
120
|
+
license_command, migrate_command, run_license, run_migrate, run_telemetry, telemetry_command,
|
|
121
|
+
};
|
|
122
|
+
use watch_run::{run_watch, watch_command};
|
|
123
|
+
|
|
124
|
+
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
125
|
+
struct CommandRequest {
|
|
126
|
+
command: ReportCommand,
|
|
127
|
+
root: PathBuf,
|
|
128
|
+
format: ReportOutputFormat,
|
|
129
|
+
entry_points: Vec<PathBuf>,
|
|
130
|
+
production: bool,
|
|
131
|
+
symbol_options: SymbolRequestOptions,
|
|
132
|
+
boundaries: Vec<BoundaryRule>,
|
|
133
|
+
boundary_coverage: bool,
|
|
134
|
+
boundary_allow_unmatched: Vec<String>,
|
|
135
|
+
boundary_calls: Vec<BoundaryCallRule>,
|
|
136
|
+
policy_packs: Vec<PathBuf>,
|
|
137
|
+
audit_base: Option<String>,
|
|
138
|
+
audit_gate: audit_run::AuditGate,
|
|
139
|
+
file_paths: Vec<PathBuf>,
|
|
140
|
+
workspace_patterns: Vec<String>,
|
|
141
|
+
changed_workspaces: Option<String>,
|
|
142
|
+
changed_since: Option<String>,
|
|
143
|
+
baseline_paths: Vec<PathBuf>,
|
|
144
|
+
security_sarif_file: Option<PathBuf>,
|
|
145
|
+
security_gate: Option<SecurityGateMode>,
|
|
146
|
+
security_diff: Option<SecurityDiffSource>,
|
|
147
|
+
security_changed_since: Option<String>,
|
|
148
|
+
security_issue_mode: SecurityIssueMode,
|
|
149
|
+
security_summary_mode: SecuritySummaryMode,
|
|
150
|
+
save_baseline: Option<PathBuf>,
|
|
151
|
+
regression_baseline: Option<PathBuf>,
|
|
152
|
+
save_regression_baseline: Option<PathBuf>,
|
|
153
|
+
regression_tolerance: RegressionTolerance,
|
|
154
|
+
fail_on_regression: bool,
|
|
155
|
+
trace_file: Option<PathBuf>,
|
|
156
|
+
trace_symbol: Option<TraceSymbolSpec>,
|
|
157
|
+
trace_dependency: Option<String>,
|
|
158
|
+
trace_clone: Option<String>,
|
|
159
|
+
duplicate_options: DuplicateOptions,
|
|
160
|
+
health_options: HealthOptions,
|
|
161
|
+
feature_flag_options: FeatureFlagOptions,
|
|
162
|
+
security_options: SecurityOptions,
|
|
163
|
+
issue_filters: issue_filter_args::IssueFilters,
|
|
164
|
+
scan_options: ScanOptions,
|
|
165
|
+
ignore_dependencies: Vec<String>,
|
|
166
|
+
ignore_dependency_overrides: Vec<IgnoreDependencyOverrideRule>,
|
|
167
|
+
rules: RuleConfig,
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
|
|
171
|
+
struct SymbolRequestOptions {
|
|
172
|
+
include_entry_exports: bool,
|
|
173
|
+
private_type_leaks: bool,
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
impl CommandRequest {
|
|
177
|
+
fn entry_point_mode(&self) -> entry_points::EntryPointMode {
|
|
178
|
+
mode_args::production_mode(self.production)
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
183
|
+
struct TraceSymbolSpec {
|
|
184
|
+
file: PathBuf,
|
|
185
|
+
symbol: String,
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/// Run Dart Decimate from explicit arguments.
|
|
189
|
+
///
|
|
190
|
+
/// # Errors
|
|
191
|
+
///
|
|
192
|
+
/// Returns [`CliError`] for invalid arguments, scan failures, or output errors.
|
|
193
|
+
pub fn run_from<I, T, W>(args: I, writer: W) -> Result<i32, CliError>
|
|
194
|
+
where
|
|
195
|
+
I: IntoIterator<Item = T>,
|
|
196
|
+
T: Into<OsString> + Clone,
|
|
197
|
+
W: Write,
|
|
198
|
+
{
|
|
199
|
+
let matches = command().try_get_matches_from(default_command::args_with_default_check(args))?;
|
|
200
|
+
match matches.subcommand() {
|
|
201
|
+
Some(("config-schema", _)) => return run_config_schema(writer),
|
|
202
|
+
Some(("report-schema", _)) => return run_report_schema(writer),
|
|
203
|
+
Some(("rule-pack-schema", _)) => return run_rule_pack_schema(writer),
|
|
204
|
+
Some(("schema", _)) => return run_manifest(writer),
|
|
205
|
+
Some(("config", subcommand)) => return run_config(subcommand, writer),
|
|
206
|
+
Some(("list", subcommand)) => return run_list(subcommand, writer),
|
|
207
|
+
Some(("workspaces", subcommand)) => return run_workspaces(subcommand, writer),
|
|
208
|
+
Some(("explain", subcommand)) => return run_explain(subcommand, writer),
|
|
209
|
+
Some(("fix", subcommand)) => return run_fix(subcommand, writer),
|
|
210
|
+
Some(("migrate", subcommand)) => return run_migrate(subcommand, writer),
|
|
211
|
+
Some(("telemetry", subcommand)) => return run_telemetry(subcommand, writer),
|
|
212
|
+
Some(("license", subcommand)) => return run_license(subcommand, writer),
|
|
213
|
+
Some(("impact", subcommand)) => return run_impact(subcommand, writer),
|
|
214
|
+
Some(("ci", subcommand)) => return run_ci(subcommand, writer),
|
|
215
|
+
Some(("ci-template", subcommand)) => return run_ci_template(subcommand, writer),
|
|
216
|
+
Some(("init", subcommand)) => return run_init(subcommand, writer),
|
|
217
|
+
Some(("hooks", subcommand)) => return run_hooks(subcommand, writer),
|
|
218
|
+
Some(("setup-hooks", subcommand)) => return run_setup_hooks(subcommand, writer),
|
|
219
|
+
Some(("watch", subcommand)) => return run_watch(subcommand, writer),
|
|
220
|
+
Some(("decision-surface", subcommand)) => {
|
|
221
|
+
return run_decision_surface(subcommand, writer, "decision-surface");
|
|
222
|
+
}
|
|
223
|
+
Some(("review", subcommand)) => return run_decision_surface(subcommand, writer, "review"),
|
|
224
|
+
Some(("coverage", subcommand)) => return run_coverage(subcommand, writer),
|
|
225
|
+
Some(("audit", subcommand)) if subcommand.get_flag("brief") => {
|
|
226
|
+
return run_decision_surface(subcommand, writer, "audit --brief");
|
|
227
|
+
}
|
|
228
|
+
_ => {}
|
|
229
|
+
}
|
|
230
|
+
let request = request_from_matches(&matches)?;
|
|
231
|
+
run_request(&request, writer)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
fn run_request<W: Write>(request: &CommandRequest, mut writer: W) -> Result<i32, CliError> {
|
|
235
|
+
let project = scan_project_with_options(&request.root, &request.scan_options)?;
|
|
236
|
+
if matches!(
|
|
237
|
+
request.command,
|
|
238
|
+
ReportCommand::TraceFile
|
|
239
|
+
| ReportCommand::TraceSymbol
|
|
240
|
+
| ReportCommand::TraceDependency
|
|
241
|
+
| ReportCommand::TraceClone
|
|
242
|
+
) {
|
|
243
|
+
return run_trace_request(request, &project, writer);
|
|
244
|
+
}
|
|
245
|
+
if request.command == ReportCommand::Inspect {
|
|
246
|
+
return run_inspect_request(request, &project, writer);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
let mut results = analyze_project(&project, request)?;
|
|
250
|
+
let audit_context = audit_run::prepare_context(&project, request, &mut results)?;
|
|
251
|
+
scope_args::apply_report_scope(&project, &mut results, request)?;
|
|
252
|
+
let mut report = build_json_report(&project, &results);
|
|
253
|
+
apply_rules_to_report(&mut report, &request.rules)?;
|
|
254
|
+
filter_report_findings(&mut report, &request.issue_filters.kinds);
|
|
255
|
+
for path in &request.baseline_paths {
|
|
256
|
+
let baseline = load_baseline(resolve_report_path(&project.root, path))?;
|
|
257
|
+
apply_baseline_to_report(&mut report, &baseline);
|
|
258
|
+
}
|
|
259
|
+
let regressed = if let Some(path) = &request.regression_baseline {
|
|
260
|
+
let baseline = load_regression_baseline(resolve_report_path(&project.root, path))?;
|
|
261
|
+
compare_regression_baseline(&report, &baseline, request.regression_tolerance).regressed()
|
|
262
|
+
} else {
|
|
263
|
+
false
|
|
264
|
+
};
|
|
265
|
+
if let Some(path) = &request.save_baseline {
|
|
266
|
+
let baseline = baseline_from_report(&report);
|
|
267
|
+
write_baseline(resolve_report_path(&project.root, path), &baseline)?;
|
|
268
|
+
}
|
|
269
|
+
if let Some(path) = &request.save_regression_baseline {
|
|
270
|
+
let baseline = regression_baseline_from_report(&report);
|
|
271
|
+
write_regression_baseline(resolve_report_path(&project.root, path), &baseline)?;
|
|
272
|
+
}
|
|
273
|
+
apply_security_gate(&project, request, &mut report)?;
|
|
274
|
+
if let Some(path) = &request.security_sarif_file {
|
|
275
|
+
let mut file = File::create(resolve_report_path(&project.root, path))?;
|
|
276
|
+
serde_json::to_writer_pretty(&mut file, &render_sarif_report(&report))?;
|
|
277
|
+
writeln!(file)?;
|
|
278
|
+
}
|
|
279
|
+
security_summary_run::apply_security_summary(request, &mut report);
|
|
280
|
+
audit_run::apply_risk(&project.root, &audit_context, &mut report);
|
|
281
|
+
apply_duplication_threshold_gate(&mut report);
|
|
282
|
+
let code = security_summary_run::exit_code(request, &report, regressed);
|
|
283
|
+
|
|
284
|
+
match request.format {
|
|
285
|
+
ReportOutputFormat::Human => writer.write_all(render_human_report(&report).as_bytes())?,
|
|
286
|
+
ReportOutputFormat::Json => {
|
|
287
|
+
serde_json::to_writer_pretty(&mut writer, &report)?;
|
|
288
|
+
writeln!(writer)?;
|
|
289
|
+
}
|
|
290
|
+
ReportOutputFormat::Sarif => {
|
|
291
|
+
serde_json::to_writer_pretty(&mut writer, &render_sarif_report(&report))?;
|
|
292
|
+
writeln!(writer)?;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
Ok(code)
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
fn apply_duplication_threshold_gate(report: &mut crate::output::JsonReport) {
|
|
300
|
+
if report.summary.duplication_threshold_exceeded {
|
|
301
|
+
report.verdict = Verdict::Fail;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
fn command() -> Command {
|
|
306
|
+
let command = Command::new("dart-decimate")
|
|
307
|
+
.about("Rust-native Dart and Flutter module-graph intelligence")
|
|
308
|
+
.subcommand_required(false)
|
|
309
|
+
.arg_required_else_help(false);
|
|
310
|
+
schema_subcommands(support_subcommands(report_subcommands(command)))
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
fn report_subcommands(command: Command) -> Command {
|
|
314
|
+
command
|
|
315
|
+
.subcommand(check_issue_filter_command(symbol_options_command(
|
|
316
|
+
dupes_command(health_command_without_top(boundary_command(
|
|
317
|
+
baseline_command(Command::new("check").about("Run all enabled graph checks")),
|
|
318
|
+
))),
|
|
319
|
+
)))
|
|
320
|
+
.subcommand(symbol_options_command(dupes_command(
|
|
321
|
+
health_command_without_top(boundary_command(report_command(audit_command()))),
|
|
322
|
+
)))
|
|
323
|
+
.subcommand(dead_code_issue_filter_command(symbol_options_command(
|
|
324
|
+
baseline_command(
|
|
325
|
+
Command::new("dead-code").about("Find Dart files unreachable from entry points"),
|
|
326
|
+
),
|
|
327
|
+
)))
|
|
328
|
+
.subcommand(baseline_command(
|
|
329
|
+
Command::new("cycles").about("Find circular file dependencies"),
|
|
330
|
+
))
|
|
331
|
+
.subcommand(dupes_command(baseline_command(
|
|
332
|
+
Command::new("dupes").about("Find duplicated Dart code blocks"),
|
|
333
|
+
)))
|
|
334
|
+
.subcommand(health_command(baseline_command(
|
|
335
|
+
Command::new("health").about("Find complex Dart functions and methods"),
|
|
336
|
+
)))
|
|
337
|
+
.subcommand(flags_command(baseline_command(
|
|
338
|
+
Command::new("flags").about("Find Dart and Flutter feature flag patterns"),
|
|
339
|
+
)))
|
|
340
|
+
.subcommand(security_command(baseline_command(
|
|
341
|
+
Command::new("security").about("Find unverified Dart and Flutter security candidates"),
|
|
342
|
+
)))
|
|
343
|
+
.subcommand(trace_file_command(scan_command(
|
|
344
|
+
Command::new("trace-file").about("Trace one Dart file"),
|
|
345
|
+
)))
|
|
346
|
+
.subcommand(trace_command(
|
|
347
|
+
Command::new("trace").about("Trace one top-level Dart symbol"),
|
|
348
|
+
))
|
|
349
|
+
.subcommand(trace_symbol_command(scan_command(
|
|
350
|
+
Command::new("trace-symbol").about("Trace one top-level Dart symbol"),
|
|
351
|
+
)))
|
|
352
|
+
.subcommand(trace_dependency_command(scan_command(
|
|
353
|
+
Command::new("trace-dependency").about("Trace one pub dependency"),
|
|
354
|
+
)))
|
|
355
|
+
.subcommand(trace_clone_command(dupes_command(scan_command(
|
|
356
|
+
Command::new("trace-clone").about("Trace one duplicate code group"),
|
|
357
|
+
))))
|
|
358
|
+
.subcommand(inspect_command(scan_command(
|
|
359
|
+
Command::new("inspect").about("Compose one evidence bundle for a file or symbol"),
|
|
360
|
+
)))
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
fn audit_command() -> Command {
|
|
364
|
+
Command::new("audit")
|
|
365
|
+
.about("Run changed-code graph checks")
|
|
366
|
+
.arg(
|
|
367
|
+
Arg::new("brief")
|
|
368
|
+
.long("brief")
|
|
369
|
+
.help("Emit a Fallow-style advisory review brief and always exit 0")
|
|
370
|
+
.action(ArgAction::SetTrue),
|
|
371
|
+
)
|
|
372
|
+
.arg(
|
|
373
|
+
Arg::new("base")
|
|
374
|
+
.long("base")
|
|
375
|
+
.value_name("REF")
|
|
376
|
+
.help("Git ref used to scope changed files")
|
|
377
|
+
.required(true),
|
|
378
|
+
)
|
|
379
|
+
.arg(audit_run::gate_arg())
|
|
380
|
+
.arg(audit_baseline_arg(
|
|
381
|
+
"dead-code-baseline",
|
|
382
|
+
"Dead-code baseline file",
|
|
383
|
+
))
|
|
384
|
+
.arg(audit_baseline_arg(
|
|
385
|
+
"health-baseline",
|
|
386
|
+
"Health baseline file",
|
|
387
|
+
))
|
|
388
|
+
.arg(audit_baseline_arg(
|
|
389
|
+
"dupes-baseline",
|
|
390
|
+
"Duplicate-code baseline file",
|
|
391
|
+
))
|
|
392
|
+
.arg(max_decisions_arg())
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
fn support_subcommands(command: Command) -> Command {
|
|
396
|
+
command
|
|
397
|
+
.subcommand(list_command())
|
|
398
|
+
.subcommand(workspaces_command())
|
|
399
|
+
.subcommand(explain_command())
|
|
400
|
+
.subcommand(fix_command())
|
|
401
|
+
.subcommand(migrate_command())
|
|
402
|
+
.subcommand(telemetry_command())
|
|
403
|
+
.subcommand(license_command())
|
|
404
|
+
.subcommand(init_command())
|
|
405
|
+
.subcommand(hooks_command())
|
|
406
|
+
.subcommand(setup_hooks_command())
|
|
407
|
+
.subcommand(watch_command())
|
|
408
|
+
.subcommand(impact_command())
|
|
409
|
+
.subcommand(ci_command())
|
|
410
|
+
.subcommand(ci_template_command())
|
|
411
|
+
.subcommand(review_command())
|
|
412
|
+
.subcommand(decision_surface_command())
|
|
413
|
+
.subcommand(coverage_command())
|
|
414
|
+
.subcommand(config_command())
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
fn schema_subcommands(command: Command) -> Command {
|
|
418
|
+
command
|
|
419
|
+
.subcommand(manifest_command())
|
|
420
|
+
.subcommand(config_schema_command())
|
|
421
|
+
.subcommand(report_schema_command())
|
|
422
|
+
.subcommand(rule_pack_schema_command())
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
fn request_from_matches(matches: &ArgMatches) -> Result<CommandRequest, CliError> {
|
|
426
|
+
let Some((name, subcommand)) = matches.subcommand() else {
|
|
427
|
+
unreachable!("clap requires a subcommand");
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
let command = report_command_from_name(name);
|
|
431
|
+
|
|
432
|
+
let root = root_path(subcommand);
|
|
433
|
+
let config = load_config(&root, subcommand)?;
|
|
434
|
+
let security_cli = security_cli_options(command, subcommand);
|
|
435
|
+
let format = if security_cli.ci {
|
|
436
|
+
ReportOutputFormat::Sarif
|
|
437
|
+
} else {
|
|
438
|
+
report_output_format(subcommand, &config)
|
|
439
|
+
};
|
|
440
|
+
let entry_points = entry_points(subcommand, &config);
|
|
441
|
+
let production = mode_args::production(subcommand, &config);
|
|
442
|
+
let symbol_options = SymbolRequestOptions {
|
|
443
|
+
include_entry_exports: mode_args::include_entry_exports(subcommand, &config),
|
|
444
|
+
private_type_leaks: mode_args::private_type_leaks(subcommand, &config),
|
|
445
|
+
};
|
|
446
|
+
let mut boundaries = config.boundaries.clone();
|
|
447
|
+
boundaries.extend(boundary_rules(command, subcommand)?);
|
|
448
|
+
let boundary_calls = request_args::boundary_call_rules(command, subcommand, &config)?;
|
|
449
|
+
let policy_packs = request_args::policy_pack_paths(command, subcommand, &config);
|
|
450
|
+
let boundary_coverage = subcommand
|
|
451
|
+
.try_get_one::<bool>("boundary-coverage")
|
|
452
|
+
.ok()
|
|
453
|
+
.flatten()
|
|
454
|
+
.copied()
|
|
455
|
+
.unwrap_or_default()
|
|
456
|
+
|| config.boundary_coverage;
|
|
457
|
+
let audit_base = (command == ReportCommand::Audit)
|
|
458
|
+
.then(|| subcommand.get_one::<String>("base").cloned())
|
|
459
|
+
.flatten();
|
|
460
|
+
let file_paths = scope_args::file_paths(command, subcommand);
|
|
461
|
+
let workspace_patterns = scope_args::workspace_patterns(command, subcommand);
|
|
462
|
+
let changed_workspaces = scope_args::changed_workspaces(command, subcommand);
|
|
463
|
+
let changed_since = scope_args::changed_since(command, subcommand);
|
|
464
|
+
let baseline_paths = baseline_paths(command, subcommand);
|
|
465
|
+
let save_baseline = if supports_global_baseline(command) {
|
|
466
|
+
subcommand.get_one::<PathBuf>("save-baseline").cloned()
|
|
467
|
+
} else {
|
|
468
|
+
None
|
|
469
|
+
};
|
|
470
|
+
let regression = regression_request_args(command, subcommand)?;
|
|
471
|
+
let regression_baseline = regression_baseline_path(command, subcommand);
|
|
472
|
+
let save_regression_baseline = save_regression_baseline_path(command, subcommand);
|
|
473
|
+
let trace = trace_request_args(command, subcommand)?;
|
|
474
|
+
let duplicate_options = duplicate_options_for(command, subcommand, &config)?;
|
|
475
|
+
let health_options = health_options_for(command, subcommand, &config);
|
|
476
|
+
let feature_flag_options = feature_flag_options_for(command, subcommand, &config);
|
|
477
|
+
let security_options = security_options_for(command, subcommand, &config);
|
|
478
|
+
let issue_filters = issue_filter_args::issue_filters(command, subcommand);
|
|
479
|
+
validate_security_cli(&security_cli, &security_options)?;
|
|
480
|
+
Ok(CommandRequest {
|
|
481
|
+
command,
|
|
482
|
+
root,
|
|
483
|
+
format,
|
|
484
|
+
entry_points,
|
|
485
|
+
production,
|
|
486
|
+
symbol_options,
|
|
487
|
+
boundaries,
|
|
488
|
+
boundary_coverage,
|
|
489
|
+
boundary_allow_unmatched: config.boundary_allow_unmatched.clone(),
|
|
490
|
+
boundary_calls,
|
|
491
|
+
policy_packs,
|
|
492
|
+
audit_base,
|
|
493
|
+
audit_gate: audit_run::gate(command, subcommand),
|
|
494
|
+
file_paths,
|
|
495
|
+
workspace_patterns,
|
|
496
|
+
changed_workspaces,
|
|
497
|
+
changed_since,
|
|
498
|
+
baseline_paths,
|
|
499
|
+
security_issue_mode: security_cli.issue_mode(),
|
|
500
|
+
security_summary_mode: security_cli.summary_mode(),
|
|
501
|
+
security_sarif_file: security_cli.sarif_file,
|
|
502
|
+
security_gate: security_cli.gate,
|
|
503
|
+
security_diff: security_cli.diff,
|
|
504
|
+
security_changed_since: security_cli.changed_since,
|
|
505
|
+
save_baseline,
|
|
506
|
+
regression_baseline,
|
|
507
|
+
save_regression_baseline,
|
|
508
|
+
regression_tolerance: regression.tolerance,
|
|
509
|
+
fail_on_regression: regression.fail_on_regression,
|
|
510
|
+
trace_file: trace.file,
|
|
511
|
+
trace_symbol: trace.symbol,
|
|
512
|
+
trace_dependency: trace.dependency,
|
|
513
|
+
trace_clone: trace.clone,
|
|
514
|
+
duplicate_options,
|
|
515
|
+
health_options,
|
|
516
|
+
feature_flag_options,
|
|
517
|
+
security_options,
|
|
518
|
+
issue_filters,
|
|
519
|
+
scan_options: ScanOptions {
|
|
520
|
+
ignore_patterns: config.ignore_patterns.clone(),
|
|
521
|
+
conditional_environment: common_args::conditional_environment(subcommand),
|
|
522
|
+
},
|
|
523
|
+
ignore_dependencies: config.ignore_dependencies.clone(),
|
|
524
|
+
ignore_dependency_overrides: config.ignore_dependency_overrides.clone(),
|
|
525
|
+
rules: config.rules.clone(),
|
|
526
|
+
})
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
fn validate_security_cli(
|
|
530
|
+
security_cli: &SecurityCliOptions,
|
|
531
|
+
security_options: &SecurityOptions,
|
|
532
|
+
) -> Result<(), CliError> {
|
|
533
|
+
if security_options.top.is_some()
|
|
534
|
+
&& (security_cli.gate.is_some()
|
|
535
|
+
|| security_cli.diff.is_some()
|
|
536
|
+
|| security_cli.changed_since.is_some())
|
|
537
|
+
{
|
|
538
|
+
return Err(CliError::UnsupportedSecurityTopScope);
|
|
539
|
+
}
|
|
540
|
+
Ok(())
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
fn baseline_paths(command: ReportCommand, subcommand: &ArgMatches) -> Vec<PathBuf> {
|
|
544
|
+
let mut paths = Vec::new();
|
|
545
|
+
if supports_global_baseline(command) {
|
|
546
|
+
if let Some(path) = subcommand.get_one::<PathBuf>("baseline") {
|
|
547
|
+
paths.push(path.clone());
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
if command == ReportCommand::Audit {
|
|
551
|
+
for id in ["dead-code-baseline", "health-baseline", "dupes-baseline"] {
|
|
552
|
+
if let Some(path) = subcommand.get_one::<PathBuf>(id) {
|
|
553
|
+
paths.push(path.clone());
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
paths
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
fn supports_global_baseline(command: ReportCommand) -> bool {
|
|
561
|
+
matches!(
|
|
562
|
+
command,
|
|
563
|
+
ReportCommand::Check
|
|
564
|
+
| ReportCommand::DeadCode
|
|
565
|
+
| ReportCommand::Cycles
|
|
566
|
+
| ReportCommand::Dupes
|
|
567
|
+
| ReportCommand::Health
|
|
568
|
+
| ReportCommand::Flags
|
|
569
|
+
| ReportCommand::Security
|
|
570
|
+
)
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
fn resolve_report_path(root: &Path, path: &Path) -> PathBuf {
|
|
574
|
+
if path.is_absolute() {
|
|
575
|
+
path.to_path_buf()
|
|
576
|
+
} else {
|
|
577
|
+
root.join(path)
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
fn load_config(root: &Path, subcommand: &ArgMatches) -> Result<DartDecimateConfig, ConfigError> {
|
|
582
|
+
load_dart_decimate_config(
|
|
583
|
+
root,
|
|
584
|
+
subcommand
|
|
585
|
+
.get_one::<PathBuf>("config")
|
|
586
|
+
.map(std::path::PathBuf::as_path),
|
|
587
|
+
)
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
fn entry_points(subcommand: &ArgMatches, config: &DartDecimateConfig) -> Vec<PathBuf> {
|
|
591
|
+
if subcommand.value_source("entry") == Some(ValueSource::CommandLine) {
|
|
592
|
+
return subcommand
|
|
593
|
+
.get_many::<PathBuf>("entry")
|
|
594
|
+
.map(|values| values.cloned().collect())
|
|
595
|
+
.unwrap_or_default();
|
|
596
|
+
}
|
|
597
|
+
config.entry_points.clone()
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
#[cfg(test)]
|
|
601
|
+
mod tests;
|
|
602
|
+
#[cfg(test)]
|
|
603
|
+
mod trace_tests;
|