UNPKG

prettier-plugin-multiline-arrays

Version:
32 lines (31 loc) 1.05 kB
import { extractTextBetweenRanges } from '../augments/array.js'; export function containsLeadingNewline(nodeLocation, children, originalLines, debug) { const firstElement = children[0]; if (firstElement) { const startLocation = nodeLocation?.start; if (!startLocation) { return false; } const endLocation = firstElement.loc?.start; if (!endLocation) { return false; } const textBeforeFirstElement = extractTextBetweenRanges(originalLines, { start: { column: startLocation.column - 1, line: startLocation.line - 1, }, end: { column: endLocation.column - 1, line: endLocation.line - 1, }, }); if (debug) { console.info(`containsLeadingNewline textBeforeFirstElement: ${textBeforeFirstElement}`); } if (textBeforeFirstElement.includes('\n')) { return true; } } return false; }