dart-decimate 0.0.76 → 0.0.78

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 (53) hide show
  1. package/Cargo.lock +1 -1
  2. package/Cargo.toml +1 -1
  3. package/README.md +8 -8
  4. package/package.json +2 -2
  5. package/src/boundaries.rs +1 -9
  6. package/src/cli/analyze.rs +33 -3
  7. package/src/cli/error.rs +16 -0
  8. package/src/cli/list_run.rs +3 -1
  9. package/src/cli/scope_args.rs +14 -3
  10. package/src/config.rs +12 -8
  11. package/src/dart_parser.rs +100 -9
  12. package/src/dependencies/analyze.rs +4 -3
  13. package/src/dependencies/discovery.rs +10 -2
  14. package/src/dependencies/flutter_usage.rs +4 -0
  15. package/src/dependencies/tests.rs +5 -5
  16. package/src/dependencies/usage.rs +0 -9
  17. package/src/dependencies.rs +12 -7
  18. package/src/dupes/declarations.rs +1 -2
  19. package/src/dupes.rs +1 -10
  20. package/src/explain/misc.rs +1 -1
  21. package/src/explain.rs +1 -1
  22. package/src/extract/members.rs +24 -15
  23. package/src/extract/tests.rs +89 -0
  24. package/src/extract.rs +51 -15
  25. package/src/graph.rs +9 -0
  26. package/src/lib.rs +3 -2
  27. package/src/output/duplication_findings.rs +1 -2
  28. package/src/output/human.rs +7 -2
  29. package/src/output/human_details.rs +6 -0
  30. package/src/output/next_steps.rs +111 -0
  31. package/src/output/route_cycle/aliases.rs +1 -2
  32. package/src/output/route_cycle/wrappers.rs +1 -2
  33. package/src/output/types.rs +2 -0
  34. package/src/output.rs +27 -5
  35. package/src/outside/loader.rs +133 -0
  36. package/src/outside/loader_tests.rs +136 -0
  37. package/src/outside/resolver.rs +484 -0
  38. package/src/outside/tests.rs +242 -0
  39. package/src/outside.rs +186 -0
  40. package/src/package_map.rs +30 -1
  41. package/src/report_schema.rs +1 -0
  42. package/src/routes.rs +2 -0
  43. package/src/scan.rs +24 -3
  44. package/src/security/detect/process_arguments.rs +106 -0
  45. package/src/security/detect.rs +98 -40
  46. package/src/symbols/extensions.rs +42 -27
  47. package/src/symbols/path_filters.rs +10 -1
  48. package/src/symbols/tests.rs +15 -0
  49. package/src/symbols.rs +489 -67
  50. package/src/trace.rs +6 -5
  51. package/src/widgets/reads.rs +4 -8
  52. package/src/widgets/resolution.rs +63 -10
  53. package/src/workspace_scope.rs +1 -10
@@ -81,8 +81,7 @@ impl DeclarationFileContext {
81
81
  }
82
82
  }
83
83
 
84
- // Class-member declaration nodes exclude concrete method bodies. Classify the
85
- // entire source before looking at clone windows, which may end mid-signature.
84
+ // Classify the whole source first, because clone windows may end mid-signature.
86
85
  fn bodyless_member_lines(path: &Path, source: &str) -> BTreeSet<usize> {
87
86
  let mut lines = BTreeSet::new();
88
87
  let Ok(parsed) = crate::dart_parser::parse_dart_source_strict(path, source) else {
package/src/dupes.rs CHANGED
@@ -56,8 +56,7 @@ pub struct DuplicateOptions {
56
56
  pub mode: DuplicateMode,
57
57
  /// Minimum normalized token count per clone window.
58
58
  pub min_tokens: usize,
59
- /// Minimum normalized line count per clone window; sparse windows may grow
60
- /// past this to satisfy `min_tokens`.
59
+ /// Minimum normalized line count per clone window.
61
60
  pub min_lines: usize,
62
61
  /// Minimum occurrences before a clone group is reported.
63
62
  pub min_occurrences: usize,
@@ -103,8 +102,6 @@ impl DuplicationThreshold {
103
102
  /// Default threshold: any duplicated lines fail the duplication gate.
104
103
  pub const ZERO: Self = Self(0);
105
104
 
106
- /// Build a threshold from a human percentage in the inclusive range `0..=100`.
107
- ///
108
105
  /// # Errors
109
106
  ///
110
107
  /// Returns an error when the value is not finite or is outside `0..=100`.
@@ -334,12 +331,6 @@ struct CloneWindow {
334
331
  token_count: usize,
335
332
  }
336
333
 
337
- /// Detect duplicated Dart code blocks.
338
- ///
339
- /// Clone windows satisfy both `min_lines` and `min_tokens`; sparse duplicated
340
- /// blocks can therefore span more than `min_lines`. Declaration-only abstract
341
- /// contracts and copied local Pub package mirrors are filtered conservatively.
342
- ///
343
334
  /// # Errors
344
335
  ///
345
336
  /// Returns [`DuplicateCodeError`] if a scanned Dart file cannot be read.
@@ -34,7 +34,7 @@ pub(super) const MISC_ISSUES: &[IssueExplanation] = &[
34
34
  ],
35
35
  "Security candidate",
36
36
  "A deterministic local security review candidate was detected.",
37
- "Dart Decimate surfaces candidates for agent verification; it does not prove exploitability.",
37
+ "Dart Decimate surfaces candidates for agent verification; it does not prove exploitability. A process call is safe only with a fixed executable, no shell and fixed arguments; a variable argument is a finding, also after a -- or in an attached --option=$value.",
38
38
  "HttpClient.badCertificateCallback or an http:// URL appears in reachable code.",
39
39
  "Verify source, sink, reachability, and product intent before changing code.",
40
40
  next_line_suppressions!("security-sink"),
package/src/explain.rs CHANGED
@@ -219,7 +219,7 @@ const ISSUES: &[IssueExplanation] = &[
219
219
  "Unused class member",
220
220
  "A private class field, getter, setter, or method is not referenced in its Dart library, or a public one of a class in lib/ is not referenced by any reachable file.",
221
221
  "Dart private names are library-scoped, including `part` files, so unused private members are cleanup candidates. Public members of a class that no reachable file uses are dead API surface.",
222
- "void _legacyHandler() {} is never called in the library, or int spare() => 1; is declared in a class that no reachable file calls it on. Annotated members, classes with extends, implements, with or on clauses, classes in libraries with generated parts, members of classes that a class extends or mixes in when it has an implements or with clause: if every type it implements or mixes in, and, with a with clause, its superclass, with their supertypes, is project code, only the members those types declare are skipped, and if any is outside the project the whole class is skipped, because the tool does not read SDK or package sources, so member names of outside types are unknown. A project mixin that any class mixes into an outside superclass (for example a Flutter State or StatelessWidget) is protected as a whole everywhere, because the tool does not read SDK or package sources (a typedef counts as its target type), entry files of a package that is not an application, classes that a published package exports, and contract names such as toString and toJson are not checked. An application exports no public API, so its lib/ classes are checked. It has publish_to: none with lib/main.dart or a bin/ script, or a Flutter dependency with lib/main.dart. A package with lib/<package name>.dart is a library, so it is never an application. An unpublished package without an entry point is a shared library and keeps its API. Each workspace package is checked from the workspace root.",
222
+ "void _legacyHandler() {} is never called in the library, or int spare() => 1; is declared in a class that no reachable file calls it on. Members of classes in lib/ and bin/ of every package are checked, including classes with extends, implements, with or on clauses. The tool reads the SDK and package sources that .dart_tool/package_config.json names and keeps every name that a supertype declares, for example the build and initState hooks of a Flutter widget or State. Annotated classes and members, classes in libraries with generated parts, entry files of a package that is not an application, classes that a published package exports, and contract names such as toString and toJson are not checked. A class keeps a whole-class skip when one of its supertypes cannot be read: the name is unresolved or ambiguous, the source is missing, the source version differs from the package config, or the file fails to parse. The summary then reports outside_types_unread. The next step is dart pub get or flutter pub get in the folder of the package that owns the file. A missing local import or part file gets its own step: dart run build_runner build for a generated suffix, otherwise create or fix the import. Both steps show when both causes exist. The verdict and exit code do not change. An application exports no public API, so its lib/ classes are checked. It has publish_to: none with lib/main.dart or a bin/ script, or a Flutter dependency with lib/main.dart. A package with lib/<package name>.dart is a library, so it is never an application. An unpublished package without an entry point is a shared library and keeps its API. Each workspace package is checked from the workspace root.",
223
223
  "Check reflection, generated bindings, and framework callbacks before removal.",
224
224
  next_line_suppressions!("unused-class-member"),
225
225
  &["dart-decimate trace-symbol --format json --symbol <file>:<class>"],
@@ -28,14 +28,19 @@ pub(super) fn push_class_like_members(
28
28
  };
29
29
  let start = members.len();
30
30
  collect_class_like_members(members, &owner, body, source);
31
- if header_has_contract(node, body, source) {
31
+ let header = source
32
+ .get(node.start_byte()..body.start_byte())
33
+ .unwrap_or_default();
34
+ let supertypes = header_supertypes(owner, header);
35
+ let annotated = header_is_annotated(header);
36
+ if annotated {
32
37
  for member in &mut members[start..] {
33
38
  member.contract = true;
34
39
  }
35
- let header = source
36
- .get(node.start_byte()..body.start_byte())
37
- .unwrap_or_default();
38
- class_supertypes.push(header_supertypes(owner, header));
40
+ }
41
+ let extends_a_type = node.kind() != "extension_declaration";
42
+ if extends_a_type && (annotated || supertypes.has_clauses()) {
43
+ class_supertypes.push(supertypes);
39
44
  }
40
45
  }
41
46
 
@@ -71,6 +76,12 @@ pub(super) fn push_type_alias_target(
71
76
  .find(|child| child.kind() == "type")
72
77
  .and_then(|child| child.utf8_text(source.as_bytes()).ok())
73
78
  .map(without_type_arguments)
79
+ .filter(|text| {
80
+ !text.trim_start().starts_with('(')
81
+ && !text
82
+ .split_whitespace()
83
+ .any(|word| word.starts_with("Function"))
84
+ })
74
85
  .and_then(|text| {
75
86
  text.split_whitespace()
76
87
  .next()
@@ -83,6 +94,7 @@ pub(super) fn push_type_alias_target(
83
94
  names: vec![target],
84
95
  mixins: Vec::new(),
85
96
  implemented: Vec::new(),
97
+ constraints: Vec::new(),
86
98
  });
87
99
  }
88
100
  }
@@ -106,7 +118,7 @@ enum Clause {
106
118
  Extends,
107
119
  With,
108
120
  Implements,
109
- Skipped,
121
+ On,
110
122
  }
111
123
 
112
124
  fn header_supertypes(owner: String, header: &str) -> ClassSupertypes {
@@ -116,6 +128,7 @@ fn header_supertypes(owner: String, header: &str) -> ClassSupertypes {
116
128
  names: Vec::new(),
117
129
  mixins: Vec::new(),
118
130
  implemented: Vec::new(),
131
+ constraints: Vec::new(),
119
132
  };
120
133
  let mut clause = None;
121
134
  for word in flat.split(|character: char| character.is_whitespace() || character == ',') {
@@ -123,7 +136,7 @@ fn header_supertypes(owner: String, header: &str) -> ClassSupertypes {
123
136
  "extends" => clause = Some(Clause::Extends),
124
137
  "with" => clause = Some(Clause::With),
125
138
  "implements" => clause = Some(Clause::Implements),
126
- "on" => clause = Some(Clause::Skipped),
139
+ "on" => clause = Some(Clause::On),
127
140
  "" => {}
128
141
  _ => {
129
142
  let name = word.trim_end_matches('?');
@@ -131,7 +144,8 @@ fn header_supertypes(owner: String, header: &str) -> ClassSupertypes {
131
144
  Some(Clause::Extends) => &mut supertypes.names,
132
145
  Some(Clause::With) => &mut supertypes.mixins,
133
146
  Some(Clause::Implements) => &mut supertypes.implemented,
134
- Some(Clause::Skipped) | None => continue,
147
+ Some(Clause::On) => &mut supertypes.constraints,
148
+ None => continue,
135
149
  };
136
150
  if !name.is_empty() {
137
151
  list.push(name.to_owned());
@@ -142,14 +156,9 @@ fn header_supertypes(owner: String, header: &str) -> ClassSupertypes {
142
156
  supertypes
143
157
  }
144
158
 
145
- fn header_has_contract(node: Node<'_>, body: Node<'_>, source: &str) -> bool {
146
- let header = source
147
- .get(node.start_byte()..body.start_byte())
148
- .unwrap_or_default();
159
+ fn header_is_annotated(header: &str) -> bool {
149
160
  header.trim_start().starts_with('@')
150
- || header.split_whitespace().any(|word| {
151
- matches!(word, "extends" | "implements" | "with" | "on") || word.starts_with('@')
152
- })
161
+ || header.split_whitespace().any(|word| word.starts_with('@'))
153
162
  }
154
163
 
155
164
  fn member_is_annotated(node: Node<'_>, source: &str) -> bool {
@@ -860,3 +860,92 @@ mixin Runner on Base {}
860
860
 
861
861
  Ok(())
862
862
  }
863
+
864
+ #[test]
865
+ fn lists_the_types_a_mixin_requires_after_on() -> Result<(), ExtractError> {
866
+ let source = "\
867
+ mixin Runner<T> on Base<T>, ui.Shared implements Other {}
868
+ mixin Plain {}
869
+ ";
870
+
871
+ let extracted = extract_dart_source("lib/items.dart", source)?;
872
+
873
+ assert_eq!(
874
+ extracted
875
+ .class_supertypes
876
+ .iter()
877
+ .map(|clause| (
878
+ clause.owner.as_str(),
879
+ clause.constraints.clone(),
880
+ clause.implemented.clone()
881
+ ))
882
+ .collect::<Vec<_>>(),
883
+ vec![(
884
+ "Runner",
885
+ vec!["Base".to_owned(), "ui.Shared".to_owned()],
886
+ vec!["Other".to_owned()]
887
+ )]
888
+ );
889
+
890
+ Ok(())
891
+ }
892
+
893
+ #[test]
894
+ fn outline_keeps_declarations_and_leaves_out_references() -> Result<(), ExtractError> {
895
+ let source = "\
896
+ import 'package:other/other.dart' show Base;
897
+ export 'src/more.dart' hide Hidden;
898
+ part 'src/part.dart';
899
+
900
+ class Item extends Base {
901
+ int size = 0;
902
+ int measure() => size + helper();
903
+ }
904
+ ";
905
+
906
+ let outline = extract_dart_outline("lib/items.dart", source)?;
907
+ let full = extract_dart_source("lib/items.dart", source)?;
908
+
909
+ assert_ne!(full.references.len(), 0);
910
+ assert_eq!(outline.references.len(), 0);
911
+ assert_eq!(outline.signature_references.len(), 0);
912
+ assert_eq!(outline.routes.len(), 0);
913
+ assert_eq!(outline.imports, full.imports);
914
+ assert_eq!(outline.exports, full.exports);
915
+ assert_eq!(outline.parts, full.parts);
916
+ assert_eq!(outline.declarations, full.declarations);
917
+ assert_eq!(outline.members, full.members);
918
+ assert_eq!(outline.class_supertypes, full.class_supertypes);
919
+
920
+ Ok(())
921
+ }
922
+
923
+ #[test]
924
+ fn outline_rejects_syntax_errors_like_the_full_extract() {
925
+ let outline = extract_dart_outline("lib/broken.dart", "class {{{");
926
+
927
+ assert!(matches!(outline, Err(ExtractError::Syntax { .. })));
928
+ }
929
+
930
+ #[test]
931
+ fn typedef_of_a_record_or_function_type_names_no_supertype() -> Result<(), ExtractError> {
932
+ let source = "\
933
+ typedef Pair = ({String id, int count});
934
+ typedef Callback = void Function(int);
935
+ typedef Loader = Future<void> Function();
936
+ typedef Items = List<int>;
937
+ ";
938
+
939
+ let extracted = extract_dart_source("lib/types.dart", source)?;
940
+
941
+ assert_eq!(
942
+ extracted
943
+ .class_supertypes
944
+ .iter()
945
+ .map(|clause| (clause.owner.as_str(), clause.names.clone()))
946
+ .collect::<Vec<_>>(),
947
+ vec![("Items", vec!["List".to_owned()])]
948
+ );
949
+
950
+ Ok(())
951
+ }
package/src/extract.rs CHANGED
@@ -215,7 +215,7 @@ pub struct TopLevelDeclaration {
215
215
  pub range: SourceRange,
216
216
  }
217
217
 
218
- /// The types a class-like declaration or `typedef Name = Type;` names after `extends`, `with` or `implements`.
218
+ /// The types a class-like declaration or `typedef Name = Type;` names after `extends`, `with`, `implements` or `on`.
219
219
  #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
220
220
  pub struct ClassSupertypes {
221
221
  /// Declared name of the class-like declaration.
@@ -226,6 +226,17 @@ pub struct ClassSupertypes {
226
226
  pub mixins: Vec<String>,
227
227
  /// Names of the types after `implements`, written like `names`.
228
228
  pub implemented: Vec<String>,
229
+ /// Names of the types after `on` in a mixin declaration, written like `names`.
230
+ pub constraints: Vec<String>,
231
+ }
232
+
233
+ impl ClassSupertypes {
234
+ pub(crate) fn has_clauses(&self) -> bool {
235
+ !(self.names.is_empty()
236
+ && self.mixins.is_empty()
237
+ && self.implemented.is_empty()
238
+ && self.constraints.is_empty())
239
+ }
229
240
  }
230
241
 
231
242
  /// A class-like member declaration that can become a future symbol node.
@@ -240,7 +251,7 @@ pub struct MemberDeclaration {
240
251
  /// Declared method return type, when the member is a method.
241
252
  #[serde(default, skip_serializing_if = "Option::is_none")]
242
253
  pub return_type: Option<String>,
243
- /// Whether an annotation or a supertype clause lets code outside the project call this member.
254
+ /// Whether an annotation lets code outside the project call this member.
244
255
  #[serde(default, skip_serializing)]
245
256
  pub contract: bool,
246
257
  /// Whether the member has an implementation: false only for an abstract method, getter or setter.
@@ -357,6 +368,39 @@ pub fn extract_dart_source(path: impl AsRef<Path>, source: &str) -> Result<DartF
357
368
  let root = parsed.tree().root_node();
358
369
  let parse_source = parsed.source();
359
370
 
371
+ let mut file = extract_declarations(path, root, parse_source);
372
+ let mut references = extract_identifier_references(root, parse_source);
373
+ references.extend(extract_dot_shorthand_references(source));
374
+ references.extend(extract_primary_constructor_identifier_references(source));
375
+ sort_identifier_references(&mut references);
376
+ let mut signature_references = extract_signature_references(root, parse_source);
377
+ signature_references.extend(extract_primary_constructor_signature_references(source));
378
+ sort_signature_references(&mut signature_references);
379
+ file.references = references;
380
+ file.signature_references = signature_references;
381
+ file.routes = extract_route_declarations(root, parse_source);
382
+
383
+ Ok(file)
384
+ }
385
+
386
+ /// Extract the directives, declarations, members and supertype clauses of Dart source text, without references, signatures or routes.
387
+ ///
388
+ /// # Errors
389
+ pub(crate) fn extract_dart_outline(
390
+ path: impl AsRef<Path>,
391
+ source: &str,
392
+ ) -> Result<DartFile, ExtractError> {
393
+ let path = path.as_ref().to_path_buf();
394
+ let parsed =
395
+ crate::dart_parser::parse_dart_source_strict(&path, source).map_err(extract_parse_error)?;
396
+ Ok(extract_declarations(
397
+ path,
398
+ parsed.tree().root_node(),
399
+ parsed.source(),
400
+ ))
401
+ }
402
+
403
+ fn extract_declarations(path: PathBuf, root: Node<'_>, parse_source: &str) -> DartFile {
360
404
  let mut library = None;
361
405
  let mut part_of = None;
362
406
  let mut imports = Vec::new();
@@ -365,14 +409,6 @@ pub fn extract_dart_source(path: impl AsRef<Path>, source: &str) -> Result<DartF
365
409
  let mut declarations = Vec::new();
366
410
  let mut members = Vec::new();
367
411
  let mut class_supertypes = Vec::new();
368
- let mut references = extract_identifier_references(root, parse_source);
369
- references.extend(extract_dot_shorthand_references(source));
370
- references.extend(extract_primary_constructor_identifier_references(source));
371
- sort_identifier_references(&mut references);
372
- let mut signature_references = extract_signature_references(root, parse_source);
373
- signature_references.extend(extract_primary_constructor_signature_references(source));
374
- sort_signature_references(&mut signature_references);
375
- let routes = extract_route_declarations(root, parse_source);
376
412
 
377
413
  let mut cursor = root.walk();
378
414
  for child in root.named_children(&mut cursor) {
@@ -420,7 +456,7 @@ pub fn extract_dart_source(path: impl AsRef<Path>, source: &str) -> Result<DartF
420
456
  }
421
457
  }
422
458
 
423
- Ok(DartFile {
459
+ DartFile {
424
460
  path,
425
461
  library,
426
462
  part_of,
@@ -430,10 +466,10 @@ pub fn extract_dart_source(path: impl AsRef<Path>, source: &str) -> Result<DartF
430
466
  declarations,
431
467
  members,
432
468
  class_supertypes,
433
- references,
434
- signature_references,
435
- routes,
436
- })
469
+ references: Vec::new(),
470
+ signature_references: Vec::new(),
471
+ routes: Vec::new(),
472
+ }
437
473
  }
438
474
 
439
475
  fn extract_parse_error(error: crate::dart_parser::DartParseError) -> ExtractError {
package/src/graph.rs CHANGED
@@ -120,6 +120,15 @@ pub struct ModuleGraph {
120
120
  }
121
121
 
122
122
  impl ModuleGraph {
123
+ pub(crate) fn resolve_specifier(
124
+ &self,
125
+ from: &Path,
126
+ specifier: &str,
127
+ ) -> Option<(PathBuf, bool)> {
128
+ resolve_local_uri(&self.root, &self.packages, from, specifier)
129
+ .map(|target| (target.path, target.local))
130
+ }
131
+
123
132
  /// Project root used to resolve package and relative imports.
124
133
  #[must_use]
125
134
  pub fn root(&self) -> &Path {
package/src/lib.rs CHANGED
@@ -35,6 +35,7 @@ pub mod intelligence;
35
35
  pub mod manifest;
36
36
  pub mod mcp;
37
37
  pub mod output;
38
+ pub(crate) mod outside;
38
39
  pub(crate) mod package_map;
39
40
  pub mod policy;
40
41
  pub mod project_list;
@@ -192,8 +193,8 @@ pub use semantic::{
192
193
  SemanticOmissionReason, SemanticReport, SemanticTypeCoupling,
193
194
  };
194
195
  pub use symbols::{
195
- DuplicateExport, DuplicateExportDeclaration, PrivateTypeLeak, SymbolAnalysisOptions,
196
- SymbolIndex, SymbolReport, UnusedExport, UnusedMember, analyze_symbols,
196
+ DuplicateExport, DuplicateExportDeclaration, MissingFile, PrivateTypeLeak,
197
+ SymbolAnalysisOptions, SymbolIndex, SymbolReport, UnusedExport, UnusedMember, analyze_symbols,
197
198
  analyze_symbols_with_options, analyze_unused_exports,
198
199
  };
199
200
  pub use trace::{
@@ -113,8 +113,7 @@ fn code_duplication_finding(root: &Path, clone: &crate::CodeClone) -> Finding {
113
113
  }
114
114
  }
115
115
 
116
- // Findings and clone inventories share suppression semantics. Reconcile all
117
- // groups before limiting details so --top cannot weaken the duplication gate.
116
+ // Reconcile all groups before limiting details so --top cannot weaken the gate.
118
117
  pub(super) fn reconcile_clone_visibility(
119
118
  report: &mut super::JsonReport,
120
119
  results: &super::AnalysisResults,
@@ -114,6 +114,7 @@ fn render_human_report_with_style(report: &JsonReport, style: Style) -> String {
114
114
  };
115
115
  let _ = writeln!(rendered, "\n{message}");
116
116
  }
117
+ render_next_steps(&mut rendered, report, style);
117
118
  return rendered;
118
119
  }
119
120
 
@@ -122,6 +123,12 @@ fn render_human_report_with_style(report: &JsonReport, style: Style) -> String {
122
123
  render_finding(&mut rendered, index + 1, finding, style);
123
124
  }
124
125
 
126
+ render_next_steps(&mut rendered, report, style);
127
+
128
+ rendered
129
+ }
130
+
131
+ fn render_next_steps(rendered: &mut String, report: &JsonReport, style: Style) {
125
132
  if !report.next_steps.is_empty() {
126
133
  let _ = writeln!(rendered, "\n{}", style.bold("Next Steps"));
127
134
  for (index, step) in report.next_steps.iter().enumerate() {
@@ -136,8 +143,6 @@ fn render_human_report_with_style(report: &JsonReport, style: Style) -> String {
136
143
  let _ = writeln!(rendered, " Why: {reason}");
137
144
  }
138
145
  }
139
-
140
- rendered
141
146
  }
142
147
 
143
148
  fn render_semantic_evidence(rendered: &mut String, report: &JsonReport, style: Style) {
@@ -172,6 +172,12 @@ fn cleanup_items(summary: &ReportSummary) -> Vec<String> {
172
172
  "unused class member",
173
173
  "unused class members",
174
174
  );
175
+ push_count(
176
+ &mut items,
177
+ summary.outside_types_unread,
178
+ "supertype name not read",
179
+ "supertype names not read",
180
+ );
175
181
  push_count(
176
182
  &mut items,
177
183
  summary.duplicate_exports,
@@ -57,6 +57,8 @@ pub(super) fn next_steps(root: &Path, results: &AnalysisResults) -> Vec<NextStep
57
57
  });
58
58
  }
59
59
 
60
+ steps.extend(read_outside_types_steps(results));
61
+
60
62
  if let Some(clone) = results
61
63
  .duplicates
62
64
  .as_ref()
@@ -101,3 +103,112 @@ pub(super) fn next_steps(root: &Path, results: &AnalysisResults) -> Vec<NextStep
101
103
 
102
104
  steps
103
105
  }
106
+
107
+ fn read_outside_types_steps(results: &AnalysisResults) -> Vec<NextStep> {
108
+ let Some(report) = results
109
+ .symbols
110
+ .as_ref()
111
+ .filter(|report| report.outside_types_unread > 0)
112
+ else {
113
+ return Vec::new();
114
+ };
115
+ let mut steps = missing_import_steps(&report.outside_missing_imports);
116
+ steps.extend(
117
+ report
118
+ .outside_unread_folders
119
+ .iter()
120
+ .map(|(folder, flutter)| {
121
+ let tool = if *flutter { "flutter pub get" } else { "dart pub get" };
122
+ NextStep {
123
+ id: "read-outside-types".to_owned(),
124
+ command: if folder.is_empty() {
125
+ tool.to_owned()
126
+ } else {
127
+ format!("cd {} && {tool}", shell_quote(folder))
128
+ },
129
+ reason: "Write the package config so SDK and package supertypes can be read, then class members that depend on them are checked"
130
+ .to_owned(),
131
+ }
132
+ }),
133
+ );
134
+ steps
135
+ }
136
+
137
+ fn is_generated_file(file: &str) -> bool {
138
+ [
139
+ ".g.dart",
140
+ ".freezed.dart",
141
+ ".gr.dart",
142
+ ".gen.dart",
143
+ ".mocks.dart",
144
+ ]
145
+ .iter()
146
+ .any(|suffix| file.ends_with(suffix))
147
+ }
148
+
149
+ fn missing_import_steps(missing: &[crate::MissingFile]) -> Vec<NextStep> {
150
+ let mut groups = std::collections::BTreeMap::<(&str, bool), Vec<&crate::MissingFile>>::new();
151
+ for file in missing {
152
+ groups
153
+ .entry((file.folder.as_str(), is_generated_file(&file.file)))
154
+ .or_default()
155
+ .push(file);
156
+ }
157
+ groups
158
+ .into_iter()
159
+ .map(|((folder, generated), files)| {
160
+ let reasons = files
161
+ .iter()
162
+ .map(|file| {
163
+ let location = if folder.is_empty() {
164
+ file.file.clone()
165
+ } else {
166
+ format!("{folder}/{}", file.file)
167
+ };
168
+ let role = if file.part { "a part" } else { "imported" };
169
+ format!("{location} is {role} but missing")
170
+ })
171
+ .collect::<Vec<_>>()
172
+ .join("; ");
173
+ if generated {
174
+ NextStep {
175
+ id: "generate-missing-import".to_owned(),
176
+ command: if folder.is_empty() {
177
+ "dart run build_runner build".to_owned()
178
+ } else {
179
+ format!("cd {} && dart run build_runner build", shell_quote(folder))
180
+ },
181
+ reason: if files.len() == 1 {
182
+ format!("{reasons}; generate it so the types it declares can be read")
183
+ } else {
184
+ format!("{reasons}; generate them so the types they declare can be read")
185
+ },
186
+ }
187
+ } else {
188
+ let names = files
189
+ .iter()
190
+ .map(|file| file.file.as_str())
191
+ .collect::<Vec<_>>()
192
+ .join(", ");
193
+ NextStep {
194
+ id: "fix-missing-import".to_owned(),
195
+ command: format!("create or fix the import of {names}"),
196
+ reason: format!(
197
+ "{reasons}, so supertypes cannot be read and class members stay unchecked"
198
+ ),
199
+ }
200
+ }
201
+ })
202
+ .collect()
203
+ }
204
+
205
+ fn shell_quote(folder: &str) -> String {
206
+ if folder
207
+ .chars()
208
+ .all(|character| character.is_ascii_alphanumeric() || "/._-".contains(character))
209
+ {
210
+ folder.to_owned()
211
+ } else {
212
+ format!("'{}'", folder.replace('\'', "'\\''"))
213
+ }
214
+ }
@@ -571,8 +571,7 @@ fn scoped_header_binding_exists(
571
571
  return false;
572
572
  }
573
573
  if for_in_iterable(scope, path_child) {
574
- // The iterable is evaluated in the enclosing scope, so even
575
- // `for (final route in route.go(context))` reads the outer `route`.
574
+ // The iterable is evaluated in the enclosing scope, so it reads the outer name.
576
575
  return false;
577
576
  }
578
577
  if header_field_binding_exists(scope, path_child, usage_start, name, source) {
@@ -105,8 +105,7 @@ fn wrapper_call_name_nodes(function: Node<'_>) -> Option<(Node<'_>, Option<Node<
105
105
  let method = function.child_by_field_name("property")?;
106
106
  return (method.kind() == "identifier").then_some((method, Some(receiver)));
107
107
  }
108
- // Dart Tree-Sitter represents `() => navigate(...)` as a call whose
109
- // function is the closure and whose body is the callee identifier.
108
+ // Tree-Sitter models `() => navigate(...)` as a call whose function is the closure.
110
109
  callback_body_identifier(function).map(|name| (name, None))
111
110
  }
112
111
 
@@ -230,6 +230,8 @@ pub struct ReportSummary {
230
230
  pub unused_enum_members: usize,
231
231
  /// Unused class-like members.
232
232
  pub unused_class_members: usize,
233
+ /// Supertype names whose SDK or package source could not be read, so their classes keep the whole-class member skip.
234
+ pub outside_types_unread: usize,
233
235
  /// Public API symbols exported from multiple declarations.
234
236
  pub duplicate_exports: usize,
235
237
  /// Typed `GoRouter` route path or name collisions.