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(tsc): add type checking to dbw audits #5069

Merged
merged 2 commits into from
Apr 30, 2018
Merged

core(tsc): add type checking to dbw audits #5069

merged 2 commits into from
Apr 30, 2018

Conversation

brendankenny
Copy link
Member

the only major cleanups are in the no-vulnerable-libraries.js.js (lots of mutations) and event-helpers.js (simplified so that the type checker could follow along).

The golden lhr changes are eliminating the duplicate vulnerability listings (because the original library objects are no longer mutated) and taking out the label entry on the event listeners since it appears to only be set, not read, and it's just a duplicate of the line/col info anyways.

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

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

wfm % nits 💣 💥

lib.detectedLib.url = lib.pkgLink;
lib.detectedLib.type = 'link';
/** @type {Array<{highestSeverity: string, vulnCount: number, detectedLib: LH.Audit.DetailsRendererLinkDetailsJSON}>} */
const vulnerableResults = [];
Copy link
Collaborator

Choose a reason for hiding this comment

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

vulnerabilities? vulnerabilityResults?

Copy link
Member Author

Choose a reason for hiding this comment

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

went with vulnerabilityResults :)

}));
/** @type {Array<{node: LH.Audit.DetailsRendererNodeDetailsJSON}>} */
const items = [];
passwordInputsWithPreventedPaste.forEach(input => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

😢 TS really can't deal with a map + assertion?

Copy link
Member Author

Choose a reason for hiding this comment

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

it loses the type 'node' (it widens to type string) :( The heuristics are wonky on widening like that, but people do want very different things at times (even we would probably usually want string in this case if it weren't for wanting to tell the difference between details types).

It's basically this or put a cast in there in addition to the declared type above, I believe, so this seemed better.

@@ -7,7 +7,7 @@
declare global {
module LH.Audit {
export interface Context {
options: Object; // audit options
options: Record<string, any>; // audit options
Copy link
Collaborator

Choose a reason for hiding this comment

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

what's the difference between Record<K, V> and Object<K, V>

Copy link
Member Author

Choose a reason for hiding this comment

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

what's the difference between Record<K, V> and Object<K, V>

Object<K, V> only works in jsdoc. It's not parameterized in typescript code

Copy link
Member Author

Choose a reason for hiding this comment

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

...we should probably come up with some sort of style rule for this vs {[p: string]: any} vs Object<> on the jsdoc side

@@ -47,7 +47,7 @@ declare global {
debugString?: string;
}

// TODO: placeholder typedefs until Details are typed
// TODO: placeholders typedefs until Details are typed
Copy link
Collaborator

Choose a reason for hiding this comment

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

revert? :)

Copy link
Member Author

Choose a reason for hiding this comment

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

done

summary?: DetailsRendererDetailsSummary;
}

export type DetailsItem = string | number | DetailsRendererNodeDetailsJSON |
Copy link
Collaborator

Choose a reason for hiding this comment

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

DetailsItemMemberChildInfo

Copy link
Member Author

Choose a reason for hiding this comment

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

DetailsItemMemberChildInfo

...Summary

@@ -3941,26 +3904,8 @@
],
"items": [
{
"name": "jQuery",
Copy link
Member

Choose a reason for hiding this comment

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

lgtm on nuking this data. it's pretty low-value anyway

@brendankenny brendankenny merged commit 7c24921 into master Apr 30, 2018
@brendankenny brendankenny deleted the tsdbw branch April 30, 2018 20:09
kdzwinel pushed a commit to kdzwinel/lighthouse that referenced this pull request Aug 16, 2018
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

3 participants