runWithReporter method
Override this method to implement your lint rule.
Use context to register callbacks for AST node types:
context.addMethodInvocation((node) {
if (condition) {
reporter.atNode(node);
}
});
Implementation
@override
void runWithReporter(
SaropaDiagnosticReporter reporter,
SaropaContext context,
) {
context.addInstanceCreationExpression((InstanceCreationExpression node) {
final String typeName = node.constructorName.type.name.lexeme;
if (typeName != 'FileImage') return;
// FP fix: `contains('asset')` matched any filesystem path that merely
// happened to include those letters (e.g. `/var/dataset/photo.png`),
// and `contains('assets/')` matched it mid-path too. A bundled asset is
// referenced by a path that STARTS with `assets/`. Look for a string
// literal argument (the File path) whose value begins with `assets/`.
if (node.argumentList.arguments.isEmpty) return;
final Expression first = node.argumentList.arguments.first;
if (_referencesBundledAssetPath(first)) {
reporter.atNode(node.constructorName, code);
}
});
}