prettier-plugin-multiline-arrays
Version:
Prettier plugin to force all arrays to be multiline.
31 lines (30 loc) • 979 B
JavaScript
import { extractTextBetweenRanges } from '../augments/array.js';
export function containsTrailingComma(nodeLocation, children, originalLines,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
debug) {
const lastElement = children[children.length - 1];
if (lastElement) {
const startLocation = lastElement.loc?.end;
if (!startLocation) {
return false;
}
const endLocation = nodeLocation?.end;
if (!endLocation) {
return false;
}
const textPastLastElement = extractTextBetweenRanges(originalLines, {
start: {
column: startLocation.column - 1,
line: startLocation.line - 1,
},
end: {
column: endLocation.column - 1,
line: endLocation.line - 1,
},
});
if (textPastLastElement.includes(',')) {
return true;
}
}
return false;
}