From 0516f519575ee28f77ebf1e9556ac294d78904ea Mon Sep 17 00:00:00 2001 From: Adrian Burlacu <63519230+adrian-burlacu-software@users.noreply.github.com> Date: Wed, 13 Jul 2022 14:47:29 -0400 Subject: [PATCH] fix: add placeholder to fix Implicit Else (#679) --- packages/istanbul-reports/lib/html/annotator.js | 17 +++++++++++++++++ .../test/fixtures/github-649.json | 5 ----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/packages/istanbul-reports/lib/html/annotator.js b/packages/istanbul-reports/lib/html/annotator.js index 84d8fc39..9414cfc5 100644 --- a/packages/istanbul-reports/lib/html/annotator.js +++ b/packages/istanbul-reports/lib/html/annotator.js @@ -142,6 +142,23 @@ function annotateBranches(fileCoverage, structuredText) { // only highlight if partial branches are missing or if there is a // single uncovered branch. if (sumCount > 0 || (sumCount === 0 && branchArray.length === 1)) { + // Need to recover the metaArray placeholder item to count an implicit else + if ( + // Check if the branch is a conditional if branch. + branchMeta[branchName].type === 'if' && + // Check if the branch has an implicit else. + branchArray.length === 2 && + // Check if the implicit else branch is unnacounted for. + metaArray.length === 1 && + // Check if the implicit else branch is uncovered. + branchArray[1] === 0 + ) { + metaArray[1] = { + start: {}, + end: {} + }; + } + for ( i = 0; i < branchArray.length && i < metaArray.length; diff --git a/packages/istanbul-reports/test/fixtures/github-649.json b/packages/istanbul-reports/test/fixtures/github-649.json index 078b36fa..68e30575 100644 --- a/packages/istanbul-reports/test/fixtures/github-649.json +++ b/packages/istanbul-reports/test/fixtures/github-649.json @@ -100,11 +100,6 @@ "line": 6, "column": 5 } - }, { - "start": { - }, - "end": { - } } ], "line": 4