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

Report: group event listener extended info by call site location #960

Merged
merged 2 commits into from
Nov 17, 2016

Conversation

ebidel
Copy link
Contributor

@ebidel ebidel commented Nov 17, 2016

R: @brendankenny

The fix for #959 with a documented explanation of it. Tried to comment the code as much as possible :)

@@ -6,6 +6,7 @@
.http-resource__code {
text-overflow: ellipsis;
overflow: hidden;
white-space: pre-line;
Copy link
Contributor Author

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.

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.

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);
Copy link
Member

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

Copy link
Contributor Author

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);
Copy link
Member

Choose a reason for hiding this comment

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

same as above

Copy link
Contributor Author

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.
Copy link
Member

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

Copy link
Contributor Author

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
Copy link
Member

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?

Copy link
Contributor Author

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});
Copy link
Member

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?

Copy link
Contributor Author

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];
Copy link
Member

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]

Copy link
Contributor Author

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();
Copy link
Member

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?

Copy link
Contributor Author

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.
Copy link
Member

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

Copy link
Contributor Author

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.
Copy link
Member

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.?

Copy link
Contributor Author

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>}
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@ebidel
Copy link
Contributor Author

ebidel commented Nov 17, 2016

PTAL

@brendankenny brendankenny changed the title Fixes #959 Report: group event listener extended info by call site location Nov 17, 2016
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

@brendankenny brendankenny merged commit f04f1c8 into master Nov 17, 2016
andrewrota pushed a commit to andrewrota/lighthouse that referenced this pull request Jan 13, 2017
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.

2 participants