run method
void
run(
- CustomLintResolver resolver,
- DiagnosticReporter reporter,
- CustomLintContext context
Emits lints for a given file.
run will only be invoked with files respecting filesToAnalyze
Implementation
@override
void run(
CustomLintResolver resolver,
DiagnosticReporter reporter,
CustomLintContext context,
) {
context.registry.addInstanceCreationExpression((node) {
final type = node.staticType;
if (type == null) {
return;
}
final typeName = type.element?.name;
// Check for TextField or TextFormField
if (typeName != 'TextField' && typeName != 'TextFormField') {
return;
}
bool hasLabel = false;
// Check for decoration parameter with labelText or label
for (final arg in node.argumentList.arguments) {
if (arg is NamedExpression && arg.name.label.name == 'decoration') {
final decoration = arg.expression;
// Check if decoration is InputDecoration
if (decoration is InstanceCreationExpression) {
hasLabel = _checkDecorationForLabel(decoration);
}
}
}
// If no label in decoration, check if wrapped in Semantics
if (!hasLabel) {
hasLabel = isWrappedInSemanticsWithLabel(node);
}
// Report if no label found
if (!hasLabel) {
reporter.atNode(node, code);
}
});
}