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(canonical): move canonical audit to LinkElements #7080

Merged
merged 10 commits into from
Mar 11, 2019

Conversation

patrickhulce
Copy link
Collaborator

Summary
More artifact improvements. This moves us off the Canonical artifact and one step closer to LinkElements being the canonical (😆) artifact for links.

I was going to try to do it in one swoop, but updating just this audit was already getting to be a very large change.

Related Issues/PRs
#6747

@paulirish paulirish mentioned this pull request Jan 28, 2019
6 tasks
@@ -75,102 +39,102 @@ class Canonical extends Audit {
* @param {LH.Audit.Context} context
* @return {Promise<LH.Audit.Product>}
*/
static audit(artifacts, context) {
static async audit(artifacts, context) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

perhaps you could split up this function in a few sub functions to make it more readable? A lot of things are going on it seems.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah good call @wardpeet!

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.

looking pretty sweet, mostly just clean up stuff

types/artifacts.d.ts Show resolved Hide resolved
lighthouse-core/gather/gatherers/link-elements.js Outdated Show resolved Hide resolved
*/
function normalizeUrlOrNull(url, finalUrl) {
try {
return new URL(url, finalUrl).href;
Copy link
Member

Choose a reason for hiding this comment

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

is this something that we should be calling to anyone's attention? How do these arise in practice? (just typos or something else?)

And why not do this in the getLinkElementsInDOM case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

accessing the .href of a link from dom already does the normalization for us

we do call attention to these cases when it matters in the audits themselves, i.e. there was an hrefRaw but no href indicates there was an error in parsing the URL

Copy link
Member

Choose a reason for hiding this comment

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

we do call attention to these cases when it matters in the audits themselves, i.e. there was an hrefRaw but no href indicates there was an error in parsing the URL

I was hoping we could do more to make it less tricky to get right for any audits using the artifact (e.g. boolean props for the different invalid permutations rather than making sure to check both href and hrefRaw), but I don't have a good suggestion, so let's wait for if it's ever an issue :)

lighthouse-core/audits/seo/canonical.js Show resolved Hide resolved
lighthouse-core/audits/seo/canonical.js Show resolved Hide resolved
}
}

return {uniqueCanonicalURLs, hreflangURLs, invalidCanonicalLink, relativeCanonicallink};
Copy link
Member

Choose a reason for hiding this comment

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

why are some of these plural and some are singular? :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

short: parity and I'm only willing to do so much cleanup for an unrelated goal :P

Copy link
Member

Choose a reason for hiding this comment

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

short: parity and I'm only willing to do so much cleanup for an unrelated goal :P

haha, very fair :)

lighthouse-core/audits/seo/canonical.js Outdated Show resolved Hide resolved
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!

*/
function normalizeUrlOrNull(url, finalUrl) {
try {
return new URL(url, finalUrl).href;
Copy link
Member

Choose a reason for hiding this comment

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

we do call attention to these cases when it matters in the audits themselves, i.e. there was an hrefRaw but no href indicates there was an error in parsing the URL

I was hoping we could do more to make it less tricky to get right for any audits using the artifact (e.g. boolean props for the different invalid permutations rather than making sure to check both href and hrefRaw), but I don't have a good suggestion, so let's wait for if it's ever an issue :)

crossOrigin: 'anonymous'|'use-credentials'|null
/** Where the link was found, either in the DOM or in the headers of the main document */
Copy link
Member

Choose a reason for hiding this comment

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

worth linking to https://html.spec.whatwg.org/multipage/links.html#body-ok (chart of which types of link elements are allowed in the body)?

(I find the ridiculously esoteric "body-ok" to be hilarious)

Copy link
Member

Choose a reason for hiding this comment

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

Actually, should we filter (in a future PR) based on body-ok and not have them appear in the artifact if they aren't ok?

Only issue is that this chart isn't exhaustive and other specs are allowed to define body-okness for their own keywords.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ooooooooh that's what you were talking about. I assumed it was a typo lol 😆 Yeah I'll add the link.

I think we should probably leave them in the artifact so some point in the future we could have an audit that flags trying to use non body-ok, but flagging them

@brendankenny brendankenny merged commit e5cfb37 into master Mar 11, 2019
@brendankenny brendankenny deleted the link_elements_canonical_support branch March 11, 2019 23:33
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.

3 participants