assembleDartDocComment function

String assembleDartDocComment(
  1. List<String?> lineList
)

Assembles a Dart documentation comment from a list of strings.

Parameters:

  • lineList: A list of String? lines to be included in the Dart doc comment.

Returns:

  • A String representing the formatted Dart doc comment, with each line prefixed by /// and empty comment lines added between entries (except after the last one).

Implementation

String assembleDartDocComment(List<String?> lineList) {
  final List<String> result = [];
  final List<String> filtered = lineList
      .map((line) => line?.trim())
      .where((line) => line != null && line.isNotEmpty)
      .cast<String>()
      .toList();

  for (int i = 0; i < filtered.length; i++) {
    final String line = filtered[i];
    result.add('/// $line');
    if (i != filtered.length - 1) {
      // Add an empty comment line between entries (except after the last one)
      result.add('///');
    }
  }

  return result.join('\n');
}