build: provide line numbers of bad patch lines when linting (#28666)

This commit is contained in:
Samuel Attard 2021-04-15 10:43:35 -07:00 committed by GitHub
parent 5ee906fd04
commit 9236e56ddc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -207,9 +207,9 @@ const LINTERS = [{
console.warn(`Patch file '${f}' has no description. Every patch must contain a justification for why the patch exists and the plan for its removal.`);
return false;
}
const trailingWhitespace = patchText.split(/\r?\n/).some(line => line.startsWith('+') && /\s+$/.test(line));
if (trailingWhitespace) {
console.warn(`Patch file '${f}' has trailing whitespace on some lines.`);
const trailingWhitespaceLines = patchText.split(/\r?\n/).map((line, index) => [line, index]).filter(([line]) => line.startsWith('+') && /\s+$/.test(line)).map(([, lineNumber]) => lineNumber + 1);
if (trailingWhitespaceLines.length > 0) {
console.warn(`Patch file '${f}' has trailing whitespace on some lines (${trailingWhitespaceLines.join(',')}).`);
return false;
}
return true;