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.addFunctionDeclaration((FunctionDeclaration node) {
    // Find functions that have important optional boolean parameters
    final FormalParameterList? params = node.functionExpression.parameters;
    if (params == null) return;

    final Set<String> optionalBoolParams = <String>{};
    for (final FormalParameter param in params.parameters) {
      if (param.isNamed || param.isOptional) {
        final String? name = param.name?.lexeme;
        if (name != null && _importantBoolParams.contains(name)) {
          optionalBoolParams.add(name);
        }
      }
    }

    if (optionalBoolParams.isEmpty) return;

    // Store for later checking of call sites
    // This rule checks at declaration site for documentation purposes
    // A more complete implementation would track call sites
  });
}