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): begin clean up of audit details types #7154

Merged
merged 3 commits into from
Feb 5, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ class Audit {
}

/**
* @param {Array<LH.ResultLite.Audit.ColumnHeading>} headings
* @param {Array<LH.ResultLite.Audit.WastedBytesDetailsItem>|Array<LH.ResultLite.Audit.WastedTimeDetailsItem>} items
* @param {Array<LH.Audit.Details.TableColumnHeading>} headings
* @param {Array<LH.Audit.Details.OpportunityItem>} items
* @param {number} overallSavingsMs
* @param {number=} overallSavingsBytes
* @return {LH.Result.Audit.OpportunityDetails}
* @return {LH.Audit.Details.Opportunity}
*/
static makeOpportunityDetails(headings, items, overallSavingsMs, overallSavingsBytes) {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const WASTED_MS_FOR_SCORE_OF_ZERO = 5000;
/**
* @typedef {object} ByteEfficiencyProduct
* @property {Array<LH.Audit.ByteEfficiencyItem>} items
* @property {LH.Result.Audit.OpportunityDetails['headings']} headings
* @property {LH.Audit.Details.Opportunity['headings']} headings
* @property {string} [displayValue]
* @property {string} [explanation]
* @property {Array<string>} [warnings]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class EfficientAnimatedContent extends ByteEfficiencyAudit {
};
});

/** @type {LH.Result.Audit.OpportunityDetails['headings']} */
/** @type {LH.Audit.Details.Opportunity['headings']} */
const headings = [
{key: 'url', valueType: 'url', label: str_(i18n.UIStrings.columnURL)},
{key: 'totalBytes', valueType: 'bytes', label: str_(i18n.UIStrings.columnSize)},
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/byte-efficiency/offscreen-images.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class OffscreenImages extends ByteEfficiencyAudit {
await TraceOfTab.request(trace, context).then(tot => tot.timestamps.traceEnd));
}

/** @type {LH.Result.Audit.OpportunityDetails['headings']} */
/** @type {LH.Audit.Details.Opportunity['headings']} */
const headings = [
{key: 'url', valueType: 'thumbnail', label: ''},
{key: 'url', valueType: 'url', label: str_(i18n.UIStrings.columnURL)},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class RenderBlockingResources extends Audit {
displayValue = str_(i18n.UIStrings.displayValueMsSavings, {wastedMs});
}

/** @type {LH.Result.Audit.OpportunityDetails['headings']} */
/** @type {LH.Audit.Details.Opportunity['headings']} */
const headings = [
{key: 'url', valueType: 'url', label: str_(i18n.UIStrings.columnURL)},
{key: 'totalBytes', valueType: 'bytes', label: str_(i18n.UIStrings.columnSize)},
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/byte-efficiency/unminified-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class UnminifiedCSS extends ByteEfficiencyAudit {
items.push(result);
}

/** @type {LH.Result.Audit.OpportunityDetails['headings']} */
/** @type {LH.Audit.Details.Opportunity['headings']} */
const headings = [
{key: 'url', valueType: 'url', label: str_(i18n.UIStrings.columnURL)},
{key: 'totalBytes', valueType: 'bytes', label: str_(i18n.UIStrings.columnSize)},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class UnminifiedJavaScript extends ByteEfficiencyAudit {
}
}

/** @type {LH.Result.Audit.OpportunityDetails['headings']} */
/** @type {LH.Audit.Details.Opportunity['headings']} */
const headings = [
{key: 'url', valueType: 'url', label: str_(i18n.UIStrings.columnURL)},
{key: 'totalBytes', valueType: 'bytes', label: str_(i18n.UIStrings.columnSize)},
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/byte-efficiency/unused-css-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class UnusedCSSRules extends ByteEfficiencyAudit {
.map(sheetId => UnusedCSSRules.mapSheetToResult(indexedSheets[sheetId], pageUrl))
.filter(sheet => sheet && sheet.wastedBytes > IGNORE_THRESHOLD_IN_BYTES);

/** @type {LH.Result.Audit.OpportunityDetails['headings']} */
/** @type {LH.Audit.Details.Opportunity['headings']} */
const headings = [
{key: 'url', valueType: 'url', label: str_(i18n.UIStrings.columnURL)},
{key: 'totalBytes', valueType: 'bytes', label: str_(i18n.UIStrings.columnSize)},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class UsesOptimizedImages extends ByteEfficiencyAudit {
});
}

/** @type {LH.Result.Audit.OpportunityDetails['headings']} */
/** @type {LH.Audit.Details.Opportunity['headings']} */
const headings = [
{key: 'url', valueType: 'thumbnail', label: ''},
{key: 'url', valueType: 'url', label: str_(i18n.UIStrings.columnURL)},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class UsesResponsiveImages extends ByteEfficiencyAudit {
const items = Array.from(resultsMap.values())
.filter(item => item.wastedBytes > IGNORE_THRESHOLD_IN_BYTES);

/** @type {LH.Result.Audit.OpportunityDetails['headings']} */
/** @type {LH.Audit.Details.Opportunity['headings']} */
const headings = [
{key: 'url', valueType: 'thumbnail', label: ''},
{key: 'url', valueType: 'url', label: str_(i18n.UIStrings.columnURL)},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class ResponsesAreCompressed extends ByteEfficiencyAudit {
});
});

/** @type {LH.Result.Audit.OpportunityDetails['headings']} */
/** @type {LH.Audit.Details.Opportunity['headings']} */
const headings = [
{key: 'url', valueType: 'url', label: str_(i18n.UIStrings.columnURL)},
{key: 'totalBytes', valueType: 'bytes', label: str_(i18n.UIStrings.columnSize)},
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/byte-efficiency/uses-webp-images.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class UsesWebPImages extends ByteEfficiencyAudit {
});
}

/** @type {LH.Result.Audit.OpportunityDetails['headings']} */
/** @type {LH.Audit.Details.Opportunity['headings']} */
const headings = [
{key: 'url', valueType: 'thumbnail', label: ''},
{key: 'url', valueType: 'url', label: str_(i18n.UIStrings.columnURL)},
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/redirects.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class Redirects extends Audit {
});
}

/** @type {LH.Result.Audit.OpportunityDetails['headings']} */
/** @type {LH.Audit.Details.Opportunity['headings']} */
const headings = [
{key: 'url', valueType: 'url', label: str_(i18n.UIStrings.columnURL)},
{key: 'wastedMs', valueType: 'timespanMs', label: str_(i18n.UIStrings.columnTimeSpent)},
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/time-to-first-byte.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class TTFBMetric extends Audit {
const passed = ttfb < TTFB_THRESHOLD;
const displayValue = str_(UIStrings.displayValue, {timeInMs: ttfb});

/** @type {LH.Result.Audit.OpportunityDetails} */
/** @type {LH.Audit.Details.Opportunity} */
const details = {
type: 'opportunity',
overallSavingsMs: ttfb - TTFB_THRESHOLD,
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/uses-rel-preconnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class UsesRelPreconnectAudit extends Audit {
results = results
.sort((a, b) => b.wastedMs - a.wastedMs);

/** @type {LH.Result.Audit.OpportunityDetails['headings']} */
/** @type {LH.Audit.Details.Opportunity['headings']} */
const headings = [
{key: 'url', valueType: 'url', label: str_(i18n.UIStrings.columnURL)},
{key: 'wastedMs', valueType: 'timespanMs', label: str_(i18n.UIStrings.columnWastedMs)},
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/uses-rel-preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class UsesRelPreloadAudit extends Audit {
.map(preloadURL => str_(UIStrings.crossoriginWarning, {preloadURL}));
}

/** @type {LH.Result.Audit.OpportunityDetails['headings']} */
/** @type {LH.Audit.Details.Opportunity['headings']} */
const headings = [
{key: 'url', valueType: 'url', label: str_(i18n.UIStrings.columnURL)},
{key: 'wastedMs', valueType: 'timespanMs', label: str_(i18n.UIStrings.columnWastedMs)},
Expand Down
12 changes: 2 additions & 10 deletions lighthouse-core/report/html/renderer/crc-details-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class CriticalRequestChainRenderer {
* @param {DocumentFragment} tmpl
* @param {CRCSegment} segment
* @param {Element} elem Parent element.
* @param {CRCDetailsJSON} details
* @param {LH.Audit.Details.CriticalRequestChain} details
*/
static buildTree(dom, tmpl, segment, elem, details) {
elem.appendChild(CriticalRequestChainRenderer.createChainNode(dom, tmpl, segment));
Expand All @@ -161,7 +161,7 @@ class CriticalRequestChainRenderer {
/**
* @param {DOM} dom
* @param {ParentNode} templateContext
* @param {CRCDetailsJSON} details
* @param {LH.Audit.Details.CriticalRequestChain} details
* @return {Element}
*/
static render(dom, templateContext, details) {
Expand Down Expand Up @@ -194,14 +194,6 @@ if (typeof module !== 'undefined' && module.exports) {
self.CriticalRequestChainRenderer = CriticalRequestChainRenderer;
}

/** @typedef {{
type: string,
header: {text: string},
longestChain: {duration: number, length: number, transferSize: number},
chains: LH.Audit.SimpleCriticalRequestNode
}} CRCDetailsJSON
*/

/** @typedef {{
node: LH.Audit.SimpleCriticalRequestNode[string],
isLastChild: boolean,
Expand Down
15 changes: 4 additions & 11 deletions lighthouse-core/report/html/renderer/details-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
/* globals self CriticalRequestChainRenderer Util URL */

/** @typedef {import('./dom.js')} DOM */
/** @typedef {import('./crc-details-renderer.js')} CRCDetailsJSON */
/** @typedef {LH.Result.Audit.OpportunityDetails} OpportunityDetails */
/** @typedef {LH.Audit.Details.Opportunity} OpportunityDetails */

/** @type {Array<string>} */
const URL_PREFIXES = ['http://', 'https://', 'data:'];
Expand Down Expand Up @@ -76,7 +75,7 @@ class DetailsRenderer {
case 'criticalrequestchain':
return CriticalRequestChainRenderer.render(this._dom, this._templateContext,
// @ts-ignore - TODO(bckenny): Fix type hierarchy
/** @type {CRCDetailsJSON} */ (details));
/** @type {LH.Audit.Details.CriticalRequestChain} */ (details));
case 'opportunity':
// @ts-ignore - TODO(bckenny): Fix type hierarchy
return this._renderOpportunityTable(details);
Expand Down Expand Up @@ -289,7 +288,7 @@ class DetailsRenderer {
for (const row of details.items) {
const rowElem = this._dom.createChildOf(tbodyElem, 'tr');
for (const heading of details.headings) {
const key = /** @type {keyof LH.Result.Audit.OpportunityDetailsItem} */ (heading.key);
const key = /** @type {keyof LH.Audit.Details.OpportunityItem} */ (heading.key);
const value = row[key];

if (typeof value === 'undefined' || value === null) {
Expand Down Expand Up @@ -360,7 +359,7 @@ class DetailsRenderer {
}

/**
* @param {FilmstripDetails} details
* @param {LH.Audit.Details.Filmstrip} details
* @return {Element}
*/
_renderFilmstrip(details) {
Expand Down Expand Up @@ -460,9 +459,3 @@ if (typeof module !== 'undefined' && module.exports) {
}} LinkDetailsJSON
*/

/** @typedef {{
type: string,
scale: number,
items: Array<{timing: number, timestamp: number, data: string}>,
}} FilmstripDetails
*/
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
/* globals self, Util, CategoryRenderer */

/** @typedef {import('./dom.js')} DOM */
/** @typedef {import('./details-renderer.js').FilmstripDetails} FilmstripDetails */
/** @typedef {LH.Result.Audit.OpportunityDetails} OpportunityDetails */
/** @typedef {LH.Audit.Details.Opportunity} OpportunityDetails */

class PerformanceCategoryRenderer extends CategoryRenderer {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const superLongURL =
'https://example.com/thisIsASuperLongURLThatWillTriggerFilenameTruncationWhichWeWantToTest.js';
const DETAILS = {
type: 'criticalrequestchain',
header: {type: 'text', text: 'CRC Header'},
Copy link
Member Author

Choose a reason for hiding this comment

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

only executable code change (though in a test). We haven't done anything with a header field in I don't know how long, though, so might as well delete it today :)

chains: {
0: {
request: {
Expand Down
2 changes: 1 addition & 1 deletion types/audit.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ declare global {
granularity?: number;
}

export interface ByteEfficiencyItem extends Result.Audit.OpportunityDetailsItem {
export interface ByteEfficiencyItem extends Audit.Details.OpportunityItem {
url: string;
wastedBytes: number;
totalBytes: number;
Expand Down
41 changes: 1 addition & 40 deletions types/lhr-lite.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,49 +70,10 @@ declare global {
/** An explanation of audit-related issues encountered on the test page. */
explanation?: string;
/** Extra information provided by some types of audits. */
details?: Audit.MetricDetails | Audit.OpportunityDetails;
details?: never;
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm going to start deleting lhr-lite-d.ts since its use didn't pan out, so starting by snipping off everything starting here

/** Error message from any exception thrown while running this audit. */
errorMessage?: string;
}

export module Audit {
export interface MetricDetails {
type: 'metric';
/** The value of the metric expressed in milliseconds. */
timespanMs?: number;
}

export interface OpportunityDetails {
type: 'opportunity';
overallSavingsMs: number
overallSavingsBytes?: number
headings: ColumnHeading[];
items: (WastedBytesDetailsItem | WastedTimeDetailsItem)[];
}

export interface ColumnHeading {
/** The property key name within DetailsItem being described. */
key: string;
/** Readable text label of the field. */
label: string;
// TODO(bckenny): should be just string and let lhr be more specific?
valueType: 'url' | 'timespanMs' | 'bytes' | 'thumbnail';
}

export interface WastedBytesDetailsItem {
url: string;
wastedBytes?: number;
totalBytes?: number;
[p: string]: number | boolean | string | undefined;
}

export interface WastedTimeDetailsItem {
url: string;
wastedMs: number;
totalBytes?: number;
[p: string]: number | boolean | string | undefined;
}
}
}
}
}
Expand Down
14 changes: 0 additions & 14 deletions types/lhr.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,6 @@ declare global {
blockedUrlPatterns: string[];
extraHeaders: Crdp.Network.Headers;
}

export module Audit {
export interface OpportunityDetailsItem {
url: string;
wastedBytes?: number;
totalBytes?: number;
wastedMs?: number;
[p: string]: number | boolean | string | undefined;
}

export interface OpportunityDetails extends ResultLite.Audit.OpportunityDetails {
items: OpportunityDetailsItem[];
}
}
}
}
}
Expand Down