forked from dart-code-checker/dart-code-metrics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
visitor.dart
35 lines (27 loc) · 785 Bytes
/
visitor.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
part of 'avoid_banned_imports_rule.dart';
class _Visitor extends RecursiveAstVisitor<void> {
final List<_AvoidBannedImportsConfigEntry> _activeEntries;
final _nodes = <_NodeWithMessage>[];
Iterable<_NodeWithMessage> get nodes => _nodes;
_Visitor(this._activeEntries);
@override
void visitImportDirective(ImportDirective node) {
final uri = node.uri.stringValue;
if (uri == null) {
return;
}
for (final entry in _activeEntries) {
if (entry.deny.any((deny) => deny.hasMatch(uri))) {
_nodes.add(_NodeWithMessage(
node,
'Avoid banned imports (${entry.message})',
));
}
}
}
}
class _NodeWithMessage {
final AstNode node;
final String message;
_NodeWithMessage(this.node, this.message);
}