format function Null safety

List<String> format(
  1. List<String> lines
)

Auto indents.

Implementation

List<String> format(List<String> lines) {
    int indent = 0;
    final RegExp reOpen = RegExp(r'\{[^\}]*$');
    final RegExp reClose = RegExp(r'^[^\{]*\}');
    for (int i = 0; i < lines.length; i++) {
        final bool increase = reOpen.hasMatch(lines[i]);
        final bool decrease = reClose.hasMatch(lines[i]);
        if (decrease) indent--;
        lines[i] = '\t' * indent + lines[i];
        if (increase) indent++;
    }
    return lines;
}