Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored filterLineCoverage() and filterBranchCoverage() in renderer.ts #406

Merged
merged 4 commits into from
May 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 15 additions & 18 deletions src/coverage-system/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,18 @@ export class Renderer {
if (!section || !section.lines) {
return;
}
// TODO cleanup this area by using maps, filters, etc
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tackling these to-dos!

section.lines.details.forEach((detail) => {
if (detail.line < 0) { 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) {
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));
// 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 {
const fullExists = coverageLines.full.find((range) => range.isEqual(lineRange));
if (!fullExists) {
if (!coverageLines.full.some((range) => range.isEqual(lineRange))) {
// only add a none coverage if no full ones exist
coverageLines.none.push(lineRange);
}
Expand All @@ -143,16 +142,14 @@ 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; }
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
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);
}
});
}
Expand Down