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

core(displayvalue): change displayValue to be string only #6767

Merged
merged 12 commits into from
Dec 18, 2018

Conversation

exterkamp
Copy link
Member

@exterkamp exterkamp commented Dec 10, 2018

Summary
Convert displayValue to be a string value only instead of [string, <string | number> ] for consistency. Also converted the only 2 audits that still use the old displayValue array format.

  • font-size
  • load-fast-enough-for-pwa

Related Issues/PRs
fixes: #6200

@exterkamp exterkamp changed the title core(displayValue): change displayValue to be string only core(displayvalue): change displayValue to be string only Dec 10, 2018
Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

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

nice! always down for some more 🇩🇪 🇨🇳 🇧🇷 and proto friendship

lighthouse-core/audits/seo/font-size.js Outdated Show resolved Hide resolved
lighthouse-core/lib/i18n/i18n.js Outdated Show resolved Hide resolved
@@ -265,8 +279,9 @@ class FontSize extends Audit {
});
}

const percentFormatted = (percentageOfPassingText / 100).toFixed(4);
Copy link
Collaborator

Choose a reason for hiding this comment

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

wait hang on, triple sorry for this I seem to be all over the place with this PR 😭

isn't this already going to be a string with 4 sigFigs before it ever gets to the i18n bit so all of what I've said is going to be moot anyhow?

Copy link
Member Author

Choose a reason for hiding this comment

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

So I make it guaranteed to be 4 digits only, but not necessarily 4 sigfigs e.g. 0.0318 -> 3.18% which is 2 decimal places after the . but is only 3 sig figs. So I guess maybe I should rename percent4sigfig to percent2trailing because it will clip off any fraction with more than 2 decimal places. Technically I don't think I need to format this to 4 digits here since Intl will do that with the 4 max digits anyway.

Copy link
Collaborator

Choose a reason for hiding this comment

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

OK how's about this.

The (percentageOfPassingText / 100).toFixed(4) is super clear to me. Will i18n lib avoid a custom formatting option entirely if we can just pass that directly as just 'percent' styled?

Copy link
Member Author

Choose a reason for hiding this comment

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

using style:percent will convert 0.XXYY -> XX%
docs

The minimum number of fraction digits to use. Possible values are from 0 to 20; the default for plain number and percent formatting is 0;
the default for percent formatting is the larger of minimumFractionDigits and 0.

So the default is 0 fractional digits. Which is why I set it to four* two to make it force have two trailing digits. In order to have more digits we have to send it those additional options.

*I was mistaken, it applies this # of digits after the x100, so 2 is the actual final number of trailing digits.

@exterkamp
Copy link
Member Author

Okay I think the naming conventions are in a good spot. decimalProportion for the ICU message var replacement name and extendedPercent for the two digit percent override.

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

arg, sorry, wrote these yesterday but missed the submit

'visitors to “pinch to zoom” in order to read. Strive to have >60% of page text ≥12px. ' +
'[Learn more](https://developers.google.com/web/tools/lighthouse/audits/font-sizes).',
/** [ICU Syntax] Label for the audit identifying font sizes that are too small. */
displayValue: '{decimalProportion, number, extendedPercent} legible text',
Copy link
Member

Choose a reason for hiding this comment

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

remember on updating these in the console we'll have to add a special extractor/replacer for extendedPercent like we've added for bytes and milliseconds

lighthouse-core/audits/load-fast-enough-for-pwa.js Outdated Show resolved Hide resolved
lighthouse-core/audits/load-fast-enough-for-pwa.js Outdated Show resolved Hide resolved
lighthouse-core/lib/i18n/i18n.js Show resolved Hide resolved
/** @type {LH.Audit.DisplayValue} */
const displayValue = ['%.1d% legible text', percentageOfPassingText];
const displayValue = str_(UIStrings.displayValue, {decimalProportion});
Copy link
Member

Choose a reason for hiding this comment

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

it's weird that we have displayValue and explanation here, they're subtly different but mostly the same, and explanation isn't localized. I don't see any localized explanations in any other audit, though.

(Really seems like there should only be an explanation here if the disclaimer is defined...otherwise it's just a repeat of the displayValue. I recognize this is all out of scope, though :)

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

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

I think I'm there, just two nits!

lighthouse-core/audits/load-fast-enough-for-pwa.js Outdated Show resolved Hide resolved
lighthouse-core/audits/seo/font-size.js Outdated Show resolved Hide resolved
@@ -71,6 +71,11 @@ const formats = {
minimumFractionDigits: 1,
maximumFractionDigits: 1,
},
extendedPercent: {
// Force allow up to two digits after decimal place in percentages. (Intl.NumberFormat options)
maximumFractionDigits: 2,
Copy link
Collaborator

Choose a reason for hiding this comment

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

this makes way more sense :)

@@ -76,4 +76,47 @@ describe('i18n', () => {
expect(i18n.lookupLocale('jk-Latn-DE-1996-a-ext-x-phonebk-i-klingon')).toEqual('en');
});
});

describe('#_formatIcuMessage', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice! great tests!

@paulirish paulirish added the 4.0 label Dec 18, 2018
@brendankenny brendankenny merged commit 51d2047 into master Dec 18, 2018
@brendankenny brendankenny deleted the display-value-string branch December 18, 2018 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Audit.Result.displayValue should always be a string
4 participants