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

Fix bug when short_name is not present name is not used for audit #350

Merged

Conversation

wardpeet
Copy link
Collaborator

Fixes #348

@googlebot
Copy link

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!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@wardpeet
Copy link
Collaborator Author

I signed it!

@googlebot
Copy link

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;
Copy link
Contributor

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

Copy link
Collaborator Author

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?

Copy link
Contributor

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

Copy link
Collaborator Author

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

@samccone
Copy link
Contributor

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.
Copy link
Member

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?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will do :)

@wardpeet
Copy link
Collaborator Author

Will have an updated pr later today :)

@wardpeet wardpeet force-pushed the bug/fix-name-without-shortname branch from 66549d6 to 87572c4 Compare May 26, 2016 15:40
@wardpeet
Copy link
Collaborator Author

wardpeet commented May 26, 2016

As promised :)
One thing i don't like is that I duplicate _getManifestShortName & _getManifestName. I rather put them in src/lib/util/manifest-helpers.js (or something) and just export those functions.

Another option is appending a getter function to the manifest object manifest.getValue('short_name')

@paulirish
Copy link
Member

It definitely gets pretty low signal:noise with this breakout.

I have a PR against ward's fork that tries out lodash.get.
It gives some nice brevity and i'm looking forward to using it elsewhere in the project.

wardpeet#1

@wardpeet
Copy link
Collaborator Author

Looks better, didn't knew i could use this resolvedName = shortNameValue || nameValue; because of @samccone comment on &&. Merging as we speak

@googlebot
Copy link

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.

@wardpeet wardpeet force-pushed the bug/fix-name-without-shortname branch from 45ced7b to b8af8fe Compare May 29, 2016 12:45
@wardpeet
Copy link
Collaborator Author

mmh somehow i get rejected but when i run it locally i have no issues.

@samccone
Copy link
Contributor

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",
Copy link
Contributor

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

Copy link
Member

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. :/

@samccone
Copy link
Contributor

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
Copy link
Member

Choose a reason for hiding this comment

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

:)

@wardpeet
Copy link
Collaborator Author

ok i got lost :p so should i go back to the helpers i created or just do the hasShortName = !!(manifest.short_name.value || manifest.name.value);

@brendankenny
Copy link
Member

@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.

@samccone
Copy link
Contributor

👍 sounds good @brendankenny

@paulirish
Copy link
Member

Unless others disagree, I believe my suggestion above is the way to go

👍

@wardpeet wardpeet force-pushed the bug/fix-name-without-shortname branch from b8af8fe to 348d5ef Compare June 2, 2016 18:50
@googlebot
Copy link

CLAs look good, thanks!

@wardpeet wardpeet force-pushed the bug/fix-name-without-shortname branch from 348d5ef to b741197 Compare June 2, 2016 19:19
@wardpeet
Copy link
Collaborator Author

wardpeet commented Jun 2, 2016

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 :)

@paulirish
Copy link
Member

lgtm. thanks for being a trooper on this, @wardpeet. we feel really bad we jerked you around. :/

@paulirish paulirish added the +1 label Jun 2, 2016
@wardpeet wardpeet force-pushed the bug/fix-name-without-shortname branch from b741197 to e3d4c11 Compare June 2, 2016 19:37
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;
Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Collaborator Author

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

@brendankenny
Copy link
Member

one last thing and then LGTM too

@wardpeet wardpeet force-pushed the bug/fix-name-without-shortname branch from e3d4c11 to 3c873c0 Compare June 2, 2016 21:13
@wardpeet
Copy link
Collaborator Author

wardpeet commented Jun 2, 2016

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
Copy link
Member

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

@wardpeet wardpeet force-pushed the bug/fix-name-without-shortname branch from 3c873c0 to 4187668 Compare June 2, 2016 21:57
@brendankenny
Copy link
Member

LGTM! Thanks for your patience

@brendankenny brendankenny added the +2 label Jun 2, 2016
@brendankenny brendankenny merged commit 644d55a into GoogleChrome:master Jun 2, 2016
@paullewis
Copy link
Contributor

Thanks from me, too... This was one lengthy PR tennis match!

@wardpeet
Copy link
Collaborator Author

wardpeet commented Jun 3, 2016

No worries ;) glad I could help. And hey now I can say I got a PR from @paulirish :p

@wardpeet wardpeet deleted the bug/fix-name-without-shortname branch April 29, 2017 10:18
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.

None yet

6 participants