Skip to content
This repository was archived by the owner on Jul 16, 2023. It is now read-only.

Commit 1bffe50

Browse files
committed
fix: handle property access for unnecessary nullable tear-offs
1 parent aa8bc9b commit 1bffe50

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

lib/src/analyzers/unnecessary_nullable_analyzer/invocations_visitor.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ class InvocationsVisitor extends RecursiveAstVisitor<void> {
2121
}
2222
}
2323

24+
@override
25+
void visitPropertyAccess(PropertyAccess node) {
26+
super.visitPropertyAccess(node);
27+
28+
if (node.propertyName.staticType is FunctionType) {
29+
_recordUsedElement(node.propertyName.staticElement, null);
30+
}
31+
}
32+
2433
@override
2534
void visitPrefixedIdentifier(PrefixedIdentifier node) {
2635
super.visitPrefixedIdentifier(node);

test/resources/unnecessary_nullable_analyzer/nullable_method_parameters.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// ignore_for_file: avoid-unused-parameters, no-empty-block
22

33
class ClassWithMethods {
4+
final inner = ClassWithMethods();
5+
46
void someMethod(String? value) {}
57

68
// LINT
@@ -24,4 +26,6 @@ class ClassWithMethods {
2426
void ignoredAlwaysNonNullable(String? anotherValue) {}
2527

2628
void tearOff(String? anotherValue) {}
29+
30+
void anotherTearOff(String? anotherValue) {}
2731
}

test/resources/unnecessary_nullable_analyzer/unnecessary_nullable_example.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ void main() {
4747
MyWidget(GlobalKey());
4848

4949
AnotherWidget(onSubmit: withMethods.tearOff);
50+
AnotherWidget(onSubmit: withMethods.inner.anotherTearOff);
5051
}
5152

5253
class _Test {

test/src/analyzers/unnecessary_nullable_analyzer/unnecessary_nullable_analyzer_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void main() {
7373
expect(firstIssue.declarationName, 'alwaysNonNullable');
7474
expect(firstIssue.declarationType, 'method');
7575
expect(firstIssue.parameters.toString(), '(String? anotherValue)');
76-
expect(firstIssue.location.line, 7);
76+
expect(firstIssue.location.line, 9);
7777
expect(firstIssue.location.column, 3);
7878

7979
final secondIssue = report.issues.last;
@@ -83,7 +83,7 @@ void main() {
8383
secondIssue.parameters.toString(),
8484
'(String? value, required String? name)',
8585
);
86-
expect(secondIssue.location.line, 16);
86+
expect(secondIssue.location.line, 18);
8787
expect(secondIssue.location.column, 3);
8888
});
8989

0 commit comments

Comments
 (0)