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,
) {
final projectInfo = ProjectContext.getProjectInfo(context.filePath);
if (projectInfo == null || !projectInfo.isFlutterProject) return;
final checker = AndroidManifestChecker.forFile(context.filePath);
if (checker == null || !checker.hasManifest) return;
// Only relevant once the app opted into broad media access; otherwise the
// system Photo Picker handles partial access and no permission is needed.
final bool declaresBroadMedia =
checker.hasPermission('READ_MEDIA_IMAGES') ||
checker.hasPermission('READ_MEDIA_VIDEO');
if (!declaresBroadMedia) return;
if (checker.hasPermission('READ_MEDIA_VISUAL_USER_SELECTED')) return;
context.addImportDirective((ImportDirective node) {
final String? uri = node.uri.stringValue;
if (uri == null) return;
if (uri.startsWith('package:image_picker/') ||
uri.startsWith('package:photo_manager/')) {
reporter.atNode(node);
}
});
}