Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: unrelated_type_cast #5062

Open
4 of 5 tasks
FMorschel opened this issue Aug 13, 2024 · 0 comments
Open
4 of 5 tasks

proposal: unrelated_type_cast #5062

FMorschel opened this issue Aug 13, 2024 · 0 comments
Labels
lint-proposal status-pending type-enhancement A request for a change that isn't a bug

Comments

@FMorschel
Copy link
Contributor

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lint-proposal status-pending type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

2 participants