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: fix NodeDetails type mismatch #11752

Merged
merged 2 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lighthouse-core/audits/accessibility/axe-audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@ class AxeAudit extends Audit {
let items = [];
if (rule && rule.nodes) {
items = rule.nodes.map(node => ({
node: /** @type {LH.Audit.Details.NodeValue} */ ({
type: 'node',
node: {
type: /** @type {'node'} */ ('node'),
lhId: node.lhId,
selector: node.selector,
path: node.devtoolsNodePath,
snippet: node.snippet,
boundingRect: node.boundingRect,
explanation: node.failureSummary,
nodeLabel: node.nodeLabel,
}),
},
}));
}

Expand Down
6 changes: 3 additions & 3 deletions lighthouse-core/audits/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,11 @@ class AutocompleteAudit extends Audit {
continue;
}
failingFormsData.push({
node: /** @type {LH.Audit.Details.NodeValue} */ ({
type: 'node',
node: {
type: /** @type {'node'} */ ('node'),
snippet: input.snippet,
nodeLabel: input.nodeLabel,
}),
},
suggestion: suggestion,
current: input.autocomplete.attribute,
});
Expand Down
12 changes: 6 additions & 6 deletions lighthouse-core/audits/dobetterweb/dom-size.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,24 +98,24 @@ class DOMSize extends Audit {
value: stats.totalBodyElements,
},
{
node: /** @type {LH.Audit.Details.NodeValue} */ ({
type: 'node',
node: {
type: /** @type {'node'} */ ('node'),
path: stats.depth.devtoolsNodePath,
snippet: stats.depth.snippet,
selector: stats.depth.selector,
nodeLabel: stats.depth.nodeLabel,
}),
},
statistic: str_(UIStrings.statisticDOMDepth),
value: stats.depth.max,
},
{
node: /** @type {LH.Audit.Details.NodeValue} */ ({
type: 'node',
node: {
type: /** @type {'node'} */ ('node'),
path: stats.width.devtoolsNodePath,
snippet: stats.width.snippet,
selector: stats.width.selector,
nodeLabel: stats.width.nodeLabel,
}),
},
statistic: str_(UIStrings.statisticDOMWidth),
value: stats.width.max,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ class ExternalAnchorsUseRelNoopenerAudit extends Audit {
})
.map(anchor => {
return {
node: /** @type {LH.Audit.Details.NodeValue} */ ({
type: 'node',
node: {
type: /** @type {'node'} */ ('node'),
path: anchor.devtoolsNodePath || '',
selector: anchor.selector || '',
nodeLabel: anchor.nodeLabel || '',
snippet: anchor.snippet || '',
}),
},
href: anchor.href || 'Unknown',
target: anchor.target || '',
rel: anchor.rel || '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ class PasswordInputsCanBePastedIntoAudit extends Audit {
const items = [];
passwordInputsWithPreventedPaste.forEach(input => {
items.push({
node: /** @type {LH.Audit.Details.NodeValue} */ ({
type: 'node',
node: {
type: /** @type {'node'} */ ('node'),
snippet: input.snippet,
path: input.devtoolsNodePath,
}),
},
});
});

Expand Down
6 changes: 3 additions & 3 deletions lighthouse-core/audits/largest-contentful-paint-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ class LargestContentfulPaintElement extends Audit {
const lcpElementDetails = [];
if (lcpElement) {
lcpElementDetails.push({
node: /** @type {LH.Audit.Details.NodeValue} */ ({
type: 'node',
node: {
type: /** @type {'node'} */ ('node'),
lhId: lcpElement.lhId,
path: lcpElement.devtoolsNodePath,
selector: lcpElement.selector,
nodeLabel: lcpElement.nodeLabel,
snippet: lcpElement.snippet,
boundingRect: lcpElement.boundingRect,
}),
},
});
}

Expand Down
6 changes: 3 additions & 3 deletions lighthouse-core/audits/layout-shift-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ class LayoutShiftElements extends Audit {

const clsElementData = clsElements.map(element => {
return {
node: /** @type {LH.Audit.Details.NodeValue} */ ({
type: 'node',
node: {
type: /** @type {'node'} */ ('node'),
lhId: element.lhId,
path: element.devtoolsNodePath,
selector: element.selector,
nodeLabel: element.nodeLabel,
snippet: element.snippet,
boundingRect: element.boundingRect,
}),
},
score: element.score,
};
});
Expand Down
6 changes: 3 additions & 3 deletions lighthouse-core/audits/unsized-images.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ class UnsizedImages extends Audit {
const url = URL.elideDataURI(image.src);
unsizedImages.push({
url,
node: /** @type {LH.Audit.Details.NodeValue} */ ({
type: 'node',
node: {
type: /** @type {'node'} */ ('node'),
path: image.devtoolsNodePath,
selector: image.selector,
nodeLabel: image.nodeLabel,
snippet: image.snippet,
}),
},
});
}

Expand Down
1 change: 0 additions & 1 deletion lighthouse-core/gather/gatherers/link-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ class LinkElements extends Gatherer {
devtoolsNodePath: '',
selector: '',
nodeLabel: '',
boundingRect: null,
snippet: '',
});
}
Expand Down
3 changes: 1 addition & 2 deletions lighthouse-core/gather/gatherers/script-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function collectAllScriptElements() {
id: script.id || null,
async: script.async,
defer: script.defer,
source: /** @type {'head'|'body'} */ (script.closest('head') ? 'head' : 'body'),
Copy link
Member Author

Choose a reason for hiding this comment

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

this cast does nothing because the untyped ...getNodeDetails() below is spreading ...any which just spreads into the whole object being any :)

source: script.closest('head') ? 'head' : 'body',
// @ts-expect-error - getNodeDetails put into scope via stringification
...getNodeDetails(script),
content: script.src ? null : script.text,
Expand Down Expand Up @@ -111,7 +111,6 @@ class ScriptElements extends Gatherer {
snippet: '',
selector: '',
nodeLabel: '',
boundingRect: null,
type: null,
src: record.url,
id: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ describe('Link Elements gatherer', () => {
devtoolsNodePath: '',
nodeLabel: '',
snippet: '',
boundingRect: null,
selector: '',
...overrides,
};
Expand Down
2 changes: 1 addition & 1 deletion types/artifacts.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ declare global {
lhId?: string,
devtoolsNodePath: string,
selector: string,
boundingRect: Rect | null,
boundingRect?: Rect,
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the functional change to the PR. In practice it shouldn't be observable because I believe null could only ever come from link-elements and script-elements and we wouldn't have been trying to put their boundingRects in the LHR in the first place, but you never know where some code is checking against undefined instead of falsiness or something.

snippet: string,
nodeLabel: string,
}
Expand Down