-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
1723 Adopt to locale string for all our number output #2553
1723 Adopt to locale string for all our number output #2553
Conversation
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 this consistency improvement @arturmiz, great first contribution!
@@ -34,7 +35,7 @@ class UnusedBytes extends Audit { | |||
* @return {string} | |||
*/ | |||
static bytesToKbString(bytes) { | |||
return Math.round(bytes / KB_IN_BYTES).toLocaleString() + ' KB'; | |||
return `${Util.formateBytesToKB(bytes)} KB`; |
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.
you inherited this typo but do you want to update it to formatBytesToKB
while you're in 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.
Ok, I'll add the 'KB' inside this helper, similar how it's done now for milliseconds. One question though as formatMilliseconds
helper looks:
return `${coarseTime.toLocaleString()}${NBSP}ms`;
Which (at least on my machine) renders to sth like 1,000ms so there is no space between number and ms
. Should I done it the same way or just ad KB
at the end for formatBytestoKB
?
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.
let's keep the nonbreaking space for now, cc: @paulirish for the final decision, but it's supposed to be a happy medium between a full space and no-space on most machines
@@ -54,7 +55,7 @@ class UnusedBytes extends Audit { | |||
* @return {string} | |||
*/ | |||
static bytesToMsString(bytes, networkThroughput) { | |||
return (Math.round(bytes / networkThroughput * 100) * 10).toLocaleString() + 'ms'; | |||
return Util.formatMilliseconds( Math.round(bytes / networkThroughput * 100) * 10, 1); |
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 think you could reduce this to just formatMilliseconds(bytes / networkThroughout * 1000)
return { | ||
url: item.tag.url, | ||
totalKb: `${Math.round(item.transferSize / 1024)} KB`, | ||
totalMs: `${Math.round((item.endTime - startTime) * 1000)}ms` | ||
totalKb: `${transferSizeKbs} KB`, |
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.
could do this inline and remove the Math.round
for just formatBytesToKB(item.transferSize, 0)
@@ -35,15 +35,16 @@ class Util { | |||
/** | |||
* Format number. | |||
* @param {number} number | |||
* @param {number} decimalPlaces Number of decimal places to include. Defaults to 1. |
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.
nit: number=
since it's optional
} | ||
|
||
/** | ||
* @param {number} size | ||
* @param {number=} decimalPlaces Number of decimal places to include. Defaults to 2. | ||
* @param {number} decimalPlaces Number of decimal places to include. Defaults to 2. |
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.
keep the =
here since it's still optional
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.
Oh, my bad, I thought it's a typo that's why I removed it... 😀
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.
haha, no worries! here's a quick guide to the closure types in case you want to decipher what all these comments mean :)
@@ -52,7 +53,7 @@ class Util { | |||
|
|||
/** | |||
* @param {number} ms | |||
* @param {number=} granularity Controls how coarse the displayed value is, defaults to 10 |
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.
ditto
Codecov Report
@@ Coverage Diff @@
## master #2553 +/- ##
==========================================
+ Coverage 84.52% 85.26% +0.74%
==========================================
Files 169 178 +9
Lines 5614 5835 +221
Branches 774 815 +41
==========================================
+ Hits 4745 4975 +230
+ Misses 855 833 -22
- Partials 14 27 +13
Continue to review full report at Codecov.
|
cc @stevepeak btw it came back ⬆️ ⬆️ ⬆️ ⬆️ |
@arturmiz are you ready for a re-review? :) |
@paulirish looks like the yaml does not exist on this specific commit: https://github.com/arturmiz/lighthouse/blob/329d5a7ab1783f14997fed7e6618c5ac672796ae/.codecov.yml 404's. Codecov always uses the commit's yaml being tested. Thoughts on how to improve this? |
@patrickhulce, anytime 😉 |
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.
looks good to me % nits, nicely done!
@@ -54,7 +55,7 @@ class UnusedBytes extends Audit { | |||
* @return {string} | |||
*/ | |||
static bytesToMsString(bytes, networkThroughput) { | |||
return (Math.round(bytes / networkThroughput * 100) * 10).toLocaleString() + 'ms'; | |||
return Util.formatMilliseconds(bytes / networkThroughput * 1000, 1); |
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.
let's keep the granularity at the default 10
here instead of 1
@@ -34,7 +35,7 @@ class UnusedBytes extends Audit { | |||
* @return {string} | |||
*/ | |||
static bytesToKbString(bytes) { | |||
return Math.round(bytes / KB_IN_BYTES).toLocaleString() + ' KB'; | |||
return Util.formatBytesToKB(bytes); |
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.
let's keep the round effect with 0 decimal places e.g. formatBytesToKB(bytes, 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.
Hm, are you sure? With 0
decimal places in some cases it will lead to misleading results e.g. instead of having 0.5 KB (50%) it will show 0 KB (50%).
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.
most of these audits should be ignoring savings less than 2-4 KB have you seen some that don't? we should fix those separately :)
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.
Ok, is it filtered on the audit level or somewhere further? If on audit level, then I can't see any such condition in this one so it returns everything. I found this example using some fake data in a unit test. I'll add it so you'll know during future fixing that this kind of result shouldn't be there.
awesome thanks again @arturmiz! 🎉 |
Thanks for accepting my PR @patrickhulce ! Happy to help! 😄 |
Thanks for taking on this bug, @arturmiz. We really appreciate it. 😁 |
fixes #1723
Hi, I have come across this beginner issue, did some debugging how it can be fixed and I noticed that there are already some changes introduced with #2295. I followed the pattern and used this utility helper across audits which I think required use of it. Waiting for your feedback, thanks! 😅