esskar / vscode-flutter-i18n-json

VS Code extension to create a binding between your translations from .json files and your Flutter app.
92 stars 22 forks source link

Generated i18n.dart doesn't follow recommended Dart code style #39

Closed Dancovich closed 4 years ago

Dancovich commented 4 years ago

Generated i18n.dart file doesn't follow some recommendations of dart code style, creating some warning when you run flutter analyze or in VS Code Problems page.

Some examples:

Use of unnecessary const. const Locale("pt", "BR") is inside a const context created by const <Locale>[] and it's unneeded.

return const <Locale>[
  const Locale("pt", "BR")
];

Use of unnecessary new. The new key word is optional and can be omited. return new SynchronousFuture<WidgetsLocalizations>(const _I18n_pt_BR());

I can place some ignore statements to make the warnings go away but if I update the translations I need to place the statements again.

JCKodel commented 4 years ago

There is a lot more:

prefer_generic_function_type_aliases: (12)

typedef void LocaleChangeCallback(Locale locale);

unnecessary_const: (25 and 51)

  static const GeneratedLocalizationsDelegate delegate =
    const GeneratedLocalizationsDelegate();
    return const <Locale>[
      const Locale("pt", "BR")
    ];

unnecessary_this: (57)

if (this.isSupported(locale)) {

avoid_renaming_method_parameters: (66)

  @override
  Future<WidgetsLocalizations> load(Locale _locale) {

unnecessary_new: (73, 76 and 79):

    if ("pt_BR" == lang) {
      return new SynchronousFuture<WidgetsLocalizations>(const _I18n_pt_BR());
    }
    else if ("pt" == languageCode) {
      return new SynchronousFuture<WidgetsLocalizations>(const _I18n_pt_BR());
    }

    return new SynchronousFuture<WidgetsLocalizations>(const I18n());
  }

Guess the only solution is to ignore the file: https://dart.dev/guides/language/analysis-options#excluding-files

esskar commented 4 years ago

fixed with version 0.27.0 thanks to @r1sim