validateSignature method

String? validateSignature({
  1. required String path,
  2. required String wildcardMatcher,
  3. required FunctionExpression function,
  4. required String createExpectedSignature(
    1. String wildcard
    ),
})

Validate the given function's signature

Returns the expected signature if invalid

Implementation

String? validateSignature({
  required String path,
  required String wildcardMatcher,
  required FunctionExpression function,
  required String Function(String wildcard) createExpectedSignature,
}) {
  final String expectedWildcard;
  final wildcards = RegExp(wildcardMatcher).allMatches(path);
  if (wildcards.length > 1) {
    // The path is invalid. This is handled by another lint.
    return null;
  } else if (wildcards.length == 1) {
    expectedWildcard = wildcards.single[1]!;
  } else {
    expectedWildcard = '_';
  }

  final expectedSignature = createExpectedSignature(expectedWildcard);
  final actualSignature = function.parameters.toString();
  if (expectedSignature != actualSignature) {
    return expectedSignature;
  }

  return null;
}