dart-decimate 0.0.74 → 0.0.76

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 (45) hide show
  1. package/Cargo.lock +1 -1
  2. package/Cargo.toml +1 -1
  3. package/README.md +11 -10
  4. package/package.json +2 -2
  5. package/src/baseline.rs +5 -16
  6. package/src/cli/issue_filter_args.rs +10 -0
  7. package/src/config/rule_aliases.rs +6 -0
  8. package/src/config/rules.rs +3 -6
  9. package/src/dependencies/analyze.rs +14 -3
  10. package/src/dependencies/overrides.rs +9 -1
  11. package/src/dependencies/package_cycles.rs +69 -0
  12. package/src/dependencies/package_graph.rs +53 -0
  13. package/src/dependencies/usage.rs +9 -0
  14. package/src/dependencies.rs +63 -8
  15. package/src/explain.rs +21 -9
  16. package/src/extract/members.rs +159 -6
  17. package/src/extract/tests.rs +35 -0
  18. package/src/extract.rs +48 -51
  19. package/src/generated.rs +10 -1
  20. package/src/graph/augment_tests.rs +1 -0
  21. package/src/graph/package_config_tests.rs +3 -0
  22. package/src/graph/pubspec_tests.rs +1 -0
  23. package/src/graph/tests.rs +3 -0
  24. package/src/graph/uri_tests.rs +1 -0
  25. package/src/health/coverage.rs +1 -1
  26. package/src/health/tests.rs +54 -0
  27. package/src/health/thresholds.rs +1 -1
  28. package/src/health/types.rs +2 -2
  29. package/src/intelligence/tests.rs +2 -0
  30. package/src/lib.rs +5 -10
  31. package/src/manifest.rs +3 -2
  32. package/src/mcp/cli_args/value_args.rs +1 -0
  33. package/src/output/dependency_findings.rs +41 -2
  34. package/src/output/human_details.rs +8 -0
  35. package/src/output/suppressions.rs +1 -0
  36. package/src/output/symbol_findings.rs +6 -2
  37. package/src/output/types.rs +10 -6
  38. package/src/output.rs +2 -0
  39. package/src/report_schema.rs +2 -0
  40. package/src/security_gate.rs +3 -6
  41. package/src/symbols/duplicate_declarations.rs +237 -0
  42. package/src/symbols/tests.rs +1 -0
  43. package/src/symbols.rs +354 -10
  44. package/src/widgets/resolution.rs +6 -6
  45. package/src/widgets.rs +1 -4
package/src/explain.rs CHANGED
@@ -217,9 +217,9 @@ const ISSUES: &[IssueExplanation] = &[
217
217
  "dart-decimate/unused-class-member",
218
218
  &["unused-class-member", "unused-class-members"],
219
219
  "Unused class member",
220
- "A private class-like field, getter, setter, or method is not referenced in its Dart library.",
221
- "Dart private names are library-scoped, including `part` files, so unused private members are cleanup candidates.",
222
- "void _legacyHandler() {} is never called in the library.",
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
+ "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.",
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>"],
@@ -229,9 +229,9 @@ const ISSUES: &[IssueExplanation] = &[
229
229
  "dart-decimate/duplicate-export",
230
230
  &["duplicate-export", "duplicate-exports"],
231
231
  "Duplicate export",
232
- "A public barrel exports the same symbol name from multiple Dart files.",
233
- "Importers may receive an ambiguous API surface when barrels expose duplicate declarations.",
234
- "lib/app.dart exports src/a.dart and src/b.dart, both declaring Api.",
232
+ "A public barrel exports the same symbol name from multiple Dart files, or one library imports or exports two lib/ files that declare the same public name.",
233
+ "Importers may receive an ambiguous API surface when barrels expose duplicate declarations, and two declarations of one name in one scope force prefixes or hide clauses.",
234
+ "lib/app.dart exports src/a.dart and src/b.dart, both declaring Api; or lib/app.dart imports src/a.dart and src/b.dart, both declaring Label. Same-name files that no library sees together, prefixed imports, show and hide clauses, platform alternatives of one conditional import and FlutterFire option files are exempt.",
235
235
  "Rename, hide, or narrow one export path after reviewing the public API.",
236
236
  file_suppressions!("duplicate-export"),
237
237
  &["dart-decimate trace-symbol --format json --symbol <file>:<symbol>"],
@@ -516,10 +516,10 @@ const ISSUES: &[IssueExplanation] = &[
516
516
  "dependency-overrides"
517
517
  ],
518
518
  "Unused dependency override",
519
- "A Dart dependency override is absent from the resolved pubspec.lock package graph.",
519
+ "A Dart dependency override targets a package that the resolved dependency graph never reaches, or that pubspec.lock does not contain.",
520
520
  "Overrides are temporary build policy and should not linger after the resolver stops using them.",
521
- "dependency_overrides: stale is declared but pubspec.lock does not contain stale.",
522
- "Compare the override with pubspec.lock and active Pub resolution before removing it.",
521
+ "dependency_overrides: stale is declared but no package in .dart_tool/package_graph.json depends on stale.",
522
+ "Compare the override with .dart_tool/package_graph.json, pubspec.lock and active Pub resolution before removing it.",
523
523
  &[],
524
524
  &["dart-decimate trace-dependency --format json --dependency <package>"],
525
525
  ),
@@ -538,6 +538,18 @@ const ISSUES: &[IssueExplanation] = &[
538
538
  &[],
539
539
  &[],
540
540
  ),
541
+ issue!(
542
+ "package-cycle",
543
+ "dart-decimate/package-cycle",
544
+ &["package-cycle", "package-cycles"],
545
+ "Package cycle",
546
+ "Two or more local pub packages depend on each other through their pubspec dependencies sections, and a lib/ import backs each dependency.",
547
+ "Packages that depend on each other cannot be built, versioned or published on their own, even when no file imports form a cycle.",
548
+ "packages/a lists b under dependencies and imports it from lib/, and packages/b lists a under dependencies and imports it from lib/. Dependencies under dev_dependencies and manifest entries with no lib/ import do not count.",
549
+ "Move the shared code into a third package, or remove one of the pubspec dependencies.",
550
+ &[],
551
+ &["dart-decimate check --package-cycles --format json"],
552
+ ),
541
553
  issue!(
542
554
  "unlisted-dependency",
543
555
  "dart-decimate/unlisted-dependency",
@@ -1,23 +1,164 @@
1
1
  use tree_sitter::Node;
2
2
 
3
3
  use super::{
4
- MemberDeclaration, MemberKind, collect_direct_identifier_children, collect_named_fields,
5
- declared_return_type, field_text, find_first_named_descendant, find_first_named_descendant_in,
6
- first_identifier_text,
4
+ ClassSupertypes, MemberDeclaration, MemberKind, collect_direct_identifier_children,
5
+ collect_named_fields, declared_return_type, field_text, find_first_named_descendant,
6
+ find_first_named_descendant_in, first_identifier_text,
7
7
  };
8
8
 
9
9
  pub(super) fn push_class_like_members(
10
10
  members: &mut Vec<MemberDeclaration>,
11
+ class_supertypes: &mut Vec<ClassSupertypes>,
11
12
  node: Node<'_>,
12
13
  source: &str,
13
14
  ) {
15
+ let mut cursor = node.walk();
16
+ let application = node
17
+ .named_children(&mut cursor)
18
+ .find(|child| child.kind() == "mixin_application_class");
19
+ if let Some(application) = application {
20
+ push_mixin_application(class_supertypes, application, source);
21
+ return;
22
+ }
14
23
  let Some(owner) = declaration_owner_name(node, source) else {
15
24
  return;
16
25
  };
17
26
  let Some(body) = node.child_by_field_name("body") else {
18
27
  return;
19
28
  };
29
+ let start = members.len();
20
30
  collect_class_like_members(members, &owner, body, source);
31
+ if header_has_contract(node, body, source) {
32
+ for member in &mut members[start..] {
33
+ member.contract = true;
34
+ }
35
+ let header = source
36
+ .get(node.start_byte()..body.start_byte())
37
+ .unwrap_or_default();
38
+ class_supertypes.push(header_supertypes(owner, header));
39
+ }
40
+ }
41
+
42
+ fn push_mixin_application(
43
+ class_supertypes: &mut Vec<ClassSupertypes>,
44
+ node: Node<'_>,
45
+ source: &str,
46
+ ) {
47
+ let flat = without_type_arguments(node.utf8_text(source.as_bytes()).unwrap_or_default());
48
+ if let Some((owner, rest)) = flat.split_once('=')
49
+ && let Some(owner) = owner.split_whitespace().next_back()
50
+ {
51
+ let header = format!("extends {}", rest.trim_end().trim_end_matches(';'));
52
+ class_supertypes.push(header_supertypes(owner.to_owned(), &header));
53
+ }
54
+ }
55
+
56
+ pub(super) fn push_type_alias_target(
57
+ class_supertypes: &mut Vec<ClassSupertypes>,
58
+ node: Node<'_>,
59
+ source: &str,
60
+ ) {
61
+ let mut cursor = node.walk();
62
+ if !node.children(&mut cursor).any(|child| child.kind() == "=") {
63
+ return;
64
+ }
65
+ let owner = node
66
+ .named_children(&mut cursor)
67
+ .find(|child| child.kind() == "type_identifier")
68
+ .and_then(|child| child.utf8_text(source.as_bytes()).ok());
69
+ let target = node
70
+ .named_children(&mut cursor)
71
+ .find(|child| child.kind() == "type")
72
+ .and_then(|child| child.utf8_text(source.as_bytes()).ok())
73
+ .map(without_type_arguments)
74
+ .and_then(|text| {
75
+ text.split_whitespace()
76
+ .next()
77
+ .map(|word| word.trim_end_matches('?').to_owned())
78
+ })
79
+ .filter(|word| !word.is_empty());
80
+ if let (Some(owner), Some(target)) = (owner, target) {
81
+ class_supertypes.push(ClassSupertypes {
82
+ owner: owner.to_owned(),
83
+ names: vec![target],
84
+ mixins: Vec::new(),
85
+ implemented: Vec::new(),
86
+ });
87
+ }
88
+ }
89
+
90
+ fn without_type_arguments(text: &str) -> String {
91
+ let mut flat = String::new();
92
+ let mut depth = 0_usize;
93
+ for character in text.chars() {
94
+ match character {
95
+ '<' => depth += 1,
96
+ '>' => depth = depth.saturating_sub(1),
97
+ _ if depth == 0 => flat.push(character),
98
+ _ => {}
99
+ }
100
+ }
101
+ flat
102
+ }
103
+
104
+ #[derive(Clone, Copy, PartialEq, Eq)]
105
+ enum Clause {
106
+ Extends,
107
+ With,
108
+ Implements,
109
+ Skipped,
110
+ }
111
+
112
+ fn header_supertypes(owner: String, header: &str) -> ClassSupertypes {
113
+ let flat = without_type_arguments(header);
114
+ let mut supertypes = ClassSupertypes {
115
+ owner,
116
+ names: Vec::new(),
117
+ mixins: Vec::new(),
118
+ implemented: Vec::new(),
119
+ };
120
+ let mut clause = None;
121
+ for word in flat.split(|character: char| character.is_whitespace() || character == ',') {
122
+ match word {
123
+ "extends" => clause = Some(Clause::Extends),
124
+ "with" => clause = Some(Clause::With),
125
+ "implements" => clause = Some(Clause::Implements),
126
+ "on" => clause = Some(Clause::Skipped),
127
+ "" => {}
128
+ _ => {
129
+ let name = word.trim_end_matches('?');
130
+ let list = match clause {
131
+ Some(Clause::Extends) => &mut supertypes.names,
132
+ Some(Clause::With) => &mut supertypes.mixins,
133
+ Some(Clause::Implements) => &mut supertypes.implemented,
134
+ Some(Clause::Skipped) | None => continue,
135
+ };
136
+ if !name.is_empty() {
137
+ list.push(name.to_owned());
138
+ }
139
+ }
140
+ }
141
+ }
142
+ supertypes
143
+ }
144
+
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();
149
+ header.trim_start().starts_with('@')
150
+ || header.split_whitespace().any(|word| {
151
+ matches!(word, "extends" | "implements" | "with" | "on") || word.starts_with('@')
152
+ })
153
+ }
154
+
155
+ fn member_is_annotated(node: Node<'_>, source: &str) -> bool {
156
+ source
157
+ .get(node.start_byte()..)
158
+ .is_some_and(|text| text.trim_start().starts_with('@'))
159
+ || node
160
+ .prev_sibling()
161
+ .is_some_and(|sibling| sibling.kind() == "annotation")
21
162
  }
22
163
 
23
164
  fn declaration_owner_name(node: Node<'_>, source: &str) -> Option<String> {
@@ -54,6 +195,7 @@ fn push_class_member(
54
195
  node: Node<'_>,
55
196
  source: &str,
56
197
  ) {
198
+ let start = members.len();
57
199
  let mut cursor = node.walk();
58
200
  for child in node.named_children(&mut cursor) {
59
201
  match child.kind() {
@@ -62,6 +204,11 @@ fn push_class_member(
62
204
  _ => {}
63
205
  }
64
206
  }
207
+ if member_is_annotated(node, source) {
208
+ for member in &mut members[start..] {
209
+ member.contract = true;
210
+ }
211
+ }
65
212
  }
66
213
 
67
214
  fn push_bodyless_member(
@@ -71,7 +218,7 @@ fn push_bodyless_member(
71
218
  source: &str,
72
219
  ) {
73
220
  if let Some(kind) = member_signature_kind(node) {
74
- push_signature_member(members, owner, kind, node, source);
221
+ push_signature_member(members, owner, kind, (node, false), source);
75
222
  return;
76
223
  }
77
224
 
@@ -82,6 +229,8 @@ fn push_bodyless_member(
82
229
  kind: MemberKind::Field,
83
230
  name,
84
231
  return_type: None,
232
+ contract: false,
233
+ has_body: true,
85
234
  location: node.start_position().into(),
86
235
  }));
87
236
  }
@@ -98,7 +247,7 @@ fn push_method_member(
98
247
  let Some(kind) = member_signature_kind(signature) else {
99
248
  return;
100
249
  };
101
- push_signature_member(members, owner, kind, signature, source);
250
+ push_signature_member(members, owner, kind, (signature, true), source);
102
251
  }
103
252
 
104
253
  fn member_signature_kind(node: Node<'_>) -> Option<MemberKind> {
@@ -121,7 +270,7 @@ fn push_signature_member(
121
270
  members: &mut Vec<MemberDeclaration>,
122
271
  owner: &str,
123
272
  kind: MemberKind,
124
- node: Node<'_>,
273
+ (node, has_body): (Node<'_>, bool),
125
274
  source: &str,
126
275
  ) {
127
276
  let Some(signature) = find_member_signature_node(node) else {
@@ -142,6 +291,8 @@ fn push_signature_member(
142
291
  kind,
143
292
  name,
144
293
  return_type,
294
+ contract: false,
295
+ has_body,
145
296
  location: node.start_position().into(),
146
297
  });
147
298
  }
@@ -190,6 +341,8 @@ fn push_member(
190
341
  kind,
191
342
  name,
192
343
  return_type: None,
344
+ contract: false,
345
+ has_body: true,
193
346
  location: node.start_position().into(),
194
347
  });
195
348
  }
@@ -825,3 +825,38 @@ export r'src\\raw.dart' if (dart.library.html) 'src\\web.dart';
825
825
 
826
826
  Ok(())
827
827
  }
828
+
829
+ #[test]
830
+ fn extracts_the_types_a_declaration_lists_after_supertype_keywords() -> Result<(), ExtractError> {
831
+ let source = "\
832
+ class Plain {}
833
+ class Item<T extends Num> extends Ordered<T> with Mixed, ui.Shared implements Comparable<Ordered>, Other? {}
834
+ mixin Runner on Base {}
835
+ ";
836
+
837
+ let extracted = extract_dart_source("lib/items.dart", source)?;
838
+
839
+ assert_eq!(
840
+ extracted
841
+ .class_supertypes
842
+ .iter()
843
+ .map(|clause| (
844
+ clause.owner.as_str(),
845
+ clause.names.clone(),
846
+ clause.mixins.clone(),
847
+ clause.implemented.clone()
848
+ ))
849
+ .collect::<Vec<_>>(),
850
+ vec![
851
+ (
852
+ "Item",
853
+ vec!["Ordered".to_owned()],
854
+ vec!["Mixed".to_owned(), "ui.Shared".to_owned()],
855
+ vec!["Comparable".to_owned(), "Other".to_owned()]
856
+ ),
857
+ ("Runner", vec![], vec![], vec![])
858
+ ]
859
+ );
860
+
861
+ Ok(())
862
+ }
package/src/extract.rs CHANGED
@@ -15,7 +15,7 @@ mod strings;
15
15
  use directives::{
16
16
  extract_directive, extract_library_name, extract_part_directive, extract_part_of_directive,
17
17
  };
18
- use members::push_class_like_members;
18
+ use members::{push_class_like_members, push_type_alias_target};
19
19
  use primary_constructors::{
20
20
  extract_primary_constructor_identifier_references,
21
21
  extract_primary_constructor_signature_references,
@@ -90,8 +90,10 @@ pub struct DartFile {
90
90
  pub declarations: Vec<TopLevelDeclaration>,
91
91
  /// Class-like member declarations in source order.
92
92
  pub members: Vec<MemberDeclaration>,
93
- /// Identifier uses in source order, including non-raw string interpolation,
94
- /// excluding import/export metadata and obvious declaration-name positions.
93
+ /// Supertype clauses of class-like declarations in source order.
94
+ #[serde(default, skip_serializing)]
95
+ pub class_supertypes: Vec<ClassSupertypes>,
96
+ /// Identifier uses in source order, excluding import/export metadata and declaration names.
95
97
  pub references: Vec<IdentifierReference>,
96
98
  /// Type references from public declaration signatures, excluding bodies.
97
99
  pub signature_references: Vec<SignatureReference>,
@@ -213,6 +215,19 @@ pub struct TopLevelDeclaration {
213
215
  pub range: SourceRange,
214
216
  }
215
217
 
218
+ /// The types a class-like declaration or `typedef Name = Type;` names after `extends`, `with` or `implements`.
219
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
220
+ pub struct ClassSupertypes {
221
+ /// Declared name of the class-like declaration.
222
+ pub owner: String,
223
+ /// Names of the types after `extends` without type arguments, keeping any import prefix.
224
+ pub names: Vec<String>,
225
+ /// Names of the types after `with`, written like `names`.
226
+ pub mixins: Vec<String>,
227
+ /// Names of the types after `implements`, written like `names`.
228
+ pub implemented: Vec<String>,
229
+ }
230
+
216
231
  /// A class-like member declaration that can become a future symbol node.
217
232
  #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
218
233
  pub struct MemberDeclaration {
@@ -225,12 +240,17 @@ pub struct MemberDeclaration {
225
240
  /// Declared method return type, when the member is a method.
226
241
  #[serde(default, skip_serializing_if = "Option::is_none")]
227
242
  pub return_type: Option<String>,
243
+ /// Whether an annotation or a supertype clause lets code outside the project call this member.
244
+ #[serde(default, skip_serializing)]
245
+ pub contract: bool,
246
+ /// Whether the member has an implementation: false only for an abstract method, getter or setter.
247
+ #[serde(default, skip_serializing)]
248
+ pub has_body: bool,
228
249
  /// Location of the member declaration node.
229
250
  pub location: Location,
230
251
  }
231
252
 
232
- /// A syntactic identifier or type identifier use, including references found in
233
- /// non-raw string interpolation.
253
+ /// A syntactic identifier or type identifier use, including non-raw string interpolation.
234
254
  #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
235
255
  pub struct IdentifierReference {
236
256
  /// Referenced identifier text.
@@ -314,16 +334,9 @@ pub enum ExtractError {
314
334
  },
315
335
  }
316
336
 
317
- /// Extract graph-relevant syntax facts from a Dart file on disk.
318
- ///
319
- /// This phase intentionally ignores function bodies and does not perform type
320
- /// evaluation, name resolution, or import resolution.
337
+ /// Extract syntax facts from a Dart file on disk, ignoring function bodies and name resolution.
321
338
  ///
322
339
  /// # Errors
323
- ///
324
- /// Returns [`ExtractError::Read`] when the file cannot be read, or a parser
325
- /// error when Tree-Sitter cannot load the Dart grammar, cannot produce a tree,
326
- /// or finds Dart syntax errors.
327
340
  pub fn extract_dart_file(path: impl AsRef<Path>) -> Result<DartFile, ExtractError> {
328
341
  let path = path.as_ref();
329
342
  let source = fs::read_to_string(path).map_err(|source| ExtractError::Read {
@@ -334,15 +347,9 @@ pub fn extract_dart_file(path: impl AsRef<Path>) -> Result<DartFile, ExtractErro
334
347
  extract_dart_source(path, &source)
335
348
  }
336
349
 
337
- /// Extract graph-relevant syntax facts from Dart source text.
338
- ///
339
- /// `path` is carried into the returned facts and error messages. It does not
340
- /// need to exist on disk.
350
+ /// Extract syntax facts from Dart source text; `path` labels the facts and need not exist.
341
351
  ///
342
352
  /// # Errors
343
- ///
344
- /// Returns a parser error when Tree-Sitter cannot load the Dart grammar, cannot
345
- /// produce a tree, or finds Dart syntax errors.
346
353
  pub fn extract_dart_source(path: impl AsRef<Path>, source: &str) -> Result<DartFile, ExtractError> {
347
354
  let path = path.as_ref().to_path_buf();
348
355
  let parsed =
@@ -357,6 +364,7 @@ pub fn extract_dart_source(path: impl AsRef<Path>, source: &str) -> Result<DartF
357
364
  let mut parts = Vec::new();
358
365
  let mut declarations = Vec::new();
359
366
  let mut members = Vec::new();
367
+ let mut class_supertypes = Vec::new();
360
368
  let mut references = extract_identifier_references(root, parse_source);
361
369
  references.extend(extract_dot_shorthand_references(source));
362
370
  references.extend(extract_primary_constructor_identifier_references(source));
@@ -379,45 +387,24 @@ pub fn extract_dart_source(path: impl AsRef<Path>, source: &str) -> Result<DartF
379
387
  }
380
388
  "class_declaration" => {
381
389
  push_class_declaration(&mut declarations, child, parse_source);
382
- push_class_like_members(&mut members, child, parse_source);
383
- }
384
- "mixin_declaration" => {
385
- push_named_declaration(
386
- &mut declarations,
387
- child,
388
- parse_source,
389
- DeclarationKind::Mixin,
390
- );
391
- push_class_like_members(&mut members, child, parse_source);
392
- }
393
- "extension_declaration" => {
394
- push_named_declaration(
395
- &mut declarations,
396
- child,
397
- parse_source,
398
- DeclarationKind::Extension,
399
- );
400
- push_class_like_members(&mut members, child, parse_source);
390
+ push_class_like_members(&mut members, &mut class_supertypes, child, parse_source);
401
391
  }
402
- "extension_type_declaration" => {
392
+ "mixin_declaration"
393
+ | "extension_declaration"
394
+ | "extension_type_declaration"
395
+ | "enum_declaration" => {
403
396
  push_named_declaration(
404
397
  &mut declarations,
405
398
  child,
406
399
  parse_source,
407
- DeclarationKind::ExtensionType,
400
+ named_declaration_kind(child.kind()),
408
401
  );
409
- push_class_like_members(&mut members, child, parse_source);
402
+ push_class_like_members(&mut members, &mut class_supertypes, child, parse_source);
410
403
  }
411
- "enum_declaration" => {
412
- push_named_declaration(
413
- &mut declarations,
414
- child,
415
- parse_source,
416
- DeclarationKind::Enum,
417
- );
418
- push_class_like_members(&mut members, child, parse_source);
404
+ "type_alias" => {
405
+ push_type_alias_declaration(&mut declarations, child, parse_source);
406
+ push_type_alias_target(&mut class_supertypes, child, parse_source);
419
407
  }
420
- "type_alias" => push_type_alias_declaration(&mut declarations, child, parse_source),
421
408
  "top_level_variable_declaration" | "external_variable_declaration" => {
422
409
  push_variable_declarations(&mut declarations, child, parse_source);
423
410
  }
@@ -442,6 +429,7 @@ pub fn extract_dart_source(path: impl AsRef<Path>, source: &str) -> Result<DartF
442
429
  parts,
443
430
  declarations,
444
431
  members,
432
+ class_supertypes,
445
433
  references,
446
434
  signature_references,
447
435
  routes,
@@ -505,6 +493,15 @@ fn push_class_declaration(
505
493
  }
506
494
  }
507
495
 
496
+ fn named_declaration_kind(node_kind: &str) -> DeclarationKind {
497
+ match node_kind {
498
+ "mixin_declaration" => DeclarationKind::Mixin,
499
+ "extension_declaration" => DeclarationKind::Extension,
500
+ "extension_type_declaration" => DeclarationKind::ExtensionType,
501
+ _ => DeclarationKind::Enum,
502
+ }
503
+ }
504
+
508
505
  fn push_named_declaration(
509
506
  declarations: &mut Vec<TopLevelDeclaration>,
510
507
  node: Node<'_>,
package/src/generated.rs CHANGED
@@ -189,7 +189,13 @@ fn is_region_subtag(part: &str) -> bool {
189
189
  pub(crate) fn is_flutterfire_options_path(path: &Path) -> bool {
190
190
  path.file_name()
191
191
  .and_then(|name| name.to_str())
192
- .is_some_and(|file_name| file_name == "firebase_options.dart")
192
+ .is_some_and(|file_name| {
193
+ file_name == "firebase_options.dart"
194
+ || (file_name.starts_with("firebase_options_")
195
+ && path
196
+ .extension()
197
+ .is_some_and(|extension| extension == "dart"))
198
+ })
193
199
  && path
194
200
  .parent()
195
201
  .and_then(|parent| parent.file_name())
@@ -243,6 +249,7 @@ mod tests {
243
249
  Path::new("test/drift/generated/schema_v31.dart"),
244
250
  Path::new("lib/firebase_options.dart"),
245
251
  Path::new("packages/foo/lib/firebase_options.dart"),
252
+ Path::new("lib/firebase_options_dev.dart"),
246
253
  ] {
247
254
  assert!(is_generated_dart_path(path), "{}", path.display());
248
255
  }
@@ -259,6 +266,8 @@ mod tests {
259
266
  Path::new("test/drift/generated/schema_version.dart"),
260
267
  Path::new("lib/src/firebase_options.dart"),
261
268
  Path::new("packages/foo/lib/config/firebase_options.dart"),
269
+ Path::new("lib/src/firebase_options_dev.dart"),
270
+ Path::new("lib/firebase_options_dev.txt"),
262
271
  ] {
263
272
  assert!(!is_generated_dart_path(path), "{}", path.display());
264
273
  }
@@ -206,6 +206,7 @@ impl Fixture {
206
206
  members: vec![],
207
207
  references: vec![],
208
208
  signature_references: vec![],
209
+ class_supertypes: vec![],
209
210
  routes: vec![],
210
211
  }
211
212
  }
@@ -49,6 +49,7 @@ fn resolves_package_imports_using_ancestor_package_config_from_member_root()
49
49
  members: Vec::new(),
50
50
  references: Vec::new(),
51
51
  signature_references: Vec::new(),
52
+ class_supertypes: Vec::new(),
52
53
  routes: Vec::new(),
53
54
  };
54
55
 
@@ -190,6 +191,7 @@ fn dart_file(path: PathBuf, import_uri: &str) -> DartFile {
190
191
  members: Vec::new(),
191
192
  references: Vec::new(),
192
193
  signature_references: Vec::new(),
194
+ class_supertypes: Vec::new(),
193
195
  routes: Vec::new(),
194
196
  }
195
197
  }
@@ -206,6 +208,7 @@ fn empty_dart_file(path: PathBuf) -> DartFile {
206
208
  members: Vec::new(),
207
209
  references: Vec::new(),
208
210
  signature_references: Vec::new(),
211
+ class_supertypes: Vec::new(),
209
212
  routes: Vec::new(),
210
213
  }
211
214
  }
@@ -113,6 +113,7 @@ impl Fixture {
113
113
  members: vec![],
114
114
  references: vec![],
115
115
  signature_references: vec![],
116
+ class_supertypes: vec![],
116
117
  routes: vec![],
117
118
  }
118
119
  }
@@ -564,6 +564,7 @@ fn preserves_import_and_export_visibility_metadata_on_edges()
564
564
  members: vec![],
565
565
  references: vec![],
566
566
  signature_references: vec![],
567
+ class_supertypes: vec![],
567
568
  routes: vec![],
568
569
  };
569
570
  let service = fixture.file("lib/src/service.dart", vec![], vec![]);
@@ -735,6 +736,7 @@ fn resolves_package_imports_to_path_dependencies() -> Result<(), Box<dyn std::er
735
736
  members: vec![],
736
737
  references: vec![],
737
738
  signature_references: vec![],
739
+ class_supertypes: vec![],
738
740
  routes: vec![],
739
741
  };
740
742
 
@@ -956,6 +958,7 @@ impl Fixture {
956
958
  members: vec![],
957
959
  references: vec![],
958
960
  signature_references: vec![],
961
+ class_supertypes: vec![],
959
962
  routes: vec![],
960
963
  }
961
964
  }
@@ -96,6 +96,7 @@ impl Fixture {
96
96
  members: vec![],
97
97
  references: vec![],
98
98
  signature_references: vec![],
99
+ class_supertypes: vec![],
99
100
  routes: vec![],
100
101
  }
101
102
  }
@@ -260,7 +260,7 @@ fn crap_finding(
260
260
  let crap_score = crap_score(function.cyclomatic, covered_lines, executable_lines);
261
261
  let thresholds = threshold_context.crap_thresholds(function, crap_score)?;
262
262
  let max_crap = thresholds.effective.max_crap?;
263
- if crap_score <= max_crap {
263
+ if crap_score < max_crap {
264
264
  return None;
265
265
  }
266
266