andrasferenczi / dart-data-plugin

IDEA plugin for generating utility methods for Dart data classes
148 stars 31 forks source link

Generated toString should not use + #27

Open dalewking opened 2 years ago

dalewking commented 2 years ago

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,'
        '}';
  }