Skip to content

Commit

Permalink
Quick lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Beytoven committed Mar 30, 2020
1 parent 32a5028 commit e05c36f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 50 deletions.
1 change: 0 additions & 1 deletion lighthouse-core/audits/metrics/largest-contentful-paint.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ class LargestContentfulPaint extends Audit {
];

const details = Audit.makeTableDetails(headings, metricNodeData);


return {
score: Audit.computeLogNormalScore(
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/gather/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,7 @@ class Driver {
/**
* @param {number} nodeId
* @param {string} attributeName
* @param {string} attributeValue
* @param {string} attributeValue
*/
async setNodeAttribute(nodeId, attributeName, attributeValue) {
await this.sendCommand('DOM.setAttributeValue', {
Expand Down
99 changes: 51 additions & 48 deletions lighthouse-core/gather/gatherers/trace-nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,61 +13,64 @@ const TraceProcessor = require('../../lib/tracehouse/trace-processor.js');
* @return {LH.Artifacts['TraceNodes']}
*/
function collectTraceNodes() {
/** @type {Array<HTMLElement>} */
// @ts-ignore - put into scope via stringification
const markedElements = getElementsInDocument('[lhtemp]'); // eslint-disable-line no-undef
/** @type {LH.Artifacts['TraceNodes']} */
const traceNodes = [];
/** @type {Array<HTMLElement>} */
// @ts-ignore - put into scope via stringification
const markedElements = getElementsInDocument('[lhtemp]'); // eslint-disable-line no-undef
/** @type {LH.Artifacts['TraceNodes']} */
const traceNodes = [];

for (const element of markedElements) {
traceNodes.push({
type: element.getAttribute('lhtemp') || '',
// @ts-ignore - put into scope via stringification
nodePath: getNodePath(element), // eslint-disable-line no-undef
// @ts-ignore - put into scope via stringification
selector: getNodeSelector(element), // eslint-disable-line no-undef
// @ts-ignore - put into scope via stringification
nodeLabel: getNodeLabel(element), // eslint-disable-line no-undef
// @ts-ignore - put into scope via stringification
snippet: getOuterHTMLSnippet(element), // eslint-disable-line no-undef
});
}
return traceNodes;
for (const element of markedElements) {
traceNodes.push({
type: element.getAttribute('lhtemp') || '',
// @ts-ignore - put into scope via stringification
nodePath: getNodePath(element), // eslint-disable-line no-undef
// @ts-ignore - put into scope via stringification
selector: getNodeSelector(element), // eslint-disable-line no-undef
// @ts-ignore - put into scope via stringification
nodeLabel: getNodeLabel(element), // eslint-disable-line no-undef
// @ts-ignore - put into scope via stringification
snippet: getOuterHTMLSnippet(element), // eslint-disable-line no-undef
});
}
return traceNodes;
}

class TraceNodes extends Gatherer {
/**
* @param {LH.Gatherer.PassContext} passContext
* @param {LH.Gatherer.LoadData} loadData
* @return {Promise<LH.Artifacts['TraceNodes']>}
*/
async afterPass(passContext, loadData) {
const driver = passContext.driver;
if (!loadData.trace) {
throw new Error('Trace is missing!');
}
const traceOfTab = TraceProcessor.computeTraceOfTab(loadData.trace);
const lcpEvent = traceOfTab.largestContentfulPaintEvt;
/**
* @param {LH.Gatherer.PassContext} passContext
* @param {LH.Gatherer.LoadData} loadData
* @return {Promise<LH.Artifacts['TraceNodes']>}
*/
async afterPass(passContext, loadData) {
const driver = passContext.driver;
if (!loadData.trace) {
throw new Error('Trace is missing!');
}
const traceOfTab = TraceProcessor.computeTraceOfTab(loadData.trace);
const lcpEvent = traceOfTab.largestContentfulPaintEvt;

const backendNodeId = lcpEvent && lcpEvent.args && lcpEvent.args.data && lcpEvent.args.data.nodeId;
if (backendNodeId) {
// The call below is necessary for pushNodesByBackendIdsToFrontend to properly retrieve nodeIds
await driver.sendCommand('DOM.getDocument', {depth: -1, pierce: true});
const translatedIds = await driver.sendCommand('DOM.pushNodesByBackendIdsToFrontend', {backendNodeIds: [backendNodeId]});
driver.setNodeAttribute(translatedIds.nodeIds[0], 'lhtemp', 'lcp');
}
const backendNodeId = lcpEvent && lcpEvent.args &&
lcpEvent.args.data && lcpEvent.args.data.nodeId;
if (backendNodeId) {
// The call below is necessary for pushNodesByBackendIdsToFrontend to properly retrieve nodeIds
await driver.sendCommand('DOM.getDocument', {depth: -1, pierce: true});
const translatedIds = await driver.sendCommand('DOM.pushNodesByBackendIdsToFrontend',
{backendNodeIds: [backendNodeId]});
driver.setNodeAttribute(translatedIds.nodeIds[0], 'lhtemp', 'lcp');
}

const expression = `(() => {
${pageFunctions.getElementsInDocumentString};
${pageFunctions.getNodePathString};
${pageFunctions.getNodeSelectorString};
${pageFunctions.getNodeLabelString};
${pageFunctions.getOuterHTMLSnippetString};
const expression = `(() => {
${pageFunctions.getElementsInDocumentString};
${pageFunctions.getNodePathString};
${pageFunctions.getNodeSelectorString};
${pageFunctions.getNodeLabelString};
${pageFunctions.getOuterHTMLSnippetString};
return (${collectTraceNodes})();
})()`;
return driver.evaluateAsync(expression, {useIsolation: true});
}
return (${collectTraceNodes})();
})()`;

return driver.evaluateAsync(expression, {useIsolation: true});
}
}

module.exports = TraceNodes;

0 comments on commit e05c36f

Please sign in to comment.