-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Fix bug when short_name is not present name is not used for audit #350
Fix bug when short_name is not present name is not used for audit #350
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
I signed it! |
CLAs look good, thanks! |
@@ -50,14 +50,17 @@ class ManifestShortNameLength extends Audit { | |||
let debugString; | |||
const manifest = artifacts.manifest.value; | |||
const suggestedLength = 12; | |||
const shortNameValue = manifest && manifest.short_name && manifest.short_name.value; |
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.
can we add helper fns here instead of depending on the && last value behavior in JS
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.
would it be ok to use Conditional (ternary) Operator?
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.
yep :) I still like just a function or something but a ternary is nicer than an && chain
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.
will make functions :) will be more readable indeed
I like what is going on here, thanks @wardpeet :) Just a few comments ... Thanks! |
|
||
if (manifest && manifest.short_name && manifest.short_name.value) { | ||
if (manifestValue) { | ||
// Historically, Chrome recommended 12 chars as the maximum length to prevent truncation. |
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.
Can you add a comment here that explains that name is used if short_name not present (hopefully with a link to the docs/source on that?)
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.
Will do :)
Will have an updated pr later today :) |
66549d6
to
87572c4
Compare
As promised :) Another option is appending a getter function to the manifest object manifest.getValue('short_name') |
It definitely gets pretty low signal:noise with this breakout. I have a PR against ward's fork that tries out lodash.get. |
Looks better, didn't knew i could use this |
We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm. |
45ced7b
to
b8af8fe
Compare
mmh somehow i get rejected but when i run it locally i have no issues. |
Fixes #350 also |
@@ -38,6 +38,7 @@ | |||
"gl-matrix": "2.3.2", | |||
"handlebars": "^4.0.5", | |||
"jszip": "2.6.0", | |||
"lodash.get": "^4.3.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 would prefer not adding a new dep and just using the previous approach for now. We can tackle this cleanup after
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 would prefer not adding a new dep and just using the previous approach for now.
This was my doing. The fix was grossly verbose without it. :/
Hey @wardpeet thanks for the PR!!! 🍝 The failure is due to the closure compiler not knowing what _get is. For now as I said in the codereview let's just drop the new dependency (we can tackle that cleanup after we land this) Thanks again for the PR, looking forward to landing this one! |
@@ -49,8 +50,11 @@ class ManifestShortName extends Audit { | |||
let hasShortName = false; | |||
const manifest = artifacts.manifest.value; | |||
|
|||
if (manifest && manifest.short_name) { | |||
hasShortName = (!!manifest.short_name.value); | |||
// putting a comment to test travis again |
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 got lost :p so should i go back to the helpers i created or just do the |
@wardpeet sorry, nothing like reviewers disagreeing with each other to make everything crystal clear :) Unless others disagree, I believe my suggestion above is the way to go. It's not verbose, as @paulirish wanted to avoid, and it doesn't introduce a new dependency, as @samccone wanted to avoid. It's also correct for handling all the possible types the manifest parser could hand back, so you'll have covered all your bases there as well. |
👍 sounds good @brendankenny |
👍 |
b8af8fe
to
348d5ef
Compare
CLAs look good, thanks! |
348d5ef
to
b741197
Compare
I used @brendankenny suggestion and it looks like it works now. I'm fixing some tests I deleted which I thought I didn't needed but i do :) |
lgtm. thanks for being a trooper on this, @wardpeet. we feel really bad we jerked you around. :/ |
b741197
to
e3d4c11
Compare
isShortNameShortEnough = (manifest.short_name.value.length <= suggestedLength); | ||
// https://developer.chrome.com/apps/manifest/name#short_name | ||
let manifestValue = manifest.short_name.value || manifest.name.value || ''; | ||
isShortNameShortEnough = manifestValue && manifestValue.length <= suggestedLength; |
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.
👍
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.
@paulirish no problem :) Glad I could be a part of the discussion :p
one last thing and then LGTM too |
e3d4c11
to
3c873c0
Compare
And it's added 👍 |
it('fails when a manifest contains no short_name and no name', () => { | ||
const inputs = JSON.stringify({ | ||
name: null, | ||
short_name: null |
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.
should live in the short-name.js
test since this isn't really testing name length
3c873c0
to
4187668
Compare
LGTM! Thanks for your patience |
Thanks from me, too... This was one lengthy PR tennis match! |
No worries ;) glad I could help. And hey now I can say I got a PR from @paulirish :p |
Fixes #348