dart-decimate 0.0.29 → 0.0.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/Cargo.lock +1 -1
  2. package/Cargo.toml +1 -1
  3. package/README.md +36 -60
  4. package/npm/bin/runner.js +26 -14
  5. package/npm/scripts/postinstall.js +89 -63
  6. package/package.json +3 -2
  7. package/src/baseline.rs +38 -0
  8. package/src/cli/health_args.rs +36 -7
  9. package/src/cli/html_open.rs +4 -0
  10. package/src/cli/issue_filter_args.rs +1 -0
  11. package/src/cli/security_summary_run.rs +1 -0
  12. package/src/config/health.rs +22 -2
  13. package/src/config/rule_aliases.rs +43 -0
  14. package/src/config/rules.rs +46 -1
  15. package/src/config.rs +2 -1
  16. package/src/dart_parser/test_support.rs +51 -0
  17. package/src/dart_parser.rs +8 -0
  18. package/src/dependencies/analyze.rs +3 -1
  19. package/src/dependencies/tests.rs +111 -7
  20. package/src/dependencies/usage.rs +5 -1
  21. package/src/dependencies.rs +7 -3
  22. package/src/explain/flutter_style.rs +43 -0
  23. package/src/explain/misc.rs +72 -0
  24. package/src/explain.rs +23 -67
  25. package/src/flutter_style/scanner.rs +883 -0
  26. package/src/flutter_style/types.rs +90 -0
  27. package/src/flutter_style/usage.rs +349 -0
  28. package/src/flutter_style.rs +72 -0
  29. package/src/generated.rs +154 -0
  30. package/src/health/large_units.rs +49 -0
  31. package/src/health/tests.rs +212 -1
  32. package/src/health/threshold_types.rs +31 -1
  33. package/src/health/thresholds.rs +49 -0
  34. package/src/health/types.rs +35 -0
  35. package/src/health.rs +72 -6
  36. package/src/inspect.rs +8 -0
  37. package/src/lib.rs +17 -5
  38. package/src/manifest.rs +7 -3
  39. package/src/output/dependency_findings.rs +14 -1
  40. package/src/output/flutter_style.rs +189 -0
  41. package/src/output/health_findings.rs +93 -10
  42. package/src/output/health_inventory.rs +121 -0
  43. package/src/output/html/tests.rs +20 -0
  44. package/src/output/html.rs +10 -1
  45. package/src/output/human.rs +85 -1
  46. package/src/output/human_details.rs +93 -12
  47. package/src/output/scope.rs +62 -2
  48. package/src/output/security_findings.rs +101 -76
  49. package/src/output/security_sarif.rs +24 -13
  50. package/src/output/suppressions.rs +4 -0
  51. package/src/output/types.rs +38 -2
  52. package/src/output/verdict.rs +12 -0
  53. package/src/output.rs +77 -74
  54. package/src/report_schema/inventory.rs +268 -4
  55. package/src/report_schema.rs +94 -60
  56. package/src/security/catalogue.rs +103 -0
  57. package/src/security/detect/weak_randomness.rs +762 -0
  58. package/src/security/detect.rs +1535 -221
  59. package/src/security/security_matchers.toml +172 -0
  60. package/src/security/tests.rs +336 -2
  61. package/src/security.rs +292 -56
  62. package/src/security_gate.rs +28 -0
  63. package/src/semantic.rs +276 -0
  64. package/src/symbols/semantic_evidence.rs +342 -0
  65. package/src/symbols.rs +20 -10
  66. package/src/trace/rendering.rs +54 -0
  67. package/src/trace/semantic.rs +126 -0
  68. package/src/trace.rs +54 -62
  69. package/src/widgets/inheritance.rs +63 -0
  70. package/src/widgets.rs +33 -3
@@ -0,0 +1,276 @@
1
+ use std::collections::{BTreeMap, BTreeSet, VecDeque};
2
+ use std::path::{Path, PathBuf};
3
+
4
+ use serde::{Deserialize, Serialize};
5
+
6
+ use crate::graph::normalize_against;
7
+ use crate::{DeclarationKind, Location, ScannedProject, TopLevelDeclaration};
8
+
9
+ pub const SEMANTIC_CANDIDATE_CAP: usize = 16_384;
10
+
11
+ /// Stable identity for one syntactically owned Dart declaration.
12
+ #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
13
+ pub struct SemanticIdentity {
14
+ /// Root-relative URI of the owning Dart library.
15
+ pub library_uri: String,
16
+ /// Root-relative declaration file.
17
+ pub path: String,
18
+ /// Stable declaration kind.
19
+ pub kind: String,
20
+ /// Declared name.
21
+ pub name: String,
22
+ /// 1-based source start line.
23
+ pub start_line: usize,
24
+ /// 0-based source start column.
25
+ pub start_column: usize,
26
+ /// Inclusive 1-based source end line.
27
+ pub end_line: usize,
28
+ }
29
+
30
+ /// Conservative semantic reconciliation decision.
31
+ #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
32
+ #[serde(rename_all = "kebab-case")]
33
+ pub enum SemanticDecision {
34
+ Confirmed,
35
+ RetainedUnresolved,
36
+ RetainedAbstained,
37
+ }
38
+
39
+ impl SemanticDecision {
40
+ #[must_use]
41
+ pub const fn as_str(self) -> &'static str {
42
+ match self {
43
+ Self::Confirmed => "confirmed",
44
+ Self::RetainedUnresolved => "retained-unresolved",
45
+ Self::RetainedAbstained => "retained-abstained",
46
+ }
47
+ }
48
+ }
49
+
50
+ /// Completeness of Rust-native semantic evidence.
51
+ #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
52
+ #[serde(rename_all = "kebab-case")]
53
+ pub enum SemanticCompleteness {
54
+ Complete,
55
+ Partial,
56
+ Unavailable,
57
+ }
58
+
59
+ impl SemanticCompleteness {
60
+ #[must_use]
61
+ pub const fn as_str(self) -> &'static str {
62
+ match self {
63
+ Self::Complete => "complete",
64
+ Self::Partial => "partial",
65
+ Self::Unavailable => "unavailable",
66
+ }
67
+ }
68
+ }
69
+
70
+ /// Stable reason why semantic evidence is incomplete or abstained.
71
+ #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
72
+ #[serde(rename_all = "kebab-case")]
73
+ pub enum SemanticOmissionReason {
74
+ DynamicAccess,
75
+ GeneratedCode,
76
+ FrameworkRegistration,
77
+ AmbiguousOwner,
78
+ ParseFailure,
79
+ Capacity,
80
+ UnsupportedSyntax,
81
+ }
82
+
83
+ /// Reconciliation evidence for one retained symbol candidate.
84
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
85
+ pub struct SemanticEvidence {
86
+ pub subject: SemanticIdentity,
87
+ pub decision: SemanticDecision,
88
+ pub reasons: Vec<SemanticOmissionReason>,
89
+ }
90
+
91
+ /// Advisory resolved type edge from one public signature.
92
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
93
+ pub struct SemanticTypeCoupling {
94
+ pub source: SemanticIdentity,
95
+ pub referenced_type: String,
96
+ pub target: SemanticIdentity,
97
+ pub line: usize,
98
+ pub column: usize,
99
+ pub decision: SemanticDecision,
100
+ }
101
+
102
+ /// Project-level semantic evidence and bounded completeness accounting.
103
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
104
+ pub struct SemanticReport {
105
+ pub completeness: SemanticCompleteness,
106
+ pub reasons: Vec<SemanticOmissionReason>,
107
+ pub candidate_count: usize,
108
+ pub processed_candidates: usize,
109
+ pub omitted_candidates: usize,
110
+ pub capacity: usize,
111
+ pub evidence: Vec<SemanticEvidence>,
112
+ pub type_couplings: Vec<SemanticTypeCoupling>,
113
+ }
114
+
115
+ impl Default for SemanticReport {
116
+ fn default() -> Self {
117
+ Self {
118
+ completeness: SemanticCompleteness::Unavailable,
119
+ reasons: vec![SemanticOmissionReason::UnsupportedSyntax],
120
+ candidate_count: 0,
121
+ processed_candidates: 0,
122
+ omitted_candidates: 0,
123
+ capacity: SEMANTIC_CANDIDATE_CAP,
124
+ evidence: Vec::new(),
125
+ type_couplings: Vec::new(),
126
+ }
127
+ }
128
+ }
129
+
130
+ pub(crate) fn declaration_identity(
131
+ root: &Path,
132
+ library_path: &Path,
133
+ path: &Path,
134
+ declaration: &TopLevelDeclaration,
135
+ ) -> SemanticIdentity {
136
+ SemanticIdentity {
137
+ library_uri: display_path(root, library_path),
138
+ path: display_path(root, path),
139
+ kind: declaration_kind(declaration.kind).to_owned(),
140
+ name: declaration.name.clone(),
141
+ start_line: declaration.location.line,
142
+ start_column: declaration.location.column,
143
+ end_line: declaration.range.end_line,
144
+ }
145
+ }
146
+
147
+ pub(crate) fn member_identity(
148
+ root: &Path,
149
+ library_path: &Path,
150
+ path: &Path,
151
+ owner: &str,
152
+ kind: &str,
153
+ name: &str,
154
+ location: Location,
155
+ ) -> SemanticIdentity {
156
+ SemanticIdentity {
157
+ library_uri: display_path(root, library_path),
158
+ path: display_path(root, path),
159
+ kind: format!("{kind}-member"),
160
+ name: format!("{owner}.{name}"),
161
+ start_line: location.line,
162
+ start_column: location.column,
163
+ end_line: location.line,
164
+ }
165
+ }
166
+
167
+ pub(crate) fn dependency_path(
168
+ project: &ScannedProject,
169
+ from: &Path,
170
+ to: &Path,
171
+ ) -> Option<Vec<String>> {
172
+ let from = normalize_against(&project.root, from);
173
+ let to = normalize_against(&project.root, to);
174
+ if from == to {
175
+ return Some(vec![display_path(&project.root, &from)]);
176
+ }
177
+ let mut adjacency = BTreeMap::<PathBuf, BTreeSet<PathBuf>>::new();
178
+ for dependency in project.graph.dependencies() {
179
+ adjacency
180
+ .entry(dependency.from_path)
181
+ .or_default()
182
+ .insert(dependency.to_path);
183
+ }
184
+ let mut queue = VecDeque::from([from.clone()]);
185
+ let mut previous = BTreeMap::<PathBuf, PathBuf>::new();
186
+ let mut seen = BTreeSet::from([from.clone()]);
187
+ while let Some(path) = queue.pop_front() {
188
+ let Some(targets) = adjacency.get(&path) else {
189
+ continue;
190
+ };
191
+ for target in targets {
192
+ if !seen.insert(target.clone()) {
193
+ continue;
194
+ }
195
+ previous.insert(target.clone(), path.clone());
196
+ if target == &to {
197
+ return Some(reconstruct_path(&project.root, &from, &to, &previous));
198
+ }
199
+ queue.push_back(target.clone());
200
+ }
201
+ }
202
+ None
203
+ }
204
+
205
+ pub(crate) fn owning_library_path(project: &ScannedProject, path: &Path) -> PathBuf {
206
+ let path = normalize_against(&project.root, path);
207
+ let part_edges = project
208
+ .graph
209
+ .dependencies()
210
+ .into_iter()
211
+ .filter(|dependency| dependency.kind == crate::DependencyKind::Part)
212
+ .collect::<Vec<_>>();
213
+ let mut owner = path.clone();
214
+ let mut seen = BTreeSet::from([path]);
215
+ while let Some(parent) = part_edges
216
+ .iter()
217
+ .filter(|dependency| dependency.to_path == owner)
218
+ .map(|dependency| dependency.from_path.clone())
219
+ .min()
220
+ {
221
+ if !seen.insert(parent.clone()) {
222
+ break;
223
+ }
224
+ owner = parent;
225
+ }
226
+ owner
227
+ }
228
+
229
+ pub(crate) fn is_test_owned_path(root: &Path, path: &Path) -> bool {
230
+ let relative = path.strip_prefix(root).unwrap_or(path);
231
+ relative.components().any(|component| {
232
+ matches!(
233
+ component.as_os_str().to_str(),
234
+ Some("test" | "integration_test")
235
+ )
236
+ })
237
+ }
238
+
239
+ pub(crate) fn display_path(root: &Path, path: &Path) -> String {
240
+ path.strip_prefix(root)
241
+ .unwrap_or(path)
242
+ .to_string_lossy()
243
+ .replace('\\', "/")
244
+ }
245
+
246
+ fn reconstruct_path(
247
+ root: &Path,
248
+ from: &Path,
249
+ to: &Path,
250
+ previous: &BTreeMap<PathBuf, PathBuf>,
251
+ ) -> Vec<String> {
252
+ let mut path = vec![to.to_path_buf()];
253
+ let mut current = to;
254
+ while current != from {
255
+ let Some(parent) = previous.get(current) else {
256
+ break;
257
+ };
258
+ path.push(parent.clone());
259
+ current = parent;
260
+ }
261
+ path.reverse();
262
+ path.iter().map(|path| display_path(root, path)).collect()
263
+ }
264
+
265
+ const fn declaration_kind(kind: DeclarationKind) -> &'static str {
266
+ match kind {
267
+ DeclarationKind::Class => "class",
268
+ DeclarationKind::Mixin => "mixin",
269
+ DeclarationKind::Extension => "extension",
270
+ DeclarationKind::ExtensionType => "extension-type",
271
+ DeclarationKind::Enum => "enum",
272
+ DeclarationKind::TypeAlias => "type-alias",
273
+ DeclarationKind::Variable => "variable",
274
+ DeclarationKind::Function => "function",
275
+ }
276
+ }
@@ -0,0 +1,342 @@
1
+ use std::collections::BTreeSet;
2
+
3
+ use crate::generated::is_generated_dart_path;
4
+ use crate::graph::normalize_against;
5
+ use crate::semantic::{
6
+ SEMANTIC_CANDIDATE_CAP, SemanticCompleteness, SemanticDecision, SemanticEvidence,
7
+ SemanticIdentity, SemanticOmissionReason, SemanticReport, SemanticTypeCoupling,
8
+ declaration_identity, member_identity,
9
+ };
10
+ use crate::{DeclarationKind, ScannedProject};
11
+
12
+ use super::{
13
+ DuplicateExport, IndexedDeclaration, PrivateTypeLeak, SymbolIndex, UnusedExport, UnusedMember,
14
+ };
15
+
16
+ pub(super) fn semantic_report(
17
+ project: &ScannedProject,
18
+ index: &SymbolIndex,
19
+ unused_exports: &[UnusedExport],
20
+ unused_members: &[UnusedMember],
21
+ private_type_leaks: &[PrivateTypeLeak],
22
+ duplicate_exports: &[DuplicateExport],
23
+ ) -> SemanticReport {
24
+ if project.files.is_empty() {
25
+ return SemanticReport::default();
26
+ }
27
+ let mut reasons = project_omission_reasons(project);
28
+ let mut evidence = finding_evidence(
29
+ project,
30
+ index,
31
+ unused_exports,
32
+ unused_members,
33
+ private_type_leaks,
34
+ duplicate_exports,
35
+ );
36
+ let mut type_couplings = type_couplings(project, index, &mut reasons);
37
+ evidence.sort_by(|left, right| {
38
+ (&left.subject, left.decision).cmp(&(&right.subject, right.decision))
39
+ });
40
+ evidence.dedup();
41
+ type_couplings.sort_by(|left, right| {
42
+ (
43
+ &left.source,
44
+ left.line,
45
+ left.column,
46
+ &left.referenced_type,
47
+ &left.target,
48
+ )
49
+ .cmp(&(
50
+ &right.source,
51
+ right.line,
52
+ right.column,
53
+ &right.referenced_type,
54
+ &right.target,
55
+ ))
56
+ });
57
+ type_couplings.dedup();
58
+ bounded_report(evidence, type_couplings, reasons)
59
+ }
60
+
61
+ fn finding_evidence(
62
+ project: &ScannedProject,
63
+ index: &SymbolIndex,
64
+ unused_exports: &[UnusedExport],
65
+ unused_members: &[UnusedMember],
66
+ private_type_leaks: &[PrivateTypeLeak],
67
+ duplicate_exports: &[DuplicateExport],
68
+ ) -> Vec<SemanticEvidence> {
69
+ let mut evidence = Vec::new();
70
+ for unused in unused_exports {
71
+ if let Some(subject) = top_level_identity(
72
+ project,
73
+ index,
74
+ &unused.path,
75
+ unused.kind,
76
+ &unused.name,
77
+ unused.location.line,
78
+ ) {
79
+ evidence.push(abstained(subject));
80
+ }
81
+ }
82
+ for unused in unused_members {
83
+ let path = normalize_against(&project.root, &unused.path);
84
+ let library = index.library_path(&path);
85
+ evidence.push(abstained(member_identity(
86
+ &project.root,
87
+ library,
88
+ &path,
89
+ &unused.owner,
90
+ member_kind(unused.kind),
91
+ &unused.name,
92
+ unused.location,
93
+ )));
94
+ }
95
+ for leak in private_type_leaks {
96
+ if let Some(subject) = top_level_identity(
97
+ project,
98
+ index,
99
+ &leak.path,
100
+ leak.declaration_kind,
101
+ &leak.declaration,
102
+ 0,
103
+ ) {
104
+ evidence.push(SemanticEvidence {
105
+ subject,
106
+ decision: SemanticDecision::Confirmed,
107
+ reasons: Vec::new(),
108
+ });
109
+ }
110
+ }
111
+ for duplicate in duplicate_exports {
112
+ for declaration in &duplicate.declarations {
113
+ if let Some(subject) = top_level_identity(
114
+ project,
115
+ index,
116
+ &declaration.path,
117
+ declaration.kind,
118
+ &duplicate.name,
119
+ declaration.location.line,
120
+ ) {
121
+ evidence.push(SemanticEvidence {
122
+ subject,
123
+ decision: SemanticDecision::RetainedUnresolved,
124
+ reasons: vec![SemanticOmissionReason::AmbiguousOwner],
125
+ });
126
+ }
127
+ }
128
+ }
129
+ evidence
130
+ }
131
+
132
+ fn type_couplings(
133
+ project: &ScannedProject,
134
+ index: &SymbolIndex,
135
+ reasons: &mut BTreeSet<SemanticOmissionReason>,
136
+ ) -> Vec<SemanticTypeCoupling> {
137
+ let mut couplings = Vec::new();
138
+ for file in &project.files {
139
+ let path = normalize_against(&project.root, &file.path);
140
+ let library = index.library_path(&path);
141
+ for reference in &file.signature_references {
142
+ let Some(source) = top_level_identity(
143
+ project,
144
+ index,
145
+ &path,
146
+ reference.declaration_kind,
147
+ &reference.declaration,
148
+ 0,
149
+ ) else {
150
+ reasons.insert(SemanticOmissionReason::AmbiguousOwner);
151
+ continue;
152
+ };
153
+ if !index.is_public_export(&path, &reference.declaration) {
154
+ continue;
155
+ }
156
+ let targets = index
157
+ .declarations
158
+ .iter()
159
+ .filter(|candidate| {
160
+ index.library_path(&candidate.path) == library
161
+ && candidate.declaration.name == reference.name
162
+ && is_type_declaration(candidate.declaration.kind)
163
+ })
164
+ .collect::<Vec<_>>();
165
+ let [target] = targets.as_slice() else {
166
+ if targets.len() > 1 {
167
+ reasons.insert(SemanticOmissionReason::AmbiguousOwner);
168
+ }
169
+ continue;
170
+ };
171
+ couplings.push(SemanticTypeCoupling {
172
+ source,
173
+ referenced_type: reference.name.clone(),
174
+ target: indexed_identity(project, index, target),
175
+ line: reference.location.line,
176
+ column: reference.location.column,
177
+ decision: SemanticDecision::Confirmed,
178
+ });
179
+ }
180
+ }
181
+ couplings
182
+ }
183
+
184
+ fn project_omission_reasons(project: &ScannedProject) -> BTreeSet<SemanticOmissionReason> {
185
+ let mut reasons = BTreeSet::from([SemanticOmissionReason::UnsupportedSyntax]);
186
+ for file in &project.files {
187
+ let path = normalize_against(&project.root, &file.path);
188
+ if is_generated_dart_path(&path) {
189
+ reasons.insert(SemanticOmissionReason::GeneratedCode);
190
+ }
191
+ if file
192
+ .references
193
+ .iter()
194
+ .any(|reference| matches!(reference.name.as_str(), "dynamic" | "noSuchMethod"))
195
+ {
196
+ reasons.insert(SemanticOmissionReason::DynamicAccess);
197
+ }
198
+ if file.references.iter().any(|reference| {
199
+ matches!(
200
+ reference.name.as_str(),
201
+ "registerFactory"
202
+ | "registerLazySingleton"
203
+ | "registerSingleton"
204
+ | "GetIt"
205
+ | "getIt"
206
+ )
207
+ }) {
208
+ reasons.insert(SemanticOmissionReason::FrameworkRegistration);
209
+ }
210
+ }
211
+ reasons
212
+ }
213
+
214
+ fn top_level_identity(
215
+ project: &ScannedProject,
216
+ index: &SymbolIndex,
217
+ path: &std::path::Path,
218
+ kind: DeclarationKind,
219
+ name: &str,
220
+ line: usize,
221
+ ) -> Option<SemanticIdentity> {
222
+ let path = normalize_against(&project.root, path);
223
+ let candidates = index
224
+ .declarations
225
+ .iter()
226
+ .filter(|candidate| {
227
+ candidate.path == path
228
+ && candidate.declaration.kind == kind
229
+ && candidate.declaration.name == name
230
+ && (line == 0 || candidate.declaration.location.line == line)
231
+ })
232
+ .collect::<Vec<_>>();
233
+ let [candidate] = candidates.as_slice() else {
234
+ return None;
235
+ };
236
+ Some(indexed_identity(project, index, candidate))
237
+ }
238
+
239
+ fn indexed_identity(
240
+ project: &ScannedProject,
241
+ index: &SymbolIndex,
242
+ indexed: &IndexedDeclaration,
243
+ ) -> SemanticIdentity {
244
+ declaration_identity(
245
+ &project.root,
246
+ index.library_path(&indexed.path),
247
+ &indexed.path,
248
+ &indexed.declaration,
249
+ )
250
+ }
251
+
252
+ fn abstained(subject: SemanticIdentity) -> SemanticEvidence {
253
+ SemanticEvidence {
254
+ subject,
255
+ decision: SemanticDecision::RetainedAbstained,
256
+ reasons: vec![SemanticOmissionReason::UnsupportedSyntax],
257
+ }
258
+ }
259
+
260
+ fn bounded_report(
261
+ mut evidence: Vec<SemanticEvidence>,
262
+ mut type_couplings: Vec<SemanticTypeCoupling>,
263
+ mut reasons: BTreeSet<SemanticOmissionReason>,
264
+ ) -> SemanticReport {
265
+ let candidate_count = evidence.len().saturating_add(type_couplings.len());
266
+ evidence.truncate(SEMANTIC_CANDIDATE_CAP);
267
+ let remaining = SEMANTIC_CANDIDATE_CAP.saturating_sub(evidence.len());
268
+ type_couplings.truncate(remaining);
269
+ let processed_candidates = evidence.len().saturating_add(type_couplings.len());
270
+ let omitted_candidates = candidate_count.saturating_sub(processed_candidates);
271
+ if omitted_candidates > 0 {
272
+ reasons.insert(SemanticOmissionReason::Capacity);
273
+ }
274
+ SemanticReport {
275
+ completeness: SemanticCompleteness::Partial,
276
+ reasons: reasons.into_iter().collect(),
277
+ candidate_count,
278
+ processed_candidates,
279
+ omitted_candidates,
280
+ capacity: SEMANTIC_CANDIDATE_CAP,
281
+ evidence,
282
+ type_couplings,
283
+ }
284
+ }
285
+
286
+ const fn is_type_declaration(kind: DeclarationKind) -> bool {
287
+ matches!(
288
+ kind,
289
+ DeclarationKind::Class
290
+ | DeclarationKind::Mixin
291
+ | DeclarationKind::ExtensionType
292
+ | DeclarationKind::Enum
293
+ | DeclarationKind::TypeAlias
294
+ )
295
+ }
296
+
297
+ const fn member_kind(kind: crate::MemberKind) -> &'static str {
298
+ match kind {
299
+ crate::MemberKind::EnumConstant => "enum-constant",
300
+ crate::MemberKind::Field => "field",
301
+ crate::MemberKind::Getter => "getter",
302
+ crate::MemberKind::Setter => "setter",
303
+ crate::MemberKind::Method => "method",
304
+ crate::MemberKind::Constructor => "constructor",
305
+ crate::MemberKind::Operator => "operator",
306
+ }
307
+ }
308
+
309
+ #[cfg(test)]
310
+ mod tests {
311
+ use super::*;
312
+
313
+ #[test]
314
+ fn capacity_retains_original_count_and_marks_omitted_tail() {
315
+ let evidence = (0..=SEMANTIC_CANDIDATE_CAP)
316
+ .map(|index| SemanticEvidence {
317
+ subject: SemanticIdentity {
318
+ library_uri: "lib/api.dart".to_owned(),
319
+ path: "lib/api.dart".to_owned(),
320
+ kind: "class".to_owned(),
321
+ name: format!("Api{index}"),
322
+ start_line: index + 1,
323
+ start_column: 0,
324
+ end_line: index + 1,
325
+ },
326
+ decision: SemanticDecision::RetainedAbstained,
327
+ reasons: vec![SemanticOmissionReason::UnsupportedSyntax],
328
+ })
329
+ .collect();
330
+
331
+ let report = bounded_report(
332
+ evidence,
333
+ Vec::new(),
334
+ BTreeSet::from([SemanticOmissionReason::UnsupportedSyntax]),
335
+ );
336
+
337
+ assert_eq!(report.candidate_count, SEMANTIC_CANDIDATE_CAP + 1);
338
+ assert_eq!(report.processed_candidates, SEMANTIC_CANDIDATE_CAP);
339
+ assert_eq!(report.omitted_candidates, 1);
340
+ assert!(report.reasons.contains(&SemanticOmissionReason::Capacity));
341
+ }
342
+ }
package/src/symbols.rs CHANGED
@@ -15,11 +15,13 @@ mod index;
15
15
  mod path_filters;
16
16
  mod private_type_leaks;
17
17
  mod riverpod;
18
+ mod semantic_evidence;
18
19
  use extensions::extend_implicit_extension_references;
19
20
  use path_filters::{is_library_source, is_private, is_public_library_entry};
20
21
  pub use private_type_leaks::PrivateTypeLeak;
21
22
  use private_type_leaks::private_type_leaks;
22
23
  use riverpod::extend_generated_provider_owner_references;
24
+ use semantic_evidence::semantic_report;
23
25
 
24
26
  /// Symbol-level dead-code result.
25
27
  #[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
@@ -32,6 +34,8 @@ pub struct SymbolReport {
32
34
  pub private_type_leaks: Vec<PrivateTypeLeak>,
33
35
  /// Public API entries that expose multiple declarations with the same name.
34
36
  pub duplicate_exports: Vec<DuplicateExport>,
37
+ /// Conservative Rust-native semantic evidence for retained candidates and type edges.
38
+ pub semantic: crate::SemanticReport,
35
39
  }
36
40
 
37
41
  /// Options for symbol-level dead-code analysis.
@@ -137,23 +141,29 @@ pub fn analyze_symbols_with_options(
137
141
  } else {
138
142
  Vec::new()
139
143
  };
140
- let Some(dead_code) = dead_code else {
141
- return SymbolReport {
142
- unused_exports: Vec::new(),
143
- unused_members: Vec::new(),
144
- private_type_leaks,
145
- duplicate_exports,
146
- };
144
+ let (unused_exports, unused_members) = if let Some(dead_code) = dead_code {
145
+ (
146
+ unused_exports(project, dead_code, &index, options),
147
+ unused_members(project, dead_code, &index),
148
+ )
149
+ } else {
150
+ (Vec::new(), Vec::new())
147
151
  };
148
-
149
- let unused_exports = unused_exports(project, dead_code, &index, options);
150
- let unused_members = unused_members(project, dead_code, &index);
152
+ let semantic = semantic_report(
153
+ project,
154
+ &index,
155
+ &unused_exports,
156
+ &unused_members,
157
+ &private_type_leaks,
158
+ &duplicate_exports,
159
+ );
151
160
 
152
161
  SymbolReport {
153
162
  unused_exports,
154
163
  unused_members,
155
164
  private_type_leaks,
156
165
  duplicate_exports,
166
+ semantic,
157
167
  }
158
168
  }
159
169