dart-lang/linter

proposal: `unrelated_type_cast`

FMorschel opened this issue · 0 comments

unrelated_type_cast

Kind

Guard against errors.

Bad Examples

final list = <String>[];
final newList = list.cast<int>(); //Bad
final map = list as Map<String, dynamic>; //Bad

Good Examples

final list = <num>[];
final newList = list.cast<int>();  //Good
final iterable = list as Iterable; //Good

Discussion

Inspired by #5052. I believe if this is ever implemented, it should be added to Effective Dart.

Discussion checklist

  • List any existing rules this proposal modifies, complements, overlaps or conflicts with.
  • List any relevant issues (reported here, the [SDK Tracker], or elsewhere).
  • If there's any prior art (e.g., in other linters), please add references here.
  • If this proposal corresponds to [Effective Dart] or [Flutter Style Guide] advice, please call it out. (If there isn't any corresponding advice, should there be?)
  • If this proposal is motivated by real-world examples, please provide as many details as you can. Demonstrating potential impact is especially valuable.