-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Number support for version color formatter #1615
Conversation
lib/color-formatters.js
Outdated
@@ -7,11 +7,13 @@ | |||
const moment = require('moment'); | |||
|
|||
function version(version) { | |||
let first = version[0]; | |||
// The passed in version may or may not already be a string. See #1599. | |||
const stringifiedVersion = '' + version; |
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.
This works! Another way I'm also fine with is like this:
version = '' + version;
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 code a lot in Java and we tend to avoid this, but I'm happy to use it here! 😄
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.
Yea… it's a matter of style. The language treats them as let
variables, though if you want you can tell eslint not to let you reassign them. The advantage of reassigning them is that it prevents you from accidentally using the unmodified value, and I think reassigning them once at the top of the function is not so confusing. Though I could be convinced otherwise. 😁
lib/color-formatters.js
Outdated
@@ -7,11 +7,13 @@ | |||
const moment = require('moment'); | |||
|
|||
function version(version) { | |||
let first = version[0]; | |||
// The passed in version may or may not already be a string. See #1599. |
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.
Since this can be inferred from the code itself, and tests will fail if this code is changed (which is really the best thing!) this comment isn't needed.
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.
Nice work, looks good to me!
Side note: on mobile right now so can't check, but does version need to be changed to a string with the updated regex?
@RedSparr0w I thought the same initially, but actually you can't cover edge cases such as floating point numbers smaller than one without the string conversion. 0.1 would show as blue for instance, whereas we should actually treat it as a beta version. |
This pull request is related to discussions in #1599.
Tests to cover cases where the version is provided as a numerical value were added. I thought of several different ways of tackling the implementation and went with one, but a more experienced Javascript reviewer may have some better ideas. 👍