validateNoBlankLinesInRange function

void validateNoBlankLinesInRange(
  1. int startLine,
  2. int endLine,
  3. List<BlankLineInfo> blankLines,
  4. bool strict,
  5. String context,
)

Validates that there are no blank lines within a specific line range and depth.

In strict mode, blank lines inside arrays/tabular rows are not allowed.

@param startLine The starting line number (inclusive) @param endLine The ending line number (inclusive) @param blankLines Array of blank line information @param strict Whether strict mode is enabled @param context Description of the context (e.g., "list array", "tabular array") @throws SyntaxError if blank lines are found in strict mode

Implementation

void validateNoBlankLinesInRange(
  int startLine,
  int endLine,
  List<BlankLineInfo> blankLines,
  bool strict,
  String context,
) {
  if (!strict) {
    return;
  }

  // Find blank lines within the range
  // Note: We don't filter by depth because ANY blank line between array items is an error,
  // regardless of its indentation level
  final blanksInRange = blankLines.where(
    (blank) => blank.lineNumber > startLine && blank.lineNumber < endLine,
  );

  if (blanksInRange.isNotEmpty) {
    throw FormatException(
      'Line ${blanksInRange.first.lineNumber}: Blank lines inside $context are not allowed in strict mode',
    );
  }
}