From 9862626ce94ae9d777b2f53ea9cbc0d5879b9054 Mon Sep 17 00:00:00 2001 From: MylesJP <96148570+MylesJP@users.noreply.github.com> Date: Sat, 6 May 2023 21:13:31 -0700 Subject: [PATCH 1/3] Refactored functions in renderer.ts --- src/coverage-system/renderer.ts | 35 +++++++++++++++------------------ 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/coverage-system/renderer.ts b/src/coverage-system/renderer.ts index d03755e..e03d612 100644 --- a/src/coverage-system/renderer.ts +++ b/src/coverage-system/renderer.ts @@ -116,21 +116,20 @@ export class Renderer { if (!section || !section.lines) { return; } - // TODO cleanup this area by using maps, filters, etc section.lines.details.forEach((detail) => { - if (detail.line < 0) { return; } - const lineRange = new Range(detail.line - 1, 0, detail.line - 1, 0); - if (detail.hit > 0) { - if (coverageLines.none.find((range) => range.isEqual(lineRange))) { - // remove all none coverage, for this line, if one full exists - coverageLines.none = coverageLines.none.filter((range) => !range.isEqual(lineRange)); - } - coverageLines.full.push(lineRange); - } else { - const fullExists = coverageLines.full.find((range) => range.isEqual(lineRange)); - if (!fullExists) { - // only add a none coverage if no full ones exist - coverageLines.none.push(lineRange); + if (detail.line >= 0) { + const lineRange = new Range(detail.line - 1, 0, detail.line - 1, 0); + if (detail.hit > 0) { + // Evaluates to true if at least one element in range is equal to LineRange + if (coverageLines.none.some((range) => range.isEqual(lineRange))) { + coverageLines.none = coverageLines.none.filter((range) => !range.isEqual(lineRange)) + } + coverageLines.full.push(lineRange); + } else { + if (!coverageLines.full.some((range) => range.isEqual(lineRange))) { + // only add a none coverage if no full ones exist + coverageLines.none.push(lineRange); + } } } }); @@ -143,13 +142,11 @@ export class Renderer { if (!section || !section.branches) { return; } - // TODO cleanup this area by using maps, filters, etc section.branches.details.forEach((detail) => { - if (detail.taken === 0) { - if (detail.line < 0) { return; } + if (detail.taken === 0 && detail.line >= 0) { const partialRange = new Range(detail.line - 1, 0, detail.line - 1, 0); - if (coverageLines.full.find((range) => range.isEqual(partialRange))) { - // remove full coverage if partial is a better match + // Evaluates to true if at least one element in range is equal to partialRange + if (coverageLines.full.some((range) => range.isEqual(partialRange))){ coverageLines.full = coverageLines.full.filter((range) => !range.isEqual(partialRange)); coverageLines.partial.push(partialRange); } From b5ec0b36021d0fed7ef889ccaace034aeffa143d Mon Sep 17 00:00:00 2001 From: MylesJP <96148570+MylesJP@users.noreply.github.com> Date: Sat, 6 May 2023 21:22:42 -0700 Subject: [PATCH 2/3] Refactored functions in renderer.ts --- src/coverage-system/renderer.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/coverage-system/renderer.ts b/src/coverage-system/renderer.ts index e03d612..2e52a18 100644 --- a/src/coverage-system/renderer.ts +++ b/src/coverage-system/renderer.ts @@ -116,8 +116,7 @@ export class Renderer { if (!section || !section.lines) { return; } - section.lines.details.forEach((detail) => { - if (detail.line >= 0) { + section.lines.details.filter((detail) => detail.line >= 0).forEach((detail) => { const lineRange = new Range(detail.line - 1, 0, detail.line - 1, 0); if (detail.hit > 0) { // Evaluates to true if at least one element in range is equal to LineRange @@ -130,7 +129,6 @@ export class Renderer { // only add a none coverage if no full ones exist coverageLines.none.push(lineRange); } - } } }); } @@ -142,15 +140,13 @@ export class Renderer { if (!section || !section.branches) { return; } - section.branches.details.forEach((detail) => { - if (detail.taken === 0 && detail.line >= 0) { + section.branches.details.filter((detail) => detail.taken === 0 && detail.line >= 0).forEach((detail) => { const partialRange = new Range(detail.line - 1, 0, detail.line - 1, 0); // Evaluates to true if at least one element in range is equal to partialRange if (coverageLines.full.some((range) => range.isEqual(partialRange))){ coverageLines.full = coverageLines.full.filter((range) => !range.isEqual(partialRange)); coverageLines.partial.push(partialRange); } - } }); } } From 81cd40a353cb0e1fd38d1a556a62c7e9d288c356 Mon Sep 17 00:00:00 2001 From: Myles Penner Date: Fri, 12 May 2023 15:54:53 -0700 Subject: [PATCH 3/3] Updated formatting and indentation --- src/coverage-system/renderer.ts | 44 ++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/src/coverage-system/renderer.ts b/src/coverage-system/renderer.ts index 2e52a18..830f210 100644 --- a/src/coverage-system/renderer.ts +++ b/src/coverage-system/renderer.ts @@ -116,19 +116,21 @@ export class Renderer { if (!section || !section.lines) { return; } - section.lines.details.filter((detail) => detail.line >= 0).forEach((detail) => { - const lineRange = new Range(detail.line - 1, 0, detail.line - 1, 0); - if (detail.hit > 0) { - // Evaluates to true if at least one element in range is equal to LineRange - if (coverageLines.none.some((range) => range.isEqual(lineRange))) { - coverageLines.none = coverageLines.none.filter((range) => !range.isEqual(lineRange)) - } - coverageLines.full.push(lineRange); - } else { - if (!coverageLines.full.some((range) => range.isEqual(lineRange))) { - // only add a none coverage if no full ones exist - coverageLines.none.push(lineRange); - } + section.lines.details + .filter((detail) => detail.line >= 0) + .forEach((detail) => { + const lineRange = new Range(detail.line - 1, 0, detail.line - 1, 0); + if (detail.hit > 0) { + // Evaluates to true if at least one element in range is equal to LineRange + if (coverageLines.none.some((range) => range.isEqual(lineRange))) { + coverageLines.none = coverageLines.none.filter((range) => !range.isEqual(lineRange)) + } + coverageLines.full.push(lineRange); + } else { + if (!coverageLines.full.some((range) => range.isEqual(lineRange))) { + // only add a none coverage if no full ones exist + coverageLines.none.push(lineRange); + } } }); } @@ -140,13 +142,15 @@ export class Renderer { if (!section || !section.branches) { return; } - section.branches.details.filter((detail) => detail.taken === 0 && detail.line >= 0).forEach((detail) => { - const partialRange = new Range(detail.line - 1, 0, detail.line - 1, 0); - // Evaluates to true if at least one element in range is equal to partialRange - if (coverageLines.full.some((range) => range.isEqual(partialRange))){ - coverageLines.full = coverageLines.full.filter((range) => !range.isEqual(partialRange)); - coverageLines.partial.push(partialRange); - } + section.branches.details + .filter((detail) => detail.taken === 0 && detail.line >= 0) + .forEach((detail) => { + const partialRange = new Range(detail.line - 1, 0, detail.line - 1, 0); + // Evaluates to true if at least one element in range is equal to partialRange + if (coverageLines.full.some((range) => range.isEqual(partialRange))){ + coverageLines.full = coverageLines.full.filter((range) => !range.isEqual(partialRange)); + coverageLines.partial.push(partialRange); + } }); } }