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,
) {
  context.addMethodInvocation((MethodInvocation node) {
    if (node.methodName.name != 'showDialog') return;

    final String argsSource = node.argumentList.toSource();

    // Check if barrierDismissible is set
    if (argsSource.contains('barrierDismissible')) return;

    // Check if dialog content contains destructive keywords
    if (_destructivePattern.hasMatch(argsSource)) {
      reporter.atNode(node);
    }
  });
}