-
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
Report: group event listener extended info by call site location #960
Conversation
@@ -6,6 +6,7 @@ | |||
.http-resource__code { | |||
text-overflow: ellipsis; | |||
overflow: hidden; | |||
white-space: pre-line; |
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 fixes some of the spacing issues on the code snippets. Still not perfect though.
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.
reviewed!
const isMutationEvent = this.MUTATION_EVENTS.indexOf(loc.type) !== -1; | ||
const sameHost = loc.url ? url.parse(loc.url).host === pageHost : true; | ||
return sameHost && isMutationEvent; | ||
}).map(EventHelpers.addFormattedCodeSnippet); | ||
|
||
results = EventHelpers.groupCodeSnippetsByLocation(results); |
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.
maybe just create a new variable (groupedResults
or whatever)?
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.
done
@@ -76,6 +76,8 @@ class PassiveEventsAudit extends Audit { | |||
!mentionsPreventDefault; | |||
}).map(EventHelpers.addFormattedCodeSnippet); | |||
|
|||
results = EventHelpers.groupCodeSnippetsByLocation(results); |
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.
same as above
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.
done
/** | ||
* Groups event listeners under url/line/col "violation buckets". | ||
* | ||
* @param {!Array<Object>} listeners Results from the event listener gatherer. |
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.
Object
is so vague it doesn't really matter, but technically could do {!Array<!Object>}
:)
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.
done
* A copy of the original listener object with the added properties. | ||
*/ | ||
function groupCodeSnippetsByLocation(listeners) { | ||
// The listener gatherer returns a list of (url/line/col) src locations where |
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.
maybe move this comment up (slightly modified) to the function description?
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.
done
const map = new Map(); | ||
listeners.forEach(loc => { | ||
const key = JSON.stringify( | ||
{line: loc.line, col: loc.col, url: loc.url, type: loc.type}); |
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 looks like it will fit on one line?
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.
yea < 100. done
const results = []; | ||
for (const item of map.entries()) { | ||
const lineColUrlObj = JSON.parse(item[0]); | ||
const listenersForLocation = item[1]; |
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.
if you do map.forEach
you get named arguments instead of having to name them with these extra lines and generic item[i]
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.
Solid. Done
// part of the codebase). Instead of showing a repetitive list of | ||
// url/line/col violations, we make each trio a unique bucket and | ||
// display the user's event handlers under each. | ||
const map = new Map(); |
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.
more descriptive variable name. locToListenersMap
or something?
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.
done
* | ||
* @param {!Array<Object>} listeners Results from the event listener gatherer. | ||
* @return {!Array<Object>} | ||
* A copy of the original listener object with the added properties. |
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.
not really a copy of the original object anymore
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.
done
}, ''); | ||
lineColUrlObj.code = codeSnippets; | ||
// All listeners under this bucket have the same line/col. We use the first | ||
// one as the label for all of them. |
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.
maybe We use the first's label as the label for all of them.
?
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.
done
* Groups event listeners under url/line/col "violation buckets". | ||
* | ||
* @param {!Array<Object>} listeners Results from the event listener gatherer. | ||
* @return {!Array<Object>} |
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.
@return {!Array<{line: number, col: number, url: string, type: string, code: string, label: string}>}
? :)
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.
done
PTAL |
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.
👂👂👂➡️🚮 LGTM
R: @brendankenny
The fix for #959 with a documented explanation of it. Tried to comment the code as much as possible :)