dart-decimate 0.0.20 → 0.0.22

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.
@@ -20,7 +20,8 @@ impl NameResolution {
20
20
  let Self::Type(type_name) = self else {
21
21
  return false;
22
22
  };
23
- accepted.contains(&type_name.as_str())
23
+ let simple = simple_type_name(type_name);
24
+ accepted.contains(&simple.as_str())
24
25
  }
25
26
  }
26
27
 
@@ -34,6 +35,21 @@ struct GoRouterFactoryCall {
34
35
  prefix: Option<String>,
35
36
  }
36
37
 
38
+ #[derive(Clone, Copy)]
39
+ enum ImportPrefix<'source> {
40
+ Unprefixed,
41
+ Prefixed(&'source str),
42
+ }
43
+
44
+ impl<'source> ImportPrefix<'source> {
45
+ const fn as_option(self) -> Option<&'source str> {
46
+ match self {
47
+ Self::Unprefixed => None,
48
+ Self::Prefixed(prefix) => Some(prefix),
49
+ }
50
+ }
51
+ }
52
+
37
53
  pub(super) fn route_extension_navigation_has_context_argument(
38
54
  root: Node<'_>,
39
55
  site: Node<'_>,
@@ -60,6 +76,95 @@ pub(super) fn navigation_receiver_accepts_route_location(
60
76
  .is_some_and(|resolution| resolution.matches(&[BUILD_CONTEXT, GO_ROUTER]))
61
77
  }
62
78
 
79
+ pub(super) fn navigation_receiver_is_imported_go_router_api(
80
+ root: Node<'_>,
81
+ site: Node<'_>,
82
+ receiver: &str,
83
+ source: &str,
84
+ ) -> bool {
85
+ let receiver = receiver.trim_end_matches(['?', '!']);
86
+ if imported_go_router_receiver_expression(root, site, receiver, source) {
87
+ return true;
88
+ }
89
+ match navigation_expression_resolution(root, site, receiver, source) {
90
+ Some(NameResolution::Type(type_name)) if simple_type_name(&type_name) == BUILD_CONTEXT => {
91
+ let Some(prefix) = resolved_type_import_prefix(&type_name, BUILD_CONTEXT) else {
92
+ return false;
93
+ };
94
+ let prefix = prefix.as_option();
95
+ any_go_router_symbol_import(root, "GoRouterHelper", source)
96
+ && framework_build_context_import(root, prefix, source)
97
+ && (prefix.is_some() || !local_type_declaration_named(root, BUILD_CONTEXT, source))
98
+ }
99
+ Some(NameResolution::Type(type_name)) if simple_type_name(&type_name) == GO_ROUTER => {
100
+ let Some(prefix) = resolved_type_import_prefix(&type_name, GO_ROUTER) else {
101
+ return false;
102
+ };
103
+ let prefix = prefix.as_option();
104
+ go_router_symbol_import(root, prefix, GO_ROUTER, source)
105
+ && (prefix.is_some() || !local_type_declaration_named(root, GO_ROUTER, source))
106
+ }
107
+ Some(NameResolution::Type(_) | NameResolution::Shadowed) | None => false,
108
+ }
109
+ }
110
+
111
+ fn imported_go_router_receiver_expression(
112
+ root: Node<'_>,
113
+ site: Node<'_>,
114
+ receiver: &str,
115
+ source: &str,
116
+ ) -> bool {
117
+ let trimmed = receiver.trim();
118
+ let unwrapped = unwrap_parenthesized_text(trimmed).unwrap_or(trimmed);
119
+ let without_postfix = unwrapped.trim_end_matches(['?', '!']).trim();
120
+ let without_keyword =
121
+ strip_constructor_keyword_prefix(without_postfix).unwrap_or(without_postfix);
122
+ let compact = strip_whitespace(without_keyword);
123
+ let unwrapped = unwrap_parenthesized_text(&compact).unwrap_or(&compact);
124
+ let receiver = unwrapped.trim_end_matches(['?', '!']);
125
+ if let Some(prefix) = direct_prefixed_constructor_call_text(receiver, GO_ROUTER) {
126
+ return !term_identifier_shadowed_at(root, site, &prefix, source)
127
+ && go_router_symbol_import(root, Some(&prefix), GO_ROUTER, source);
128
+ }
129
+ if direct_constructor_call_text(receiver, GO_ROUTER) {
130
+ return !term_identifier_shadowed_at(root, site, GO_ROUTER, source)
131
+ && go_router_symbol_import(root, None, GO_ROUTER, source)
132
+ && !local_type_declaration_named(root, GO_ROUTER, source);
133
+ }
134
+ let Some(factory) = go_router_factory_call(receiver) else {
135
+ return false;
136
+ };
137
+ if let Some(prefix) = factory.prefix.as_deref() {
138
+ return !term_identifier_shadowed_at(root, site, prefix, source)
139
+ && go_router_symbol_import(root, Some(prefix), GO_ROUTER, source);
140
+ }
141
+ !term_identifier_shadowed_at(root, site, GO_ROUTER, source)
142
+ && go_router_symbol_import(root, None, GO_ROUTER, source)
143
+ && !local_type_declaration_named(root, GO_ROUTER, source)
144
+ }
145
+
146
+ pub(super) fn local_type_declaration_named(root: Node<'_>, name: &str, source: &str) -> bool {
147
+ let mut found = false;
148
+ visit_named(root, &mut |node| {
149
+ if found
150
+ || !matches!(
151
+ node.kind(),
152
+ "class_declaration"
153
+ | "mixin_declaration"
154
+ | "enum_declaration"
155
+ | "extension_type_declaration"
156
+ | "type_alias"
157
+ )
158
+ {
159
+ return;
160
+ }
161
+ if field_text(node, "name", source).as_deref() == Some(name) {
162
+ found = true;
163
+ }
164
+ });
165
+ found
166
+ }
167
+
63
168
  fn go_router_receiver_expression(
64
169
  root: Node<'_>,
65
170
  site: Node<'_>,
@@ -77,7 +182,7 @@ fn go_router_receiver_expression(
77
182
  };
78
183
  if let Some(prefix) = factory.prefix.as_deref() {
79
184
  return !term_identifier_shadowed_at(root, site, prefix, source)
80
- && go_router_import(root, Some(prefix), source);
185
+ && go_router_symbol_import(root, Some(prefix), GO_ROUTER, source);
81
186
  }
82
187
  !term_identifier_shadowed_at(root, site, GO_ROUTER, source)
83
188
  && go_router_factory_available(root, factory.method, source)
@@ -123,11 +228,21 @@ fn direct_prefixed_static_member_call_text(
123
228
  .then(|| prefix.to_owned())
124
229
  }
125
230
 
231
+ fn direct_prefixed_constructor_call_text(text: &str, type_name: &str) -> Option<String> {
232
+ let receiver = unwrap_parenthesized_text(text.trim())?;
233
+ let type_marker = format!(".{type_name}");
234
+ let type_start = receiver.find(&type_marker)?;
235
+ let prefix = &receiver[..type_start];
236
+ (is_simple_identifier(prefix)
237
+ && direct_constructor_call_text(&receiver[type_start + 1..], type_name))
238
+ .then(|| prefix.to_owned())
239
+ }
240
+
126
241
  fn go_router_factory_available(root: Node<'_>, method: &str, source: &str) -> bool {
127
242
  if let Some(class) = local_go_router_class(root, source) {
128
243
  return local_go_router_class_has_factory(class, method, source);
129
244
  }
130
- go_router_import(root, None, source)
245
+ go_router_symbol_import(root, None, GO_ROUTER, source)
131
246
  }
132
247
 
133
248
  fn local_go_router_class<'tree>(root: Node<'tree>, source: &str) -> Option<Node<'tree>> {
@@ -179,13 +294,46 @@ fn class_has_named_constructor(node: Node<'_>, method: &str, source: &str) -> bo
179
294
  .any(|prefix| compact.starts_with(prefix))
180
295
  }
181
296
 
182
- fn go_router_import(root: Node<'_>, prefix: Option<&str>, source: &str) -> bool {
297
+ pub(super) fn go_router_symbol_import(
298
+ root: Node<'_>,
299
+ prefix: Option<&str>,
300
+ symbol: &str,
301
+ source: &str,
302
+ ) -> bool {
303
+ matching_go_router_symbol_import(root, symbol, source, |candidate| candidate == prefix)
304
+ }
305
+
306
+ fn any_go_router_symbol_import(root: Node<'_>, symbol: &str, source: &str) -> bool {
307
+ matching_go_router_symbol_import(root, symbol, source, |_| true)
308
+ }
309
+
310
+ fn matching_go_router_symbol_import(
311
+ root: Node<'_>,
312
+ symbol: &str,
313
+ source: &str,
314
+ prefix_matches: impl Fn(Option<&str>) -> bool,
315
+ ) -> bool {
183
316
  let mut found = false;
184
317
  visit_named(root, &mut |node| {
185
318
  if found || node.kind() != "library_import" {
186
319
  return;
187
320
  }
188
- if import_alias(node, source).as_deref() != prefix {
321
+ if !prefix_matches(import_alias(node, source).as_deref()) {
322
+ return;
323
+ }
324
+ if import_uri(node, source).as_deref() == Some("package:go_router/go_router.dart")
325
+ && import_exposes_symbol(node, symbol, source)
326
+ {
327
+ found = true;
328
+ }
329
+ });
330
+ found
331
+ }
332
+
333
+ pub(super) fn has_go_router_import(root: Node<'_>, source: &str) -> bool {
334
+ let mut found = false;
335
+ visit_named(root, &mut |node| {
336
+ if found || node.kind() != "library_import" {
189
337
  return;
190
338
  }
191
339
  if import_uri(node, source).as_deref() == Some("package:go_router/go_router.dart") {
@@ -195,6 +343,45 @@ fn go_router_import(root: Node<'_>, prefix: Option<&str>, source: &str) -> bool
195
343
  found
196
344
  }
197
345
 
346
+ fn import_exposes_symbol(node: Node<'_>, symbol: &str, source: &str) -> bool {
347
+ let Some(specification) = find_first_named_descendant(node, "import_specification") else {
348
+ return true;
349
+ };
350
+ let mut shown = None;
351
+ let mut hidden = false;
352
+ let mut cursor = specification.walk();
353
+ for combinator in specification
354
+ .named_children(&mut cursor)
355
+ .filter(|child| child.kind() == "combinator")
356
+ {
357
+ let text = combinator
358
+ .utf8_text(source.as_bytes())
359
+ .unwrap_or_default()
360
+ .trim();
361
+ let contains_symbol = combinator_identifiers(combinator, source)
362
+ .iter()
363
+ .any(|name| name == symbol);
364
+ if text.starts_with("show") {
365
+ shown = Some(shown.unwrap_or(true) && contains_symbol);
366
+ } else if text.starts_with("hide") && contains_symbol {
367
+ hidden = true;
368
+ }
369
+ }
370
+ shown.unwrap_or(true) && !hidden
371
+ }
372
+
373
+ fn combinator_identifiers(node: Node<'_>, source: &str) -> Vec<String> {
374
+ let mut identifiers = Vec::new();
375
+ visit_named(node, &mut |candidate| {
376
+ if candidate.kind() == "identifier"
377
+ && let Ok(name) = candidate.utf8_text(source.as_bytes())
378
+ {
379
+ identifiers.push(name.to_owned());
380
+ }
381
+ });
382
+ identifiers
383
+ }
384
+
198
385
  fn import_alias(node: Node<'_>, source: &str) -> Option<String> {
199
386
  find_first_named_descendant(node, "import_specification")
200
387
  .and_then(|specification| field_text(specification, "alias", source))
@@ -350,7 +537,7 @@ fn navigation_expression_resolution(
350
537
  else {
351
538
  return Some(NameResolution::Shadowed);
352
539
  };
353
- local_type_member_resolution(root, &owner_type, member, source)
540
+ local_type_member_resolution(root, &simple_type_name(&owner_type), member, source)
354
541
  }
355
542
 
356
543
  fn navigator_context_expression(
@@ -426,6 +613,33 @@ fn visible_name_resolution_at(
426
613
  path_child = scope;
427
614
  parent = scope.parent();
428
615
  }
616
+ top_level_name_resolution(root, name, source)
617
+ }
618
+
619
+ fn top_level_name_resolution(root: Node<'_>, name: &str, source: &str) -> Option<NameResolution> {
620
+ let mut cursor = root.walk();
621
+ for declaration in root.named_children(&mut cursor) {
622
+ if matches!(
623
+ declaration.kind(),
624
+ "top_level_variable_declaration" | "external_variable_declaration"
625
+ ) && declaration_binds_name(declaration, name, source)
626
+ {
627
+ return Some(declaration_type_resolution(root, declaration, name, source));
628
+ }
629
+ if (is_callable_node(declaration.kind())
630
+ && local_function_name(declaration, source).as_deref() == Some(name))
631
+ || (matches!(
632
+ declaration.kind(),
633
+ "class_declaration"
634
+ | "mixin_declaration"
635
+ | "enum_declaration"
636
+ | "extension_type_declaration"
637
+ | "type_alias"
638
+ ) && field_text(declaration, "name", source).as_deref() == Some(name))
639
+ {
640
+ return Some(NameResolution::Shadowed);
641
+ }
642
+ }
429
643
  None
430
644
  }
431
645
 
@@ -620,14 +834,32 @@ fn declared_navigation_type(root: Node<'_>, type_name: &str, source: &str) -> Op
620
834
  }
621
835
  return match simple {
622
836
  BUILD_CONTEXT => framework_build_context_import(root, Some(prefix), source),
623
- GO_ROUTER => go_router_import(root, Some(prefix), source),
837
+ GO_ROUTER => go_router_symbol_import(root, Some(prefix), GO_ROUTER, source),
624
838
  _ => false,
625
839
  }
626
- .then(|| simple.to_owned());
840
+ .then(|| base.to_owned());
627
841
  }
628
842
  Some(simple_type_name(base))
629
843
  }
630
844
 
845
+ fn resolved_type_import_prefix<'source>(
846
+ type_name: &'source str,
847
+ expected: &str,
848
+ ) -> Option<ImportPrefix<'source>> {
849
+ let base = type_name
850
+ .trim()
851
+ .trim_end_matches('?')
852
+ .split('<')
853
+ .next()
854
+ .unwrap_or(type_name)
855
+ .trim();
856
+ if base == expected {
857
+ return Some(ImportPrefix::Unprefixed);
858
+ }
859
+ let (prefix, simple) = base.rsplit_once('.')?;
860
+ (simple == expected && is_simple_identifier(prefix)).then_some(ImportPrefix::Prefixed(prefix))
861
+ }
862
+
631
863
  fn framework_build_context_import(root: Node<'_>, prefix: Option<&str>, source: &str) -> bool {
632
864
  let mut found = false;
633
865
  visit_named(root, &mut |node| {
@@ -637,7 +869,9 @@ fn framework_build_context_import(root: Node<'_>, prefix: Option<&str>, source:
637
869
  if import_alias(node, source).as_deref() != prefix {
638
870
  return;
639
871
  }
640
- if import_uri(node, source).is_some_and(|uri| uri.starts_with("package:flutter/")) {
872
+ if import_uri(node, source).is_some_and(|uri| uri.starts_with("package:flutter/"))
873
+ && import_exposes_symbol(node, BUILD_CONTEXT, source)
874
+ {
641
875
  found = true;
642
876
  }
643
877
  });
@@ -675,6 +909,14 @@ fn initializer_type(root: Node<'_>, node: Node<'_>, source: &str) -> Option<Stri
675
909
  let unwrapped = unwrap_parenthesized_text(without_postfix).unwrap_or(without_postfix);
676
910
  let without_keyword = strip_constructor_keyword_prefix(unwrapped).unwrap_or(unwrapped);
677
911
  let compact = strip_whitespace(without_keyword);
912
+ let prefixed_go_router = direct_prefixed_constructor_call_text(&compact, GO_ROUTER)
913
+ .or_else(|| go_router_factory_call(&compact).and_then(|factory| factory.prefix));
914
+ if let Some(prefix) = prefixed_go_router
915
+ && !term_identifier_shadowed_at(root, node, &prefix, source)
916
+ && go_router_symbol_import(root, Some(&prefix), GO_ROUTER, source)
917
+ {
918
+ return Some(format!("{prefix}.{GO_ROUTER}"));
919
+ }
678
920
  for target_type in [BUILD_CONTEXT, GO_ROUTER] {
679
921
  if direct_constructor_call_text(&compact, target_type)
680
922
  || (target_type == GO_ROUTER
@@ -901,6 +1143,7 @@ fn binding_name(node: Node<'_>, source: &str) -> Option<String> {
901
1143
  "formal_parameter"
902
1144
  | "initialized_identifier"
903
1145
  | "initialized_variable_definition"
1146
+ | "static_final_declaration"
904
1147
  | "typed_identifier"
905
1148
  | "variable_pattern"
906
1149
  ) {
@@ -4,6 +4,7 @@ use tree_sitter::Node;
4
4
 
5
5
  mod aliases;
6
6
  mod classification;
7
+ mod mixed_style;
7
8
  mod navigation;
8
9
  mod receivers;
9
10
  mod registry_api;
@@ -15,6 +16,7 @@ use aliases::{route_alias_receiver_node, route_alias_receiver_text, route_aliase
15
16
  pub(super) use classification::{
16
17
  ResidualCycle, TypedGoRouterCycle, decompose_typed_go_router_cycle,
17
18
  };
19
+ pub(super) use mixed_style::{MixedGoRouterUse, MixedGoRouterUseKind, mixed_go_router_uses};
18
20
  use navigation::{
19
21
  navigation_receiver_accepts_route_location, route_extension_navigation_has_context_argument,
20
22
  };
@@ -2,11 +2,12 @@ use std::collections::BTreeSet;
2
2
  use std::path::Path;
3
3
 
4
4
  use super::format::display_path;
5
+ use super::route_cycle::{MixedGoRouterUse, MixedGoRouterUseKind, mixed_go_router_uses};
5
6
  use super::{Finding, FindingAction, FindingKind, Severity};
6
- use crate::{RouteCollision, RouteCollisionKind, RouteCollisionReport};
7
+ use crate::{RouteCollision, RouteCollisionKind, RouteCollisionReport, scan::ScannedProject};
7
8
 
8
9
  pub(super) fn add_route_findings(
9
- root: &Path,
10
+ project: &ScannedProject,
10
11
  report: &RouteCollisionReport,
11
12
  findings: &mut Vec<Finding>,
12
13
  ) {
@@ -14,7 +15,12 @@ pub(super) fn add_route_findings(
14
15
  report
15
16
  .collisions
16
17
  .iter()
17
- .filter_map(|collision| route_collision_finding(root, collision)),
18
+ .filter_map(|collision| route_collision_finding(&project.root, collision)),
19
+ );
20
+ findings.extend(
21
+ mixed_go_router_uses(project)
22
+ .iter()
23
+ .map(|usage| mixed_go_router_finding(&project.root, usage)),
18
24
  );
19
25
  }
20
26
 
@@ -66,6 +72,69 @@ fn route_collision_finding(root: &Path, collision: &RouteCollision) -> Option<Fi
66
72
  })
67
73
  }
68
74
 
75
+ fn mixed_go_router_finding(root: &Path, usage: &MixedGoRouterUse) -> Finding {
76
+ let path = display_path(root, &usage.path);
77
+ let (message, description, target_symbol) = match &usage.kind {
78
+ MixedGoRouterUseKind::RouteDefinition => (
79
+ "A raw `GoRoute` definition is used after typed routes were adopted".to_owned(),
80
+ "Define the route with `TypedGoRoute` and `GoRouteData` so route construction remains compile-time checked",
81
+ "GoRoute".to_owned(),
82
+ ),
83
+ MixedGoRouterUseKind::Navigation { method } => (
84
+ format!("Raw GoRouter navigation `{method}` is used after typed routes were adopted"),
85
+ "Navigate with the generated route object so route parameters remain compile-time checked",
86
+ method.clone(),
87
+ ),
88
+ MixedGoRouterUseKind::RedirectDestination => (
89
+ "A raw redirect destination is used after typed routes were adopted".to_owned(),
90
+ "Return a generated typed route object's `.location` so redirect parameters remain compile-time checked",
91
+ "redirect".to_owned(),
92
+ ),
93
+ };
94
+ Finding {
95
+ rule_id: "dart-decimate/mixed-go-router-style".to_owned(),
96
+ fingerprint: Some(mixed_go_router_fingerprint(&path, usage)),
97
+ kind: FindingKind::MixedGoRouterStyle,
98
+ severity: Severity::Error,
99
+ message,
100
+ path: path.clone(),
101
+ line: usage.location.line,
102
+ column: usage.location.column,
103
+ safe_to_delete: false,
104
+ files: vec![path.clone()],
105
+ edge: None,
106
+ actions: vec![
107
+ FindingAction::new("use-typed-go-router", description, false)
108
+ .with_target_path(path)
109
+ .with_target_symbol(target_symbol)
110
+ .with_suppression_comment(
111
+ "// dart-decimate-ignore-next-line mixed-go-router-style -- <reason>",
112
+ ),
113
+ ],
114
+ }
115
+ }
116
+
117
+ fn mixed_go_router_fingerprint(path: &str, usage: &MixedGoRouterUse) -> String {
118
+ let mut hash = 0xcbf2_9ce4_8422_2325_u64;
119
+ for byte in format!(
120
+ "{}:{}:{}:{}",
121
+ path,
122
+ usage.location.line,
123
+ usage.location.column,
124
+ match &usage.kind {
125
+ MixedGoRouterUseKind::RouteDefinition => "GoRoute",
126
+ MixedGoRouterUseKind::Navigation { method } => method,
127
+ MixedGoRouterUseKind::RedirectDestination => "redirect",
128
+ }
129
+ )
130
+ .as_bytes()
131
+ {
132
+ hash ^= u64::from(*byte);
133
+ hash = hash.wrapping_mul(0x0000_0100_0000_01b3);
134
+ }
135
+ format!("route-style:{:08x}", hash & 0xffff_ffff)
136
+ }
137
+
69
138
  fn route_collision_fingerprint(collision: &RouteCollision) -> String {
70
139
  let mut hash = 0xcbf2_9ce4_8422_2325_u64;
71
140
  for byte in format!("{:?}:{}", collision.kind, collision.value).as_bytes() {
@@ -286,6 +286,7 @@ const fn kind_key(kind: FindingKind) -> &'static str {
286
286
  FindingKind::UnusedClassMember => "unused-class-member",
287
287
  FindingKind::DuplicateExport => "duplicate-export",
288
288
  FindingKind::RouteCollision => "route-collision",
289
+ FindingKind::MixedGoRouterStyle => "mixed-go-router-style",
289
290
  FindingKind::PrivateWidgetClass => "private-widget-class",
290
291
  FindingKind::WidgetTopLevelFunctionBoundary => "widget-top-level-function-boundary",
291
292
  FindingKind::UnusedWidgetParam => "unused-widget-param",
@@ -218,6 +218,8 @@ pub struct ReportSummary {
218
218
  pub duplicate_exports: usize,
219
219
  /// Typed `GoRouter` route path or name collisions.
220
220
  pub route_collisions: usize,
221
+ /// Raw `GoRouter` definitions or destination APIs used after typed-route adoption.
222
+ pub mixed_go_router_styles: usize,
221
223
  /// Private classes extending Flutter widget bases.
222
224
  pub private_widget_classes: usize,
223
225
  /// Top-level Flutter widget helper functions.
@@ -355,6 +357,8 @@ pub enum FindingKind {
355
357
  DuplicateExport,
356
358
  /// Typed `GoRouter` routes declare the same path or route name.
357
359
  RouteCollision,
360
+ /// Typed and raw `GoRouter` navigation styles coexist.
361
+ MixedGoRouterStyle,
358
362
  /// Private class extends a Flutter widget base.
359
363
  PrivateWidgetClass,
360
364
  /// Top-level function belongs behind a Flutter widget boundary.
package/src/output.rs CHANGED
@@ -328,7 +328,7 @@ fn report_findings(
328
328
  add_security_findings(&project.root, security, &mut findings);
329
329
  }
330
330
  if let Some(routes) = &results.routes {
331
- add_route_findings(&project.root, routes, &mut findings);
331
+ add_route_findings(project, routes, &mut findings);
332
332
  }
333
333
  if let Some(widgets) = &results.widgets {
334
334
  add_widget_findings(&project.root, widgets, &mut findings);
@@ -441,6 +441,7 @@ fn apply_cleanup_summary(
441
441
  summary.unused_class_members = kind_count(findings, FindingKind::UnusedClassMember);
442
442
  summary.duplicate_exports = kind_count(findings, FindingKind::DuplicateExport);
443
443
  summary.route_collisions = kind_count(findings, FindingKind::RouteCollision);
444
+ summary.mixed_go_router_styles = kind_count(findings, FindingKind::MixedGoRouterStyle);
444
445
  }
445
446
 
446
447
  fn apply_widget_summary(summary: &mut ReportSummary, findings: &[Finding]) {
@@ -597,6 +598,7 @@ fn apply_scoped_counts(summary: &mut ReportSummary, findings: &[Finding]) {
597
598
  summary.unused_class_members = kind_count(findings, FindingKind::UnusedClassMember);
598
599
  summary.duplicate_exports = kind_count(findings, FindingKind::DuplicateExport);
599
600
  summary.route_collisions = kind_count(findings, FindingKind::RouteCollision);
601
+ summary.mixed_go_router_styles = kind_count(findings, FindingKind::MixedGoRouterStyle);
600
602
  summary.private_widget_classes = kind_count(findings, FindingKind::PrivateWidgetClass);
601
603
  summary.widget_top_level_functions =
602
604
  kind_count(findings, FindingKind::WidgetTopLevelFunctionBoundary);
@@ -134,6 +134,7 @@ fn summary_schema() -> Value {
134
134
  "unused_class_members",
135
135
  "duplicate_exports",
136
136
  "route_collisions",
137
+ "mixed_go_router_styles",
137
138
  "private_widget_classes",
138
139
  "widget_top_level_functions",
139
140
  "unused_widget_params",
@@ -299,6 +300,7 @@ fn finding_kind_values() -> Value {
299
300
  "unused-class-member",
300
301
  "duplicate-export",
301
302
  "route-collision",
303
+ "mixed-go-router-style",
302
304
  "private-widget-class",
303
305
  "widget-top-level-function-boundary",
304
306
  "unused-widget-param",
@@ -421,6 +421,7 @@ fn recompute_summary(report: &mut JsonReport) {
421
421
  report.summary.unused_class_members = kind_count(report, FindingKind::UnusedClassMember);
422
422
  report.summary.duplicate_exports = kind_count(report, FindingKind::DuplicateExport);
423
423
  report.summary.route_collisions = kind_count(report, FindingKind::RouteCollision);
424
+ report.summary.mixed_go_router_styles = kind_count(report, FindingKind::MixedGoRouterStyle);
424
425
  report.summary.private_widget_classes = kind_count(report, FindingKind::PrivateWidgetClass);
425
426
  report.summary.widget_top_level_functions =
426
427
  kind_count(report, FindingKind::WidgetTopLevelFunctionBoundary);
@@ -2,7 +2,7 @@ use std::path::Path;
2
2
 
3
3
  use tree_sitter::Node;
4
4
 
5
- use crate::WidgetTopLevelFunction;
5
+ use crate::{WidgetTopLevelFunction, extract::declared_return_type};
6
6
 
7
7
  pub(super) fn top_level_widget_functions(
8
8
  path: &Path,
@@ -41,7 +41,7 @@ fn function_candidate(path: &Path, node: Node<'_>, source: &str) -> Option<Widge
41
41
  }
42
42
 
43
43
  let signature_text = signature.utf8_text(source.as_bytes()).ok()?;
44
- let return_type = declared_return_type(signature, name_node, source);
44
+ let return_type = declared_return_type(signature, source);
45
45
  let returns_widget = return_type.as_deref().is_some_and(return_type_has_ui_type);
46
46
  let build_helper =
47
47
  is_build_helper_name(&name) && (signature_text.contains("BuildContext") || returns_widget);
@@ -57,13 +57,6 @@ fn function_candidate(path: &Path, node: Node<'_>, source: &str) -> Option<Widge
57
57
  })
58
58
  }
59
59
 
60
- fn declared_return_type(signature: Node<'_>, name: Node<'_>, source: &str) -> Option<String> {
61
- let before_name = source
62
- .get(signature.start_byte()..name.start_byte())?
63
- .trim();
64
- (!before_name.is_empty()).then(|| before_name.to_owned())
65
- }
66
-
67
60
  fn return_type_has_ui_type(return_type: &str) -> bool {
68
61
  return_type
69
62
  .split(|character: char| !(character.is_ascii_alphanumeric() || character == '_'))