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.addInstanceCreationExpression((InstanceCreationExpression node) {
    final String typeName = node.constructorName.type.name.lexeme;
    if (typeName != 'ShellRoute') return;

    // Check for tab-related patterns in builder
    final ArgumentList args = node.argumentList;
    for (final Expression arg in args.arguments) {
      if (arg is NamedExpression && arg.name.label.name == 'builder') {
        final String builderSource = arg.expression.toSource();
        // Look for tab-related widgets
        if (builderSource.contains('BottomNavigationBar') ||
            builderSource.contains('NavigationBar') ||
            builderSource.contains('TabBar') ||
            builderSource.contains('IndexedStack')) {
          reporter.atNode(node);
          return;
        }
      }
    }
  });
}