dart-decimate 0.0.29 → 0.0.31

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,54 @@
1
+ use std::fmt::Write as _;
2
+
3
+ use super::{DependencyTraceReport, FileTraceReport, SymbolTraceReport};
4
+
5
+ /// Render a concise human file trace.
6
+ #[must_use]
7
+ pub fn render_file_trace(report: &FileTraceReport) -> String {
8
+ let mut rendered = String::new();
9
+ let _ = writeln!(
10
+ rendered,
11
+ "trace-file {}: found={} reachable={} entry_point={}",
12
+ report.path, report.found, report.reachable, report.entry_point
13
+ );
14
+ let _ = writeln!(rendered, "{}", report.reason);
15
+ rendered
16
+ }
17
+
18
+ /// Render a concise human symbol trace.
19
+ #[must_use]
20
+ pub fn render_symbol_trace(report: &SymbolTraceReport) -> String {
21
+ let mut rendered = String::new();
22
+ let _ = writeln!(
23
+ rendered,
24
+ "trace-symbol {}:{}: found={} reachable_file={} references={}",
25
+ report.path,
26
+ report.symbol,
27
+ report.found,
28
+ report.reachable_file,
29
+ report.direct_references.len()
30
+ );
31
+ let _ = writeln!(
32
+ rendered,
33
+ "semantic={} completeness={} impact_paths={} suggested_tests={}",
34
+ report.semantic_decision.as_str(),
35
+ report.completeness.status.as_str(),
36
+ report.impact_paths.len(),
37
+ report.suggested_tests.len()
38
+ );
39
+ let _ = writeln!(rendered, "{}", report.reason);
40
+ rendered
41
+ }
42
+
43
+ /// Render a concise human dependency trace.
44
+ #[must_use]
45
+ pub fn render_dependency_trace(report: &DependencyTraceReport) -> String {
46
+ let mut rendered = String::new();
47
+ let _ = writeln!(
48
+ rendered,
49
+ "trace-dependency {}: found={} declared={} used={} imports={}",
50
+ report.dependency, report.found, report.declared, report.is_used, report.total_import_count
51
+ );
52
+ let _ = writeln!(rendered, "{}", report.reason);
53
+ rendered
54
+ }
@@ -0,0 +1,126 @@
1
+ use std::collections::BTreeSet;
2
+ use std::path::Path;
3
+
4
+ use serde::{Deserialize, Serialize};
5
+
6
+ use crate::graph::normalize_against;
7
+ use crate::semantic::{
8
+ SemanticCompleteness, SemanticDecision, SemanticIdentity, SemanticOmissionReason,
9
+ declaration_identity, dependency_path, is_test_owned_path, owning_library_path,
10
+ };
11
+ use crate::{ScannedProject, TopLevelDeclaration};
12
+
13
+ use super::{TraceReference, display_path};
14
+
15
+ /// Completeness of one symbol trace.
16
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
17
+ pub struct TraceSemanticCompleteness {
18
+ pub status: SemanticCompleteness,
19
+ pub reasons: Vec<SemanticOmissionReason>,
20
+ }
21
+
22
+ /// One resolved dependency path from a symbol reference to its declaration file.
23
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
24
+ pub struct TraceImpactPath {
25
+ pub from: String,
26
+ pub to: String,
27
+ pub files: Vec<String>,
28
+ }
29
+
30
+ /// Existing test-owned importer suggested for targeted verification.
31
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
32
+ pub struct TraceTestSuggestion {
33
+ pub path: String,
34
+ pub import_path: Vec<String>,
35
+ pub reason: String,
36
+ }
37
+
38
+ pub(super) struct SymbolSemanticEvidence {
39
+ pub(super) identity: Option<SemanticIdentity>,
40
+ pub(super) decision: SemanticDecision,
41
+ pub(super) completeness: TraceSemanticCompleteness,
42
+ pub(super) impact_paths: Vec<TraceImpactPath>,
43
+ pub(super) suggested_tests: Vec<TraceTestSuggestion>,
44
+ }
45
+
46
+ pub(super) fn symbol_semantic_evidence(
47
+ project: &ScannedProject,
48
+ path: &Path,
49
+ declarations: &[&TopLevelDeclaration],
50
+ references: &[TraceReference],
51
+ ) -> SymbolSemanticEvidence {
52
+ let identity = (declarations.len() == 1).then(|| {
53
+ declaration_identity(
54
+ &project.root,
55
+ &owning_library_path(project, path),
56
+ path,
57
+ declarations[0],
58
+ )
59
+ });
60
+ let decision = if identity.is_some() {
61
+ SemanticDecision::Confirmed
62
+ } else if declarations.is_empty() {
63
+ SemanticDecision::RetainedUnresolved
64
+ } else {
65
+ SemanticDecision::RetainedAbstained
66
+ };
67
+ let impact_paths = impact_paths(project, path, references);
68
+ let suggested_tests = suggested_tests(project, &impact_paths);
69
+ SymbolSemanticEvidence {
70
+ identity,
71
+ decision,
72
+ completeness: trace_completeness(path, declarations.len()),
73
+ impact_paths,
74
+ suggested_tests,
75
+ }
76
+ }
77
+
78
+ fn impact_paths(
79
+ project: &ScannedProject,
80
+ target: &Path,
81
+ references: &[TraceReference],
82
+ ) -> Vec<TraceImpactPath> {
83
+ let mut paths = references
84
+ .iter()
85
+ .filter_map(|reference| {
86
+ let from = normalize_against(&project.root, Path::new(&reference.path));
87
+ dependency_path(project, &from, target).map(|files| TraceImpactPath {
88
+ from: reference.path.clone(),
89
+ to: display_path(&project.root, target),
90
+ files,
91
+ })
92
+ })
93
+ .collect::<Vec<_>>();
94
+ paths.sort_by(|left, right| (&left.from, &left.files).cmp(&(&right.from, &right.files)));
95
+ paths.dedup();
96
+ paths
97
+ }
98
+
99
+ fn suggested_tests(
100
+ project: &ScannedProject,
101
+ impact_paths: &[TraceImpactPath],
102
+ ) -> Vec<TraceTestSuggestion> {
103
+ impact_paths
104
+ .iter()
105
+ .filter(|path| is_test_owned_path(&project.root, &project.root.join(&path.from)))
106
+ .map(|path| TraceTestSuggestion {
107
+ path: path.from.clone(),
108
+ import_path: path.files.clone(),
109
+ reason: "Existing test-owned importer resolves to this declaration".to_owned(),
110
+ })
111
+ .collect()
112
+ }
113
+
114
+ fn trace_completeness(path: &Path, declaration_count: usize) -> TraceSemanticCompleteness {
115
+ let mut reasons = BTreeSet::from([SemanticOmissionReason::UnsupportedSyntax]);
116
+ if declaration_count > 1 {
117
+ reasons.insert(SemanticOmissionReason::AmbiguousOwner);
118
+ }
119
+ if crate::generated::is_generated_dart_path(path) {
120
+ reasons.insert(SemanticOmissionReason::GeneratedCode);
121
+ }
122
+ TraceSemanticCompleteness {
123
+ status: SemanticCompleteness::Partial,
124
+ reasons: reasons.into_iter().collect(),
125
+ }
126
+ }
package/src/trace.rs CHANGED
@@ -1,5 +1,4 @@
1
1
  use std::collections::BTreeSet;
2
- use std::fmt::Write as _;
3
2
  use std::path::{Path, PathBuf};
4
3
 
5
4
  use serde::{Deserialize, Serialize};
@@ -11,11 +10,18 @@ use crate::dependencies::{
11
10
  use crate::dependency_scripts::package_used_in_tooling;
12
11
  use crate::graph::normalize_against;
13
12
  use crate::output::TRACE_SCHEMA_VERSION;
13
+ use crate::semantic::{SemanticDecision, SemanticIdentity};
14
14
  use crate::{
15
15
  DartCombinatorKind, DeadCodeReport, DeclarationKind, DependencyHygieneError, DependencyKind,
16
16
  DependencySection, ScannedProject, TopLevelDeclaration,
17
17
  };
18
18
 
19
+ mod rendering;
20
+ mod semantic;
21
+ pub use rendering::{render_dependency_trace, render_file_trace, render_symbol_trace};
22
+ use semantic::symbol_semantic_evidence;
23
+ pub use semantic::{TraceImpactPath, TraceSemanticCompleteness, TraceTestSuggestion};
24
+
19
25
  /// File trace JSON envelope.
20
26
  #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
21
27
  pub struct FileTraceReport {
@@ -72,10 +78,20 @@ pub struct SymbolTraceReport {
72
78
  pub entry_point: bool,
73
79
  /// Matched top-level declaration, if any.
74
80
  pub declaration: Option<TraceDeclaration>,
81
+ /// Stable declaration identity when the requested owner is unambiguous.
82
+ pub identity: Option<SemanticIdentity>,
83
+ /// Conservative reconciliation decision for this trace.
84
+ pub semantic_decision: SemanticDecision,
85
+ /// Completeness and omission reasons for semantic trace evidence.
86
+ pub completeness: TraceSemanticCompleteness,
75
87
  /// Syntactic references to the symbol.
76
88
  pub direct_references: Vec<TraceReference>,
77
89
  /// Export chains that expose this file through barrels.
78
90
  pub re_export_chains: Vec<Vec<String>>,
91
+ /// Resolved import/export/part paths from referencing files to this declaration.
92
+ pub impact_paths: Vec<TraceImpactPath>,
93
+ /// Existing test-owned importers that are evidence-backed test suggestions.
94
+ pub suggested_tests: Vec<TraceTestSuggestion>,
79
95
  /// Short trace interpretation.
80
96
  pub reason: String,
81
97
  }
@@ -282,12 +298,16 @@ pub fn trace_symbol(
282
298
  .iter()
283
299
  .cloned()
284
300
  .collect::<BTreeSet<_>>();
285
- let declaration = find_declaration(project, &path, symbol);
301
+ let declarations = find_declarations(project, &path, symbol);
302
+ let declaration = declarations
303
+ .first()
304
+ .map(|declaration| trace_declaration(declaration));
286
305
  let found = declaration.is_some();
287
306
  let reachable_file = reachable_files.contains(&path);
288
307
  let entry_point = dead_code.entry_points.iter().any(|file| file == &path);
289
308
  let direct_references = direct_references(project, &reachable_files, symbol);
290
309
  let re_export_chains = re_export_chains(project, &path, symbol);
310
+ let semantic = symbol_semantic_evidence(project, &path, &declarations, &direct_references);
291
311
 
292
312
  SymbolTraceReport {
293
313
  schema_version: TRACE_SCHEMA_VERSION.to_owned(),
@@ -300,9 +320,14 @@ pub fn trace_symbol(
300
320
  reachable_file,
301
321
  entry_point,
302
322
  declaration,
323
+ identity: semantic.identity,
324
+ semantic_decision: semantic.decision,
325
+ completeness: semantic.completeness,
303
326
  reason: symbol_reason(found, reachable_file, entry_point, &direct_references),
304
327
  direct_references,
305
328
  re_export_chains,
329
+ impact_paths: semantic.impact_paths,
330
+ suggested_tests: semantic.suggested_tests,
306
331
  }
307
332
  }
308
333
 
@@ -368,49 +393,6 @@ pub fn trace_dependency(
368
393
  })
369
394
  }
370
395
 
371
- /// Render a concise human file trace.
372
- #[must_use]
373
- pub fn render_file_trace(report: &FileTraceReport) -> String {
374
- let mut rendered = String::new();
375
- let _ = writeln!(
376
- rendered,
377
- "trace-file {}: found={} reachable={} entry_point={}",
378
- report.path, report.found, report.reachable, report.entry_point
379
- );
380
- let _ = writeln!(rendered, "{}", report.reason);
381
- rendered
382
- }
383
-
384
- /// Render a concise human symbol trace.
385
- #[must_use]
386
- pub fn render_symbol_trace(report: &SymbolTraceReport) -> String {
387
- let mut rendered = String::new();
388
- let _ = writeln!(
389
- rendered,
390
- "trace-symbol {}:{}: found={} reachable_file={} references={}",
391
- report.path,
392
- report.symbol,
393
- report.found,
394
- report.reachable_file,
395
- report.direct_references.len()
396
- );
397
- let _ = writeln!(rendered, "{}", report.reason);
398
- rendered
399
- }
400
-
401
- /// Render a concise human dependency trace.
402
- #[must_use]
403
- pub fn render_dependency_trace(report: &DependencyTraceReport) -> String {
404
- let mut rendered = String::new();
405
- let _ = writeln!(
406
- rendered,
407
- "trace-dependency {}: found={} declared={} used={} imports={}",
408
- report.dependency, report.found, report.declared, report.is_used, report.total_import_count
409
- );
410
- let _ = writeln!(rendered, "{}", report.reason);
411
- rendered
412
- }
413
-
414
396
  fn declarations(declarations: &[TopLevelDeclaration]) -> Vec<TraceDeclaration> {
415
397
  declarations
416
398
  .iter()
@@ -499,25 +481,35 @@ fn dependency_directives(
499
481
  .collect()
500
482
  }
501
483
 
502
- fn find_declaration(
503
- project: &ScannedProject,
484
+ fn find_declarations<'a>(
485
+ project: &'a ScannedProject,
504
486
  path: &Path,
505
487
  symbol: &str,
506
- ) -> Option<TraceDeclaration> {
507
- project.files.iter().find_map(|file| {
508
- if normalize_against(&project.root, &file.path) != path {
509
- return None;
510
- }
511
- file.declarations
512
- .iter()
513
- .find(|declaration| declaration.name == symbol)
514
- .map(|declaration| TraceDeclaration {
515
- kind: declaration.kind,
516
- name: declaration.name.clone(),
517
- line: declaration.location.line,
518
- column: declaration.location.column,
519
- })
520
- })
488
+ ) -> Vec<&'a TopLevelDeclaration> {
489
+ project
490
+ .files
491
+ .iter()
492
+ .find_map(|file| {
493
+ if normalize_against(&project.root, &file.path) != path {
494
+ return None;
495
+ }
496
+ Some(
497
+ file.declarations
498
+ .iter()
499
+ .filter(|declaration| declaration.name == symbol)
500
+ .collect(),
501
+ )
502
+ })
503
+ .unwrap_or_default()
504
+ }
505
+
506
+ fn trace_declaration(declaration: &TopLevelDeclaration) -> TraceDeclaration {
507
+ TraceDeclaration {
508
+ kind: declaration.kind,
509
+ name: declaration.name.clone(),
510
+ line: declaration.location.line,
511
+ column: declaration.location.column,
512
+ }
521
513
  }
522
514
 
523
515
  fn direct_references(
@@ -38,6 +38,69 @@ pub(super) fn inherited_param_uses_across_files(
38
38
  uses
39
39
  }
40
40
 
41
+ pub(super) fn flutter_framework_classes_across_files(
42
+ files: &[WidgetFileFacts],
43
+ resolver: &DeclarationResolver,
44
+ ) -> BTreeSet<(PathBuf, String)> {
45
+ let facts = files
46
+ .iter()
47
+ .flat_map(|file| file.classes.iter())
48
+ .collect::<Vec<_>>();
49
+ let mut framework = facts
50
+ .iter()
51
+ .filter(|fact| {
52
+ fact.superclass
53
+ .as_deref()
54
+ .is_some_and(is_flutter_framework_base)
55
+ })
56
+ .map(|fact| fact.class_key())
57
+ .collect::<BTreeSet<_>>();
58
+
59
+ loop {
60
+ let mut changed = false;
61
+ for fact in &facts {
62
+ let key = fact.class_key();
63
+ if framework.contains(&key) {
64
+ continue;
65
+ }
66
+ let Some(parent) = fact.superclass.as_deref() else {
67
+ continue;
68
+ };
69
+ let reference = parent.split('<').next().unwrap_or(parent).trim();
70
+ let ancestors = resolver.resolve(&fact.path, reference);
71
+ if !ancestors.is_empty()
72
+ && ancestors
73
+ .iter()
74
+ .all(|ancestor| framework.contains(ancestor))
75
+ {
76
+ changed |= framework.insert(key);
77
+ }
78
+ }
79
+ if !changed {
80
+ break;
81
+ }
82
+ }
83
+
84
+ framework
85
+ .into_iter()
86
+ .map(|class| (class.path, class.name))
87
+ .collect()
88
+ }
89
+
90
+ fn is_flutter_framework_base(superclass: &str) -> bool {
91
+ let base = superclass.split('<').next().unwrap_or(superclass);
92
+ matches!(
93
+ simple_type_name(base).as_str(),
94
+ "AnimatedWidget"
95
+ | "StatelessWidget"
96
+ | "ConsumerWidget"
97
+ | "HookWidget"
98
+ | "HookConsumerWidget"
99
+ | "State"
100
+ | "ConsumerState"
101
+ )
102
+ }
103
+
41
104
  pub(super) fn class_facts(
42
105
  path: &Path,
43
106
  classes: &[Node<'_>],
package/src/widgets.rs CHANGED
@@ -196,7 +196,33 @@ pub fn analyze_widgets(
196
196
  })
197
197
  }
198
198
 
199
- fn widget_analysis_paths(
199
+ pub(crate) fn flutter_framework_classes_from_facts(
200
+ project: &ScannedProject,
201
+ file_facts: &[WidgetFileFacts],
202
+ ) -> BTreeSet<(PathBuf, String)> {
203
+ let resolver = DeclarationResolver::new(
204
+ project,
205
+ file_facts.iter().flat_map(|file| {
206
+ file.reachability.class_names.iter().map(|name| ClassKey {
207
+ path: file.reachability.path.clone(),
208
+ name: name.clone(),
209
+ })
210
+ }),
211
+ );
212
+ inheritance::flutter_framework_classes_across_files(file_facts, &resolver)
213
+ }
214
+
215
+ pub(crate) fn inheritance_file_facts(path: &Path, root: Node<'_>, source: &str) -> WidgetFileFacts {
216
+ let mut classes = Vec::new();
217
+ collect_class_declarations(root, &mut classes);
218
+ WidgetFileFacts {
219
+ findings: FileWidgetFindings::default(),
220
+ classes: inheritance::class_facts(path, &classes, source),
221
+ reachability: unrendered::reachability_facts(path, root, &classes, source),
222
+ }
223
+ }
224
+
225
+ pub(crate) fn widget_analysis_paths(
200
226
  project: &ScannedProject,
201
227
  dead_code: Option<&DeadCodeReport>,
202
228
  ) -> Vec<PathBuf> {
@@ -215,10 +241,14 @@ fn widget_analysis_paths(
215
241
  .map(|file| normalize_against(&project.root, &file.path))
216
242
  .filter(|path| path.starts_with(&project.root))
217
243
  .filter(|path| !dead_files.contains(path))
218
- .filter(|path| !is_generated_dart_path(path) && !is_test_path(path))
244
+ .filter(|path| is_widget_analysis_path(path))
219
245
  .collect()
220
246
  }
221
247
 
248
+ pub(crate) fn is_widget_analysis_path(path: &Path) -> bool {
249
+ !is_generated_dart_path(path) && !is_test_path(path)
250
+ }
251
+
222
252
  fn merge_file_widget_findings(file_findings: Vec<FileWidgetFindings>) -> FileWidgetFindings {
223
253
  let mut merged = FileWidgetFindings::default();
224
254
  for mut findings in file_findings {
@@ -352,7 +382,7 @@ struct FileWidgetFindings {
352
382
  }
353
383
 
354
384
  #[derive(Debug)]
355
- struct WidgetFileFacts {
385
+ pub(crate) struct WidgetFileFacts {
356
386
  findings: FileWidgetFindings,
357
387
  classes: Vec<inheritance::ProjectClassFact>,
358
388
  reachability: unrendered::FileReachabilityFacts,