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.
package/Cargo.lock CHANGED
@@ -102,7 +102,7 @@ checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
102
102
 
103
103
  [[package]]
104
104
  name = "dart-decimate"
105
- version = "0.0.20"
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.20"
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.20"
94
+ "dart-decimate": "^0.0.22"
95
95
  }
96
96
  }
97
97
  ```
@@ -262,6 +262,9 @@ Clone windows must meet both line and token thresholds; sparse duplicated blocks
262
262
  can span more than `--min-lines`, and `line_count` reports the actual match.
263
263
  Declaration-only abstract contracts are filtered, and copied local Pub package
264
264
  mirrors are canonicalized before same-mirror matches are ignored.
265
+ Pair-only class clones joined by an explicit `toEntity()` or `toDomain()` mapper
266
+ are treated as intentional boundaries by default. Set
267
+ `dupes.ignore_mapper_pairs = false` to report those pairs.
265
268
 
266
269
  Useful commands:
267
270
 
@@ -284,10 +287,11 @@ Dart Decimate finds:
284
287
  - import/export/part/augment targets that do not resolve
285
288
  - invalid `part` / `part of` relationships
286
289
 
287
- Generated typed GoRouter route registry back-edges are warning-level only when
288
- the importing file uses real typed-route navigation helpers. Mixed cycles still
289
- emit error-level residual findings for unrelated edges, registry-to-registry
290
- 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.
291
295
 
292
296
  Useful commands:
293
297
 
@@ -359,12 +363,23 @@ and Dart patterns only to avoid false positives and to find graph problems.
359
363
  Dart Decimate finds:
360
364
 
361
365
  - GoRouter route path/name collisions
366
+ - raw GoRouter definitions or destination APIs mixed into a typed-route project
362
367
  - private Flutter widget classes
363
368
  - top-level widget helper functions
364
369
  - unused widget constructor parameters
365
370
  - widget classes that are never constructed
366
371
  - missing `context.mounted` guards after awaited widget work
367
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
+
368
383
  `unused-widget-param` counts normal field reads, transformed constructor
369
384
  initializer reads, inherited field reads, forwarding helpers, and Dart object
370
385
  patterns that destructure the widget class itself. `unrendered-widget` counts
@@ -611,6 +626,7 @@ targets = true
611
626
  mode = "semantic"
612
627
  min_tokens = 80
613
628
  threshold = 5
629
+ ignore_mapper_pairs = true
614
630
 
615
631
  [flags]
616
632
  allow = ["SKIP_PERMISSION_PROMPT"]
@@ -675,7 +691,7 @@ This repository forbids `unsafe_code`.
675
691
 
676
692
  ## Release Flow
677
693
 
678
- Current version: `0.0.20`.
694
+ Current version: `0.0.22`.
679
695
 
680
696
  After the first public release, changes should go through pull requests. Every
681
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.20",
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/config.rs CHANGED
@@ -116,6 +116,9 @@ pub struct DuplicateConfig {
116
116
  /// Ignore import/export/part/augment directives.
117
117
  #[serde(default, alias = "ignoreImports")]
118
118
  pub ignore_imports: Option<bool>,
119
+ /// Ignore pair-only clones joined by an explicit entity/domain mapper.
120
+ #[serde(default, alias = "ignoreMapperPairs")]
121
+ pub ignore_mapper_pairs: Option<bool>,
119
122
  }
120
123
 
121
124
  /// Feature flag analyzer config defaults.
@@ -331,6 +334,9 @@ impl DuplicateConfig {
331
334
  if let Some(ignore_imports) = self.ignore_imports {
332
335
  options.ignore_imports = ignore_imports;
333
336
  }
337
+ if let Some(ignore_mapper_pairs) = self.ignore_mapper_pairs {
338
+ options.ignore_mapper_pairs = ignore_mapper_pairs;
339
+ }
334
340
  }
335
341
  }
336
342
 
@@ -581,7 +587,9 @@ fn dupes_schema() -> Value {
581
587
  "skip_local": { "type": "boolean" },
582
588
  "skipLocal": { "type": "boolean" },
583
589
  "ignore_imports": { "type": "boolean" },
584
- "ignoreImports": { "type": "boolean" }
590
+ "ignoreImports": { "type": "boolean" },
591
+ "ignore_mapper_pairs": { "type": "boolean" },
592
+ "ignoreMapperPairs": { "type": "boolean" }
585
593
  }
586
594
  })
587
595
  }
@@ -25,18 +25,20 @@ impl MappingBoundaryFilter {
25
25
  let model_path = normalize_against(&project.root, &model_file.path);
26
26
  for member in model_file.members.iter().filter(|member| {
27
27
  member.kind == MemberKind::Method
28
- && member.name == "toEntity"
29
- && member.owner.ends_with("Model")
28
+ && matches!(member.name.as_str(), "toEntity" | "toDomain")
30
29
  }) {
31
30
  let Some(model) = model_file.declarations.iter().find(|declaration| {
32
31
  declaration.kind == DeclarationKind::Class && declaration.name == member.owner
33
32
  }) else {
34
33
  continue;
35
34
  };
36
- let Some(prefix) = model.name.strip_suffix("Model") else {
35
+ let Some(entity_name) = member
36
+ .return_type
37
+ .as_deref()
38
+ .and_then(mapper_target_class_name)
39
+ else {
37
40
  continue;
38
41
  };
39
- let entity_name = format!("{prefix}Entity");
40
42
 
41
43
  for dependency in dependencies.iter().filter(|dependency| {
42
44
  dependency.kind == DependencyKind::Import && dependency.from_path == model_path
@@ -94,6 +96,32 @@ impl MappingBoundaryFilter {
94
96
  }
95
97
  }
96
98
 
99
+ fn mapper_target_class_name(return_type: &str) -> Option<&str> {
100
+ let qualified_name = return_type.strip_suffix('?').unwrap_or(return_type);
101
+ let mut segments = qualified_name.split('.');
102
+ let first = segments.next()?;
103
+ let second = segments.next();
104
+ if segments.next().is_some() {
105
+ return None;
106
+ }
107
+ let name = match second {
108
+ Some(name) if is_identifier(first) => name,
109
+ Some(_) => return None,
110
+ None => first,
111
+ };
112
+ let first = name.chars().next()?;
113
+ (first.is_ascii_uppercase() && is_identifier(name)).then_some(name)
114
+ }
115
+
116
+ fn is_identifier(name: &str) -> bool {
117
+ let mut characters = name.chars();
118
+ let Some(first) = characters.next() else {
119
+ return false;
120
+ };
121
+ (first.is_ascii_alphabetic() || first == '_')
122
+ && characters.all(|character| character.is_ascii_alphanumeric() || character == '_')
123
+ }
124
+
97
125
  fn instance_inside(instance: &CodeCloneInstance, path: &PathBuf, range: SourceRange) -> bool {
98
126
  instance.path == *path
99
127
  && instance.start_line >= range.start_line
@@ -321,6 +321,7 @@ fn options(mode: DuplicateMode, min_lines: usize, min_tokens: usize) -> Duplicat
321
321
  min_occurrences: 2,
322
322
  skip_local: false,
323
323
  ignore_imports: true,
324
+ ignore_mapper_pairs: true,
324
325
  top: None,
325
326
  threshold: None,
326
327
  }
package/src/dupes.rs CHANGED
@@ -65,6 +65,9 @@ pub struct DuplicateOptions {
65
65
  pub skip_local: bool,
66
66
  /// Ignore import/export/part/augment directives.
67
67
  pub ignore_imports: bool,
68
+ /// Ignore pair-only clones joined by an explicit entity/domain mapper.
69
+ #[serde(default = "default_ignore_mapper_pairs")]
70
+ pub ignore_mapper_pairs: bool,
68
71
  /// Limit output to the N largest clone groups.
69
72
  pub top: Option<usize>,
70
73
  /// Fail when duplicated lines exceed this percentage.
@@ -81,12 +84,17 @@ impl Default for DuplicateOptions {
81
84
  min_occurrences: 2,
82
85
  skip_local: false,
83
86
  ignore_imports: true,
87
+ ignore_mapper_pairs: true,
84
88
  top: None,
85
89
  threshold: None,
86
90
  }
87
91
  }
88
92
  }
89
93
 
94
+ const fn default_ignore_mapper_pairs() -> bool {
95
+ true
96
+ }
97
+
90
98
  /// Duplicate percentage threshold represented as percentage basis points.
91
99
  #[derive(Debug, Clone, Copy, PartialEq, Eq)]
92
100
  pub struct DuplicationThreshold(u32);
@@ -389,8 +397,10 @@ pub fn detect_duplicates(
389
397
  clone_groups.retain(|group| group_satisfies_occurrence_options(group, options));
390
398
  let mut declaration_filter = DeclarationCloneFilter::new();
391
399
  clone_groups.retain(|group| !declaration_filter.is_declaration_only_clone(group));
392
- let mapping_filter = MappingBoundaryFilter::new(project);
393
- clone_groups.retain(|group| !mapping_filter.is_mapping_boundary_clone(group));
400
+ if options.ignore_mapper_pairs {
401
+ let mapping_filter = MappingBoundaryFilter::new(project);
402
+ clone_groups.retain(|group| !mapping_filter.is_mapping_boundary_clone(group));
403
+ }
394
404
  sort_clone_groups(&mut clone_groups);
395
405
  clone_groups = collapse_overlapping_groups(clone_groups);
396
406
  clone_groups.retain(|group| !copied_packages.is_copied_package_clone(group));
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",
@@ -2,7 +2,8 @@ use tree_sitter::Node;
2
2
 
3
3
  use super::{
4
4
  MemberDeclaration, MemberKind, collect_direct_identifier_children, collect_named_fields,
5
- field_text, find_first_named_descendant, find_first_named_descendant_in, first_identifier_text,
5
+ declared_return_type, field_text, find_first_named_descendant, find_first_named_descendant_in,
6
+ first_identifier_text,
6
7
  };
7
8
 
8
9
  pub(super) fn push_class_like_members(
@@ -80,6 +81,7 @@ fn push_bodyless_member(
80
81
  owner: owner.to_owned(),
81
82
  kind: MemberKind::Field,
82
83
  name,
84
+ return_type: None,
83
85
  location: node.start_position().into(),
84
86
  }));
85
87
  }
@@ -132,10 +134,14 @@ fn push_signature_member(
132
134
  .map(|name| member_name_without_owner(&name, owner)),
133
135
  };
134
136
  if let Some(name) = name {
137
+ let return_type = (kind == MemberKind::Method)
138
+ .then(|| declared_return_type(signature, source))
139
+ .flatten();
135
140
  members.push(MemberDeclaration {
136
141
  owner: owner.to_owned(),
137
142
  kind,
138
143
  name,
144
+ return_type,
139
145
  location: node.start_position().into(),
140
146
  });
141
147
  }
@@ -183,6 +189,7 @@ fn push_member(
183
189
  owner: owner.to_owned(),
184
190
  kind,
185
191
  name,
192
+ return_type: None,
186
193
  location: node.start_position().into(),
187
194
  });
188
195
  }
package/src/extract.rs CHANGED
@@ -27,6 +27,14 @@ pub use signatures::SignatureReference;
27
27
  use signatures::extract_signature_references;
28
28
  use strings::unquote_dart_string;
29
29
 
30
+ pub(crate) fn declared_return_type(signature: Node<'_>, source: &str) -> Option<String> {
31
+ let name = signature.child_by_field_name("name")?;
32
+ let before_name = source
33
+ .get(signature.start_byte()..name.start_byte())?
34
+ .trim();
35
+ (!before_name.is_empty()).then(|| before_name.to_owned())
36
+ }
37
+
30
38
  /// A 1-based line and 0-based byte column in a Dart source file.
31
39
  #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
32
40
  pub struct Location {
@@ -214,6 +222,9 @@ pub struct MemberDeclaration {
214
222
  pub kind: MemberKind,
215
223
  /// Declared member name.
216
224
  pub name: String,
225
+ /// Declared method return type, when the member is a method.
226
+ #[serde(default, skip_serializing_if = "Option::is_none")]
227
+ pub return_type: Option<String>,
217
228
  /// Location of the member declaration node.
218
229
  pub location: Location,
219
230
  }
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(