Skip to content

Commit

Permalink
fix: add placeholder to fix Implicit Else (#679)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian-burlacu-software committed Jul 13, 2022
1 parent c7693d4 commit 0516f51
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
17 changes: 17 additions & 0 deletions packages/istanbul-reports/lib/html/annotator.js
Expand Up @@ -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;
Expand Down
5 changes: 0 additions & 5 deletions packages/istanbul-reports/test/fixtures/github-649.json
Expand Up @@ -100,11 +100,6 @@
"line": 6,
"column": 5
}
}, {
"start": {
},
"end": {
}
}
],
"line": 4
Expand Down

0 comments on commit 0516f51

Please sign in to comment.