dart-decimate 0.0.21 → 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.
package/Cargo.lock CHANGED
@@ -102,7 +102,7 @@ checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
102
102
 
103
103
  [[package]]
104
104
  name = "dart-decimate"
105
- version = "0.0.21"
105
+ version = "0.0.22"
106
106
  dependencies = [
107
107
  "clap",
108
108
  "glob",
package/Cargo.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "dart-decimate"
3
- version = "0.0.21"
3
+ version = "0.0.22"
4
4
  edition = "2024"
5
5
  rust-version = "1.85"
6
6
  description = "Rust-native codebase intelligence for Dart and Flutter module graphs."
package/README.md CHANGED
@@ -91,7 +91,7 @@ Add this to `package.json` if you want a short project command:
91
91
  "dart-decimate": "dart-decimate json ."
92
92
  },
93
93
  "devDependencies": {
94
- "dart-decimate": "^0.0.21"
94
+ "dart-decimate": "^0.0.22"
95
95
  }
96
96
  }
97
97
  ```
@@ -287,10 +287,11 @@ Dart Decimate finds:
287
287
  - import/export/part/augment targets that do not resolve
288
288
  - invalid `part` / `part of` relationships
289
289
 
290
- Generated typed GoRouter route registry back-edges are warning-level only when
291
- the importing file uses real typed-route navigation helpers. Mixed cycles still
292
- emit error-level residual findings for unrelated edges, registry-to-registry
293
- imports, exports, or non-route registry API usage.
290
+ Canonical typed GoRouter route-registry back-edges are omitted when the
291
+ importing file uses generated typed-route navigation helpers. Only those proven
292
+ navigation back-edges are waived: unrelated edges, registry-to-registry
293
+ imports, exports, and non-route registry API usage remain error-level cycle
294
+ findings.
294
295
 
295
296
  Useful commands:
296
297
 
@@ -362,12 +363,23 @@ and Dart patterns only to avoid false positives and to find graph problems.
362
363
  Dart Decimate finds:
363
364
 
364
365
  - GoRouter route path/name collisions
366
+ - raw GoRouter definitions or destination APIs mixed into a typed-route project
365
367
  - private Flutter widget classes
366
368
  - top-level widget helper functions
367
369
  - unused widget constructor parameters
368
370
  - widget classes that are never constructed
369
371
  - missing `context.mounted` guards after awaited widget work
370
372
 
373
+ Typed consistency activates after production code declares an imported
374
+ `TypedGoRoute`/`GoRouteData` route. From then on, `check` and `audit` report raw
375
+ `GoRoute` declarations, resolved `BuildContext`/`GoRouter` destination calls,
376
+ and literal raw redirect destinations as errors. Generated route-object
377
+ navigation and `.location` redirects remain clean. Raw-only projects,
378
+ `Navigator` flows, `pop`, incoming deep links, tests, generated files, and
379
+ same-named user APIs are not classified as mixed routing. A deliberate
380
+ exception can use a reasoned line suppression such as
381
+ `// dart-decimate-ignore-next-line mixed-go-router-style -- legacy URL migration`.
382
+
371
383
  `unused-widget-param` counts normal field reads, transformed constructor
372
384
  initializer reads, inherited field reads, forwarding helpers, and Dart object
373
385
  patterns that destructure the widget class itself. `unrendered-widget` counts
@@ -679,7 +691,7 @@ This repository forbids `unsafe_code`.
679
691
 
680
692
  ## Release Flow
681
693
 
682
- Current version: `0.0.21`.
694
+ Current version: `0.0.22`.
683
695
 
684
696
  After the first public release, changes should go through pull requests. Every
685
697
  PR to `main` must bump both `Cargo.toml` and `package.json` above the base
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dart-decimate",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "description": "Rust-native codebase intelligence for Dart and Flutter module graphs.",
5
5
  "license": "MIT",
6
6
  "bin": {
package/src/baseline.rs CHANGED
@@ -570,6 +570,8 @@ fn recompute_summary(report: &mut JsonReport) {
570
570
  kind_count(&report.findings, FindingKind::UnusedClassMember);
571
571
  report.summary.duplicate_exports = kind_count(&report.findings, FindingKind::DuplicateExport);
572
572
  report.summary.route_collisions = kind_count(&report.findings, FindingKind::RouteCollision);
573
+ report.summary.mixed_go_router_styles =
574
+ kind_count(&report.findings, FindingKind::MixedGoRouterStyle);
573
575
  report.summary.private_widget_classes =
574
576
  kind_count(&report.findings, FindingKind::PrivateWidgetClass);
575
577
  report.summary.widget_top_level_functions = kind_count(
@@ -193,6 +193,7 @@ fn recompute_summary(report: &mut JsonReport) {
193
193
  summary.unused_class_members = kind_count(&report.findings, FindingKind::UnusedClassMember);
194
194
  summary.duplicate_exports = kind_count(&report.findings, FindingKind::DuplicateExport);
195
195
  summary.route_collisions = kind_count(&report.findings, FindingKind::RouteCollision);
196
+ summary.mixed_go_router_styles = kind_count(&report.findings, FindingKind::MixedGoRouterStyle);
196
197
  summary.private_widget_classes = kind_count(&report.findings, FindingKind::PrivateWidgetClass);
197
198
  summary.widget_top_level_functions = kind_count(
198
199
  &report.findings,
package/src/explain.rs CHANGED
@@ -241,6 +241,18 @@ const ISSUES: &[IssueExplanation] = &[
241
241
  &["// dart-decimate-ignore-next-line route-collision"],
242
242
  &["dart-decimate inspect --format json --file <path>"],
243
243
  ),
244
+ issue!(
245
+ "mixed-go-router-style",
246
+ "dart-decimate/mixed-go-router-style",
247
+ &["mixed-go-router-style"],
248
+ "Mixed GoRouter style",
249
+ "A raw GoRouter route definition, destination call, or redirect is used after production code adopts typed routes.",
250
+ "Generated route objects preserve compile-time checking for route parameters and keep one navigation style across the repository.",
251
+ "context.go('/users/42') is used alongside @TypedGoRoute<UserRoute>.",
252
+ "Replace the raw destination with a generated route object or document a narrow migration exception.",
253
+ &["// dart-decimate-ignore-next-line mixed-go-router-style -- <reason>"],
254
+ &["dart-decimate check --format json"],
255
+ ),
244
256
  issue!(
245
257
  "private-widget-class",
246
258
  "dart-decimate/private-widget-class",
package/src/manifest.rs CHANGED
@@ -461,6 +461,7 @@ fn issue_types() -> Value {
461
461
  "unused-class-member",
462
462
  "duplicate-export",
463
463
  "route-collision",
464
+ "mixed-go-router-style",
464
465
  "private-widget-class",
465
466
  "widget-top-level-function-boundary",
466
467
  "unused-widget-param",
@@ -97,15 +97,12 @@ struct CycleClassification {
97
97
  severity: Severity,
98
98
  action: &'static str,
99
99
  description: &'static str,
100
- route_registry: bool,
101
100
  typed_route_residual: bool,
102
101
  }
103
102
 
104
103
  impl CycleClassification {
105
104
  fn message(self, file_count: usize) -> String {
106
- if self.route_registry {
107
- format!("Typed GoRouter route registry cycle spans {file_count} Dart files")
108
- } else if self.typed_route_residual {
105
+ if self.typed_route_residual {
109
106
  format!(
110
107
  "Circular dependency spans {file_count} Dart files after typed GoRouter helper imports are excluded"
111
108
  )
@@ -119,17 +116,6 @@ impl CycleClassification {
119
116
  severity: Severity::Error,
120
117
  action: "break-cycle",
121
118
  description: "Inspect the cycle edge; split barrels or move shared ownership before expanding imports",
122
- route_registry: false,
123
- typed_route_residual: false,
124
- }
125
- }
126
-
127
- const fn typed_route_warning() -> Self {
128
- Self {
129
- severity: Severity::Warning,
130
- action: "review-typed-route-cycle",
131
- description: "Keep typed routes if this is only the route registry to screen navigation helper cycle; split unrelated imports out of the cycle",
132
- route_registry: true,
133
119
  typed_route_residual: false,
134
120
  }
135
121
  }
@@ -139,7 +125,6 @@ impl CycleClassification {
139
125
  severity: Severity::Error,
140
126
  action: "break-cycle",
141
127
  description: "Inspect the non-route cycle edge after excluding typed GoRouter helper imports",
142
- route_registry: false,
143
128
  typed_route_residual: true,
144
129
  }
145
130
  }
@@ -153,13 +138,6 @@ fn add_typed_go_router_cycle_findings(
153
138
  for residual in &typed_cycle.residual_cycles {
154
139
  push_residual_cycle_finding(project, residual, findings);
155
140
  }
156
- push_cycle_finding(
157
- project,
158
- &typed_cycle.typed_route_files,
159
- CycleClassification::typed_route_warning(),
160
- None,
161
- findings,
162
- );
163
141
  }
164
142
 
165
143
  fn push_residual_cycle_finding(
@@ -71,6 +71,12 @@ fn architecture_items(summary: &ReportSummary) -> Vec<String> {
71
71
  "route collision",
72
72
  "route collisions",
73
73
  );
74
+ push_count(
75
+ &mut items,
76
+ summary.mixed_go_router_styles,
77
+ "mixed GoRouter style",
78
+ "mixed GoRouter styles",
79
+ );
74
80
  push_count(
75
81
  &mut items,
76
82
  summary.part_of_violations,
@@ -290,6 +296,7 @@ pub(super) const fn kind_label(kind: FindingKind) -> &'static str {
290
296
  FindingKind::UnusedClassMember => "Unused class member",
291
297
  FindingKind::DuplicateExport => "Duplicate export",
292
298
  FindingKind::RouteCollision => "Route collision",
299
+ FindingKind::MixedGoRouterStyle => "Mixed GoRouter style",
293
300
  FindingKind::PrivateWidgetClass => "Private widget class",
294
301
  FindingKind::WidgetTopLevelFunctionBoundary => "Top-level widget helper",
295
302
  FindingKind::UnusedWidgetParam => "Unused widget parameter",
@@ -381,6 +388,9 @@ pub(super) const fn why_text(kind: FindingKind) -> &'static str {
381
388
  FindingKind::RouteCollision => {
382
389
  "Two typed route declarations resolve to the same route name or path."
383
390
  }
391
+ FindingKind::MixedGoRouterStyle => {
392
+ "A raw GoRouter route, destination call, or redirect bypasses the generated API after typed routes were adopted."
393
+ }
384
394
  FindingKind::CodeDuplication => {
385
395
  "The same token sequence appears in multiple Dart locations, increasing maintenance cost when behavior changes."
386
396
  }
@@ -21,7 +21,6 @@ use crate::{
21
21
  #[derive(Debug, Clone, PartialEq, Eq)]
22
22
  pub(in crate::output) struct TypedGoRouterCycle {
23
23
  pub residual_cycles: Vec<ResidualCycle>,
24
- pub typed_route_files: Vec<PathBuf>,
25
24
  }
26
25
 
27
26
  #[derive(Debug, Clone, PartialEq, Eq)]
@@ -106,10 +105,7 @@ pub(in crate::output) fn decompose_typed_go_router_cycle(
106
105
  append_route_registry_edge_errors(&route_files, &residual_dependencies, &mut residual_cycles);
107
106
  residual_cycles.sort_by(|left, right| left.files.cmp(&right.files));
108
107
 
109
- Some(TypedGoRouterCycle {
110
- residual_cycles,
111
- typed_route_files,
112
- })
108
+ Some(TypedGoRouterCycle { residual_cycles })
113
109
  }
114
110
 
115
111
  fn is_typed_go_router_navigation_back_edge(
@@ -0,0 +1,515 @@
1
+ use std::fs;
2
+ use std::path::{Path, PathBuf};
3
+
4
+ use tree_sitter::Node;
5
+
6
+ use crate::{DartFile, Location, generated::is_generated_dart_path, scan::ScannedProject};
7
+
8
+ use super::navigation::{
9
+ go_router_symbol_import, has_go_router_import, local_type_declaration_named,
10
+ navigation_receiver_is_imported_go_router_api,
11
+ };
12
+ use super::{
13
+ argument_list, direct_named_child, field_text, find_first_named_descendant,
14
+ strip_method_type_arguments, strip_whitespace, visit_named,
15
+ };
16
+
17
+ #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
18
+ pub(in crate::output) enum MixedGoRouterUseKind {
19
+ RouteDefinition,
20
+ Navigation { method: String },
21
+ RedirectDestination,
22
+ }
23
+
24
+ #[derive(Debug, Clone, PartialEq, Eq)]
25
+ pub(in crate::output) struct MixedGoRouterUse {
26
+ pub path: PathBuf,
27
+ pub location: Location,
28
+ pub kind: MixedGoRouterUseKind,
29
+ }
30
+
31
+ pub(in crate::output) fn mixed_go_router_uses(project: &ScannedProject) -> Vec<MixedGoRouterUse> {
32
+ if !project.files.iter().any(is_typed_route_adoption) {
33
+ return Vec::new();
34
+ }
35
+
36
+ let mut uses = project
37
+ .files
38
+ .iter()
39
+ .filter(|file| is_production_path(&file.path))
40
+ .flat_map(mixed_go_router_uses_in_file)
41
+ .collect::<Vec<_>>();
42
+ uses.sort_by(|left, right| {
43
+ (
44
+ &left.path,
45
+ left.location.line,
46
+ left.location.column,
47
+ &left.kind,
48
+ )
49
+ .cmp(&(
50
+ &right.path,
51
+ right.location.line,
52
+ right.location.column,
53
+ &right.kind,
54
+ ))
55
+ });
56
+ uses
57
+ }
58
+
59
+ fn is_typed_route_adoption(file: &DartFile) -> bool {
60
+ if !is_production_path(&file.path) || !file_imports_go_router(file) {
61
+ return false;
62
+ }
63
+ let Ok(source) = fs::read_to_string(&file.path) else {
64
+ return false;
65
+ };
66
+ let Ok(parsed) = crate::dart_parser::parse_dart_source_lossy(&file.path, &source) else {
67
+ return false;
68
+ };
69
+ let root = parsed.tree().root_node();
70
+ let source = parsed.source();
71
+ let mut adopted = false;
72
+ visit_named(root, &mut |node| {
73
+ if adopted || node.kind() != "class_declaration" {
74
+ return;
75
+ }
76
+ adopted = typed_route_class_uses_imported_api(root, node, source);
77
+ });
78
+ adopted
79
+ }
80
+
81
+ fn typed_route_class_uses_imported_api(root: Node<'_>, class: Node<'_>, source: &str) -> bool {
82
+ let mut cursor = class.walk();
83
+ let imported_annotation = class
84
+ .named_children(&mut cursor)
85
+ .filter(|child| child.kind() == "annotation")
86
+ .any(|annotation| imported_typed_route_annotation(root, annotation, source));
87
+ imported_annotation
88
+ && class
89
+ .child_by_field_name("superclass")
90
+ .and_then(|superclass| superclass.utf8_text(source.as_bytes()).ok())
91
+ .is_some_and(|superclass| imported_route_data_superclass(root, superclass, source))
92
+ }
93
+
94
+ fn imported_typed_route_annotation(root: Node<'_>, annotation: Node<'_>, source: &str) -> bool {
95
+ let compact = annotation
96
+ .utf8_text(source.as_bytes())
97
+ .map(strip_whitespace)
98
+ .unwrap_or_default();
99
+ let reference = compact
100
+ .strip_prefix('@')
101
+ .unwrap_or(&compact)
102
+ .split('<')
103
+ .next()
104
+ .unwrap_or_default();
105
+ [
106
+ "TypedGoRoute",
107
+ "TypedRelativeGoRoute",
108
+ "TypedShellRoute",
109
+ "TypedStatefulShellRoute",
110
+ "TypedStatefulShellBranch",
111
+ ]
112
+ .iter()
113
+ .any(|type_name| imported_go_router_type_reference(root, reference, type_name, source))
114
+ }
115
+
116
+ fn imported_route_data_superclass(root: Node<'_>, superclass: &str, source: &str) -> bool {
117
+ let compact = strip_whitespace(superclass);
118
+ let reference = compact.strip_prefix("extends").unwrap_or(&compact);
119
+ [
120
+ "GoRouteData",
121
+ "RelativeGoRouteData",
122
+ "ShellRouteData",
123
+ "StatefulShellRouteData",
124
+ "StatefulShellBranchData",
125
+ ]
126
+ .iter()
127
+ .any(|type_name| imported_go_router_type_reference(root, reference, type_name, source))
128
+ }
129
+
130
+ fn mixed_go_router_uses_in_file(file: &DartFile) -> Vec<MixedGoRouterUse> {
131
+ if !file_imports_go_router(file) {
132
+ return Vec::new();
133
+ }
134
+ let Ok(source) = fs::read_to_string(&file.path) else {
135
+ return Vec::new();
136
+ };
137
+ let Ok(parsed) = crate::dart_parser::parse_dart_source_lossy(&file.path, &source) else {
138
+ return Vec::new();
139
+ };
140
+ let root = parsed.tree().root_node();
141
+ let source = parsed.source();
142
+ if !has_go_router_import(root, source) {
143
+ return Vec::new();
144
+ }
145
+
146
+ let mut uses = Vec::new();
147
+ collect_imported_raw_go_route_definitions(root, source, &file.path, &mut uses);
148
+ collect_raw_go_router_navigation(root, source, &file.path, &mut uses);
149
+ collect_raw_redirect_destinations(root, source, file, &mut uses);
150
+ uses
151
+ }
152
+
153
+ fn collect_imported_raw_go_route_definitions(
154
+ root: Node<'_>,
155
+ source: &str,
156
+ path: &Path,
157
+ uses: &mut Vec<MixedGoRouterUse>,
158
+ ) {
159
+ visit_named(root, &mut |node| {
160
+ if !matches!(
161
+ node.kind(),
162
+ "call_expression"
163
+ | "constructor_invocation"
164
+ | "const_object_expression"
165
+ | "new_expression"
166
+ ) {
167
+ return;
168
+ }
169
+ let Some(arguments) = argument_list(node) else {
170
+ return;
171
+ };
172
+ if !has_named_argument(arguments, "path", source) {
173
+ return;
174
+ }
175
+ let Some(prefix) = source.get(node.start_byte()..arguments.start_byte()) else {
176
+ return;
177
+ };
178
+ if imported_go_router_type_reference(root, prefix, "GoRoute", source) {
179
+ uses.push(MixedGoRouterUse {
180
+ path: path.to_path_buf(),
181
+ location: node.start_position().into(),
182
+ kind: MixedGoRouterUseKind::RouteDefinition,
183
+ });
184
+ }
185
+ });
186
+ }
187
+
188
+ fn collect_raw_go_router_navigation(
189
+ root: Node<'_>,
190
+ source: &str,
191
+ path: &Path,
192
+ uses: &mut Vec<MixedGoRouterUse>,
193
+ ) {
194
+ visit_named(root, &mut |node| {
195
+ if !matches!(
196
+ node.kind(),
197
+ "call_expression" | "function_expression_invocation"
198
+ ) {
199
+ return;
200
+ }
201
+ let Some(arguments) = argument_list(node) else {
202
+ return;
203
+ };
204
+ let Some(prefix) = source.get(node.start_byte()..arguments.start_byte()) else {
205
+ return;
206
+ };
207
+ let Some(method) = raw_go_router_navigation_name(prefix) else {
208
+ return;
209
+ };
210
+ let Some(receiver) = navigation_receiver(prefix, &method) else {
211
+ return;
212
+ };
213
+ if navigation_receiver_is_imported_go_router_api(root, node, &receiver, source) {
214
+ uses.push(MixedGoRouterUse {
215
+ path: path.to_path_buf(),
216
+ location: node.start_position().into(),
217
+ kind: MixedGoRouterUseKind::Navigation { method },
218
+ });
219
+ }
220
+ });
221
+ }
222
+
223
+ fn collect_raw_redirect_destinations(
224
+ root: Node<'_>,
225
+ source: &str,
226
+ file: &DartFile,
227
+ uses: &mut Vec<MixedGoRouterUse>,
228
+ ) {
229
+ visit_named(root, &mut |node| {
230
+ if node.kind() == "class_declaration"
231
+ && typed_route_class_uses_imported_api(root, node, source)
232
+ {
233
+ collect_typed_route_redirect_methods(node, source, &file.path, uses);
234
+ }
235
+ if is_imported_go_router_constructor(root, node, source) {
236
+ collect_go_router_redirect_argument(node, source, &file.path, uses);
237
+ }
238
+ });
239
+ }
240
+
241
+ fn collect_typed_route_redirect_methods(
242
+ class: Node<'_>,
243
+ source: &str,
244
+ path: &Path,
245
+ uses: &mut Vec<MixedGoRouterUse>,
246
+ ) {
247
+ let Some(body) = class.child_by_field_name("body") else {
248
+ return;
249
+ };
250
+ let mut cursor = body.walk();
251
+ for member in body.named_children(&mut cursor) {
252
+ let Some(method) = find_first_named_descendant(member, "method_declaration") else {
253
+ continue;
254
+ };
255
+ if method_name(method, source).as_deref() != Some("redirect") {
256
+ continue;
257
+ }
258
+ if method
259
+ .child_by_field_name("body")
260
+ .is_some_and(|body| redirect_body_has_raw_literal(body, source))
261
+ {
262
+ uses.push(MixedGoRouterUse {
263
+ path: path.to_path_buf(),
264
+ location: method.start_position().into(),
265
+ kind: MixedGoRouterUseKind::RedirectDestination,
266
+ });
267
+ }
268
+ }
269
+ }
270
+
271
+ fn collect_go_router_redirect_argument(
272
+ constructor: Node<'_>,
273
+ source: &str,
274
+ path: &Path,
275
+ uses: &mut Vec<MixedGoRouterUse>,
276
+ ) {
277
+ let Some(arguments) = argument_list(constructor) else {
278
+ return;
279
+ };
280
+ let mut cursor = arguments.walk();
281
+ for argument in arguments.named_children(&mut cursor) {
282
+ if argument.kind() != "named_argument"
283
+ || named_argument_label(argument, source).as_deref() != Some("redirect")
284
+ {
285
+ continue;
286
+ }
287
+ let Some(value) = named_argument_value(argument) else {
288
+ continue;
289
+ };
290
+ if redirect_callback_has_raw_literal(value, source) {
291
+ uses.push(MixedGoRouterUse {
292
+ path: path.to_path_buf(),
293
+ location: argument.start_position().into(),
294
+ kind: MixedGoRouterUseKind::RedirectDestination,
295
+ });
296
+ }
297
+ }
298
+ }
299
+
300
+ fn redirect_callback_has_raw_literal(value: Node<'_>, source: &str) -> bool {
301
+ let body = if value.kind() == "function_expression" {
302
+ value.child_by_field_name("body")
303
+ } else {
304
+ find_first_named_descendant(value, "function_expression_body")
305
+ };
306
+ let Some(body) = body else {
307
+ return false;
308
+ };
309
+ redirect_body_has_raw_literal(body, source)
310
+ }
311
+
312
+ fn redirect_body_has_raw_literal(body: Node<'_>, source: &str) -> bool {
313
+ let Some(expression_or_block) = first_non_label_named_child(body) else {
314
+ return false;
315
+ };
316
+ if expression_or_block.kind() != "block" {
317
+ return raw_redirect_expression(expression_or_block, source);
318
+ }
319
+
320
+ let mut found = false;
321
+ visit_returns_without_nested_callables(expression_or_block, &mut |return_statement| {
322
+ if first_non_label_named_child(return_statement)
323
+ .is_some_and(|expression| raw_redirect_expression(expression, source))
324
+ {
325
+ found = true;
326
+ }
327
+ });
328
+ found
329
+ }
330
+
331
+ fn raw_redirect_expression(node: Node<'_>, source: &str) -> bool {
332
+ let text = node.utf8_text(source.as_bytes()).unwrap_or_default().trim();
333
+ if is_dart_string_literal(text) {
334
+ return true;
335
+ }
336
+ if node.kind() == "conditional_expression" {
337
+ return ["consequence", "alternative"].into_iter().any(|field| {
338
+ node.child_by_field_name(field)
339
+ .is_some_and(|branch| raw_redirect_expression(branch, source))
340
+ });
341
+ }
342
+ if node.kind() == "if_null_expression" {
343
+ let mut cursor = node.walk();
344
+ return node
345
+ .named_children(&mut cursor)
346
+ .any(|branch| raw_redirect_expression(branch, source));
347
+ }
348
+ matches!(
349
+ node.kind(),
350
+ "parenthesized_expression" | "function_expression_body"
351
+ ) && first_non_label_named_child(node)
352
+ .is_some_and(|expression| raw_redirect_expression(expression, source))
353
+ }
354
+
355
+ fn is_dart_string_literal(text: &str) -> bool {
356
+ let text = text.trim_start_matches("const").trim();
357
+ let text = text.strip_prefix('r').unwrap_or(text);
358
+ text.starts_with('\'') || text.starts_with('"')
359
+ }
360
+
361
+ fn visit_returns_without_nested_callables(node: Node<'_>, visitor: &mut impl FnMut(Node<'_>)) {
362
+ if node.kind() == "return_statement" {
363
+ visitor(node);
364
+ return;
365
+ }
366
+ if matches!(
367
+ node.kind(),
368
+ "function_expression" | "method_declaration" | "function_declaration"
369
+ ) {
370
+ return;
371
+ }
372
+ let mut cursor = node.walk();
373
+ for child in node.named_children(&mut cursor) {
374
+ visit_returns_without_nested_callables(child, visitor);
375
+ }
376
+ }
377
+
378
+ fn is_imported_go_router_constructor(root: Node<'_>, node: Node<'_>, source: &str) -> bool {
379
+ if !matches!(
380
+ node.kind(),
381
+ "call_expression" | "constructor_invocation" | "const_object_expression" | "new_expression"
382
+ ) {
383
+ return false;
384
+ }
385
+ let Some(arguments) = argument_list(node) else {
386
+ return false;
387
+ };
388
+ let Some(prefix) = source.get(node.start_byte()..arguments.start_byte()) else {
389
+ return false;
390
+ };
391
+ imported_go_router_type_reference(root, prefix, "GoRouter", source)
392
+ }
393
+
394
+ fn imported_go_router_type_reference(
395
+ root: Node<'_>,
396
+ prefix: &str,
397
+ type_name: &str,
398
+ source: &str,
399
+ ) -> bool {
400
+ let compact = strip_whitespace(prefix);
401
+ let reference = compact
402
+ .strip_prefix("const")
403
+ .or_else(|| compact.strip_prefix("new"))
404
+ .unwrap_or(&compact)
405
+ .split('<')
406
+ .next()
407
+ .unwrap_or_default();
408
+ if reference == type_name {
409
+ return go_router_symbol_import(root, None, type_name, source)
410
+ && !local_type_declaration_named(root, type_name, source);
411
+ }
412
+ let Some(import_prefix) = reference.strip_suffix(&format!(".{type_name}")) else {
413
+ return false;
414
+ };
415
+ is_identifier(import_prefix)
416
+ && go_router_symbol_import(root, Some(import_prefix), type_name, source)
417
+ }
418
+
419
+ fn has_named_argument(arguments: Node<'_>, name: &str, source: &str) -> bool {
420
+ let mut cursor = arguments.walk();
421
+ arguments.named_children(&mut cursor).any(|argument| {
422
+ argument.kind() == "named_argument"
423
+ && named_argument_label(argument, source).as_deref() == Some(name)
424
+ })
425
+ }
426
+
427
+ fn named_argument_label(node: Node<'_>, source: &str) -> Option<String> {
428
+ direct_named_child(node, "label")
429
+ .and_then(|label| label.utf8_text(source.as_bytes()).ok())
430
+ .map(str::trim)
431
+ .and_then(|label| label.strip_suffix(':'))
432
+ .map(str::to_owned)
433
+ }
434
+
435
+ fn named_argument_value(node: Node<'_>) -> Option<Node<'_>> {
436
+ let mut cursor = node.walk();
437
+ node.named_children(&mut cursor)
438
+ .find(|child| child.kind() != "label")
439
+ }
440
+
441
+ fn first_non_label_named_child(node: Node<'_>) -> Option<Node<'_>> {
442
+ let mut cursor = node.walk();
443
+ node.named_children(&mut cursor)
444
+ .find(|child| child.kind() != "label")
445
+ }
446
+
447
+ fn method_name(node: Node<'_>, source: &str) -> Option<String> {
448
+ find_first_named_descendant(node, "function_signature")
449
+ .and_then(|signature| field_text(signature, "name", source))
450
+ }
451
+
452
+ fn raw_go_router_navigation_name(prefix: &str) -> Option<String> {
453
+ let compact = strip_whitespace(prefix);
454
+ let name = compact.rsplit('.').next().unwrap_or(compact.as_str());
455
+ let name = strip_method_type_arguments(name);
456
+ matches!(
457
+ name,
458
+ "go" | "push"
459
+ | "pushReplacement"
460
+ | "replace"
461
+ | "goNamed"
462
+ | "pushNamed"
463
+ | "pushReplacementNamed"
464
+ | "replaceNamed"
465
+ | "namedLocation"
466
+ )
467
+ .then(|| name.to_owned())
468
+ }
469
+
470
+ fn navigation_receiver(prefix: &str, method: &str) -> Option<String> {
471
+ let prefix = prefix.trim();
472
+ let without_keyword = super::strip_constructor_keyword_prefix(prefix).unwrap_or(prefix);
473
+ let compact = strip_whitespace(without_keyword);
474
+ let suffix = format!(".{method}");
475
+ compact
476
+ .strip_suffix(&suffix)
477
+ .or_else(|| {
478
+ compact
479
+ .strip_suffix('>')
480
+ .and_then(|without_end| without_end.rfind('<').map(|start| &compact[..start]))
481
+ .and_then(|without_type_arguments| without_type_arguments.strip_suffix(&suffix))
482
+ })
483
+ .map(str::to_owned)
484
+ }
485
+
486
+ fn is_identifier(text: &str) -> bool {
487
+ let mut chars = text.chars();
488
+ chars
489
+ .next()
490
+ .is_some_and(|first| first == '_' || first == '$' || first.is_ascii_alphabetic())
491
+ && chars.all(|character| {
492
+ character == '_' || character == '$' || character.is_ascii_alphanumeric()
493
+ })
494
+ }
495
+
496
+ fn is_production_path(path: &Path) -> bool {
497
+ !is_generated_dart_path(path) && !is_test_dart_path(path)
498
+ }
499
+
500
+ fn file_imports_go_router(file: &DartFile) -> bool {
501
+ file.imports
502
+ .iter()
503
+ .any(|import| import.uri == "package:go_router/go_router.dart")
504
+ }
505
+
506
+ fn is_test_dart_path(path: &Path) -> bool {
507
+ path.file_name()
508
+ .and_then(|name| name.to_str())
509
+ .is_some_and(|name| name.ends_with("_test.dart"))
510
+ || path.components().any(|component| {
511
+ component.as_os_str().to_str().is_some_and(|segment| {
512
+ matches!(segment, "test" | "integration_test" | "test_driver")
513
+ })
514
+ })
515
+ }
@@ -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);