validator function

Future<String?> validator(
  1. String input
)

Implementation

Future<String?> validator(String input) async {
  await scratch.copy(nextPath);
  nextScratch.writeAsStringSync(input + '\n',
      mode: FileMode.append, flush: true);

  final collection = AnalysisContextCollection(
      includedPaths: [nextScratch.absolute.path],
      resourceProvider: PhysicalResourceProvider.INSTANCE);

  for (final context in collection.contexts) {
    for (final filePath in context.contextRoot.analyzedFiles()) {
      final errorsResult = await context.currentSession.getErrors(filePath);
      if (errorsResult is ErrorsResult) {
        for (final error in errorsResult.errors) {
          if (error.errorCode.type != ErrorType.TODO) {
            return error.message;
          }
        }
      }
    }
  }
  await nextScratch.copy(scratchPath);
  return null;
}