dart-decimate 0.0.44 → 0.0.46

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 = "a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6"
102
102
 
103
103
  [[package]]
104
104
  name = "dart-decimate"
105
- version = "0.0.44"
105
+ version = "0.0.46"
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.44"
3
+ version = "0.0.46"
4
4
  edition = "2024"
5
5
  rust-version = "1.90"
6
6
  description = "Rust-native codebase intelligence for Dart and Flutter module graphs."
package/README.md CHANGED
@@ -90,7 +90,7 @@ You do not need to install anything permanently. Use the command above.
90
90
  For repeatable automation, pin the version:
91
91
 
92
92
  ```bash
93
- npx --yes dart-decimate@0.0.44
93
+ npx --yes dart-decimate@0.0.46
94
94
  ```
95
95
 
96
96
  Add this to `package.json` if you want a short project command:
@@ -101,7 +101,7 @@ Add this to `package.json` if you want a short project command:
101
101
  "dart-decimate": "dart-decimate json ."
102
102
  },
103
103
  "devDependencies": {
104
- "dart-decimate": "0.0.44"
104
+ "dart-decimate": "0.0.46"
105
105
  }
106
106
  }
107
107
  ```
@@ -115,7 +115,7 @@ npm run dart-decimate
115
115
  If you prefer Cargo, install the matching tagged source:
116
116
 
117
117
  ```bash
118
- cargo install --git https://github.com/sgaabdu4/dart-decimate.git --tag v0.0.44 --locked
118
+ cargo install --git https://github.com/sgaabdu4/dart-decimate.git --tag v0.0.46 --locked
119
119
  ```
120
120
 
121
121
  The npm release `X.Y.Z` and Cargo tag `vX.Y.Z` are verified against each other
@@ -126,7 +126,7 @@ Confirm a Cargo build's version with:
126
126
 
127
127
  ```bash
128
128
  dart-decimate --version
129
- # dart-decimate 0.0.44
129
+ # dart-decimate 0.0.46
130
130
  ```
131
131
 
132
132
  ## npx
@@ -255,8 +255,13 @@ Dart Decimate finds exact and semantic clone groups. Each clone group gets a sta
255
255
  fingerprint like `dup:abc12345`, so agents can trace it before touching code.
256
256
  Clone windows must meet both line and token thresholds; sparse duplicated blocks
257
257
  can span more than `--min-lines`, and `line_count` reports the actual match.
258
- Declaration-only abstract contracts are filtered, and copied local Pub package
258
+ Bodyless contract declarations are excluded even when a clone window covers
259
+ only part of a signature or matches a concrete implementation. Matching concrete
260
+ implementations remain eligible for duplication checks. Copied local Pub package
259
261
  mirrors are canonicalized before same-mirror matches are ignored.
262
+ A next-line `code-duplication` suppression on the reported group anchor removes
263
+ that group from findings, clone details, and duplication-threshold accounting.
264
+ `--top` limits displayed groups without reducing the remaining duplication total.
260
265
  Pair-only class clones joined by an explicit `toEntity()` or `toDomain()` mapper
261
266
  are treated as intentional boundaries by default. Set
262
267
  `dupes.ignore_mapper_pairs = false` to report those pairs.
@@ -531,7 +536,7 @@ Example shape:
531
536
  {
532
537
  "schema_version": "dart-decimate.report.v1",
533
538
  "kind": "combined",
534
- "tool": "dart-decimate 0.0.44",
539
+ "tool": "dart-decimate 0.0.46",
535
540
  "command": "check",
536
541
  "verdict": "fail",
537
542
  "summary": {
@@ -547,7 +552,7 @@ Example shape:
547
552
 
548
553
  The `dart-decimate.report.v1` field layout is unchanged. Its existing `tool`
549
554
  string includes the producing version so saved reports identify the exact
550
- build, for example `dart-decimate 0.0.44`.
555
+ build, for example `dart-decimate 0.0.46`.
551
556
 
552
557
  When grouped security findings hide additional occurrences, `next_steps` can
553
558
  include `review-security-surface`, which reruns
@@ -635,7 +640,7 @@ you need the installed binary's exact list.
635
640
  For a complete repository check, including discovered local packages:
636
641
 
637
642
  ```bash
638
- npx --yes dart-decimate@0.0.44 --strict
643
+ npx --yes dart-decimate@0.0.46 --strict
639
644
  ```
640
645
 
641
646
  This runs every enabled check from the repository root. The default duplication
@@ -678,7 +683,7 @@ This repository forbids `unsafe_code`.
678
683
 
679
684
  ## Release Flow
680
685
 
681
- Current source version: `0.0.44`.
686
+ Current source version: `0.0.46`.
682
687
 
683
688
  After the first public release, changes should go through pull requests. Every
684
689
  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.44",
3
+ "version": "0.0.46",
4
4
  "description": "Rust-native codebase intelligence for Dart and Flutter module graphs.",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -274,9 +274,15 @@ fn analyze_project_duplicates(
274
274
  request: &CommandRequest,
275
275
  ) -> Result<Option<crate::DuplicateCodeReport>, CliError> {
276
276
  match request.command {
277
- ReportCommand::Check | ReportCommand::Audit | ReportCommand::Dupes => Ok(Some(
278
- detect_duplicates(project, &request.duplicate_options)?,
279
- )),
277
+ ReportCommand::Check | ReportCommand::Audit | ReportCommand::Dupes => {
278
+ // Suppression and threshold accounting need all groups. Apply the
279
+ // requested detail limit only after the report has reconciled them.
280
+ let mut options = request.duplicate_options.clone();
281
+ options.top = None;
282
+ let mut report = detect_duplicates(project, &options)?;
283
+ report.options.top = request.duplicate_options.top;
284
+ Ok(Some(report))
285
+ }
280
286
  ReportCommand::DeadCode
281
287
  | ReportCommand::Cycles
282
288
  | ReportCommand::Health
@@ -2,7 +2,9 @@ use std::collections::{BTreeMap, BTreeSet};
2
2
  use std::fs;
3
3
  use std::path::{Path, PathBuf};
4
4
 
5
- use super::{CodeClone, CodeCloneInstance};
5
+ #[cfg(test)]
6
+ use super::CodeClone;
7
+ use super::CodeCloneInstance;
6
8
 
7
9
  pub(super) struct DeclarationCloneFilter {
8
10
  files: BTreeMap<PathBuf, Option<DeclarationFileContext>>,
@@ -15,6 +17,7 @@ impl DeclarationCloneFilter {
15
17
  }
16
18
  }
17
19
 
20
+ #[cfg(test)]
18
21
  pub(super) fn is_declaration_only_clone(&mut self, group: &CodeClone) -> bool {
19
22
  group
20
23
  .instances
@@ -22,7 +25,10 @@ impl DeclarationCloneFilter {
22
25
  .all(|instance| self.clone_instance_is_declaration_only(instance))
23
26
  }
24
27
 
25
- fn clone_instance_is_declaration_only(&mut self, instance: &CodeCloneInstance) -> bool {
28
+ pub(super) fn clone_instance_is_declaration_only(
29
+ &mut self,
30
+ instance: &CodeCloneInstance,
31
+ ) -> bool {
26
32
  let path = instance.path.clone();
27
33
  let Some(file) = self
28
34
  .files
@@ -43,7 +49,11 @@ impl DeclarationCloneFilter {
43
49
  })
44
50
  .filter(|(_, line)| !line.is_empty())
45
51
  .collect::<Vec<_>>();
46
- !lines.is_empty() && declaration_only_lines(&lines, &file.context.direct_type_body_lines)
52
+ !lines.is_empty()
53
+ && (lines
54
+ .iter()
55
+ .all(|(line, _)| file.bodyless_lines.contains(line))
56
+ || declaration_only_lines(&lines, &file.context.direct_type_body_lines))
47
57
  }
48
58
 
49
59
  #[cfg(test)]
@@ -55,13 +65,69 @@ impl DeclarationCloneFilter {
55
65
  struct DeclarationFileContext {
56
66
  source: String,
57
67
  context: DeclarationContext,
68
+ bodyless_lines: BTreeSet<usize>,
58
69
  }
59
70
 
60
71
  impl DeclarationFileContext {
61
72
  fn read(path: &Path) -> Option<Self> {
62
73
  let source = fs::read_to_string(path).ok()?;
63
74
  let context = DeclarationContext::from_source(&source);
64
- Some(Self { source, context })
75
+ let bodyless_lines = bodyless_member_lines(path, &source);
76
+ Some(Self {
77
+ source,
78
+ context,
79
+ bodyless_lines,
80
+ })
81
+ }
82
+ }
83
+
84
+ // Class-member declaration nodes exclude concrete method bodies. Classify the
85
+ // entire source before looking at clone windows, which may end mid-signature.
86
+ fn bodyless_member_lines(path: &Path, source: &str) -> BTreeSet<usize> {
87
+ let mut lines = BTreeSet::new();
88
+ let Ok(parsed) = crate::dart_parser::parse_dart_source_strict(path, source) else {
89
+ return lines;
90
+ };
91
+ collect_bodyless_lines(parsed.tree().root_node(), parsed.source(), &mut lines);
92
+ lines
93
+ }
94
+
95
+ fn collect_bodyless_lines(node: tree_sitter::Node<'_>, source: &str, lines: &mut BTreeSet<usize>) {
96
+ if node.kind() == "class_member" {
97
+ let mut cursor = node.walk();
98
+ let bodyless = node.named_children(&mut cursor).any(|child| {
99
+ child.kind() == "declaration" && {
100
+ let mut cursor = child.walk();
101
+ child.named_children(&mut cursor).any(|signature| {
102
+ matches!(
103
+ signature.kind(),
104
+ "function_signature"
105
+ | "getter_signature"
106
+ | "setter_signature"
107
+ | "operator_signature"
108
+ )
109
+ })
110
+ }
111
+ });
112
+ // Keep the existing conservative treatment of default values.
113
+ let text = &source[node.byte_range()];
114
+ if bodyless && !signature_contains_non_operator_equals(text) {
115
+ let start = node.start_position();
116
+ let end = node.end_position();
117
+ for (row, line) in source.lines().enumerate().take(end.row + 1).skip(start.row) {
118
+ let before = row != start.row || line[..start.column].trim().is_empty();
119
+ let after =
120
+ row != end.row || strip_line_comment(&line[end.column..]).trim().is_empty();
121
+ if before && after {
122
+ lines.insert(row + 1);
123
+ }
124
+ }
125
+ }
126
+ return;
127
+ }
128
+ let mut cursor = node.walk();
129
+ for child in node.named_children(&mut cursor) {
130
+ collect_bodyless_lines(child, source, lines);
65
131
  }
66
132
  }
67
133
 
package/src/dupes.rs CHANGED
@@ -415,7 +415,12 @@ pub fn detect_duplicates(
415
415
  }
416
416
  clone_groups.retain(|group| group_satisfies_occurrence_options(group, options));
417
417
  let mut declaration_filter = DeclarationCloneFilter::new();
418
- clone_groups.retain(|group| !declaration_filter.is_declaration_only_clone(group));
418
+ for group in &mut clone_groups {
419
+ group
420
+ .instances
421
+ .retain(|instance| !declaration_filter.clone_instance_is_declaration_only(instance));
422
+ }
423
+ clone_groups.retain(|group| group_satisfies_occurrence_options(group, options));
419
424
  if options.ignore_mapper_pairs {
420
425
  let mapping_filter = MappingBoundaryFilter::new(project);
421
426
  clone_groups.retain(|group| !mapping_filter.is_mapping_boundary_clone(group));
@@ -112,3 +112,51 @@ fn code_duplication_finding(root: &Path, clone: &crate::CodeClone) -> Finding {
112
112
  ],
113
113
  }
114
114
  }
115
+
116
+ // Findings and clone inventories share suppression semantics. Reconcile all
117
+ // groups before limiting details so --top cannot weaken the duplication gate.
118
+ pub(super) fn reconcile_clone_visibility(
119
+ report: &mut super::JsonReport,
120
+ results: &super::AnalysisResults,
121
+ ) {
122
+ let original_count = report.clone_groups.len();
123
+ report.clone_groups.retain(|group| {
124
+ report.findings.iter().any(|finding| {
125
+ finding.kind == FindingKind::CodeDuplication
126
+ && finding.fingerprint.as_ref() == Some(&group.fingerprint)
127
+ })
128
+ });
129
+ if report.clone_groups.len() != original_count {
130
+ super::recompute_visible_duplication_summary(report);
131
+ }
132
+ if let Some(top) = results
133
+ .duplicates
134
+ .as_ref()
135
+ .and_then(|dupes| dupes.options.top)
136
+ {
137
+ report.clone_groups.truncate(top);
138
+ report.findings.retain(|finding| {
139
+ finding.kind != FindingKind::CodeDuplication
140
+ || report
141
+ .clone_groups
142
+ .iter()
143
+ .any(|group| finding.fingerprint.as_ref() == Some(&group.fingerprint))
144
+ });
145
+ report.summary.code_duplications = report.clone_groups.len();
146
+ report.summary.findings = report.findings.len();
147
+ report.verdict = super::report_verdict(&report.findings);
148
+ }
149
+ report.next_steps.retain_mut(|step| {
150
+ if step.id != "trace-code-duplication" {
151
+ return true;
152
+ }
153
+ let Some(group) = report.clone_groups.first() else {
154
+ return false;
155
+ };
156
+ step.command = format!(
157
+ "dart-decimate trace-clone --format json --fingerprint {}",
158
+ group.fingerprint
159
+ );
160
+ true
161
+ });
162
+ }
@@ -13,6 +13,7 @@ use super::{
13
13
  registry_api::{VisibleNonRouteRegistryApi, visible_non_route_registry_api},
14
14
  route_extension_navigation_call, route_location_argument, route_location_expression_member,
15
15
  typed_route_navigation_call, visit_named,
16
+ wrappers::helper_has_typed_route_wrapper_call,
16
17
  };
17
18
  use crate::{
18
19
  DartFile, DependencyCycle, DependencyKind, Location, ResolvedDependency, scan::ScannedProject,
@@ -173,6 +174,14 @@ fn is_typed_go_router_navigation_helper(
173
174
  return false;
174
175
  }
175
176
  helper_has_typed_route_navigation_call(root, source, &route_classes)
177
+ || helper_has_typed_route_wrapper_call(
178
+ helper_file,
179
+ root,
180
+ source,
181
+ &route_classes,
182
+ files_by_path,
183
+ dependencies,
184
+ )
176
185
  }
177
186
 
178
187
  fn helper_references_imported_api(
@@ -224,7 +224,7 @@ fn is_route_registry_infrastructure_declaration(name: &str) -> bool {
224
224
  )
225
225
  }
226
226
 
227
- fn dependency_imports_name(dependency: &ResolvedDependency, name: &str) -> bool {
227
+ pub(super) fn dependency_imports_name(dependency: &ResolvedDependency, name: &str) -> bool {
228
228
  let mut show_seen = false;
229
229
  let mut shown = false;
230
230
  for combinator in &dependency.visibility.combinators {
@@ -0,0 +1,238 @@
1
+ use std::collections::{BTreeMap, BTreeSet};
2
+ use std::fs;
3
+ use std::path::PathBuf;
4
+
5
+ use tree_sitter::Node;
6
+
7
+ use super::{
8
+ argument_list,
9
+ navigation::{go_router_symbol_import, term_identifier_shadowed_at},
10
+ registry_api::dependency_imports_name,
11
+ route_constructor_receiver, visit_named,
12
+ };
13
+ use crate::{DartFile, DependencyKind, ResolvedDependency};
14
+
15
+ pub(super) fn helper_has_typed_route_wrapper_call(
16
+ helper_file: &DartFile,
17
+ root: Node<'_>,
18
+ source: &str,
19
+ route_classes: &BTreeSet<String>,
20
+ files_by_path: &BTreeMap<PathBuf, &DartFile>,
21
+ dependencies: &[ResolvedDependency],
22
+ ) -> bool {
23
+ let mut found = false;
24
+ let mut wrapper_results = BTreeMap::new();
25
+ visit_named(root, &mut |call| {
26
+ if found || call.kind() != "call_expression" {
27
+ return;
28
+ }
29
+ let Some(function) = call.child_by_field_name("function") else {
30
+ return;
31
+ };
32
+ let Some((function, prefix)) = wrapper_call_name_nodes(function) else {
33
+ return;
34
+ };
35
+ let Ok(function_name) = function.utf8_text(source.as_bytes()) else {
36
+ return;
37
+ };
38
+ let prefix_name = prefix.and_then(|node| node.utf8_text(source.as_bytes()).ok());
39
+ if prefix.is_some() && prefix_name.is_none() {
40
+ return;
41
+ }
42
+ if (prefix.is_none()
43
+ && helper_file
44
+ .declarations
45
+ .iter()
46
+ .any(|declaration| declaration.name == function_name))
47
+ || prefix.is_some_and(|node| {
48
+ term_identifier_shadowed_at(root, node, prefix_name.unwrap_or_default(), source)
49
+ })
50
+ || (prefix.is_none()
51
+ && term_identifier_shadowed_at(root, function, function_name, source))
52
+ {
53
+ return;
54
+ }
55
+ let Some(arguments) = argument_list(call) else {
56
+ return;
57
+ };
58
+ let mut cursor = arguments.walk();
59
+ for argument in arguments.named_children(&mut cursor) {
60
+ let Some((parameter_name, value)) = named_argument(argument, source) else {
61
+ continue;
62
+ };
63
+ if !route_constructor_receiver(root, value, route_classes, source) {
64
+ continue;
65
+ }
66
+ found = dependencies.iter().any(|import| {
67
+ import.kind == DependencyKind::Import
68
+ && import.from_path == helper_file.path
69
+ && import.visibility.prefix.as_deref() == prefix_name
70
+ && dependency_imports_name(import, function_name)
71
+ && files_by_path
72
+ .get(&import.to_path)
73
+ .is_some_and(|wrapper_file| {
74
+ *wrapper_results
75
+ .entry((
76
+ import.to_path.clone(),
77
+ function_name.to_owned(),
78
+ parameter_name.to_owned(),
79
+ ))
80
+ .or_insert_with(|| {
81
+ wrapper_navigates_parameter(
82
+ wrapper_file,
83
+ function_name,
84
+ parameter_name,
85
+ )
86
+ })
87
+ })
88
+ });
89
+ if found {
90
+ break;
91
+ }
92
+ }
93
+ });
94
+ found
95
+ }
96
+
97
+ fn wrapper_call_name_nodes(function: Node<'_>) -> Option<(Node<'_>, Option<Node<'_>>)> {
98
+ if function.kind() == "identifier" {
99
+ return Some((function, None));
100
+ }
101
+ if function.kind() == "member_expression" {
102
+ let receiver = function.child_by_field_name("object")?;
103
+ let receiver = callback_body_identifier(receiver)
104
+ .or_else(|| (receiver.kind() == "identifier").then_some(receiver))?;
105
+ let method = function.child_by_field_name("property")?;
106
+ return (method.kind() == "identifier").then_some((method, Some(receiver)));
107
+ }
108
+ // Dart Tree-Sitter represents `() => navigate(...)` as a call whose
109
+ // function is the closure and whose body is the callee identifier.
110
+ callback_body_identifier(function).map(|name| (name, None))
111
+ }
112
+
113
+ fn callback_body_identifier(function: Node<'_>) -> Option<Node<'_>> {
114
+ if function.kind() != "function_expression" {
115
+ return None;
116
+ }
117
+ let parameters = function.child_by_field_name("parameters")?;
118
+ if parameters.named_child_count() != 0 {
119
+ return None;
120
+ }
121
+ let body = function.child_by_field_name("body")?;
122
+ if body.kind() != "function_expression_body" || body.named_child_count() != 1 {
123
+ return None;
124
+ }
125
+ let name = body.named_child(0)?;
126
+ (name.kind() == "identifier").then_some(name)
127
+ }
128
+
129
+ fn named_argument<'tree, 'source>(
130
+ argument: Node<'tree>,
131
+ source: &'source str,
132
+ ) -> Option<(&'source str, Node<'tree>)> {
133
+ if argument.kind() != "named_argument" {
134
+ return None;
135
+ }
136
+ let mut cursor = argument.walk();
137
+ let mut children = argument.named_children(&mut cursor);
138
+ let label = children.next()?;
139
+ if label.kind() != "label" {
140
+ return None;
141
+ }
142
+ let name = label.named_child(0)?.utf8_text(source.as_bytes()).ok()?;
143
+ Some((name, children.next()?))
144
+ }
145
+
146
+ fn wrapper_navigates_parameter(file: &DartFile, function_name: &str, parameter_name: &str) -> bool {
147
+ let Ok(source) = fs::read_to_string(&file.path) else {
148
+ return false;
149
+ };
150
+ let Ok(parsed) = crate::dart_parser::parse_dart_source_lossy(&file.path, &source) else {
151
+ return false;
152
+ };
153
+ let root = parsed.tree().root_node();
154
+ let source = parsed.source();
155
+ if !go_router_symbol_import(root, None, "GoRouteData", source) {
156
+ return false;
157
+ }
158
+ let mut cursor = root.walk();
159
+ root.named_children(&mut cursor).any(|function| {
160
+ if function.kind() != "function_declaration" {
161
+ return false;
162
+ }
163
+ let Some(signature) = function.child_by_field_name("signature") else {
164
+ return false;
165
+ };
166
+ if field_text(signature, "name", source) != Some(function_name) {
167
+ return false;
168
+ }
169
+ let Some(parameters) = signature.child_by_field_name("parameters") else {
170
+ return false;
171
+ };
172
+ if !typed_parameter(parameters, parameter_name, "GoRouteData", source) {
173
+ return false;
174
+ }
175
+ let Some(body) = function.child_by_field_name("body") else {
176
+ return false;
177
+ };
178
+ let mut navigates = false;
179
+ visit_named(body, &mut |call| {
180
+ if navigates || call.kind() != "call_expression" {
181
+ return;
182
+ }
183
+ let Some(member) = call.child_by_field_name("function") else {
184
+ return;
185
+ };
186
+ if member.kind() != "member_expression"
187
+ || field_text(member, "object", source) != Some(parameter_name)
188
+ || !matches!(
189
+ field_text(member, "property", source),
190
+ Some("go" | "push" | "pushReplacement" | "replace")
191
+ )
192
+ {
193
+ return;
194
+ }
195
+ let Some(destination) = member.child_by_field_name("object") else {
196
+ return;
197
+ };
198
+ if term_identifier_shadowed_at(body, destination, parameter_name, source) {
199
+ return;
200
+ }
201
+ let Some(arguments) = argument_list(call) else {
202
+ return;
203
+ };
204
+ let Some(context) = arguments.named_child(0) else {
205
+ return;
206
+ };
207
+ let Ok(context_name) = context.utf8_text(source.as_bytes()) else {
208
+ return;
209
+ };
210
+ navigates = context.kind() == "identifier"
211
+ && !term_identifier_shadowed_at(body, context, context_name, source)
212
+ && typed_parameter(parameters, context_name, "BuildContext", source);
213
+ });
214
+ navigates
215
+ })
216
+ }
217
+
218
+ fn typed_parameter(parameters: Node<'_>, name: &str, type_name: &str, source: &str) -> bool {
219
+ let mut found = false;
220
+ visit_named(parameters, &mut |parameter| {
221
+ if found || parameter.kind() != "formal_parameter" {
222
+ return;
223
+ }
224
+ let mut cursor = parameter.walk();
225
+ found = field_text(parameter, "name", source) == Some(name)
226
+ && parameter
227
+ .named_children(&mut cursor)
228
+ .find(|child| child.kind() == "type")
229
+ .is_some_and(|kind| kind.utf8_text(source.as_bytes()).ok() == Some(type_name));
230
+ });
231
+ found
232
+ }
233
+
234
+ fn field_text<'source>(node: Node<'_>, field: &str, source: &'source str) -> Option<&'source str> {
235
+ node.child_by_field_name(field)?
236
+ .utf8_text(source.as_bytes())
237
+ .ok()
238
+ }
@@ -11,6 +11,7 @@ mod registry_api;
11
11
  mod state_context;
12
12
  #[cfg(test)]
13
13
  mod tests;
14
+ mod wrappers;
14
15
 
15
16
  use aliases::{route_alias_receiver_node, route_alias_receiver_text, route_aliases_at};
16
17
  pub(super) use classification::{
package/src/output.rs CHANGED
@@ -226,6 +226,7 @@ pub fn build_json_report(project: &ScannedProject, results: &AnalysisResults) ->
226
226
  scoped_duplication_analyzed_lines(project, scope);
227
227
  recompute_visible_duplication_summary(&mut report);
228
228
  }
229
+ duplication_findings::reconcile_clone_visibility(&mut report, results);
229
230
  report
230
231
  }
231
232
 
@@ -103,7 +103,6 @@ const PATTERN_ANCESTORS: &[&str] = &[
103
103
  "null_assert_pattern",
104
104
  "null_check_pattern",
105
105
  "object_pattern",
106
- "pattern_variable_declaration",
107
106
  "record_pattern",
108
107
  "rest_pattern",
109
108
  "variable_pattern",
@@ -135,6 +134,7 @@ fn is_widget_member_access(body: Node<'_>, node: Node<'_>, name: &str, source: &
135
134
  let Some(object) = node.child_by_field_name("object") else {
136
135
  return false;
137
136
  };
137
+ let object = state_member_receiver(object).unwrap_or(object);
138
138
  let Some(object_name @ ("widget" | "oldWidget")) = object.utf8_text(source.as_bytes()).ok()
139
139
  else {
140
140
  return false;
@@ -142,6 +142,20 @@ fn is_widget_member_access(body: Node<'_>, node: Node<'_>, name: &str, source: &
142
142
  state_root_receiver_available(body, object, object_name, source)
143
143
  }
144
144
 
145
+ fn state_member_receiver(object: Node<'_>) -> Option<Node<'_>> {
146
+ if object.kind() != "function_expression" {
147
+ return None;
148
+ }
149
+ // The Dart grammar attaches `().onSubmit` to the closure instead of its
150
+ // expression body for `() => widget.onSubmit?.call()`.
151
+ let body = object.child_by_field_name("body")?;
152
+ if body.kind() != "function_expression_body" || body.named_child_count() != 1 {
153
+ return None;
154
+ }
155
+ let receiver = body.named_child(0)?;
156
+ matches!(receiver.kind(), "identifier" | "identifier_dollar_escaped").then_some(receiver)
157
+ }
158
+
145
159
  fn state_root_receiver_available(
146
160
  boundary: Node<'_>,
147
161
  node: Node<'_>,
@@ -308,6 +308,36 @@ class _UsedViaStateState extends State<UsedViaState> {
308
308
  Ok(())
309
309
  }
310
310
 
311
+ #[test]
312
+ fn record_rhs_reads_and_state_callback_reads_count_widget_fields()
313
+ -> Result<(), Box<dyn std::error::Error>> {
314
+ let source = r"
315
+ class RecordCard extends StatelessWidget {
316
+ RecordCard({required this.data, required this.unused});
317
+ final String data;
318
+ final String unused;
319
+ Widget build(BuildContext context) {
320
+ final (:value) = (value: data);
321
+ return Text(value);
322
+ }
323
+ }
324
+ class CallbackCard extends StatefulWidget {
325
+ CallbackCard({this.onSubmit, this.unused});
326
+ final void Function()? onSubmit;
327
+ final String? unused;
328
+ State<CallbackCard> createState() => _CallbackCardState();
329
+ }
330
+ class _CallbackCardState extends State<CallbackCard> {
331
+ Widget build(BuildContext context) => Tile(
332
+ onPressed: () => widget.onSubmit?.call(),
333
+ );
334
+ }
335
+ ";
336
+ let targets = unused_param_targets(parse_findings(source)?.unused_params);
337
+ assert_eq!(targets, vec!["RecordCard.unused", "CallbackCard.unused"]);
338
+ Ok(())
339
+ }
340
+
311
341
  #[test]
312
342
  fn state_field_reads_ignore_widget_root_shadows() -> Result<(), Box<dyn std::error::Error>> {
313
343
  let targets =