dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.28k stars 1.58k forks source link

`dart fix` applies fixes in part files mutliple times #59572

Open denniskaselow opened 1 day ago

denniskaselow commented 1 day ago

Dart SDK version: 3.7.0-157.0.dev (dev) (Sat Nov 16 12:03:16 2024 -0800) on "windows_x64"

Running dart fix --apply on this code will apply the fixes in b.dart multiple times:

// a.dart
part 'b.dart';

void a() {
  // need to trigger a lint in a.dart for the bug to happen
  ;
  b();
}

// b.dart
part of 'a.dart';

Stream<String> b() {
  // dart fix should only add a single const
  return Stream.empty();
}
# analysis_options.yaml
linter:
  rules:
    - empty_statements
    - prefer_const_constructors

The fix adds const 3 times in b.dart:

part of 'a.dart';

Stream<String> b() {
  // dart fix should only add a single const
  return const const const Stream.empty();
}

Output of dart fix --apply:

Applying fixes...

lib\a.dart
  empty_statements • 1 fix

lib\b.dart
  prefer_const_constructors • 3 fixes

It's not limited to these lints. For example the fix for require_trailing_commas would add multiple commas.