dart-code-checker / dart-code-metrics

Software analytics tool that helps developers analyse and improve software quality.
https://dcm.dev
Other
860 stars 265 forks source link

[New rule] Avoid returning an unawaited future #1197

Closed vHanda closed 1 year ago

vHanda commented 1 year ago

Rule details

Please see the code below -

What type of rule is this?

Warns about a potential problem

Example code

void main() {
  foo();
}

Future<String> foo() async {
  try {
    return bar();
  } catch (_) {
    return "Error";
  }
}

Future<String> bar() async {
  throw Exception("Bar Error");
}

Participation

Additional comments

Calling foo will result in a crash as an exception isn't handled. This is because we were calling bar but not awaiting its result, and therefore the exception is thrown out of the try and catch block.

I've spent over 6 hours because of this and wondering why an app was crashing when it shouldn't have been.

incendial commented 1 year ago

This one is actually already implemented and will become available with the upcoming 1.2.0 release of "Teams" version (~ March 6th). No plans to add it to the "Individuals" though.

vHanda commented 1 year ago

I completely understand.

Would you be open to adding it to the individual version if someone else contributed the code? (I completely understand if you still rather not).

Regardless, let me see if I can make a case with this client for the Teams version. Thank you for all your work on this.

incendial commented 1 year ago

Thank you for the kind words!

Would you be open to adding it to the individual version if someone else contributed the code? (I completely understand if you still rather not).

Even though the contributions are very welcome, I'm not sure that I really want any extra maintenance burden, especially, if this is already implemented by me in Teams version and that all my focus is on that version now. But with that said, I won't reject any PR just based on the idea that something already exists in the Teams version.

Regardless, let me see if I can make a case with this client for the Teams version. Thank you for all your work on this.

If my math is correct, then if the tool saves at least one hour a month for a developer, the Teams version is already worth it.

incendial commented 1 year ago

Available in Teams version 1.2.0 https://dcm.dev/docs/rules/common/prefer-return-await/

incendial commented 1 year ago

@vHanda hey, it feels like you either didn't get any of my emails or don't have time to answer. Is there any other way to contact you if it's the former?