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

Consistent version formatting #1246

Merged
merged 6 commits into from
Nov 11, 2017
Merged
Changes from 1 commit
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
13 changes: 7 additions & 6 deletions lib/text-formatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,15 @@ function omitv(version) {
return version;
}

// Add a starting v to the version number if needed.
const ignoredVersionPatterns = /^[^0-9]+|[0-9]{4}-[0-9]{2}-[0-9]{2}/;
// Add a starting v to the version unless:
// - it does not start with a digit
// - it is a date (yyyy-mm-dd)
Copy link
Member

Choose a reason for hiding this comment

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

👍

const ignoredVersionPatterns = /^[^0-9]|[0-9]{4}-[0-9]{2}-[0-9]{2}/;
function addv(version) {
Copy link
Member

Choose a reason for hiding this comment

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

Double negatives are hard to understand, so when it's possible to rewrite an if/else to eliminate them, I tend to do that. Mercifully, we now have String#startsWith. I think this is a bit clearer that way.

if (version.startsWith('v') || ignoredVersionPatterns.test(version)) {
    return version;
} else {
    return `v${version}`;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, I should have been more clever than just copy pasting the leftovers of the old function. ^^

const first = version[0];
if (first !== 'v' && !ignoredVersionPatterns.test(version)) {
return 'v' + version;
} else {
if (version.startsWith('v') || ignoredVersionPatterns.test(version)) {
return version;
} else {
return `v${version}`;
}
}

Expand Down