Skip to content

Commit aa85631

Browse files
fix: handle null awareness
1 parent dc1db07 commit aa85631

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

lib/src/lints/prefer_first/fixes/prefer_first_fix.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ class PreferFirstFix extends ParsedCorrectionProducer {
4444

4545
String _createCorrection(Expression expression) {
4646
switch (expression) {
47-
case MethodInvocation(isCascaded: true):
48-
case IndexExpression(isCascaded: true):
49-
return '..first';
47+
case MethodInvocation(isCascaded: true, :final isNullAware):
48+
case IndexExpression(isCascaded: true, :final isNullAware):
49+
return isNullAware ? '?.first' : '..first';
5050

51-
case MethodInvocation(:final target?):
52-
case IndexExpression(:final target?):
53-
return '$target.first';
51+
case MethodInvocation(:final target?, :final isNullAware):
52+
case IndexExpression(:final target?, :final isNullAware):
53+
return isNullAware ? '$target?.first' : '$target.first';
5454

5555
default:
5656
return '.first';

0 commit comments

Comments
 (0)