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,99 @@
|
|
|
1
|
+
use std::io::Write;
|
|
2
|
+
|
|
3
|
+
use clap::{Arg, ArgMatches, Command, value_parser};
|
|
4
|
+
|
|
5
|
+
use crate::changed_scope::changed_files;
|
|
6
|
+
use crate::decision_surface::{
|
|
7
|
+
decision_surface_report_for_command, render_decision_surface_report,
|
|
8
|
+
};
|
|
9
|
+
use crate::scan::{ScanOptions, scan_project_with_options};
|
|
10
|
+
|
|
11
|
+
use super::common_args::{config_arg, format_arg, root_arg, root_flag_arg, root_path};
|
|
12
|
+
use super::{CliError, OutputFormat};
|
|
13
|
+
|
|
14
|
+
pub(super) fn decision_surface_command() -> Command {
|
|
15
|
+
decision_surface_command_named(
|
|
16
|
+
"decision-surface",
|
|
17
|
+
"Surface changed-code structural decisions for review",
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
pub(super) fn review_command() -> Command {
|
|
22
|
+
decision_surface_command_named(
|
|
23
|
+
"review",
|
|
24
|
+
"Review changed-code structural decisions without failing CI",
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
pub(super) fn max_decisions_arg() -> Arg {
|
|
29
|
+
Arg::new("max-decisions")
|
|
30
|
+
.long("max-decisions")
|
|
31
|
+
.value_name("N")
|
|
32
|
+
.help("Maximum decisions to emit")
|
|
33
|
+
.default_value("5")
|
|
34
|
+
.value_parser(value_parser!(usize))
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
fn decision_surface_command_named(name: &'static str, about: &'static str) -> Command {
|
|
38
|
+
Command::new(name)
|
|
39
|
+
.about(about)
|
|
40
|
+
.arg(root_arg())
|
|
41
|
+
.arg(root_flag_arg())
|
|
42
|
+
.arg(format_arg())
|
|
43
|
+
.arg(config_arg())
|
|
44
|
+
.arg(
|
|
45
|
+
Arg::new("base")
|
|
46
|
+
.long("base")
|
|
47
|
+
.value_name("REF")
|
|
48
|
+
.help("Git ref used to scope changed files")
|
|
49
|
+
.required(true),
|
|
50
|
+
)
|
|
51
|
+
.arg(max_decisions_arg())
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
pub(super) fn run_decision_surface<W: Write>(
|
|
55
|
+
subcommand: &ArgMatches,
|
|
56
|
+
mut writer: W,
|
|
57
|
+
command: &str,
|
|
58
|
+
) -> Result<i32, CliError> {
|
|
59
|
+
let root = root_path(subcommand);
|
|
60
|
+
let config = super::load_config(&root, subcommand)?;
|
|
61
|
+
let project = scan_project_with_options(
|
|
62
|
+
&root,
|
|
63
|
+
&ScanOptions {
|
|
64
|
+
ignore_patterns: config.ignore_patterns.clone(),
|
|
65
|
+
..ScanOptions::default()
|
|
66
|
+
},
|
|
67
|
+
)?;
|
|
68
|
+
let Some(base) = subcommand.get_one::<String>("base") else {
|
|
69
|
+
unreachable!("clap requires --base for decision-surface");
|
|
70
|
+
};
|
|
71
|
+
let changed = changed_files(&project.root, base)?;
|
|
72
|
+
let max_decisions = subcommand
|
|
73
|
+
.get_one::<usize>("max-decisions")
|
|
74
|
+
.copied()
|
|
75
|
+
.unwrap_or(5);
|
|
76
|
+
let report =
|
|
77
|
+
decision_surface_report_for_command(&project, base, &changed, max_decisions, command);
|
|
78
|
+
|
|
79
|
+
match output_format(subcommand) {
|
|
80
|
+
OutputFormat::Human => {
|
|
81
|
+
writer.write_all(render_decision_surface_report(&report).as_bytes())?;
|
|
82
|
+
}
|
|
83
|
+
OutputFormat::Json => {
|
|
84
|
+
serde_json::to_writer_pretty(&mut writer, &report)?;
|
|
85
|
+
writeln!(writer)?;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
Ok(0)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
fn output_format(subcommand: &ArgMatches) -> OutputFormat {
|
|
92
|
+
match subcommand
|
|
93
|
+
.get_one::<String>("format")
|
|
94
|
+
.map_or("human", String::as_str)
|
|
95
|
+
{
|
|
96
|
+
"json" => OutputFormat::Json,
|
|
97
|
+
_ => OutputFormat::Human,
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
use std::ffi::OsString;
|
|
2
|
+
|
|
3
|
+
const COMMANDS: &[&str] = &[
|
|
4
|
+
"audit",
|
|
5
|
+
"check",
|
|
6
|
+
"ci",
|
|
7
|
+
"ci-template",
|
|
8
|
+
"config",
|
|
9
|
+
"config-schema",
|
|
10
|
+
"coverage",
|
|
11
|
+
"cycles",
|
|
12
|
+
"dead-code",
|
|
13
|
+
"decision-surface",
|
|
14
|
+
"dupes",
|
|
15
|
+
"explain",
|
|
16
|
+
"fix",
|
|
17
|
+
"flags",
|
|
18
|
+
"health",
|
|
19
|
+
"hooks",
|
|
20
|
+
"impact",
|
|
21
|
+
"init",
|
|
22
|
+
"inspect",
|
|
23
|
+
"license",
|
|
24
|
+
"list",
|
|
25
|
+
"migrate",
|
|
26
|
+
"report-schema",
|
|
27
|
+
"review",
|
|
28
|
+
"rule-pack-schema",
|
|
29
|
+
"schema",
|
|
30
|
+
"security",
|
|
31
|
+
"setup-hooks",
|
|
32
|
+
"telemetry",
|
|
33
|
+
"trace",
|
|
34
|
+
"trace-clone",
|
|
35
|
+
"trace-dependency",
|
|
36
|
+
"trace-file",
|
|
37
|
+
"trace-symbol",
|
|
38
|
+
"watch",
|
|
39
|
+
"workspaces",
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
pub(super) fn args_with_default_check<I, T>(args: I) -> Vec<OsString>
|
|
43
|
+
where
|
|
44
|
+
I: IntoIterator<Item = T>,
|
|
45
|
+
T: Into<OsString>,
|
|
46
|
+
{
|
|
47
|
+
let mut args = args.into_iter().map(Into::into).collect::<Vec<_>>();
|
|
48
|
+
if should_insert_check(&args) {
|
|
49
|
+
args.insert(1, OsString::from("check"));
|
|
50
|
+
}
|
|
51
|
+
args
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
fn should_insert_check(args: &[OsString]) -> bool {
|
|
55
|
+
let Some(first) = args.get(1).and_then(|arg| arg.to_str()) else {
|
|
56
|
+
return args.len() == 1;
|
|
57
|
+
};
|
|
58
|
+
if matches!(first, "-h" | "--help" | "-V" | "--version") {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
first_non_flag(args).is_none_or(|candidate| !COMMANDS.contains(&candidate))
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
fn first_non_flag(args: &[OsString]) -> Option<&str> {
|
|
65
|
+
args.iter()
|
|
66
|
+
.skip(1)
|
|
67
|
+
.filter_map(|arg| arg.to_str())
|
|
68
|
+
.find(|arg| !arg.starts_with('-'))
|
|
69
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
use clap::{Arg, ArgAction, ArgMatches, Command, parser::ValueSource, value_parser};
|
|
2
|
+
|
|
3
|
+
use crate::{DuplicateMode, DuplicateOptions, DuplicationThreshold};
|
|
4
|
+
|
|
5
|
+
use super::CliError;
|
|
6
|
+
|
|
7
|
+
pub(super) fn dupes_command(command: Command) -> Command {
|
|
8
|
+
command
|
|
9
|
+
.arg(
|
|
10
|
+
Arg::new("mode")
|
|
11
|
+
.long("mode")
|
|
12
|
+
.value_name("MODE")
|
|
13
|
+
.help("Detection mode")
|
|
14
|
+
.default_value("mild")
|
|
15
|
+
.value_parser(["strict", "mild", "weak", "semantic"]),
|
|
16
|
+
)
|
|
17
|
+
.arg(
|
|
18
|
+
Arg::new("min-tokens")
|
|
19
|
+
.long("min-tokens")
|
|
20
|
+
.value_name("N")
|
|
21
|
+
.help("Minimum tokens per clone")
|
|
22
|
+
.default_value("50")
|
|
23
|
+
.value_parser(value_parser!(usize)),
|
|
24
|
+
)
|
|
25
|
+
.arg(
|
|
26
|
+
Arg::new("min-lines")
|
|
27
|
+
.long("min-lines")
|
|
28
|
+
.value_name("N")
|
|
29
|
+
.help("Minimum lines per clone")
|
|
30
|
+
.default_value("5")
|
|
31
|
+
.value_parser(value_parser!(usize)),
|
|
32
|
+
)
|
|
33
|
+
.arg(
|
|
34
|
+
Arg::new("min-occurrences")
|
|
35
|
+
.long("min-occurrences")
|
|
36
|
+
.value_name("N")
|
|
37
|
+
.help("Minimum clone instances per group")
|
|
38
|
+
.default_value("2")
|
|
39
|
+
.value_parser(value_parser!(usize)),
|
|
40
|
+
)
|
|
41
|
+
.arg(
|
|
42
|
+
Arg::new("top")
|
|
43
|
+
.long("top")
|
|
44
|
+
.value_name("N")
|
|
45
|
+
.help("Show only the N largest clone groups")
|
|
46
|
+
.value_parser(value_parser!(usize)),
|
|
47
|
+
)
|
|
48
|
+
.arg(
|
|
49
|
+
Arg::new("threshold")
|
|
50
|
+
.long("threshold")
|
|
51
|
+
.value_name("PERCENT")
|
|
52
|
+
.help("Fail when duplicated Dart lines exceed this percentage")
|
|
53
|
+
.value_parser(parse_threshold),
|
|
54
|
+
)
|
|
55
|
+
.arg(
|
|
56
|
+
Arg::new("skip-local")
|
|
57
|
+
.long("skip-local")
|
|
58
|
+
.help("Only report cross-directory duplicates")
|
|
59
|
+
.action(ArgAction::SetTrue),
|
|
60
|
+
)
|
|
61
|
+
.arg(
|
|
62
|
+
Arg::new("cross-language")
|
|
63
|
+
.long("cross-language")
|
|
64
|
+
.help("Unsupported for Dart-only analysis")
|
|
65
|
+
.action(ArgAction::SetTrue),
|
|
66
|
+
)
|
|
67
|
+
.arg(
|
|
68
|
+
Arg::new("no-ignore-imports")
|
|
69
|
+
.long("no-ignore-imports")
|
|
70
|
+
.help("Count import/export/part/library directives")
|
|
71
|
+
.action(ArgAction::SetTrue)
|
|
72
|
+
.conflicts_with("ignore-imports"),
|
|
73
|
+
)
|
|
74
|
+
.arg(
|
|
75
|
+
Arg::new("ignore-imports")
|
|
76
|
+
.long("ignore-imports")
|
|
77
|
+
.help("Ignore import/export/part/library directives")
|
|
78
|
+
.action(ArgAction::SetTrue)
|
|
79
|
+
.conflicts_with("no-ignore-imports"),
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
pub(super) fn trace_clone_command(command: Command) -> Command {
|
|
84
|
+
command.arg(
|
|
85
|
+
Arg::new("fingerprint")
|
|
86
|
+
.long("fingerprint")
|
|
87
|
+
.alias("trace")
|
|
88
|
+
.value_name("TRACE")
|
|
89
|
+
.help("Clone fingerprint or FILE:LINE selector")
|
|
90
|
+
.required(true),
|
|
91
|
+
)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
pub(super) fn duplicate_options_with_defaults(
|
|
95
|
+
matches: &ArgMatches,
|
|
96
|
+
mut options: DuplicateOptions,
|
|
97
|
+
) -> Result<DuplicateOptions, CliError> {
|
|
98
|
+
if is_command_line(matches, "cross-language") && matches.get_flag("cross-language") {
|
|
99
|
+
return Err(CliError::UnsupportedCrossLanguageDupes);
|
|
100
|
+
}
|
|
101
|
+
if is_command_line(matches, "mode") {
|
|
102
|
+
if let Some(mode) = matches.get_one::<String>("mode") {
|
|
103
|
+
options.mode = DuplicateMode::parse(mode).unwrap_or(DuplicateMode::Mild);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if is_command_line(matches, "min-tokens") {
|
|
107
|
+
if let Some(min_tokens) = matches.get_one::<usize>("min-tokens") {
|
|
108
|
+
options.min_tokens = *min_tokens;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if is_command_line(matches, "min-lines") {
|
|
112
|
+
if let Some(min_lines) = matches.get_one::<usize>("min-lines") {
|
|
113
|
+
options.min_lines = *min_lines;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if is_command_line(matches, "min-occurrences") {
|
|
117
|
+
if let Some(min_occurrences) = matches.get_one::<usize>("min-occurrences") {
|
|
118
|
+
options.min_occurrences = (*min_occurrences).max(2);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if is_command_line(matches, "top") {
|
|
122
|
+
options.top = matches.get_one::<usize>("top").copied();
|
|
123
|
+
}
|
|
124
|
+
if is_command_line(matches, "threshold") {
|
|
125
|
+
options.threshold = matches
|
|
126
|
+
.get_one::<DuplicationThreshold>("threshold")
|
|
127
|
+
.copied();
|
|
128
|
+
}
|
|
129
|
+
if is_command_line(matches, "skip-local") {
|
|
130
|
+
options.skip_local = matches.get_flag("skip-local");
|
|
131
|
+
}
|
|
132
|
+
if is_command_line(matches, "ignore-imports") {
|
|
133
|
+
options.ignore_imports = matches.get_flag("ignore-imports");
|
|
134
|
+
}
|
|
135
|
+
if is_command_line(matches, "no-ignore-imports") {
|
|
136
|
+
options.ignore_imports = !matches.get_flag("no-ignore-imports");
|
|
137
|
+
}
|
|
138
|
+
Ok(options)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
fn is_command_line(matches: &ArgMatches, id: &str) -> bool {
|
|
142
|
+
matches.value_source(id) == Some(ValueSource::CommandLine)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
fn parse_threshold(value: &str) -> Result<DuplicationThreshold, String> {
|
|
146
|
+
value
|
|
147
|
+
.parse::<f64>()
|
|
148
|
+
.map_err(|_| "threshold must be a percentage from 0 to 100".to_owned())
|
|
149
|
+
.and_then(DuplicationThreshold::from_percent)
|
|
150
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
use std::path::{Component, Path, PathBuf};
|
|
2
|
+
|
|
3
|
+
use super::CliError;
|
|
4
|
+
use crate::scan::ScannedProject;
|
|
5
|
+
|
|
6
|
+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
7
|
+
pub(super) enum EntryPointMode {
|
|
8
|
+
All,
|
|
9
|
+
Production,
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
pub(super) fn entry_points_for_check(
|
|
13
|
+
project: &ScannedProject,
|
|
14
|
+
explicit: &[PathBuf],
|
|
15
|
+
mode: EntryPointMode,
|
|
16
|
+
) -> Vec<PathBuf> {
|
|
17
|
+
if explicit.is_empty() {
|
|
18
|
+
default_entry_points(project, mode)
|
|
19
|
+
} else {
|
|
20
|
+
explicit.to_vec()
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
pub(super) fn entry_points_for_dead_code(
|
|
25
|
+
project: &ScannedProject,
|
|
26
|
+
explicit: &[PathBuf],
|
|
27
|
+
mode: EntryPointMode,
|
|
28
|
+
) -> Result<Vec<PathBuf>, CliError> {
|
|
29
|
+
let entries = entry_points_for_check(project, explicit, mode);
|
|
30
|
+
if entries.is_empty() {
|
|
31
|
+
return Err(CliError::MissingEntryPoints {
|
|
32
|
+
root: project.root.clone(),
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
Ok(entries)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
fn default_entry_points(project: &ScannedProject, mode: EntryPointMode) -> Vec<PathBuf> {
|
|
39
|
+
let mut entries = project
|
|
40
|
+
.files
|
|
41
|
+
.iter()
|
|
42
|
+
.filter(|file| is_default_entry_point(&project.root, &file.path, mode))
|
|
43
|
+
.map(|file| file.path.clone())
|
|
44
|
+
.collect::<Vec<_>>();
|
|
45
|
+
entries.sort();
|
|
46
|
+
entries
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
fn is_default_entry_point(root: &Path, path: &Path, mode: EntryPointMode) -> bool {
|
|
50
|
+
let relative = path.strip_prefix(root).unwrap_or(path);
|
|
51
|
+
is_public_library_entry_point(relative)
|
|
52
|
+
|| has_path_suffix(relative, &["lib", "main.dart"])
|
|
53
|
+
|| is_bin_entry_point(relative)
|
|
54
|
+
|| (mode == EntryPointMode::All
|
|
55
|
+
&& (is_direct_script_entry_point(relative) || is_test_entry_point(relative)))
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
fn is_public_library_entry_point(path: &Path) -> bool {
|
|
59
|
+
let mut components = path.components();
|
|
60
|
+
components
|
|
61
|
+
.next()
|
|
62
|
+
.is_some_and(|component| component.as_os_str() == "lib")
|
|
63
|
+
&& components
|
|
64
|
+
.next()
|
|
65
|
+
.is_none_or(|component| component.as_os_str() != "src")
|
|
66
|
+
&& path
|
|
67
|
+
.extension()
|
|
68
|
+
.is_some_and(|extension| extension == "dart")
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
fn is_bin_entry_point(path: &Path) -> bool {
|
|
72
|
+
path.extension()
|
|
73
|
+
.is_some_and(|extension| extension == "dart")
|
|
74
|
+
&& path
|
|
75
|
+
.parent()
|
|
76
|
+
.and_then(Path::file_name)
|
|
77
|
+
.is_some_and(|name| name == "bin")
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
fn is_direct_script_entry_point(path: &Path) -> bool {
|
|
81
|
+
path.extension()
|
|
82
|
+
.is_some_and(|extension| extension == "dart")
|
|
83
|
+
&& path.parent().and_then(Path::file_name).is_some_and(|name| {
|
|
84
|
+
matches!(
|
|
85
|
+
name.to_str(),
|
|
86
|
+
Some("test" | "integration_test" | "test_driver" | "tool" | "pigeon")
|
|
87
|
+
)
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
fn is_test_entry_point(path: &Path) -> bool {
|
|
92
|
+
let file_name = path.file_name().and_then(|name| name.to_str());
|
|
93
|
+
let is_test_file = file_name.is_some_and(|name| name.ends_with("_test.dart"));
|
|
94
|
+
is_test_file
|
|
95
|
+
&& path.components().any(|component| {
|
|
96
|
+
matches!(
|
|
97
|
+
component,
|
|
98
|
+
Component::Normal(name)
|
|
99
|
+
if name == "test" || name == "integration_test" || name == "test_driver"
|
|
100
|
+
)
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
fn has_path_suffix(path: &Path, suffix: &[&str]) -> bool {
|
|
105
|
+
if suffix.is_empty() {
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
let components = path
|
|
110
|
+
.components()
|
|
111
|
+
.filter_map(|component| match component {
|
|
112
|
+
Component::Normal(value) => value.to_str(),
|
|
113
|
+
_ => None,
|
|
114
|
+
})
|
|
115
|
+
.collect::<Vec<_>>();
|
|
116
|
+
|
|
117
|
+
components
|
|
118
|
+
.windows(suffix.len())
|
|
119
|
+
.last()
|
|
120
|
+
.is_some_and(|window| window == suffix)
|
|
121
|
+
}
|
package/src/cli/error.rs
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
use std::io;
|
|
2
|
+
use std::path::PathBuf;
|
|
3
|
+
|
|
4
|
+
use thiserror::Error;
|
|
5
|
+
|
|
6
|
+
use crate::baseline::BaselineError;
|
|
7
|
+
use crate::changed_scope::ChangedScopeError;
|
|
8
|
+
use crate::config::ConfigError;
|
|
9
|
+
use crate::scan::ScanError;
|
|
10
|
+
use crate::{
|
|
11
|
+
DependencyHygieneError, DuplicateCodeError, FeatureFlagError, HealthError, PolicyError,
|
|
12
|
+
SecurityError, WidgetAnalysisError, WorkspaceScopeError,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/// CLI execution errors.
|
|
16
|
+
#[derive(Debug, Error)]
|
|
17
|
+
pub enum CliError {
|
|
18
|
+
/// Argument parsing failed.
|
|
19
|
+
#[error(transparent)]
|
|
20
|
+
Clap(#[from] clap::Error),
|
|
21
|
+
/// Project scanning failed.
|
|
22
|
+
#[error(transparent)]
|
|
23
|
+
Scan(#[from] ScanError),
|
|
24
|
+
/// Dependency hygiene analysis failed.
|
|
25
|
+
#[error(transparent)]
|
|
26
|
+
DependencyHygiene(#[from] DependencyHygieneError),
|
|
27
|
+
/// Duplicate-code analysis failed.
|
|
28
|
+
#[error(transparent)]
|
|
29
|
+
DuplicateCode(#[from] DuplicateCodeError),
|
|
30
|
+
/// Health analysis failed.
|
|
31
|
+
#[error(transparent)]
|
|
32
|
+
Health(#[from] HealthError),
|
|
33
|
+
/// Feature flag analysis failed.
|
|
34
|
+
#[error(transparent)]
|
|
35
|
+
FeatureFlags(#[from] FeatureFlagError),
|
|
36
|
+
/// Security candidate analysis failed.
|
|
37
|
+
#[error(transparent)]
|
|
38
|
+
Security(#[from] SecurityError),
|
|
39
|
+
/// Flutter widget parameter analysis failed.
|
|
40
|
+
#[error(transparent)]
|
|
41
|
+
Widgets(#[from] WidgetAnalysisError),
|
|
42
|
+
/// Security top truncation cannot safely run before changed-line scoping.
|
|
43
|
+
#[error(
|
|
44
|
+
"security --top cannot be combined with --gate, --diff-file, --diff-stdin, or --changed-since"
|
|
45
|
+
)]
|
|
46
|
+
UnsupportedSecurityTopScope,
|
|
47
|
+
/// Cross-language duplicate detection is JavaScript/TypeScript-specific in Fallow.
|
|
48
|
+
#[error("dupes --cross-language is not supported for Dart-only analysis")]
|
|
49
|
+
UnsupportedCrossLanguageDupes,
|
|
50
|
+
/// User-level agent hook installation is intentionally not supported.
|
|
51
|
+
#[error(
|
|
52
|
+
"setup-hooks --user is not supported; Dart Decimate only manages repo-local agent hooks"
|
|
53
|
+
)]
|
|
54
|
+
UnsupportedSetupHooksUser,
|
|
55
|
+
/// Mutating `.gitignore` from setup-hooks is intentionally not supported.
|
|
56
|
+
#[error("setup-hooks --gitignore-claude is not supported; update .gitignore explicitly")]
|
|
57
|
+
UnsupportedSetupHooksGitignoreClaude,
|
|
58
|
+
/// Security review gate could not be applied.
|
|
59
|
+
#[error(transparent)]
|
|
60
|
+
SecurityGate(#[from] crate::security_gate::SecurityGateError),
|
|
61
|
+
/// Changed-file scope could not be computed.
|
|
62
|
+
#[error(transparent)]
|
|
63
|
+
ChangedScope(#[from] ChangedScopeError),
|
|
64
|
+
/// Workspace scope could not be computed.
|
|
65
|
+
#[error(transparent)]
|
|
66
|
+
WorkspaceScope(#[from] WorkspaceScopeError),
|
|
67
|
+
/// Dart Decimate config could not be loaded.
|
|
68
|
+
#[error(transparent)]
|
|
69
|
+
Config(#[from] ConfigError),
|
|
70
|
+
/// Dart Decimate rule config could not be applied.
|
|
71
|
+
#[error(transparent)]
|
|
72
|
+
Rule(#[from] crate::config::RuleError),
|
|
73
|
+
/// Finding baseline could not be loaded or saved.
|
|
74
|
+
#[error(transparent)]
|
|
75
|
+
Baseline(#[from] BaselineError),
|
|
76
|
+
/// Regression tolerance syntax was invalid.
|
|
77
|
+
#[error("invalid regression tolerance {value:?}; expected COUNT or PERCENT like 2 or 10%")]
|
|
78
|
+
Tolerance {
|
|
79
|
+
/// Raw tolerance value.
|
|
80
|
+
value: String,
|
|
81
|
+
},
|
|
82
|
+
/// JSON rendering failed.
|
|
83
|
+
#[error(transparent)]
|
|
84
|
+
Json(#[from] serde_json::Error),
|
|
85
|
+
/// Output writing failed.
|
|
86
|
+
#[error(transparent)]
|
|
87
|
+
Io(#[from] io::Error),
|
|
88
|
+
/// Boundary rule syntax was invalid.
|
|
89
|
+
#[error("invalid boundary rule {value:?}; expected FROM:DISALLOW")]
|
|
90
|
+
BoundaryRule {
|
|
91
|
+
/// Raw boundary argument.
|
|
92
|
+
value: String,
|
|
93
|
+
},
|
|
94
|
+
/// Boundary call rule syntax was invalid.
|
|
95
|
+
#[error("invalid boundary call rule {value:?}; expected FROM:PATTERN")]
|
|
96
|
+
BoundaryCallRule {
|
|
97
|
+
/// Raw boundary call argument.
|
|
98
|
+
value: String,
|
|
99
|
+
},
|
|
100
|
+
/// Policy pack loading or analysis failed.
|
|
101
|
+
#[error(transparent)]
|
|
102
|
+
Policy(#[from] PolicyError),
|
|
103
|
+
/// Trace-file target was missing after argument parsing.
|
|
104
|
+
#[error("trace-file requires --file PATH")]
|
|
105
|
+
MissingTraceFile,
|
|
106
|
+
/// Trace-dependency package was missing after argument parsing.
|
|
107
|
+
#[error("trace-dependency requires --dependency PACKAGE")]
|
|
108
|
+
MissingTraceDependency,
|
|
109
|
+
/// Inspect target was missing after argument parsing.
|
|
110
|
+
#[error("inspect requires --file PATH or --symbol FILE:SYMBOL")]
|
|
111
|
+
MissingInspectTarget,
|
|
112
|
+
/// Symbol trace syntax was invalid.
|
|
113
|
+
#[error("invalid trace symbol {value:?}; expected FILE:SYMBOL or --file FILE --symbol SYMBOL")]
|
|
114
|
+
TraceSymbol {
|
|
115
|
+
/// Raw symbol trace argument.
|
|
116
|
+
value: String,
|
|
117
|
+
},
|
|
118
|
+
/// Dead-code analysis did not have any entry points.
|
|
119
|
+
#[error("no entry points provided and no default Dart entry points found under {root}")]
|
|
120
|
+
MissingEntryPoints {
|
|
121
|
+
/// Project root.
|
|
122
|
+
root: PathBuf,
|
|
123
|
+
},
|
|
124
|
+
#[error("coverage analyze requires --runtime-coverage PATH")]
|
|
125
|
+
MissingRuntimeCoverage,
|
|
126
|
+
#[error("cloud runtime coverage is not supported yet; provide --runtime-coverage PATH")]
|
|
127
|
+
UnsupportedCoverageCloud,
|
|
128
|
+
#[error("{command} is offline-only in this release; pass --dry-run")]
|
|
129
|
+
CoverageUploadDryRunRequired { command: &'static str },
|
|
130
|
+
#[error("coverage upload-source-maps directory does not exist: {path}")]
|
|
131
|
+
CoverageUploadDir { path: PathBuf },
|
|
132
|
+
#[error("invalid coverage upload git SHA {value:?}; expected 7 to 40 hex characters")]
|
|
133
|
+
CoverageUploadGitSha { value: String },
|
|
134
|
+
#[error("invalid coverage upload repo {value:?}; expected OWNER/REPO")]
|
|
135
|
+
CoverageUploadRepo { value: String },
|
|
136
|
+
#[error("ci reconcile-review requires --envelope PATH")]
|
|
137
|
+
MissingCiReviewEnvelope,
|
|
138
|
+
#[error(transparent)]
|
|
139
|
+
CiTemplate(#[from] crate::CiTemplateError),
|
|
140
|
+
/// Project initialization failed.
|
|
141
|
+
#[error(transparent)]
|
|
142
|
+
Init(#[from] crate::InitError),
|
|
143
|
+
/// Hook management failed.
|
|
144
|
+
#[error(transparent)]
|
|
145
|
+
Hooks(#[from] crate::HooksError),
|
|
146
|
+
/// SARIF output is not available for this command.
|
|
147
|
+
#[error("--format sarif is not supported by dart-decimate {command}")]
|
|
148
|
+
UnsupportedSarifFormat { command: &'static str },
|
|
149
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
use std::ffi::OsString;
|
|
2
|
+
use std::io::{self, Write};
|
|
3
|
+
|
|
4
|
+
use serde::Serialize;
|
|
5
|
+
|
|
6
|
+
use super::{CliError, run_from};
|
|
7
|
+
|
|
8
|
+
/// Run Dart Decimate from process arguments and return an exit code.
|
|
9
|
+
#[must_use]
|
|
10
|
+
pub fn run_from_env() -> i32 {
|
|
11
|
+
let args = std::env::args_os().collect::<Vec<_>>();
|
|
12
|
+
let json_requested = format_json_requested(&args);
|
|
13
|
+
|
|
14
|
+
match run_from(args, io::stdout().lock()) {
|
|
15
|
+
Ok(code) => code,
|
|
16
|
+
Err(CliError::Clap(error)) if json_requested => {
|
|
17
|
+
let code = error.exit_code();
|
|
18
|
+
let _ = write_json_error(io::stdout().lock(), &error.to_string(), code);
|
|
19
|
+
code
|
|
20
|
+
}
|
|
21
|
+
Err(CliError::Clap(error)) => {
|
|
22
|
+
let code = error.exit_code();
|
|
23
|
+
let _ = error.print();
|
|
24
|
+
code
|
|
25
|
+
}
|
|
26
|
+
Err(error) if json_requested => {
|
|
27
|
+
let code = 2;
|
|
28
|
+
let _ = write_json_error(io::stdout().lock(), &error.to_string(), code);
|
|
29
|
+
code
|
|
30
|
+
}
|
|
31
|
+
Err(error) => {
|
|
32
|
+
eprintln!("{error}");
|
|
33
|
+
2
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
fn format_json_requested(args: &[OsString]) -> bool {
|
|
39
|
+
let mut args = args.iter().skip(1).filter_map(|arg| arg.to_str());
|
|
40
|
+
while let Some(arg) = args.next() {
|
|
41
|
+
if arg == "--format" && args.next().is_some_and(|value| value == "json") {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
if arg == "--format=json" {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
false
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
fn write_json_error<W: Write>(mut writer: W, message: &str, exit_code: i32) -> io::Result<()> {
|
|
52
|
+
serde_json::to_writer_pretty(
|
|
53
|
+
&mut writer,
|
|
54
|
+
&JsonError {
|
|
55
|
+
error: true,
|
|
56
|
+
message,
|
|
57
|
+
exit_code,
|
|
58
|
+
},
|
|
59
|
+
)?;
|
|
60
|
+
writeln!(writer)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
#[derive(Debug, Serialize)]
|
|
64
|
+
struct JsonError<'a> {
|
|
65
|
+
error: bool,
|
|
66
|
+
message: &'a str,
|
|
67
|
+
exit_code: i32,
|
|
68
|
+
}
|