Skip to content

core(canonical): move canonical audit to LinkElements#7080

Merged
brendankenny merged 10 commits into
masterfrom
link_elements_canonical_support
Mar 11, 2019
Merged

core(canonical): move canonical audit to LinkElements#7080
brendankenny merged 10 commits into
masterfrom
link_elements_canonical_support

Conversation

@patrickhulce

Copy link
Copy Markdown
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
Comment thread lighthouse-core/audits/seo/canonical.js Outdated
* @return {Promise<LH.Audit.Product>}
*/
static audit(artifacts, context) {
static async audit(artifacts, context) {

Copy link
Copy Markdown
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
Copy Markdown
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!

@brendankenny brendankenny left a comment

Copy link
Copy Markdown
Contributor

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

Comment thread lighthouse-core/lib/dependency-graph/simulator/network-analyzer.js
Comment thread types/artifacts.d.ts
Comment thread lighthouse-core/gather/gatherers/link-elements.js
Comment thread lighthouse-core/gather/gatherers/link-elements.js Outdated
*/
function normalizeUrlOrNull(url, finalUrl) {
try {
return new URL(url, finalUrl).href;

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
Contributor

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

Comment thread lighthouse-core/audits/seo/canonical.js
Comment thread lighthouse-core/audits/seo/canonical.js
}
}

return {uniqueCanonicalURLs, hreflangURLs, invalidCanonicalLink, relativeCanonicallink};

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
Contributor

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

Comment thread lighthouse-core/audits/seo/canonical.js Outdated
Comment thread lighthouse-core/test/audits/seo/canonical-test.js

@brendankenny brendankenny left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

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

Comment thread types/artifacts.d.ts
as: string
/** The `crossOrigin` attribute of the link */
crossOrigin: 'anonymous'|'use-credentials'|null
/** Where the link was found, either in the DOM or in the headers of the main document */

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

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
Copy Markdown
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