From 7bd07aa93fc6c47cdd2dc0673e3bdb9abc2442ce Mon Sep 17 00:00:00 2001 From: Francois Daoust Date: Thu, 22 Aug 2024 18:36:33 +0200 Subject: [PATCH] Filter out empty strings (and add reminder) --- src/reporting/file-issue-for-review.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/reporting/file-issue-for-review.js b/src/reporting/file-issue-for-review.js index 2eeaa768..f5cea3f8 100644 --- a/src/reporting/file-issue-for-review.js +++ b/src/reporting/file-issue-for-review.js @@ -105,10 +105,14 @@ Usage notes for some of the options: const currentBranch = execSync('git branch --show-current', execParams).trim(); console.log(`- current branch: ${currentBranch}`); + // Possibly useful reminder about calls to `filter` below: + // `split` on an empty string does not return an empty array! console.log('How many issue files ought to be reported?'); - const toadd = execSync('git diff --name-only --diff-filter=d issues/*.md', execParams).trim().split('\n'); + const toadd = execSync('git diff --name-only --diff-filter=d issues/*.md', execParams) + .trim().split('\n').filter(x => !!x); console.log(`- nb issue files to add/update: ${toadd.length}`); - const todelete = execSync('git diff --name-only --diff-filter=D issues/*.md', execParams).trim().split('\n'); + const todelete = execSync('git diff --name-only --diff-filter=D issues/*.md', execParams) + .trim().split('\n').filter(x => !!x); console.log(`- nb issue files to delete: ${todelete.length}`); const toreport = toadd.map(name => { return { action: 'add', filename: name }; }) .concat(todelete.map(name => { return { action: 'delete', filename: name }; }))