isDuplicateDeclaration method

bool isDuplicateDeclaration(
  1. AFCommandContext context,
  2. List<String> lines
)

Implementation

bool isDuplicateDeclaration(AFCommandContext context, List<String> lines) {
  if(lines.isEmpty) {
    throw AFException("Expected at least one line, found $lines");
  }

  // just checking the first line works for both function and id declarations
  var firstNonEmpty = lines.firstWhere((element) => element.isNotEmpty);

  for(final lineTest in buffer.lines) {
    if(lineTest.contains(firstNonEmpty)) {
      return true;
    }
  }
  return false;
}