Skip to content

Commit de6f83a

Browse files
committed
lint is working for extensions
1 parent 76546be commit de6f83a

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## 0.4.0
22

33
- Added `allow_with_comments` parameter for `no_empty_block` lint.
4-
4+
- Fixed an issue with `avoid_using_api` for extensions
55
## 0.3.0
66

77
- Added `exclude` parameter for the following lints:

lib/src/lints/avoid_using_api/avoid_using_api_linter.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,5 +245,30 @@ class AvoidUsingApiLinter {
245245
);
246246
}
247247
});
248+
249+
context.registry.addMethodInvocation((node) {
250+
final methodName = node.methodName.name;
251+
if (methodName != identifier) {
252+
return;
253+
}
254+
255+
final element = node.methodName.staticElement;
256+
if (element == null || element.enclosingElement3 is! ExtensionElement) {
257+
return;
258+
}
259+
260+
final extensionElement = element.enclosingElement3! as ExtensionElement;
261+
262+
if (extensionElement.name != className) {
263+
return;
264+
}
265+
266+
final sourcePath = extensionElement.librarySource.uri.toString();
267+
if (!_matchesSource(sourcePath, source)) {
268+
return;
269+
}
270+
271+
reporter.atNode(node.methodName, entryCode);
272+
});
248273
}
249274
}

0 commit comments

Comments
 (0)