-
Notifications
You must be signed in to change notification settings - Fork 90
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,22 +116,19 @@ 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); | ||
} | ||
section.lines.details.filter((detail) => detail.line >= 0).forEach((detail) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar here as below (around re-ability and a small tweak to the indent) 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);
}
}
}); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense, thanks for the feedback Ryan. I'll make those changes right away. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sweet, thanks! I will try to take a look within the week. |
||
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,17 +140,13 @@ 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; } | ||
section.branches.details.filter((detail) => detail.taken === 0 && detail.line >= 0).forEach((detail) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this filter, but we might want to put it on multiple lines to aid in readability (if possible). 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);
}
}); |
||
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); | ||
} | ||
} | ||
}); | ||
} | ||
} |
There was a problem hiding this comment.
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!