dart-decimate 0.0.46 → 0.0.47

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.46"
105
+ version = "0.0.47"
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.46"
3
+ version = "0.0.47"
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.46
93
+ npx --yes dart-decimate@0.0.47
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.46"
104
+ "dart-decimate": "0.0.47"
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.46 --locked
118
+ cargo install --git https://github.com/sgaabdu4/dart-decimate.git --tag v0.0.47 --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.46
129
+ # dart-decimate 0.0.47
130
130
  ```
131
131
 
132
132
  ## npx
@@ -536,7 +536,7 @@ Example shape:
536
536
  {
537
537
  "schema_version": "dart-decimate.report.v1",
538
538
  "kind": "combined",
539
- "tool": "dart-decimate 0.0.46",
539
+ "tool": "dart-decimate 0.0.47",
540
540
  "command": "check",
541
541
  "verdict": "fail",
542
542
  "summary": {
@@ -552,7 +552,7 @@ Example shape:
552
552
 
553
553
  The `dart-decimate.report.v1` field layout is unchanged. Its existing `tool`
554
554
  string includes the producing version so saved reports identify the exact
555
- build, for example `dart-decimate 0.0.46`.
555
+ build, for example `dart-decimate 0.0.47`.
556
556
 
557
557
  When grouped security findings hide additional occurrences, `next_steps` can
558
558
  include `review-security-surface`, which reruns
@@ -640,7 +640,7 @@ you need the installed binary's exact list.
640
640
  For a complete repository check, including discovered local packages:
641
641
 
642
642
  ```bash
643
- npx --yes dart-decimate@0.0.46 --strict
643
+ npx --yes dart-decimate@0.0.47 --strict
644
644
  ```
645
645
 
646
646
  This runs every enabled check from the repository root. The default duplication
@@ -683,7 +683,7 @@ This repository forbids `unsafe_code`.
683
683
 
684
684
  ## Release Flow
685
685
 
686
- Current source version: `0.0.46`.
686
+ Current source version: `0.0.47`.
687
687
 
688
688
  After the first public release, changes should go through pull requests. Every
689
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.46",
3
+ "version": "0.0.47",
4
4
  "description": "Rust-native codebase intelligence for Dart and Flutter module graphs.",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -422,6 +422,11 @@ pub(super) fn scoped_header_binding_exists(
422
422
  ) {
423
423
  return false;
424
424
  }
425
+ if for_in_iterable(scope, path_child) {
426
+ // The iterable is evaluated in the enclosing scope, so even
427
+ // `for (final widget in widget.items)` reads the outer `widget`.
428
+ return false;
429
+ }
425
430
  if header_field_binding_exists(scope, path_child, usage_start, name, source) {
426
431
  return true;
427
432
  }
@@ -432,7 +437,7 @@ pub(super) fn scoped_header_binding_exists(
432
437
  }
433
438
  if header_binding_child(scope.kind(), child)
434
439
  && child.end_byte() <= usage_start
435
- && node_contains_binding_name(child, name, source)
440
+ && header_child_binds_name(child, name, source)
436
441
  {
437
442
  return true;
438
443
  }
@@ -440,6 +445,22 @@ pub(super) fn scoped_header_binding_exists(
440
445
  false
441
446
  }
442
447
 
448
+ fn for_in_iterable(scope: Node<'_>, path_child: Node<'_>) -> bool {
449
+ matches!(scope.kind(), "for_element" | "for_statement")
450
+ && scope
451
+ .child_by_field_name("value")
452
+ .is_some_and(|value| same_node(value, path_child))
453
+ }
454
+
455
+ fn header_child_binds_name(child: Node<'_>, name: &str, source: &str) -> bool {
456
+ // A classic `for` initializer binds only its declared names; its
457
+ // initializer expressions are reads.
458
+ if child.kind() == "local_variable_declaration" {
459
+ return declaration_binds_name(child, name, source);
460
+ }
461
+ node_contains_binding_name(child, name, source)
462
+ }
463
+
443
464
  fn catch_header_binding_exists(
444
465
  scope: Node<'_>,
445
466
  path_child: Node<'_>,
@@ -537,10 +558,13 @@ fn pattern_or_local_binding_owner(node: Node<'_>) -> bool {
537
558
  }
538
559
 
539
560
  fn header_binding_child(scope_kind: &str, child: Node<'_>) -> bool {
540
- if matches!(scope_kind, "for_element" | "for_statement") {
541
- return !is_body_statement_child(child.kind())
542
- || child.kind() == "local_variable_declaration";
561
+ if matches!(scope_kind, "for_element" | "for_statement")
562
+ && child.kind() == "local_variable_declaration"
563
+ {
564
+ return true;
543
565
  }
566
+ // Loop iterables, conditions, updates, and element types are expressions,
567
+ // not bindings; only pattern-bearing header children can bind names.
544
568
  !is_body_statement_child(child.kind()) && node_can_contain_pattern_binding(child)
545
569
  }
546
570
 
@@ -2263,3 +2263,215 @@ fn unused_param_targets(unused: Vec<UnusedWidgetParam>) -> Vec<String> {
2263
2263
  .map(|param| format!("{}.{}", param.widget_class, param.param_name))
2264
2264
  .collect()
2265
2265
  }
2266
+
2267
+ const FOR_IN_ITERABLE_WIDGET_READS_SOURCE: &str = r"
2268
+ class CatalogSection extends StatefulWidget {
2269
+ CatalogSection({required this.items, this.selectedIds = const {}, this.contextId, this.unused});
2270
+ final List<Item> items;
2271
+ final Set<String> selectedIds;
2272
+ final String? contextId;
2273
+ final String? unused;
2274
+ State<CatalogSection> createState() => _CatalogSectionState();
2275
+ }
2276
+ class _CatalogSectionState extends State<CatalogSection> {
2277
+ Widget build(BuildContext context) => Column(children: [
2278
+ for (final item in widget.items)
2279
+ Tile(
2280
+ enabled: !widget.selectedIds.contains(item.id),
2281
+ contextId: widget.contextId,
2282
+ ),
2283
+ ]);
2284
+ }
2285
+ class StatementLoopSection extends StatefulWidget {
2286
+ const StatementLoopSection({super.key, required this.items, required this.label, this.unused});
2287
+ final List<String> items;
2288
+ final String label;
2289
+ final String? unused;
2290
+ State<StatementLoopSection> createState() => _StatementLoopSectionState();
2291
+ }
2292
+ class _StatementLoopSectionState extends State<StatementLoopSection> {
2293
+ Widget build(BuildContext context) {
2294
+ for (final item in widget.items) {
2295
+ Text('$item ${widget.label}');
2296
+ }
2297
+ return const SizedBox();
2298
+ }
2299
+ }
2300
+ class PatternLoopSection extends StatefulWidget {
2301
+ const PatternLoopSection({super.key, required this.pairs, required this.label, this.unused});
2302
+ final List<(String, String)> pairs;
2303
+ final String label;
2304
+ final String? unused;
2305
+ State<PatternLoopSection> createState() => _PatternLoopSectionState();
2306
+ }
2307
+ class _PatternLoopSectionState extends State<PatternLoopSection> {
2308
+ Widget build(BuildContext context) => Column(children: [
2309
+ for (final (left, right) in widget.pairs) Text('$left $right ${widget.label}'),
2310
+ ]);
2311
+ }
2312
+ class IndexedLoopSection extends StatefulWidget {
2313
+ const IndexedLoopSection({super.key, required this.items, required this.label, this.unused});
2314
+ final List<String> items;
2315
+ final String label;
2316
+ final String? unused;
2317
+ State<IndexedLoopSection> createState() => _IndexedLoopSectionState();
2318
+ }
2319
+ class _IndexedLoopSectionState extends State<IndexedLoopSection> {
2320
+ Widget build(BuildContext context) => Column(children: [
2321
+ for (var i = 0; i < widget.items.length; i++) Text(widget.label),
2322
+ ]);
2323
+ }
2324
+ class TypedLoopSection extends StatefulWidget {
2325
+ const TypedLoopSection({super.key, required this.items, required this.label, this.unused});
2326
+ final List<String> items;
2327
+ final String label;
2328
+ final String? unused;
2329
+ State<TypedLoopSection> createState() => _TypedLoopSectionState();
2330
+ }
2331
+ class _TypedLoopSectionState extends State<TypedLoopSection> {
2332
+ Widget build(BuildContext context) {
2333
+ for (String item in widget.items) {
2334
+ Text('$item ${widget.label}');
2335
+ }
2336
+ return const SizedBox();
2337
+ }
2338
+ }
2339
+ class AwaitLoopSection extends StatefulWidget {
2340
+ const AwaitLoopSection({super.key, required this.stream, required this.label, this.unused});
2341
+ final Stream<String> stream;
2342
+ final String label;
2343
+ final String? unused;
2344
+ State<AwaitLoopSection> createState() => _AwaitLoopSectionState();
2345
+ }
2346
+ class _AwaitLoopSectionState extends State<AwaitLoopSection> {
2347
+ Future<void> listen() async {
2348
+ await for (final event in widget.stream) {
2349
+ Text('$event ${widget.label}');
2350
+ }
2351
+ }
2352
+ Widget build(BuildContext context) => const SizedBox();
2353
+ }
2354
+ class ObjectPatternLoopSection extends StatefulWidget {
2355
+ const ObjectPatternLoopSection({super.key, required this.items, required this.label, this.unused});
2356
+ final List<Item> items;
2357
+ final String label;
2358
+ final String? unused;
2359
+ State<ObjectPatternLoopSection> createState() => _ObjectPatternLoopSectionState();
2360
+ }
2361
+ class _ObjectPatternLoopSectionState extends State<ObjectPatternLoopSection> {
2362
+ Widget build(BuildContext context) => Column(children: [
2363
+ for (final Item(:id) in widget.items) Text('$id ${widget.label}'),
2364
+ ]);
2365
+ }
2366
+ class InitializerLoopSection extends StatefulWidget {
2367
+ const InitializerLoopSection({super.key, required this.start, required this.label, this.unused});
2368
+ final int start;
2369
+ final String label;
2370
+ final String? unused;
2371
+ State<InitializerLoopSection> createState() => _InitializerLoopSectionState();
2372
+ }
2373
+ class _InitializerLoopSectionState extends State<InitializerLoopSection> {
2374
+ Widget build(BuildContext context) => Column(children: [
2375
+ for (var i = widget.start; i < 3; i++) Text(widget.label),
2376
+ ]);
2377
+ }
2378
+ class ShadowInitializerLoopSection extends StatefulWidget {
2379
+ const ShadowInitializerLoopSection({super.key, required this.title});
2380
+ final String title;
2381
+ State<ShadowInitializerLoopSection> createState() => _ShadowInitializerLoopSectionState();
2382
+ }
2383
+ class _ShadowInitializerLoopSectionState extends State<ShadowInitializerLoopSection> {
2384
+ Widget build(BuildContext context) => Column(children: [
2385
+ for (var widget = const ShadowInitializerLoopSection(title: 'local'); widget.title.isEmpty;)
2386
+ Text(widget.title),
2387
+ ]);
2388
+ }
2389
+ class ShadowLoopSection extends StatefulWidget {
2390
+ const ShadowLoopSection({super.key, required this.items, required this.title});
2391
+ final List<ShadowLoopSection> items;
2392
+ final String title;
2393
+ State<ShadowLoopSection> createState() => _ShadowLoopSectionState();
2394
+ }
2395
+ class _ShadowLoopSectionState extends State<ShadowLoopSection> {
2396
+ Widget build(BuildContext context) => Column(children: [
2397
+ for (final widget in widget.items) Text(widget.title),
2398
+ ]);
2399
+ }
2400
+ class ShadowStatementLoopSection extends StatefulWidget {
2401
+ const ShadowStatementLoopSection({super.key, required this.items, required this.title});
2402
+ final List<ShadowStatementLoopSection> items;
2403
+ final String title;
2404
+ State<ShadowStatementLoopSection> createState() => _ShadowStatementLoopSectionState();
2405
+ }
2406
+ class _ShadowStatementLoopSectionState extends State<ShadowStatementLoopSection> {
2407
+ Widget build(BuildContext context) {
2408
+ for (final widget in widget.items) {
2409
+ Text(widget.title);
2410
+ }
2411
+ return const SizedBox();
2412
+ }
2413
+ }
2414
+ class ShadowPatternLoopSection extends StatefulWidget {
2415
+ const ShadowPatternLoopSection({super.key, required this.pairs, required this.title});
2416
+ final List<(ShadowPatternLoopSection, int)> pairs;
2417
+ final String title;
2418
+ State<ShadowPatternLoopSection> createState() => _ShadowPatternLoopSectionState();
2419
+ }
2420
+ class _ShadowPatternLoopSectionState extends State<ShadowPatternLoopSection> {
2421
+ Widget build(BuildContext context) => Column(children: [
2422
+ for (final (widget, _) in widget.pairs) Text(widget.title),
2423
+ ]);
2424
+ }
2425
+ ";
2426
+
2427
+ #[test]
2428
+ fn state_field_reads_survive_for_in_iterables_over_widget() -> Result<(), Box<dyn std::error::Error>>
2429
+ {
2430
+ let targets =
2431
+ unused_param_targets(parse_findings(FOR_IN_ITERABLE_WIDGET_READS_SOURCE)?.unused_params);
2432
+
2433
+ assert_eq!(
2434
+ targets,
2435
+ vec![
2436
+ "CatalogSection.unused",
2437
+ "StatementLoopSection.unused",
2438
+ "PatternLoopSection.unused",
2439
+ "IndexedLoopSection.unused",
2440
+ "TypedLoopSection.unused",
2441
+ "AwaitLoopSection.unused",
2442
+ "ObjectPatternLoopSection.unused",
2443
+ "InitializerLoopSection.unused",
2444
+ "ShadowInitializerLoopSection.title",
2445
+ "ShadowLoopSection.title",
2446
+ "ShadowStatementLoopSection.title",
2447
+ "ShadowPatternLoopSection.title"
2448
+ ]
2449
+ );
2450
+ Ok(())
2451
+ }
2452
+
2453
+ #[test]
2454
+ fn direct_field_reads_survive_for_in_iterables_named_like_the_loop_variable()
2455
+ -> Result<(), Box<dyn std::error::Error>> {
2456
+ let source = r"
2457
+ class TagsCard extends StatelessWidget {
2458
+ const TagsCard({super.key, required this.tags, this.unused});
2459
+ final String tags;
2460
+ final String? unused;
2461
+ Widget build(BuildContext context) => Column(children: [
2462
+ for (final tags in tags.split(',')) Text(tags),
2463
+ ]);
2464
+ }
2465
+ class ShadowTagsCard extends StatelessWidget {
2466
+ const ShadowTagsCard({super.key, required this.title});
2467
+ final String title;
2468
+ Widget build(BuildContext context) => Column(children: [
2469
+ for (final title in ['local']) Text(title),
2470
+ ]);
2471
+ }
2472
+ ";
2473
+ let targets = unused_param_targets(parse_findings(source)?.unused_params);
2474
+
2475
+ assert_eq!(targets, vec!["TagsCard.unused", "ShadowTagsCard.title"]);
2476
+ Ok(())
2477
+ }