Skip to content

Commit ac92672

Browse files
Yurii PrykhodkoYurii Prykhodko
authored andcommitted
simplify
1 parent e1548ea commit ac92672

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

lib/src/lints/avoid_using_api/avoid_using_api_linter.dart

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -248,22 +248,15 @@ class AvoidUsingApiLinter {
248248

249249
context.registry.addMethodInvocation((node) {
250250
final methodName = node.methodName.name;
251-
if (methodName != identifier) {
252-
return;
253-
}
251+
if (methodName != identifier) return;
254252

255-
final element = node.methodName.staticElement;
256-
if (element == null || element.enclosingElement3 is! ExtensionElement) {
253+
final enclosingElement = node.methodName.staticElement?.enclosingElement3;
254+
if (enclosingElement is! ExtensionElement ||
255+
enclosingElement.name != className) {
257256
return;
258257
}
259258

260-
final extensionElement = element.enclosingElement3! as ExtensionElement;
261-
262-
if (extensionElement.name != className) {
263-
return;
264-
}
265-
266-
final sourcePath = extensionElement.librarySource.uri.toString();
259+
final sourcePath = enclosingElement.librarySource.uri.toString();
267260
if (!_matchesSource(sourcePath, source)) {
268261
return;
269262
}
@@ -275,15 +268,13 @@ class AvoidUsingApiLinter {
275268
final propertyName = node.identifier.name;
276269
if (propertyName != identifier) return;
277270

278-
final element = node.identifier.staticElement;
279-
if (element == null || element.enclosingElement3 is! ExtensionElement) {
271+
final enclosingElement = node.identifier.staticElement?.enclosingElement3;
272+
if (enclosingElement is! ExtensionElement ||
273+
enclosingElement.name != className) {
280274
return;
281275
}
282276

283-
final extensionElement = element.enclosingElement3! as ExtensionElement;
284-
if (extensionElement.name != className) return;
285-
286-
final sourcePath = extensionElement.librarySource.uri.toString();
277+
final sourcePath = enclosingElement.librarySource.uri.toString();
287278
if (!_matchesSource(sourcePath, source)) return;
288279

289280
reporter.atNode(node.identifier, entryCode);

0 commit comments

Comments
 (0)