runWithReporter method

  1. @override
void runWithReporter(
  1. SaropaDiagnosticReporter reporter,
  2. SaropaContext context
)
override

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 String fileSource = context.fileContent;

  // Check for app lifecycle handling
  if (fileSource.contains('WidgetsBindingObserver') &&
      fileSource.contains('didChangeAppLifecycleState')) {
    return; // Already using Flutter's unified lifecycle handler
  }

  context.addSimpleStringLiteral((SimpleStringLiteral node) {
    final String value = node.value;

    if (value.contains('applicationDidBecomeActive') ||
        value.contains('applicationWillResignActive') ||
        value.contains('applicationDidEnterBackground')) {
      reporter.atNode(node);
    }
  });
}