-
Notifications
You must be signed in to change notification settings - Fork 664
refactor(semver): removing unreachable code, bringing coverage to 100% #6924
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
base: main
Are you sure you want to change the base?
Conversation
| return cmp < 0; | ||
| case "!=": | ||
| return false; | ||
| return cmp >= 0; |
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.
I'll admit this one had me scratching my head a bit. It seems that, in the context of this internal utility function, simply inverting the outcome for the != operator (compared to the = operator) should suffice for producing the intended effect.
| return cmp > 0; | ||
| case "!=": | ||
| return false; | ||
| return cmp <= 0; |
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.
See comments on greater_than_range.ts
|
|
||
| if (!groups) return null; | ||
|
|
||
| const { operator, prerelease, buildmetadata } = |
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.
Unless I'm missing something here, if the regex match succeeds at all, the resulting groups will contain elements for each semver component. This code was attempting to manually parse what this regex was already doing.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6924 +/- ##
==========================================
+ Coverage 94.17% 94.22% +0.04%
==========================================
Files 584 584
Lines 43087 43072 -15
Branches 6875 6870 -5
==========================================
+ Hits 40578 40585 +7
+ Misses 2457 2436 -21
+ Partials 52 51 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| const prerelease = parsePrerelease(groups.prerelease ?? ""); | ||
| const build = parseBuild(groups.build ?? ""); | ||
| return [{ operator: undefined, major, minor, patch, prerelease, build }]; | ||
|
|
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.
We can use the = string if we have it, the net-effect is the same.
| throw new Error( | ||
| `Cannot parse version range: '${groups.operator}' is not a valid operator`, | ||
| ); | ||
| return handleEqualOperator(groups); |
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.
The existing default case should not be possible, so we can use the equals/empty operator to exercise a switch default.
This change refactors a handful of internal functionality to remove unreachable code, and adds a couple of new tests to bring up line coverage.
Comments added inline, I hope this helps!