run method
void
run(
- CustomLintResolver resolver,
- ErrorReporter reporter,
- CustomLintContext context
Emits lints for a given file.
run will only be invoked with files respecting filesToAnalyze
Implementation
@override
void run(
CustomLintResolver resolver,
ErrorReporter reporter,
CustomLintContext context,
) {
context.registry.addInstanceCreationExpression((node) {
// Skip if this is a const constructor (const widgets are optimized already)
if (node.isConst) return;
final type = node.constructorName.type.type;
if (type == null) return;
// Skip certain widgets that don't benefit from keys or are used in contexts
// where keys aren't typically needed
final String typeName = type.toString();
if (_isExemptWidget(typeName)) return;
// Check if it's a Widget subclass
if (_isWidgetType(type) && !_hasKeyParameter(node)) {
reporter.atNode(node, code);
}
});
}