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 2 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
39 changes: 16 additions & 23 deletions src/coverage-system/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,19 @@ 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; }
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) => {
Copy link
Owner

Choose a reason for hiding this comment

The 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);
          }
      }
  });

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Owner

Choose a reason for hiding this comment

The 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);
}
}
});
}
Expand All @@ -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) => {
Copy link
Owner

Choose a reason for hiding this comment

The 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);
}
}
});
}
}