Skip to content

dart fix --apply fails to fix lint #49043

Open
@osa1

Description

@osa1

Tried with sdk 7fa9a67.

Input:

class Test {
  List<int> lengthDelimited = <int>[];
  List<int> varints = <int>[];
  List<int> fixed32s = <int>[];
  List<int> fixed64s = <int>[];
  List<int> groups = <int>[];

  List get values => <int>[]
    ..addAll(lengthDelimited)
    ..addAll(varints)
    ..addAll(fixed32s)
    ..addAll(fixed64s)
    ..addAll(groups);
}

void main() {}

dart analyze output:

   info - protobuf_test.dart:9:7 - Use spread collections when possible. - prefer_spread_collections

File after running dart fix --apply:

class Test {
  List<int> lengthDelimited = <int>[];
  List<int> varints = <int>[];
  List<int> fixed32s = <int>[];
  List<int> fixed64s = <int>[];
  List<int> groups = <int>[];

  List get values => <int>[...lengthDelimited, ...varints, ...fixed32s, ...fixed64s]
    
    
    
    
    ..addAll(groups);
}

void main() {}

Note that groups is not moved to the list syntax, and the new file has the same lint error.

Interestingly if I remove ..addAll(groups) in the original program then dart fix --apply doesn't leave the last addAll outside the list syntax and produces lint-free output. Is there a hard-coded limit on the depth of the tree to transform maybe?

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.dart-cli-fixdevexp-quick-fixIssues with analysis server (quick) fixestype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions