check method
void
check(
- DcqRegistry registry
)
Implementation
@override
void check(DcqRegistry registry) {
var hasBlocImport = false;
registry.addImportDirective((node) {
final uri = node.uri.stringValue;
if (uri != null && uri.startsWith('package:flutter_bloc/')) {
hasBlocImport = true;
}
});
final pendingNodes = <ConstructorName>[];
registry.addInstanceCreationExpression((node) {
final name = node.constructorName.type.name.lexeme;
if (!_providerTypes.contains(name)) return;
// Check if the child is also a provider.
final childArg = node.argumentList.arguments
.whereType<NamedExpression>()
.where((a) => a.name.label.name == 'child')
.firstOrNull;
if (childArg != null) {
final child = childArg.expression;
if (child is InstanceCreationExpression) {
final childName = child.constructorName.type.name.lexeme;
if (_providerTypes.contains(childName)) {
pendingNodes.add(node.constructorName);
}
}
}
});
registry.afterLibrary(() {
if (!hasBlocImport) return;
for (final node in pendingNodes) {
reportAtNode(node);
}
});
}