UNPKG

@twilio-labs/languagetool-cli

Version:

Run LanguageTool for linting Markdown files during CI

47 lines 1.33 kB
export function getChangedLineNumbersFromPatch(patch) { const fileLinesRegex = /^@@ -([0-9]*),?\S* \+([0-9]*),?/; const lineNumbersInDiff = []; if (!patch) return []; splitIntoParts(patch.split("\n"), "@@ ").forEach((lines) => { const fileLinesLine = lines.shift(); const matches = fileLinesLine.match(fileLinesRegex); if (!matches) return []; const [, a, b] = matches; let nA = parseInt(a); let nB = parseInt(b); lines.forEach((line) => { if (line.startsWith("+")) { nA--; lineNumbersInDiff.push(nB); } else if (line.startsWith("-")) { nB--; } nA++; nB++; }); }); return lineNumbersInDiff; } function splitIntoParts(lines, separator) { const parts = []; let currentPart = undefined; lines.forEach((line) => { if (line.startsWith(separator)) { if (currentPart) { parts.push(currentPart); } currentPart = [line]; } else if (currentPart) { currentPart.push(line); } }); if (currentPart) { parts.push(currentPart); } return parts; } //# sourceMappingURL=parseGitPatch.js.map