dart-data-plugin icon indicating copy to clipboard operation
dart-data-plugin copied to clipboard

Generated toString should not use +

Open dalewking opened this issue 3 years ago • 0 comments

Per the example the generated toString looks like this:

  @override
  String toString() {
    return 'Person{' +
        ' id: $id,' +
        ' _firstName: $_firstName,' +
        ' _lastName: $_lastName,' +
        ' age: $age,' +
        ' income: $income,' +
        '}';
  }

Which fails this lint check: https://dart-lang.github.io/linter/lints/prefer_interpolation_to_compose_strings.html

It may not be well known but the + operators are not necessary for concatenating string literals and are the source of the issue. As mentioned here, "Adjacent string literals are concatenated automatically".

So what you should generate is this:

  @override
  String toString() {
    return 'Person{'
        ' id: $id,'
        ' _firstName: $_firstName,'
        ' _lastName: $_lastName,'
        ' age: $age,'
        ' income: $income,'
        '}';
  }

dalewking avatar Sep 10 '22 14:09 dalewking