Open parlough opened 2 months ago
Some options:
verbose_conditional_collection_spread
unnecessary_null_check_and_spread
prefer_null_aware_spread_operator
The analyzer produces this diagnostic when a list is added to a collection literal with a spread operator after checking if it's not null.
style, languageFeatureUsage
style
languageFeatureUsage
final list = [ itemOne, itemTwo, if (extraItems != null) ...extraItems, ];
final list = [ itemOne, itemTwo, ...?extraItems, ];
A widely applicable fix should be possible. If the lint isn't seen as valuable enough to many, just the assist would still be valuable.
Expand prefer_null_aware_operators to cover these cases as it covers other conditional checks then usages.
prefer_null_aware_operators
prefer_spread_collections could also work as it already covers some null-aware cases, and I imagine if one wants that, they'd almost always prefer to use it here too.
prefer_spread_collections
I'd be in favor of enhancing prefer_spread_collections.
Name
Some options:
verbose_conditional_collection_spread
unnecessary_null_check_and_spread
prefer_null_aware_spread_operator
Description
The analyzer produces this diagnostic when a list is added to a collection literal with a spread operator after checking if it's not null.
Categories
style
,languageFeatureUsage
Bad examples
Good examples
Fix discussion
A widely applicable fix should be possible. If the lint isn't seen as valuable enough to many, just the assist would still be valuable.
Alternative(s)
Expand
prefer_null_aware_operators
to cover these cases as it covers other conditional checks then usages.prefer_spread_collections
could also work as it already covers some null-aware cases, and I imagine if one wants that, they'd almost always prefer to use it here too.