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
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
use std::io::Write;
|
|
2
|
+
|
|
3
|
+
use clap::{Arg, ArgAction, ArgMatches, Command};
|
|
4
|
+
|
|
5
|
+
use super::common_args::{
|
|
6
|
+
conditional_environment, config_arg, dart_platform_arg, entry_arg, format_arg, root_arg,
|
|
7
|
+
root_flag_arg, root_path,
|
|
8
|
+
};
|
|
9
|
+
use super::entry_points::entry_points_for_check;
|
|
10
|
+
use super::{CliError, OutputFormat, entry_points, load_config, output_format};
|
|
11
|
+
use crate::{
|
|
12
|
+
ProjectListOptions, ProjectListSection, local_pub_packages, project_list_report,
|
|
13
|
+
scan::{ScannedProject, scan_project_with_options},
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
pub(super) fn list_command() -> Command {
|
|
17
|
+
Command::new("list")
|
|
18
|
+
.about("List Dart Decimate project structure")
|
|
19
|
+
.arg(root_arg())
|
|
20
|
+
.arg(root_flag_arg())
|
|
21
|
+
.arg(format_arg())
|
|
22
|
+
.arg(config_arg())
|
|
23
|
+
.arg(entry_arg())
|
|
24
|
+
.arg(dart_platform_arg())
|
|
25
|
+
.arg(super::mode_args::production_arg())
|
|
26
|
+
.arg(super::mode_args::no_production_arg())
|
|
27
|
+
.arg(section_arg("files", "Include parsed Dart files"))
|
|
28
|
+
.arg(section_arg(
|
|
29
|
+
"entry-points",
|
|
30
|
+
"Include effective Dart entry points",
|
|
31
|
+
))
|
|
32
|
+
.arg(section_arg(
|
|
33
|
+
"workspaces",
|
|
34
|
+
"Include discovered local pub packages",
|
|
35
|
+
))
|
|
36
|
+
.arg(section_arg(
|
|
37
|
+
"plugins",
|
|
38
|
+
"Include active Dart Decimate adapters",
|
|
39
|
+
))
|
|
40
|
+
.arg(section_arg(
|
|
41
|
+
"boundaries",
|
|
42
|
+
"Include configured architecture boundaries",
|
|
43
|
+
))
|
|
44
|
+
.arg(super::scope_args::file_arg())
|
|
45
|
+
.arg(super::scope_args::workspace_arg())
|
|
46
|
+
.arg(super::scope_args::changed_workspaces_arg())
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
pub(super) fn workspaces_command() -> Command {
|
|
50
|
+
Command::new("workspaces")
|
|
51
|
+
.about("List discovered local pub packages")
|
|
52
|
+
.arg(root_arg())
|
|
53
|
+
.arg(root_flag_arg())
|
|
54
|
+
.arg(format_arg())
|
|
55
|
+
.arg(config_arg())
|
|
56
|
+
.arg(entry_arg())
|
|
57
|
+
.arg(dart_platform_arg())
|
|
58
|
+
.arg(super::mode_args::production_arg())
|
|
59
|
+
.arg(super::mode_args::no_production_arg())
|
|
60
|
+
.arg(super::scope_args::file_arg())
|
|
61
|
+
.arg(super::scope_args::workspace_arg())
|
|
62
|
+
.arg(super::scope_args::changed_workspaces_arg())
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
pub(super) fn run_list<W: Write>(subcommand: &ArgMatches, mut writer: W) -> Result<i32, CliError> {
|
|
66
|
+
run_list_with_options(subcommand, &mut writer, "list", &list_options(subcommand))
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
pub(super) fn run_workspaces<W: Write>(
|
|
70
|
+
subcommand: &ArgMatches,
|
|
71
|
+
mut writer: W,
|
|
72
|
+
) -> Result<i32, CliError> {
|
|
73
|
+
run_list_with_options(
|
|
74
|
+
subcommand,
|
|
75
|
+
&mut writer,
|
|
76
|
+
"workspaces",
|
|
77
|
+
&ProjectListOptions::from_sections([ProjectListSection::Workspaces]),
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
fn run_list_with_options<W: Write>(
|
|
82
|
+
subcommand: &ArgMatches,
|
|
83
|
+
writer: &mut W,
|
|
84
|
+
command_name: &str,
|
|
85
|
+
options: &ProjectListOptions,
|
|
86
|
+
) -> Result<i32, CliError> {
|
|
87
|
+
let root = root_path(subcommand);
|
|
88
|
+
let config = load_config(&root, subcommand)?;
|
|
89
|
+
let format = output_format(subcommand, &config);
|
|
90
|
+
let explicit_entries = entry_points(subcommand, &config);
|
|
91
|
+
let production = super::mode_args::production(subcommand, &config);
|
|
92
|
+
let entry_source = entry_source(subcommand, explicit_entries.is_empty(), production);
|
|
93
|
+
let scan_options = crate::ScanOptions {
|
|
94
|
+
ignore_patterns: config.ignore_patterns.clone(),
|
|
95
|
+
conditional_environment: conditional_environment(subcommand),
|
|
96
|
+
};
|
|
97
|
+
let project = scan_project_with_options(&root, &scan_options)?;
|
|
98
|
+
let mut packages = local_pub_packages(&project.root)?;
|
|
99
|
+
let project = scoped_project(subcommand, project, &mut packages, production)?;
|
|
100
|
+
let entries = entry_points_for_check(
|
|
101
|
+
&project,
|
|
102
|
+
&explicit_entries,
|
|
103
|
+
super::mode_args::production_mode(production),
|
|
104
|
+
);
|
|
105
|
+
let mut report = project_list_report(
|
|
106
|
+
&project,
|
|
107
|
+
&packages,
|
|
108
|
+
&entries,
|
|
109
|
+
entry_source,
|
|
110
|
+
crate::ProjectListBoundaryConfig {
|
|
111
|
+
rules: &config.boundaries,
|
|
112
|
+
presets: &config.boundary_presets,
|
|
113
|
+
allow_unmatched: &config.boundary_allow_unmatched,
|
|
114
|
+
},
|
|
115
|
+
options,
|
|
116
|
+
);
|
|
117
|
+
command_name.clone_into(&mut report.command);
|
|
118
|
+
|
|
119
|
+
match format {
|
|
120
|
+
OutputFormat::Json => {
|
|
121
|
+
serde_json::to_writer_pretty(&mut *writer, &report)?;
|
|
122
|
+
writeln!(writer)?;
|
|
123
|
+
}
|
|
124
|
+
OutputFormat::Human => writer.write_all(render_list(&report).as_bytes())?,
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
Ok(0)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
fn scoped_project(
|
|
131
|
+
matches: &ArgMatches,
|
|
132
|
+
project: ScannedProject,
|
|
133
|
+
packages: &mut Vec<crate::LocalPubPackage>,
|
|
134
|
+
production: bool,
|
|
135
|
+
) -> Result<ScannedProject, CliError> {
|
|
136
|
+
let request = crate::cli::CommandRequest {
|
|
137
|
+
command: crate::ReportCommand::Check,
|
|
138
|
+
root: project.root.clone(),
|
|
139
|
+
format: super::ReportOutputFormat::Json,
|
|
140
|
+
entry_points: Vec::new(),
|
|
141
|
+
production,
|
|
142
|
+
symbol_options: super::SymbolRequestOptions::default(),
|
|
143
|
+
boundaries: Vec::new(),
|
|
144
|
+
boundary_coverage: false,
|
|
145
|
+
boundary_allow_unmatched: Vec::new(),
|
|
146
|
+
boundary_calls: Vec::new(),
|
|
147
|
+
policy_packs: Vec::new(),
|
|
148
|
+
audit_base: None,
|
|
149
|
+
audit_gate: super::audit_run::AuditGate::default(),
|
|
150
|
+
file_paths: matches
|
|
151
|
+
.get_many::<std::path::PathBuf>("file")
|
|
152
|
+
.map(|values| values.cloned().collect::<Vec<_>>())
|
|
153
|
+
.unwrap_or_default(),
|
|
154
|
+
workspace_patterns: matches
|
|
155
|
+
.get_many::<String>("workspace")
|
|
156
|
+
.map(|values| values.cloned().collect::<Vec<_>>())
|
|
157
|
+
.unwrap_or_default(),
|
|
158
|
+
changed_workspaces: matches.get_one::<String>("changed-workspaces").cloned(),
|
|
159
|
+
changed_since: None,
|
|
160
|
+
baseline_paths: Vec::new(),
|
|
161
|
+
security_sarif_file: None,
|
|
162
|
+
security_gate: None,
|
|
163
|
+
security_diff: None,
|
|
164
|
+
security_changed_since: None,
|
|
165
|
+
security_issue_mode: super::security_args::SecurityIssueMode::default(),
|
|
166
|
+
security_summary_mode: super::security_args::SecuritySummaryMode::default(),
|
|
167
|
+
save_baseline: None,
|
|
168
|
+
regression_baseline: None,
|
|
169
|
+
save_regression_baseline: None,
|
|
170
|
+
regression_tolerance: crate::RegressionTolerance::default(),
|
|
171
|
+
fail_on_regression: false,
|
|
172
|
+
trace_file: None,
|
|
173
|
+
trace_symbol: None,
|
|
174
|
+
trace_dependency: None,
|
|
175
|
+
trace_clone: None,
|
|
176
|
+
duplicate_options: crate::DuplicateOptions::default(),
|
|
177
|
+
health_options: crate::HealthOptions::default(),
|
|
178
|
+
feature_flag_options: crate::FeatureFlagOptions::default(),
|
|
179
|
+
security_options: crate::SecurityOptions::default(),
|
|
180
|
+
issue_filters: super::issue_filter_args::IssueFilters::default(),
|
|
181
|
+
scan_options: crate::ScanOptions::default(),
|
|
182
|
+
ignore_dependencies: Vec::new(),
|
|
183
|
+
ignore_dependency_overrides: Vec::new(),
|
|
184
|
+
rules: crate::config::RuleConfig::default(),
|
|
185
|
+
};
|
|
186
|
+
let mut results = crate::output::AnalysisResults {
|
|
187
|
+
command: crate::ReportCommand::Check,
|
|
188
|
+
dead_code: None,
|
|
189
|
+
symbols: None,
|
|
190
|
+
cycles: Vec::new(),
|
|
191
|
+
re_export_cycles: Vec::new(),
|
|
192
|
+
boundary_violations: Vec::new(),
|
|
193
|
+
boundary_coverage: Vec::new(),
|
|
194
|
+
boundary_call_violations: Vec::new(),
|
|
195
|
+
policy_violations: Vec::new(),
|
|
196
|
+
dependency_hygiene: None,
|
|
197
|
+
duplicates: None,
|
|
198
|
+
health: None,
|
|
199
|
+
feature_flags: None,
|
|
200
|
+
security: None,
|
|
201
|
+
routes: None,
|
|
202
|
+
widgets: None,
|
|
203
|
+
file_scope: None,
|
|
204
|
+
require_suppression_reasons: false,
|
|
205
|
+
};
|
|
206
|
+
super::scope_args::apply_report_scope(&project, &mut results, &request)?;
|
|
207
|
+
let Some(scope) = results.file_scope else {
|
|
208
|
+
return Ok(project);
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
let scope = scope.into_iter().collect::<std::collections::BTreeSet<_>>();
|
|
212
|
+
let package_roots = packages
|
|
213
|
+
.iter()
|
|
214
|
+
.map(|package| package.root.clone())
|
|
215
|
+
.collect::<Vec<_>>();
|
|
216
|
+
packages.retain(|package| package_in_scope(package, &package_roots, &scope));
|
|
217
|
+
Ok(ScannedProject {
|
|
218
|
+
root: project.root,
|
|
219
|
+
files: project
|
|
220
|
+
.files
|
|
221
|
+
.into_iter()
|
|
222
|
+
.filter(|file| scope.contains(&file.path))
|
|
223
|
+
.collect(),
|
|
224
|
+
graph: project.graph,
|
|
225
|
+
})
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
fn package_in_scope(
|
|
229
|
+
package: &crate::LocalPubPackage,
|
|
230
|
+
package_roots: &[std::path::PathBuf],
|
|
231
|
+
scope: &std::collections::BTreeSet<std::path::PathBuf>,
|
|
232
|
+
) -> bool {
|
|
233
|
+
scope.contains(&package.pubspec_path)
|
|
234
|
+
|| scope
|
|
235
|
+
.iter()
|
|
236
|
+
.any(|path| owning_root(package_roots, path) == Some(&package.root))
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
fn owning_root<'root>(
|
|
240
|
+
roots: &'root [std::path::PathBuf],
|
|
241
|
+
path: &std::path::Path,
|
|
242
|
+
) -> Option<&'root std::path::PathBuf> {
|
|
243
|
+
roots
|
|
244
|
+
.iter()
|
|
245
|
+
.filter(|root| path.starts_with(root))
|
|
246
|
+
.max_by_key(|root| root.components().count())
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
fn section_arg(id: &'static str, help: &'static str) -> Arg {
|
|
250
|
+
Arg::new(id).long(id).help(help).action(ArgAction::SetTrue)
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
fn list_options(matches: &ArgMatches) -> ProjectListOptions {
|
|
254
|
+
let any = [
|
|
255
|
+
"files",
|
|
256
|
+
"entry-points",
|
|
257
|
+
"workspaces",
|
|
258
|
+
"plugins",
|
|
259
|
+
"boundaries",
|
|
260
|
+
]
|
|
261
|
+
.into_iter()
|
|
262
|
+
.any(|id| matches.get_flag(id));
|
|
263
|
+
if !any {
|
|
264
|
+
return ProjectListOptions::all();
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
ProjectListOptions::from_sections(
|
|
268
|
+
[
|
|
269
|
+
(matches.get_flag("files"), ProjectListSection::Files),
|
|
270
|
+
(
|
|
271
|
+
matches.get_flag("entry-points"),
|
|
272
|
+
ProjectListSection::EntryPoints,
|
|
273
|
+
),
|
|
274
|
+
(
|
|
275
|
+
matches.get_flag("workspaces"),
|
|
276
|
+
ProjectListSection::Workspaces,
|
|
277
|
+
),
|
|
278
|
+
(matches.get_flag("plugins"), ProjectListSection::Plugins),
|
|
279
|
+
(
|
|
280
|
+
matches.get_flag("boundaries"),
|
|
281
|
+
ProjectListSection::Boundaries,
|
|
282
|
+
),
|
|
283
|
+
]
|
|
284
|
+
.into_iter()
|
|
285
|
+
.filter_map(|(enabled, section)| enabled.then_some(section)),
|
|
286
|
+
)
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
fn entry_source(matches: &ArgMatches, defaulted: bool, production: bool) -> &'static str {
|
|
290
|
+
if defaulted && production {
|
|
291
|
+
"production"
|
|
292
|
+
} else if defaulted {
|
|
293
|
+
"default"
|
|
294
|
+
} else if matches.value_source("entry") == Some(clap::parser::ValueSource::CommandLine) {
|
|
295
|
+
"cli"
|
|
296
|
+
} else {
|
|
297
|
+
"config"
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
fn render_list(report: &crate::ProjectListReport) -> String {
|
|
302
|
+
format!(
|
|
303
|
+
"Files: {}\nEdges: {}\nEntry points: {}\nWorkspaces: {}\nPlugins: {}\nBoundaries: {}\n",
|
|
304
|
+
report.summary.files,
|
|
305
|
+
report.summary.edges,
|
|
306
|
+
report.summary.entry_points,
|
|
307
|
+
report.summary.workspaces,
|
|
308
|
+
report.summary.plugins,
|
|
309
|
+
report.summary.boundary_zones
|
|
310
|
+
)
|
|
311
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
use clap::{Arg, ArgAction, ArgMatches};
|
|
2
|
+
|
|
3
|
+
use crate::config::{DartDecimateConfig, private_type_leaks_enabled};
|
|
4
|
+
|
|
5
|
+
use super::entry_points::EntryPointMode;
|
|
6
|
+
|
|
7
|
+
pub(super) fn production_arg() -> Arg {
|
|
8
|
+
Arg::new("production")
|
|
9
|
+
.long("production")
|
|
10
|
+
.help("Infer reachability from production Dart entry points only")
|
|
11
|
+
.action(ArgAction::SetTrue)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
pub(super) fn no_production_arg() -> Arg {
|
|
15
|
+
Arg::new("no-production")
|
|
16
|
+
.long("no-production")
|
|
17
|
+
.help("Disable production-only reachability from config defaults")
|
|
18
|
+
.conflicts_with("production")
|
|
19
|
+
.action(ArgAction::SetTrue)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
pub(super) fn include_entry_exports_arg() -> Arg {
|
|
23
|
+
Arg::new("include-entry-exports")
|
|
24
|
+
.long("include-entry-exports")
|
|
25
|
+
.help("Report unused public declarations exposed through entry libraries")
|
|
26
|
+
.action(ArgAction::SetTrue)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
pub(super) fn private_type_leaks_arg() -> Arg {
|
|
30
|
+
Arg::new("private-type-leaks")
|
|
31
|
+
.long("private-type-leaks")
|
|
32
|
+
.help("Report exported signatures that expose same-library private Dart types")
|
|
33
|
+
.action(ArgAction::SetTrue)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
pub(super) fn production(matches: &ArgMatches, config: &DartDecimateConfig) -> bool {
|
|
37
|
+
if matches.get_flag("no-production") {
|
|
38
|
+
false
|
|
39
|
+
} else if matches.get_flag("production") {
|
|
40
|
+
true
|
|
41
|
+
} else {
|
|
42
|
+
config.production
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
pub(super) fn production_mode(production: bool) -> EntryPointMode {
|
|
47
|
+
if production {
|
|
48
|
+
EntryPointMode::Production
|
|
49
|
+
} else {
|
|
50
|
+
EntryPointMode::All
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
pub(super) fn include_entry_exports(matches: &ArgMatches, config: &DartDecimateConfig) -> bool {
|
|
55
|
+
matches
|
|
56
|
+
.try_get_one::<bool>("include-entry-exports")
|
|
57
|
+
.ok()
|
|
58
|
+
.flatten()
|
|
59
|
+
.copied()
|
|
60
|
+
.unwrap_or_default()
|
|
61
|
+
|| config.include_entry_exports
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
pub(super) fn private_type_leaks(matches: &ArgMatches, config: &DartDecimateConfig) -> bool {
|
|
65
|
+
matches
|
|
66
|
+
.try_get_one::<bool>("private-type-leaks")
|
|
67
|
+
.ok()
|
|
68
|
+
.flatten()
|
|
69
|
+
.copied()
|
|
70
|
+
.unwrap_or_default()
|
|
71
|
+
|| private_type_leaks_enabled(&config.rules)
|
|
72
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
use clap::{ArgMatches, parser::ValueSource};
|
|
2
|
+
|
|
3
|
+
use crate::config::{ConfigOutputFormat, DartDecimateConfig};
|
|
4
|
+
|
|
5
|
+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
6
|
+
pub(super) enum OutputFormat {
|
|
7
|
+
Human,
|
|
8
|
+
Json,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
12
|
+
pub(super) enum ReportOutputFormat {
|
|
13
|
+
Human,
|
|
14
|
+
Json,
|
|
15
|
+
Sarif,
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
pub(super) fn output_format(subcommand: &ArgMatches, config: &DartDecimateConfig) -> OutputFormat {
|
|
19
|
+
if subcommand.value_source("format") == Some(ValueSource::CommandLine) {
|
|
20
|
+
return output_format_value(subcommand);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
match config.output_format {
|
|
24
|
+
Some(ConfigOutputFormat::Json) => OutputFormat::Json,
|
|
25
|
+
Some(ConfigOutputFormat::Human) | None => output_format_value(subcommand),
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
pub(super) fn output_format_value(subcommand: &ArgMatches) -> OutputFormat {
|
|
30
|
+
match subcommand
|
|
31
|
+
.get_one::<String>("format")
|
|
32
|
+
.map_or("human", String::as_str)
|
|
33
|
+
{
|
|
34
|
+
"json" => OutputFormat::Json,
|
|
35
|
+
_ => OutputFormat::Human,
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
pub(super) fn report_output_format(
|
|
40
|
+
subcommand: &ArgMatches,
|
|
41
|
+
config: &DartDecimateConfig,
|
|
42
|
+
) -> ReportOutputFormat {
|
|
43
|
+
if subcommand.value_source("format") == Some(ValueSource::CommandLine) {
|
|
44
|
+
return report_output_format_value(subcommand);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
match config.output_format {
|
|
48
|
+
Some(ConfigOutputFormat::Json) => ReportOutputFormat::Json,
|
|
49
|
+
Some(ConfigOutputFormat::Human) | None => report_output_format_value(subcommand),
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
fn report_output_format_value(subcommand: &ArgMatches) -> ReportOutputFormat {
|
|
54
|
+
match subcommand
|
|
55
|
+
.get_one::<String>("format")
|
|
56
|
+
.map_or("human", String::as_str)
|
|
57
|
+
{
|
|
58
|
+
"json" => ReportOutputFormat::Json,
|
|
59
|
+
"sarif" => ReportOutputFormat::Sarif,
|
|
60
|
+
_ => ReportOutputFormat::Human,
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
use std::path::PathBuf;
|
|
2
|
+
|
|
3
|
+
use clap::{Arg, ArgAction, ArgMatches, Command, value_parser};
|
|
4
|
+
|
|
5
|
+
use crate::RegressionTolerance;
|
|
6
|
+
use crate::output::ReportCommand;
|
|
7
|
+
|
|
8
|
+
use super::CliError;
|
|
9
|
+
|
|
10
|
+
pub(super) const DEFAULT_REGRESSION_BASELINE: &str = ".dart-decimate/regression-baseline.json";
|
|
11
|
+
|
|
12
|
+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
13
|
+
pub(super) struct RegressionRequestArgs {
|
|
14
|
+
pub(super) tolerance: RegressionTolerance,
|
|
15
|
+
pub(super) fail_on_regression: bool,
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
pub(super) fn regression_command(command: Command) -> Command {
|
|
19
|
+
command
|
|
20
|
+
.arg(regression_baseline_arg())
|
|
21
|
+
.arg(save_regression_baseline_arg())
|
|
22
|
+
.arg(fail_on_regression_arg())
|
|
23
|
+
.arg(tolerance_arg())
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
pub(super) fn regression_baseline_path(
|
|
27
|
+
command: ReportCommand,
|
|
28
|
+
subcommand: &ArgMatches,
|
|
29
|
+
) -> Option<PathBuf> {
|
|
30
|
+
if !supports_regression(command) {
|
|
31
|
+
return None;
|
|
32
|
+
}
|
|
33
|
+
subcommand
|
|
34
|
+
.get_one::<PathBuf>("regression-baseline")
|
|
35
|
+
.cloned()
|
|
36
|
+
.or_else(|| {
|
|
37
|
+
subcommand
|
|
38
|
+
.get_flag("fail-on-regression")
|
|
39
|
+
.then(|| PathBuf::from(DEFAULT_REGRESSION_BASELINE))
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
pub(super) fn save_regression_baseline_path(
|
|
44
|
+
command: ReportCommand,
|
|
45
|
+
subcommand: &ArgMatches,
|
|
46
|
+
) -> Option<PathBuf> {
|
|
47
|
+
supports_regression(command)
|
|
48
|
+
.then(|| {
|
|
49
|
+
subcommand
|
|
50
|
+
.get_one::<PathBuf>("save-regression-baseline")
|
|
51
|
+
.cloned()
|
|
52
|
+
})
|
|
53
|
+
.flatten()
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
pub(super) fn regression_request_args(
|
|
57
|
+
command: ReportCommand,
|
|
58
|
+
subcommand: &ArgMatches,
|
|
59
|
+
) -> Result<RegressionRequestArgs, CliError> {
|
|
60
|
+
if !supports_regression(command) {
|
|
61
|
+
return Ok(RegressionRequestArgs {
|
|
62
|
+
tolerance: RegressionTolerance::default(),
|
|
63
|
+
fail_on_regression: false,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
Ok(RegressionRequestArgs {
|
|
67
|
+
tolerance: subcommand
|
|
68
|
+
.get_one::<String>("tolerance")
|
|
69
|
+
.map_or(Ok(RegressionTolerance::default()), |value| {
|
|
70
|
+
parse_tolerance(value)
|
|
71
|
+
})?,
|
|
72
|
+
fail_on_regression: subcommand.get_flag("fail-on-regression"),
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
fn regression_baseline_arg() -> Arg {
|
|
77
|
+
Arg::new("regression-baseline")
|
|
78
|
+
.long("regression-baseline")
|
|
79
|
+
.value_name("PATH")
|
|
80
|
+
.help("Compare current finding counts against a regression baseline")
|
|
81
|
+
.value_parser(value_parser!(PathBuf))
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
fn save_regression_baseline_arg() -> Arg {
|
|
85
|
+
Arg::new("save-regression-baseline")
|
|
86
|
+
.long("save-regression-baseline")
|
|
87
|
+
.value_name("PATH")
|
|
88
|
+
.help("Write current finding counts to a regression baseline")
|
|
89
|
+
.value_parser(value_parser!(PathBuf))
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
fn fail_on_regression_arg() -> Arg {
|
|
93
|
+
Arg::new("fail-on-regression")
|
|
94
|
+
.long("fail-on-regression")
|
|
95
|
+
.help("Exit non-zero only when finding counts exceed the regression baseline")
|
|
96
|
+
.action(ArgAction::SetTrue)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
fn tolerance_arg() -> Arg {
|
|
100
|
+
Arg::new("tolerance")
|
|
101
|
+
.long("tolerance")
|
|
102
|
+
.value_name("COUNT_OR_PERCENT")
|
|
103
|
+
.help("Allowed count increase for --fail-on-regression, such as 0, 2, or 10%")
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
fn supports_regression(command: ReportCommand) -> bool {
|
|
107
|
+
matches!(
|
|
108
|
+
command,
|
|
109
|
+
ReportCommand::Check
|
|
110
|
+
| ReportCommand::DeadCode
|
|
111
|
+
| ReportCommand::Cycles
|
|
112
|
+
| ReportCommand::Dupes
|
|
113
|
+
| ReportCommand::Health
|
|
114
|
+
| ReportCommand::Flags
|
|
115
|
+
| ReportCommand::Security
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
fn parse_tolerance(value: &str) -> Result<RegressionTolerance, CliError> {
|
|
120
|
+
let value = value.trim();
|
|
121
|
+
if let Some(percent) = value.strip_suffix('%') {
|
|
122
|
+
return parse_percent_tolerance(percent).map(RegressionTolerance::PercentBasisPoints);
|
|
123
|
+
}
|
|
124
|
+
value
|
|
125
|
+
.parse::<usize>()
|
|
126
|
+
.map(RegressionTolerance::Absolute)
|
|
127
|
+
.map_err(|_| CliError::Tolerance {
|
|
128
|
+
value: value.to_owned(),
|
|
129
|
+
})
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
fn parse_percent_tolerance(value: &str) -> Result<u32, CliError> {
|
|
133
|
+
let value = value.trim();
|
|
134
|
+
let Some((whole, fraction)) = value.split_once('.') else {
|
|
135
|
+
return value
|
|
136
|
+
.parse::<u32>()
|
|
137
|
+
.map(|whole| whole.saturating_mul(100))
|
|
138
|
+
.map_err(|_| CliError::Tolerance {
|
|
139
|
+
value: format!("{value}%"),
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
if fraction.len() > 2 || whole.is_empty() || fraction.is_empty() {
|
|
143
|
+
return Err(CliError::Tolerance {
|
|
144
|
+
value: format!("{value}%"),
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
let whole = whole.parse::<u32>().map_err(|_| CliError::Tolerance {
|
|
148
|
+
value: format!("{value}%"),
|
|
149
|
+
})?;
|
|
150
|
+
let fraction = format!("{fraction:0<2}")
|
|
151
|
+
.parse::<u32>()
|
|
152
|
+
.map_err(|_| CliError::Tolerance {
|
|
153
|
+
value: format!("{value}%"),
|
|
154
|
+
})?;
|
|
155
|
+
Ok(whole.saturating_mul(100).saturating_add(fraction))
|
|
156
|
+
}
|