-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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: strict typing for audit requested artifacts #9946
Conversation
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 like the function approach, seems like we could put this onto Audit as .artfiacts()
, still have it accept an array and do one massive replace
requiredArtifacts: Audit.artifacts([ ]),
@patrickhulce would need to do |
@patrickhulce this shows how to pull |
I'm happy with this:
see |
}; | ||
} | ||
|
||
static get requiredArtifacts() { |
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.
Could define this in the Axe audit base class, instead of in each axe audit. sg?
/** | ||
* @param {LH.Artifacts} artifacts | ||
* @param {LH.Artifacts.Select<typeof module.exports>} artifacts |
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.
this works! And made the global find & replace feasible.
@patrickhulce would you be the reviewer for this? It's mostly 140 mechanical changes :) |
oof, mostly except for the part where we decide to alter our requiredArtifacts properties to getters forever ;) I'm happy to review this change in its entirety if we get cursory buy-in to this new approach from the entire team first. I'm fine with it, personally, but also somewhat skeptical of its usefulness compared to the noise. Is it nice to have it typed? Ya, but generally getting this wrong results in colossal obvious failure when missed, so 🤷♂ |
summoning @GoogleChrome/lighthouse-hackers , OK with
? |
Let's discuss in Monday eng meeting. |
We pass only the artifacts that an audit declares via
.meta.requiredArtifacts
. However, the audit function takes the entire artifact type (LH.Artifacts
) as a parameter, and assumes you declared things properly. This is a little scary when you consider boolean artifacts, since failure to declare one results in the audit not crashing at runtime, but always acting like it wasfalse
.We could type this fairly easily. It's not as nice as it could be, since there's no direct way to use an array of property names in
Pick<T, K>
without declaring the array as a const, which is not yet supported in JSDoc. So there's duplication in the declaration - one for the type comment and one for the value itself.EDIT: found a good way to remove duplication without loss of typing.
I keep both implementations in the draft for comparison.