Browse Source

build: account for `subjectAndDescription` null in patch linting (#42636)

fix: account for subjectAndDescription null in patch linting
Shelley Vohr 9 months ago
parent
commit
3534923bd2
1 changed files with 4 additions and 2 deletions
  1. 4 2
      script/lint.js

+ 4 - 2
script/lint.js

@@ -252,8 +252,10 @@ const LINTERS = [{
 
     const allOk = filenames.length > 0 && filenames.map(f => {
       const patchText = fs.readFileSync(f, 'utf8');
-      const subjectAndDescription = /Subject: (.*?)\n\n([\s\S]*?)\s*(?=diff)/ms.exec(patchText);
-      if (!subjectAndDescription[2]) {
+
+      const regex = /Subject: (.*?)\n\n([\s\S]*?)\s*(?=diff)/ms;
+      const subjectAndDescription = regex.exec(patchText);
+      if (!subjectAndDescription?.[2]) {
         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;
       }