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,257 @@
|
|
|
1
|
+
use std::path::Path;
|
|
2
|
+
|
|
3
|
+
use super::format::{declaration_kind, display_path};
|
|
4
|
+
use super::{Finding, FindingAction, FindingKind, Severity, SymbolReport};
|
|
5
|
+
use crate::{
|
|
6
|
+
DeclarationKind, DuplicateExport, MemberKind, PrivateTypeLeak, UnusedExport, UnusedMember,
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
pub(super) fn add_symbol_findings(root: &Path, report: &SymbolReport, findings: &mut Vec<Finding>) {
|
|
10
|
+
findings.extend(
|
|
11
|
+
report
|
|
12
|
+
.unused_exports
|
|
13
|
+
.iter()
|
|
14
|
+
.map(|unused| unused_export_finding(root, unused)),
|
|
15
|
+
);
|
|
16
|
+
findings.extend(
|
|
17
|
+
report
|
|
18
|
+
.duplicate_exports
|
|
19
|
+
.iter()
|
|
20
|
+
.map(|duplicate| duplicate_export_finding(root, duplicate)),
|
|
21
|
+
);
|
|
22
|
+
findings.extend(
|
|
23
|
+
report
|
|
24
|
+
.private_type_leaks
|
|
25
|
+
.iter()
|
|
26
|
+
.map(|leak| private_type_leak_finding(root, leak)),
|
|
27
|
+
);
|
|
28
|
+
findings.extend(
|
|
29
|
+
report
|
|
30
|
+
.unused_members
|
|
31
|
+
.iter()
|
|
32
|
+
.map(|unused| unused_member_finding(root, unused)),
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
fn private_type_leak_finding(root: &Path, leak: &PrivateTypeLeak) -> Finding {
|
|
37
|
+
let path = display_path(root, &leak.path);
|
|
38
|
+
let symbol_target = format!("{path}:{}", leak.declaration);
|
|
39
|
+
Finding {
|
|
40
|
+
rule_id: "dart-decimate/private-type-leak".to_owned(),
|
|
41
|
+
fingerprint: None,
|
|
42
|
+
kind: FindingKind::PrivateTypeLeak,
|
|
43
|
+
severity: Severity::Error,
|
|
44
|
+
message: format!(
|
|
45
|
+
"Public {} signature exposes private Dart library type {}: {}",
|
|
46
|
+
declaration_kind(leak.declaration_kind),
|
|
47
|
+
leak.private_type,
|
|
48
|
+
leak.declaration
|
|
49
|
+
),
|
|
50
|
+
path: path.clone(),
|
|
51
|
+
line: leak.location.line,
|
|
52
|
+
column: leak.location.column,
|
|
53
|
+
safe_to_delete: leak.safe_to_delete,
|
|
54
|
+
files: Vec::new(),
|
|
55
|
+
edge: None,
|
|
56
|
+
actions: vec![
|
|
57
|
+
FindingAction::new(
|
|
58
|
+
"review-public-api",
|
|
59
|
+
"Rename the private type, hide this declaration, or expose a public signature type",
|
|
60
|
+
false,
|
|
61
|
+
)
|
|
62
|
+
.with_target_path(path.clone())
|
|
63
|
+
.with_target_symbol(leak.declaration.clone())
|
|
64
|
+
.with_dart_decimate_args([
|
|
65
|
+
"inspect",
|
|
66
|
+
"--format",
|
|
67
|
+
"json",
|
|
68
|
+
"--symbol",
|
|
69
|
+
symbol_target.as_str(),
|
|
70
|
+
])
|
|
71
|
+
.with_suppression_comment("// dart-decimate-ignore-next-line private-type-leak"),
|
|
72
|
+
],
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
fn unused_export_finding(root: &Path, unused: &UnusedExport) -> Finding {
|
|
77
|
+
let path = display_path(root, &unused.path);
|
|
78
|
+
let symbol_target = format!("{path}:{}", unused.name);
|
|
79
|
+
let kind = unused_top_level_kind(unused.kind);
|
|
80
|
+
let mut actions = vec![
|
|
81
|
+
FindingAction::new(
|
|
82
|
+
"trace-symbol",
|
|
83
|
+
"Trace this symbol before removing it",
|
|
84
|
+
false,
|
|
85
|
+
)
|
|
86
|
+
.with_target_path(path.clone())
|
|
87
|
+
.with_target_symbol(unused.name.clone())
|
|
88
|
+
.with_dart_decimate_args([
|
|
89
|
+
"inspect",
|
|
90
|
+
"--format",
|
|
91
|
+
"json",
|
|
92
|
+
"--symbol",
|
|
93
|
+
symbol_target.as_str(),
|
|
94
|
+
])
|
|
95
|
+
.with_suppression_comment(format!(
|
|
96
|
+
"// dart-decimate-ignore-next-line {}",
|
|
97
|
+
kind_key(kind)
|
|
98
|
+
)),
|
|
99
|
+
];
|
|
100
|
+
if unused.safe_to_delete {
|
|
101
|
+
actions.insert(
|
|
102
|
+
0,
|
|
103
|
+
FindingAction::new(
|
|
104
|
+
"remove-declaration",
|
|
105
|
+
"Remove this unused one-line top-level Dart declaration",
|
|
106
|
+
true,
|
|
107
|
+
)
|
|
108
|
+
.with_target_path(path.clone())
|
|
109
|
+
.with_target_symbol(unused.name.clone())
|
|
110
|
+
.with_target_end_line(unused.location.line),
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
Finding {
|
|
114
|
+
rule_id: unused_top_level_rule_id(unused.kind).to_owned(),
|
|
115
|
+
fingerprint: None,
|
|
116
|
+
kind,
|
|
117
|
+
severity: Severity::Error,
|
|
118
|
+
message: unused_top_level_message(unused),
|
|
119
|
+
path: path.clone(),
|
|
120
|
+
line: unused.location.line,
|
|
121
|
+
column: unused.location.column,
|
|
122
|
+
safe_to_delete: unused.safe_to_delete,
|
|
123
|
+
files: Vec::new(),
|
|
124
|
+
edge: None,
|
|
125
|
+
actions,
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const fn unused_top_level_rule_id(kind: DeclarationKind) -> &'static str {
|
|
130
|
+
match kind {
|
|
131
|
+
DeclarationKind::TypeAlias => "dart-decimate/unused-type",
|
|
132
|
+
_ => "dart-decimate/unused-export",
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const fn unused_top_level_kind(kind: DeclarationKind) -> FindingKind {
|
|
137
|
+
match kind {
|
|
138
|
+
DeclarationKind::TypeAlias => FindingKind::UnusedType,
|
|
139
|
+
_ => FindingKind::UnusedExport,
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
fn unused_top_level_message(unused: &UnusedExport) -> String {
|
|
144
|
+
if unused.kind == DeclarationKind::TypeAlias {
|
|
145
|
+
return format!(
|
|
146
|
+
"Public type alias is not referenced from reachable Dart files: {}",
|
|
147
|
+
unused.name
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
format!(
|
|
151
|
+
"Public top-level {} is not referenced from reachable Dart files: {}",
|
|
152
|
+
declaration_kind(unused.kind),
|
|
153
|
+
unused.name
|
|
154
|
+
)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
fn duplicate_export_finding(root: &Path, duplicate: &DuplicateExport) -> Finding {
|
|
158
|
+
let path = display_path(root, &duplicate.entry_path);
|
|
159
|
+
let symbol_target = format!("{path}:{}", duplicate.name);
|
|
160
|
+
let files = duplicate
|
|
161
|
+
.declarations
|
|
162
|
+
.iter()
|
|
163
|
+
.map(|declaration| display_path(root, &declaration.path))
|
|
164
|
+
.collect::<Vec<_>>();
|
|
165
|
+
Finding {
|
|
166
|
+
rule_id: "dart-decimate/duplicate-export".to_owned(),
|
|
167
|
+
fingerprint: None,
|
|
168
|
+
kind: FindingKind::DuplicateExport,
|
|
169
|
+
severity: Severity::Error,
|
|
170
|
+
message: format!(
|
|
171
|
+
"Public API entry exports multiple declarations named {}",
|
|
172
|
+
duplicate.name
|
|
173
|
+
),
|
|
174
|
+
path: path.clone(),
|
|
175
|
+
line: 1,
|
|
176
|
+
column: 0,
|
|
177
|
+
safe_to_delete: duplicate.safe_to_delete,
|
|
178
|
+
files,
|
|
179
|
+
edge: None,
|
|
180
|
+
actions: vec![
|
|
181
|
+
FindingAction::new(
|
|
182
|
+
"inspect-export-surface",
|
|
183
|
+
"Rename, hide, or redirect one export so the public API exposes one declaration",
|
|
184
|
+
false,
|
|
185
|
+
)
|
|
186
|
+
.with_target_path(path.clone())
|
|
187
|
+
.with_target_symbol(duplicate.name.clone())
|
|
188
|
+
.with_dart_decimate_args([
|
|
189
|
+
"inspect",
|
|
190
|
+
"--format",
|
|
191
|
+
"json",
|
|
192
|
+
"--symbol",
|
|
193
|
+
symbol_target.as_str(),
|
|
194
|
+
]),
|
|
195
|
+
],
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
fn unused_member_finding(root: &Path, unused: &UnusedMember) -> Finding {
|
|
200
|
+
let path = display_path(root, &unused.path);
|
|
201
|
+
let symbol_target = format!("{path}:{}", unused.owner);
|
|
202
|
+
let (rule_id, kind, noun) = match unused.kind {
|
|
203
|
+
MemberKind::EnumConstant => (
|
|
204
|
+
"dart-decimate/unused-enum-member",
|
|
205
|
+
FindingKind::UnusedEnumMember,
|
|
206
|
+
"enum constant",
|
|
207
|
+
),
|
|
208
|
+
_ => (
|
|
209
|
+
"dart-decimate/unused-class-member",
|
|
210
|
+
FindingKind::UnusedClassMember,
|
|
211
|
+
"private class-like member",
|
|
212
|
+
),
|
|
213
|
+
};
|
|
214
|
+
Finding {
|
|
215
|
+
rule_id: rule_id.to_owned(),
|
|
216
|
+
fingerprint: None,
|
|
217
|
+
kind,
|
|
218
|
+
severity: Severity::Error,
|
|
219
|
+
message: format!(
|
|
220
|
+
"Unused {} {}.{} is not referenced from reachable Dart files",
|
|
221
|
+
noun, unused.owner, unused.name
|
|
222
|
+
),
|
|
223
|
+
path: path.clone(),
|
|
224
|
+
line: unused.location.line,
|
|
225
|
+
column: unused.location.column,
|
|
226
|
+
safe_to_delete: unused.safe_to_delete,
|
|
227
|
+
files: Vec::new(),
|
|
228
|
+
edge: None,
|
|
229
|
+
actions: vec![
|
|
230
|
+
FindingAction::new(
|
|
231
|
+
"review-member",
|
|
232
|
+
"Review same-library references before removing this member; Dart Decimate has no fix preview yet",
|
|
233
|
+
false,
|
|
234
|
+
)
|
|
235
|
+
.with_target_path(path.clone())
|
|
236
|
+
.with_target_symbol(format!("{}.{}", unused.owner, unused.name))
|
|
237
|
+
.with_dart_decimate_args([
|
|
238
|
+
"inspect",
|
|
239
|
+
"--format",
|
|
240
|
+
"json",
|
|
241
|
+
"--symbol",
|
|
242
|
+
symbol_target.as_str(),
|
|
243
|
+
])
|
|
244
|
+
.with_suppression_comment(format!("// dart-decimate-ignore-next-line {}", kind_key(kind))),
|
|
245
|
+
],
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const fn kind_key(kind: FindingKind) -> &'static str {
|
|
250
|
+
match kind {
|
|
251
|
+
FindingKind::UnusedEnumMember => "unused-enum-member",
|
|
252
|
+
FindingKind::UnusedClassMember => "unused-class-member",
|
|
253
|
+
FindingKind::UnusedType => "unused-type",
|
|
254
|
+
FindingKind::PrivateTypeLeak => "private-type-leak",
|
|
255
|
+
_ => "unused-export",
|
|
256
|
+
}
|
|
257
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
use std::fs;
|
|
2
|
+
|
|
3
|
+
use tempfile::TempDir;
|
|
4
|
+
|
|
5
|
+
use super::*;
|
|
6
|
+
use crate::{analyze_symbols, find_dead_code, scan::scan_project};
|
|
7
|
+
|
|
8
|
+
#[test]
|
|
9
|
+
fn emits_agent_actionable_dead_file_findings() -> Result<(), Box<dyn std::error::Error>> {
|
|
10
|
+
let fixture = tempfile::tempdir()?;
|
|
11
|
+
write(&fixture, "pubspec.yaml", "name: app\n")?;
|
|
12
|
+
write(&fixture, "lib/main.dart", "void main() {}\n")?;
|
|
13
|
+
write(&fixture, "lib/dead.dart", "class Dead {}\n")?;
|
|
14
|
+
let project = scan_project(fixture.path())?;
|
|
15
|
+
let dead_code = find_dead_code(&project.graph, ["lib/main.dart"]);
|
|
16
|
+
|
|
17
|
+
let report = build_json_report(
|
|
18
|
+
&project,
|
|
19
|
+
&AnalysisResults {
|
|
20
|
+
command: ReportCommand::DeadCode,
|
|
21
|
+
dead_code: Some(dead_code),
|
|
22
|
+
symbols: None,
|
|
23
|
+
cycles: Vec::new(),
|
|
24
|
+
re_export_cycles: Vec::new(),
|
|
25
|
+
boundary_violations: Vec::new(),
|
|
26
|
+
boundary_coverage: Vec::new(),
|
|
27
|
+
boundary_call_violations: Vec::new(),
|
|
28
|
+
policy_violations: Vec::new(),
|
|
29
|
+
dependency_hygiene: None,
|
|
30
|
+
duplicates: None,
|
|
31
|
+
health: None,
|
|
32
|
+
feature_flags: None,
|
|
33
|
+
security: None,
|
|
34
|
+
routes: None,
|
|
35
|
+
widgets: None,
|
|
36
|
+
file_scope: None,
|
|
37
|
+
require_suppression_reasons: false,
|
|
38
|
+
},
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
assert_eq!(report.schema_version, SCHEMA_VERSION);
|
|
42
|
+
assert_eq!(report.verdict, Verdict::Fail);
|
|
43
|
+
assert_eq!(report.summary.dead_files, 1);
|
|
44
|
+
assert_eq!(report.findings[0].rule_id, "dart-decimate/dead-file");
|
|
45
|
+
assert_eq!(report.findings[0].path, "lib/dead.dart");
|
|
46
|
+
assert!(report.findings[0].safe_to_delete);
|
|
47
|
+
assert!(report.findings[0].actions[0].auto_fixable);
|
|
48
|
+
|
|
49
|
+
Ok(())
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
#[test]
|
|
53
|
+
fn emits_agent_actionable_duplicate_export_findings() -> Result<(), Box<dyn std::error::Error>> {
|
|
54
|
+
let fixture = tempfile::tempdir()?;
|
|
55
|
+
write(&fixture, "pubspec.yaml", "name: package\n")?;
|
|
56
|
+
write(
|
|
57
|
+
&fixture,
|
|
58
|
+
"lib/package.dart",
|
|
59
|
+
"export 'src/a.dart';\nexport 'src/b.dart';\n",
|
|
60
|
+
)?;
|
|
61
|
+
write(&fixture, "lib/src/a.dart", "class Api {}\n")?;
|
|
62
|
+
write(&fixture, "lib/src/b.dart", "class Api {}\n")?;
|
|
63
|
+
let project = scan_project(fixture.path())?;
|
|
64
|
+
let symbols = analyze_symbols(&project, None);
|
|
65
|
+
|
|
66
|
+
let report = build_json_report(
|
|
67
|
+
&project,
|
|
68
|
+
&AnalysisResults {
|
|
69
|
+
command: ReportCommand::Check,
|
|
70
|
+
dead_code: None,
|
|
71
|
+
symbols: Some(symbols),
|
|
72
|
+
cycles: Vec::new(),
|
|
73
|
+
re_export_cycles: Vec::new(),
|
|
74
|
+
boundary_violations: Vec::new(),
|
|
75
|
+
boundary_coverage: Vec::new(),
|
|
76
|
+
boundary_call_violations: Vec::new(),
|
|
77
|
+
policy_violations: Vec::new(),
|
|
78
|
+
dependency_hygiene: None,
|
|
79
|
+
duplicates: None,
|
|
80
|
+
health: None,
|
|
81
|
+
feature_flags: None,
|
|
82
|
+
security: None,
|
|
83
|
+
routes: None,
|
|
84
|
+
widgets: None,
|
|
85
|
+
file_scope: None,
|
|
86
|
+
require_suppression_reasons: false,
|
|
87
|
+
},
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
assert_eq!(report.verdict, Verdict::Fail);
|
|
91
|
+
assert_eq!(report.summary.duplicate_exports, 1);
|
|
92
|
+
assert_eq!(report.findings[0].rule_id, "dart-decimate/duplicate-export");
|
|
93
|
+
assert_eq!(report.findings[0].kind, FindingKind::DuplicateExport);
|
|
94
|
+
assert_eq!(report.findings[0].path, "lib/package.dart");
|
|
95
|
+
assert_eq!(
|
|
96
|
+
report.findings[0].files,
|
|
97
|
+
vec!["lib/src/a.dart", "lib/src/b.dart"]
|
|
98
|
+
);
|
|
99
|
+
assert!(!report.findings[0].safe_to_delete);
|
|
100
|
+
assert_eq!(
|
|
101
|
+
report.findings[0].actions[0].action,
|
|
102
|
+
"inspect-export-surface"
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
Ok(())
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
fn write(fixture: &TempDir, path: &str, source: &str) -> Result<(), std::io::Error> {
|
|
109
|
+
let path = fixture.path().join(path);
|
|
110
|
+
if let Some(parent) = path.parent() {
|
|
111
|
+
fs::create_dir_all(parent)?;
|
|
112
|
+
}
|
|
113
|
+
fs::write(path, source)
|
|
114
|
+
}
|