From b066160e4bb99bdeff667f770c12b19f2ec538bc Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Tue, 2 Nov 2021 19:27:14 -0700 Subject: [PATCH] tests(eslint): add export rule (#13282) --- build/build-treemap.js | 2 +- flow-report/.eslintrc.cjs | 2 ++ flow-report/src/common.tsx | 15 +++++++--- flow-report/src/i18n/i18n.tsx | 16 ++++++---- flow-report/src/icons.tsx | 30 +++++++++++++------ flow-report/src/sidebar/sidebar.tsx | 12 ++++++-- flow-report/src/summary/category.tsx | 9 ++++-- flow-report/src/summary/summary.tsx | 12 ++++++-- flow-report/src/util.ts | 30 +++++++++++++------ flow-report/src/wrappers/report-renderer.tsx | 12 ++++++-- flow-report/src/wrappers/report.tsx | 9 ++++-- flow-report/test/setup/env-setup.ts | 2 +- lighthouse-cli/.eslintrc.cjs | 2 ++ lighthouse-core/audits/audit.js | 2 +- lighthouse-core/computed/resource-summary.js | 2 +- lighthouse-core/lib/url-shim.js | 2 +- lighthouse-core/scripts/.eslintrc.cjs | 2 ++ lighthouse-core/scripts/copy-util-commonjs.sh | 3 +- .../scripts/i18n/collect-strings.js | 2 +- lighthouse-core/util-commonjs.js | 17 ++++++----- report/.eslintrc.cjs | 2 ++ report/renderer/crc-details-renderer.js | 29 ++++++++++-------- report/renderer/open-tab.js | 12 ++++++-- report/renderer/util.js | 18 ++++++----- treemap/.eslintrc.cjs | 2 ++ treemap/app/src/util.js | 9 ++++-- viewer/.eslintrc.cjs | 2 ++ viewer/app/src/psi-api.js | 9 ++++-- viewer/test/test-helpers.js | 9 ++++-- 29 files changed, 190 insertions(+), 85 deletions(-) diff --git a/build/build-treemap.js b/build/build-treemap.js index 58e61193ef..1c23bd57f7 100644 --- a/build/build-treemap.js +++ b/build/build-treemap.js @@ -19,7 +19,7 @@ function buildStrings() { const locales = require('../shared/localization/locales.js'); // TODO(esmodules): use dynamic import when build/ is esm. const utilCode = fs.readFileSync(LH_ROOT + '/treemap/app/src/util.js', 'utf-8'); - const {UIStrings} = eval(utilCode.replace(/export /g, '') + '\nmodule.exports = TreemapUtil;'); + const {UIStrings} = eval(utilCode.replace(/export {/g, 'module.exports = {')); const strings = /** @type {Record} */ ({}); for (const [locale, lhlMessages] of Object.entries(locales)) { diff --git a/flow-report/.eslintrc.cjs b/flow-report/.eslintrc.cjs index 127895112b..66b7e06d68 100644 --- a/flow-report/.eslintrc.cjs +++ b/flow-report/.eslintrc.cjs @@ -27,6 +27,8 @@ module.exports = { ], 'newlines-between': 'always', }], + 'import/group-exports': 2, + 'import/exports-last': 2, '@typescript-eslint/type-annotation-spacing': 2, }, overrides: [ diff --git a/flow-report/src/common.tsx b/flow-report/src/common.tsx index 517c9e5295..0590930566 100644 --- a/flow-report/src/common.tsx +++ b/flow-report/src/common.tsx @@ -12,11 +12,11 @@ import {getFilmstripFrames, getScreenDimensions, getFullPageScreenshot} from './ const ANIMATION_FRAME_DURATION_MS = 500; -export const Separator: FunctionComponent = () => { +const Separator: FunctionComponent = () => { return
; }; -export const FlowStepIcon: FunctionComponent<{mode: LH.Result.GatherMode}> = ({mode}) => { +const FlowStepIcon: FunctionComponent<{mode: LH.Result.GatherMode}> = ({mode}) => { return <> { mode === 'navigation' && @@ -30,7 +30,7 @@ export const FlowStepIcon: FunctionComponent<{mode: LH.Result.GatherMode}> = ({m ; }; -export const FlowSegment: FunctionComponent<{mode?: LH.Result.GatherMode}> = ({mode}) => { +const FlowSegment: FunctionComponent<{mode?: LH.Result.GatherMode}> = ({mode}) => { return (
@@ -71,7 +71,7 @@ const FlowStepAnimatedThumbnail: FunctionComponent<{ ); }; -export const FlowStepThumbnail: FunctionComponent<{ +const FlowStepThumbnail: FunctionComponent<{ lhr: LH.Result, width?: number, height?: number, @@ -114,3 +114,10 @@ export const FlowStepThumbnail: FunctionComponent<{ } ; }; + +export { + Separator, + FlowStepIcon, + FlowSegment, + FlowStepThumbnail, +}; diff --git a/flow-report/src/i18n/i18n.tsx b/flow-report/src/i18n/i18n.tsx index a31260deae..996946b1b2 100644 --- a/flow-report/src/i18n/i18n.tsx +++ b/flow-report/src/i18n/i18n.tsx @@ -31,23 +31,23 @@ function useLhrLocale() { }; } -export function useI18n() { +function useI18n() { return useContext(I18nContext); } -export function useLocalizedStrings() { +function useLocalizedStrings() { const i18n = useI18n(); return i18n.strings; } -export function useStringFormatter() { +function useStringFormatter() { const {locale} = useLhrLocale(); return (str: string, values?: Record) => { return formatMessage(str, values, locale); }; } -export const I18nProvider: FunctionComponent = ({children}) => { +const I18nProvider: FunctionComponent = ({children}) => { const {locale, lhrStrings} = useLhrLocale(); const i18n = useMemo(() => { @@ -65,7 +65,6 @@ export const I18nProvider: FunctionComponent = ({children}) => { // Initialize renderer util i18n for strings rendered in wrapped components. // TODO: Don't attach global i18n to `Util`. - // @ts-ignore TS reports as read-only. Util.i18n = i18n; return i18n; @@ -78,4 +77,9 @@ export const I18nProvider: FunctionComponent = ({children}) => { ); }; - +export { + useI18n, + useLocalizedStrings, + useStringFormatter, + I18nProvider, +}; diff --git a/flow-report/src/icons.tsx b/flow-report/src/icons.tsx index c73ed95c5e..8f56bd3da6 100644 --- a/flow-report/src/icons.tsx +++ b/flow-report/src/icons.tsx @@ -8,7 +8,7 @@ import {FunctionComponent} from 'preact'; /* eslint-disable max-len */ -export const SummaryIcon: FunctionComponent = () => { +const SummaryIcon: FunctionComponent = () => { return ( @@ -16,7 +16,7 @@ export const SummaryIcon: FunctionComponent = () => { ); }; -export const NavigationIcon: FunctionComponent = () => { +const NavigationIcon: FunctionComponent = () => { return ( { ); }; -export const TimespanIcon: FunctionComponent = () => { +const TimespanIcon: FunctionComponent = () => { return ( { ); }; -export const SnapshotIcon: FunctionComponent = () => { +const SnapshotIcon: FunctionComponent = () => { return ( { ); }; -export const CloseIcon: FunctionComponent = () => { +const CloseIcon: FunctionComponent = () => { return ( { ); }; -export const EnvIcon: FunctionComponent = () => { +const EnvIcon: FunctionComponent = () => { return ( @@ -104,7 +104,7 @@ export const EnvIcon: FunctionComponent = () => { ); }; -export const CpuIcon: FunctionComponent = () => { +const CpuIcon: FunctionComponent = () => { return ( @@ -112,7 +112,7 @@ export const CpuIcon: FunctionComponent = () => { ); }; -export const HamburgerIcon: FunctionComponent = () => { +const HamburgerIcon: FunctionComponent = () => { return ( @@ -122,10 +122,22 @@ export const HamburgerIcon: FunctionComponent = () => { ); }; -export const InfoIcon: FunctionComponent = () => { +const InfoIcon: FunctionComponent = () => { return ( ); }; + +export { + SummaryIcon, + NavigationIcon, + TimespanIcon, + SnapshotIcon, + CloseIcon, + EnvIcon, + CpuIcon, + HamburgerIcon, + InfoIcon, +}; diff --git a/flow-report/src/sidebar/sidebar.tsx b/flow-report/src/sidebar/sidebar.tsx index 0fcbf13930..d697cf95cc 100644 --- a/flow-report/src/sidebar/sidebar.tsx +++ b/flow-report/src/sidebar/sidebar.tsx @@ -12,7 +12,7 @@ import {CpuIcon, EnvIcon, SummaryIcon} from '../icons'; import {classNames, useHashState, useFlowResult} from '../util'; import {SidebarFlow} from './flow'; -export const SidebarSummary: FunctionComponent = () => { +const SidebarSummary: FunctionComponent = () => { const hashState = useHashState(); const strings = useLocalizedStrings(); @@ -59,7 +59,7 @@ const SidebarRuntimeSettings: FunctionComponent<{settings: LH.ConfigSettings}> = ); }; -export const SidebarHeader: FunctionComponent<{title: string, date: string}> = ({title, date}) => { +const SidebarHeader: FunctionComponent<{title: string, date: string}> = ({title, date}) => { const i18n = useI18n(); return (
@@ -69,7 +69,7 @@ export const SidebarHeader: FunctionComponent<{title: string, date: string}> = ( ); }; -export const Sidebar: FunctionComponent = () => { +const Sidebar: FunctionComponent = () => { const flowResult = useFlowResult(); const firstLhr = flowResult.steps[0].lhr; return ( @@ -84,3 +84,9 @@ export const Sidebar: FunctionComponent = () => {
); }; + +export { + SidebarSummary, + SidebarHeader, + Sidebar, +}; diff --git a/flow-report/src/summary/category.tsx b/flow-report/src/summary/category.tsx index 02449e36ed..1989715263 100644 --- a/flow-report/src/summary/category.tsx +++ b/flow-report/src/summary/category.tsx @@ -95,7 +95,7 @@ const SummaryTooltipAudits: FunctionComponent<{category: LH.ReportResult.Categor ); }; -export const SummaryTooltip: FunctionComponent<{ +const SummaryTooltip: FunctionComponent<{ category: LH.ReportResult.Category, gatherMode: LH.Result.GatherMode, url: string, @@ -153,7 +153,7 @@ export const SummaryTooltip: FunctionComponent<{ ); }; -export const SummaryCategory: FunctionComponent<{ +const SummaryCategory: FunctionComponent<{ category: LH.ReportResult.Category|undefined, href: string, gatherMode: LH.Result.GatherMode, @@ -176,3 +176,8 @@ export const SummaryCategory: FunctionComponent<{
); }; + +export { + SummaryTooltip, + SummaryCategory, +}; diff --git a/flow-report/src/summary/summary.tsx b/flow-report/src/summary/summary.tsx index 456c98feab..234f2fde15 100644 --- a/flow-report/src/summary/summary.tsx +++ b/flow-report/src/summary/summary.tsx @@ -44,7 +44,7 @@ const SummaryNavigationHeader: FunctionComponent<{lhr: LH.Result}> = ({lhr}) => /** * The div should behave like a JSX <>.... This still allows us to identify "rows" with CSS selectors. */ -export const SummaryFlowStep: FunctionComponent<{ +const SummaryFlowStep: FunctionComponent<{ lhr: LH.Result, label: string, hashIndex: number, @@ -106,7 +106,7 @@ const SummaryFlow: FunctionComponent = () => { ); }; -export const SummaryHeader: FunctionComponent = () => { +const SummaryHeader: FunctionComponent = () => { const flowResult = useFlowResult(); const strings = useLocalizedStrings(); const str_ = useStringFormatter(); @@ -151,7 +151,7 @@ const SummarySectionHeader: FunctionComponent = ({children}) => { ); }; -export const Summary: FunctionComponent = () => { +const Summary: FunctionComponent = () => { const strings = useLocalizedStrings(); return ( @@ -163,3 +163,9 @@ export const Summary: FunctionComponent = () => {
); }; + +export { + SummaryFlowStep, + SummaryHeader, + Summary, +}; diff --git a/flow-report/src/util.ts b/flow-report/src/util.ts index 32833938f1..3207926a08 100644 --- a/flow-report/src/util.ts +++ b/flow-report/src/util.ts @@ -9,14 +9,14 @@ import {useContext, useEffect, useMemo, useState} from 'preact/hooks'; import type {UIStringsType} from './i18n/ui-strings'; -export const FlowResultContext = createContext(undefined); +const FlowResultContext = createContext(undefined); function getHashParam(param: string): string|null { const params = new URLSearchParams(location.hash.replace('#', '?')); return params.get(param); } -export function classNames(...args: Array>): string { +function classNames(...args: Array>): string { const classes = []; for (const arg of args) { if (!arg) continue; @@ -35,12 +35,12 @@ export function classNames(...args: Array | undefined { const filmstripAudit = reportResult.audits['screenshot-thumbnails']; @@ -65,7 +65,7 @@ export function getFilmstripFrames( return frameItems || undefined; } -export function getModeDescription(mode: LH.Result.GatherMode, strings: UIStringsType) { +function getModeDescription(mode: LH.Result.GatherMode, strings: UIStringsType) { switch (mode) { case 'navigation': return strings.navigationDescription; case 'timespan': return strings.timespanDescription; @@ -73,13 +73,13 @@ export function getModeDescription(mode: LH.Result.GatherMode, strings: UIString } } -export function useFlowResult(): LH.FlowResult { +function useFlowResult(): LH.FlowResult { const flowResult = useContext(FlowResultContext); if (!flowResult) throw Error('useFlowResult must be called in the FlowResultContext'); return flowResult; } -export function useHashParams(...params: string[]) { +function useHashParams(...params: string[]) { const [paramValues, setParamValues] = useState(params.map(getHashParam)); // Use two-way-binding on the URL hash. @@ -97,7 +97,7 @@ export function useHashParams(...params: string[]) { return paramValues; } -export function useHashState(): LH.FlowResult.HashState|null { +function useHashState(): LH.FlowResult.HashState|null { const flowResult = useFlowResult(); const [indexString, anchor] = useHashParams('index', 'anchor'); @@ -120,3 +120,15 @@ export function useHashState(): LH.FlowResult.HashState|null { return {currentLhr: step.lhr, index, anchor}; }, [indexString, flowResult, anchor]); } + +export { + FlowResultContext, + classNames, + getScreenDimensions, + getFullPageScreenshot, + getFilmstripFrames, + getModeDescription, + useFlowResult, + useHashParams, + useHashState, +}; diff --git a/flow-report/src/wrappers/report-renderer.tsx b/flow-report/src/wrappers/report-renderer.tsx index 63a60e961d..8ad261a480 100644 --- a/flow-report/src/wrappers/report-renderer.tsx +++ b/flow-report/src/wrappers/report-renderer.tsx @@ -19,15 +19,15 @@ interface ReportRendererGlobals { reportRenderer: ReportRenderer, } -export const ReportRendererContext = createContext(undefined); +const ReportRendererContext = createContext(undefined); -export function useReportRenderer() { +function useReportRenderer() { const globals = useContext(ReportRendererContext); if (!globals) throw Error('Globals not defined'); return globals; } -export const ReportRendererProvider: FunctionComponent = ({children}) => { +const ReportRendererProvider: FunctionComponent = ({children}) => { const globals = useMemo(() => { const dom = new DOM(document); const detailsRenderer = new DetailsRenderer(dom); @@ -44,3 +44,9 @@ export const ReportRendererProvider: FunctionComponent = ({children}) => { {children} ); }; + +export { + ReportRendererContext, + ReportRendererProvider, + useReportRenderer, +}; diff --git a/flow-report/src/wrappers/report.tsx b/flow-report/src/wrappers/report.tsx index eaa259b222..3cd80c2115 100644 --- a/flow-report/src/wrappers/report.tsx +++ b/flow-report/src/wrappers/report.tsx @@ -16,7 +16,7 @@ import {useReportRenderer} from './report-renderer'; * This function converts any anchor links under the provided element to a flow report link. * e.g. -> */ -export function convertChildAnchors(element: HTMLElement, index: number) { +function convertChildAnchors(element: HTMLElement, index: number) { const links = element.querySelectorAll('a[href]') as NodeListOf; for (const link of links) { // Check if the link destination is in the report. @@ -38,7 +38,7 @@ export function convertChildAnchors(element: HTMLElement, index: number) { } } -export const Report: FunctionComponent<{hashState: LH.FlowResult.HashState}> = +const Report: FunctionComponent<{hashState: LH.FlowResult.HashState}> = ({hashState}) => { const {dom, reportRenderer} = useReportRenderer(); const ref = useRef(null); @@ -71,3 +71,8 @@ export const Report: FunctionComponent<{hashState: LH.FlowResult.HashState}> =
); }; + +export { + convertChildAnchors, + Report, +}; diff --git a/flow-report/test/setup/env-setup.ts b/flow-report/test/setup/env-setup.ts index d6caf2ba85..ac51de8f4c 100644 --- a/flow-report/test/setup/env-setup.ts +++ b/flow-report/test/setup/env-setup.ts @@ -10,7 +10,7 @@ import {JSDOM} from 'jsdom'; /** * The jest environment "jsdom" does not work when preact is combined with the report renderer. */ -export function setupJsDom() { +function setupJsDom() { const {window} = new JSDOM(undefined, { url: 'file:///Users/example/report.html/', }); diff --git a/lighthouse-cli/.eslintrc.cjs b/lighthouse-cli/.eslintrc.cjs index 938d7e233f..bd03f9a23a 100644 --- a/lighthouse-cli/.eslintrc.cjs +++ b/lighthouse-cli/.eslintrc.cjs @@ -23,5 +23,7 @@ module.exports = { ], 'newlines-between': 'always', }], + 'import/group-exports': 2, + 'import/exports-last': 2, }, }; diff --git a/lighthouse-core/audits/audit.js b/lighthouse-core/audits/audit.js index 30b892bd4c..a2a386cc56 100644 --- a/lighthouse-core/audits/audit.js +++ b/lighthouse-core/audits/audit.js @@ -7,7 +7,7 @@ const {isUnderTest} = require('../lib/lh-env.js'); const statistics = require('../lib/statistics.js'); -const Util = require('../util-commonjs.js'); +const {Util} = require('../util-commonjs.js'); const DEFAULT_PASS = 'defaultPass'; diff --git a/lighthouse-core/computed/resource-summary.js b/lighthouse-core/computed/resource-summary.js index 41082bcc20..9d76b70698 100644 --- a/lighthouse-core/computed/resource-summary.js +++ b/lighthouse-core/computed/resource-summary.js @@ -10,7 +10,7 @@ const NetworkRecords = require('./network-records.js'); const URL = require('../lib/url-shim.js'); const NetworkRequest = require('../lib/network-request.js'); const Budget = require('../config/budget.js'); -const Util = require('../util-commonjs.js'); +const {Util} = require('../util-commonjs.js'); /** @typedef {{count: number, resourceSize: number, transferSize: number}} ResourceEntry */ diff --git a/lighthouse-core/lib/url-shim.js b/lighthouse-core/lib/url-shim.js index fbb5dd7582..bcaded9a7a 100644 --- a/lighthouse-core/lib/url-shim.js +++ b/lighthouse-core/lib/url-shim.js @@ -9,7 +9,7 @@ * URL shim so we keep our code DRY */ -const Util = require('../util-commonjs.js'); +const {Util} = require('../util-commonjs.js'); /** @typedef {import('./network-request.js')} NetworkRequest */ diff --git a/lighthouse-core/scripts/.eslintrc.cjs b/lighthouse-core/scripts/.eslintrc.cjs index 938d7e233f..bd03f9a23a 100644 --- a/lighthouse-core/scripts/.eslintrc.cjs +++ b/lighthouse-core/scripts/.eslintrc.cjs @@ -23,5 +23,7 @@ module.exports = { ], 'newlines-between': 'always', }], + 'import/group-exports': 2, + 'import/exports-last': 2, }, }; diff --git a/lighthouse-core/scripts/copy-util-commonjs.sh b/lighthouse-core/scripts/copy-util-commonjs.sh index 7f83cd7f46..eb7fa59a08 100644 --- a/lighthouse-core/scripts/copy-util-commonjs.sh +++ b/lighthouse-core/scripts/copy-util-commonjs.sh @@ -16,5 +16,4 @@ OUT_FILE="$LH_ROOT_DIR"/lighthouse-core/util-commonjs.js echo '// @ts-nocheck' > "$OUT_FILE" echo '// Auto-generated by lighthouse-core/scripts/copy-util-commonjs.sh' >> "$OUT_FILE" echo '// Temporary solution until all our code uses esmodules' >> "$OUT_FILE" -sed 's/export class Util/class Util/g; s/export const UIStrings = Util.UIStrings;//g' "$LH_ROOT_DIR"/report/renderer/util.js >> "$OUT_FILE" -echo 'module.exports = Util;' >> "$OUT_FILE" +sed 's/export /module.exports = /' "$LH_ROOT_DIR"/report/renderer/util.js >> "$OUT_FILE" diff --git a/lighthouse-core/scripts/i18n/collect-strings.js b/lighthouse-core/scripts/i18n/collect-strings.js index 1b5e1500fc..852397728e 100644 --- a/lighthouse-core/scripts/i18n/collect-strings.js +++ b/lighthouse-core/scripts/i18n/collect-strings.js @@ -17,7 +17,7 @@ import tsc from 'typescript'; import MessageParser from 'intl-messageformat-parser'; import esMain from 'es-main'; -import Util from '../../../lighthouse-core/util-commonjs.js'; +import {Util} from '../../../lighthouse-core/util-commonjs.js'; import {collectAndBakeCtcStrings} from './bake-ctc-to-lhl.js'; import {pruneObsoleteLhlMessages} from './prune-obsolete-lhl-messages.js'; import {countTranslatedMessages} from './count-translated.js'; diff --git a/lighthouse-core/util-commonjs.js b/lighthouse-core/util-commonjs.js index cc727c99fb..9fa4056acc 100644 --- a/lighthouse-core/util-commonjs.js +++ b/lighthouse-core/util-commonjs.js @@ -42,6 +42,10 @@ const listOfTlds = [ ]; class Util { + /** @type {I18n} */ + // @ts-expect-error: Is set in report renderer. + static i18n = null; + static get PASS_THRESHOLD() { return PASS_THRESHOLD; } @@ -557,14 +561,10 @@ Util.getUniqueSuffix = (() => { }; })(); -/** @type {I18n} */ -// @ts-expect-error: Is set in report renderer. -Util.i18n = null; - /** * Report-renderer-specific strings. */ -Util.UIStrings = { +const UIStrings = { /** Disclaimer shown to users below the metric values (First Contentful Paint, Time to Interactive, etc) to warn them that the numbers they see will likely change slightly the next time they run Lighthouse. */ varianceDisclaimer: 'Values are estimated and may vary. The [performance score is calculated](https://web.dev/performance-scoring/) directly from these metrics.', /** Text link pointing to an interactive calculator that explains Lighthouse scoring. The link text should be fairly short. */ @@ -677,6 +677,9 @@ Util.UIStrings = { /** Label indicating that Lighthouse throttled the page using custom throttling settings. */ runtimeCustom: 'Custom throttling', }; +Util.UIStrings = UIStrings; - -module.exports = Util; +module.exports = { + Util, + UIStrings, +}; diff --git a/report/.eslintrc.cjs b/report/.eslintrc.cjs index fed386bf37..d245b51b2b 100644 --- a/report/.eslintrc.cjs +++ b/report/.eslintrc.cjs @@ -29,5 +29,7 @@ module.exports = { ], 'newlines-between': 'always', }], + 'import/group-exports': 2, + 'import/exports-last': 2, }, }; diff --git a/report/renderer/crc-details-renderer.js b/report/renderer/crc-details-renderer.js index 1ef5d3417a..d496314355 100644 --- a/report/renderer/crc-details-renderer.js +++ b/report/renderer/crc-details-renderer.js @@ -21,12 +21,21 @@ * critical request chains network tree. */ -/** @typedef {import('./dom.js').DOM} DOM */ -/** @typedef {import('./details-renderer.js').DetailsRenderer} DetailsRenderer */ - import {Util} from './util.js'; -export class CriticalRequestChainRenderer { +/** @typedef {import('./dom.js').DOM} DOM */ +/** @typedef {import('./details-renderer.js').DetailsRenderer} DetailsRenderer */ +/** + * @typedef CRCSegment + * @property {LH.Audit.Details.SimpleCriticalRequestNode[string]} node + * @property {boolean} isLastChild + * @property {boolean} hasChildren + * @property {number} startTime + * @property {number} transferSize + * @property {boolean[]} treeMarkers + */ + +class CriticalRequestChainRenderer { /** * Create render context for critical-request-chain tree display. * @param {LH.Audit.Details.SimpleCriticalRequestNode} tree @@ -191,12 +200,6 @@ export class CriticalRequestChainRenderer { // Alias b/c the name is really long. const CRCRenderer = CriticalRequestChainRenderer; -/** @typedef {{ - node: LH.Audit.Details.SimpleCriticalRequestNode[string], - isLastChild: boolean, - hasChildren: boolean, - startTime: number, - transferSize: number, - treeMarkers: Array - }} CRCSegment - */ +export { + CriticalRequestChainRenderer, +}; diff --git a/report/renderer/open-tab.js b/report/renderer/open-tab.js index 5ee2850393..68b87b4d96 100644 --- a/report/renderer/open-tab.js +++ b/report/renderer/open-tab.js @@ -90,7 +90,7 @@ async function openTabWithUrlData(data, url_, windowName) { * @param {LH.Result} lhr * @protected */ -export async function openViewer(lhr) { +async function openViewer(lhr) { const windowName = 'viewer-' + computeWindowNameSuffix(lhr); const url = getAppsOrigin() + '/viewer/'; await openTabWithUrlData({lhr}, url, windowName); @@ -101,7 +101,7 @@ export async function openViewer(lhr) { * @param {LH.Result} lhr * @protected */ -export async function openViewerAndSendData(lhr) { +async function openViewerAndSendData(lhr) { const windowName = 'viewer-' + computeWindowNameSuffix(lhr); const url = getAppsOrigin() + '/viewer/'; openTabAndSendData({lhr}, url, windowName); @@ -111,7 +111,7 @@ export async function openViewerAndSendData(lhr) { * Opens a new tab to the treemap app and sends the JSON results using URL.fragment * @param {LH.Result} json */ -export function openTreemap(json) { +function openTreemap(json) { const treemapData = json.audits['script-treemap-data'].details; if (!treemapData) { throw new Error('no script treemap data found'); @@ -135,3 +135,9 @@ export function openTreemap(json) { openTabWithUrlData(treemapOptions, url, windowName); } + +export { + openViewer, + openViewerAndSendData, + openTreemap, +}; diff --git a/report/renderer/util.js b/report/renderer/util.js index 57d3f682db..bd167821cf 100644 --- a/report/renderer/util.js +++ b/report/renderer/util.js @@ -38,7 +38,11 @@ const listOfTlds = [ 'web', 'spb', 'blog', 'jus', 'kiev', 'mil', 'wi', 'qc', 'ca', 'bel', 'on', ]; -export class Util { +class Util { + /** @type {I18n} */ + // @ts-expect-error: Is set in report renderer. + static i18n = null; + static get PASS_THRESHOLD() { return PASS_THRESHOLD; } @@ -554,14 +558,10 @@ Util.getUniqueSuffix = (() => { }; })(); -/** @type {I18n} */ -// @ts-expect-error: Is set in report renderer. -Util.i18n = null; - /** * Report-renderer-specific strings. */ -Util.UIStrings = { +const UIStrings = { /** Disclaimer shown to users below the metric values (First Contentful Paint, Time to Interactive, etc) to warn them that the numbers they see will likely change slightly the next time they run Lighthouse. */ varianceDisclaimer: 'Values are estimated and may vary. The [performance score is calculated](https://web.dev/performance-scoring/) directly from these metrics.', /** Text link pointing to an interactive calculator that explains Lighthouse scoring. The link text should be fairly short. */ @@ -674,5 +674,9 @@ Util.UIStrings = { /** Label indicating that Lighthouse throttled the page using custom throttling settings. */ runtimeCustom: 'Custom throttling', }; +Util.UIStrings = UIStrings; -export const UIStrings = Util.UIStrings; +export { + Util, + UIStrings, +}; diff --git a/treemap/.eslintrc.cjs b/treemap/.eslintrc.cjs index 938d7e233f..bd03f9a23a 100644 --- a/treemap/.eslintrc.cjs +++ b/treemap/.eslintrc.cjs @@ -23,5 +23,7 @@ module.exports = { ], 'newlines-between': 'always', }], + 'import/group-exports': 2, + 'import/exports-last': 2, }, }; diff --git a/treemap/app/src/util.js b/treemap/app/src/util.js index 353f1dd8b7..787d29a19c 100644 --- a/treemap/app/src/util.js +++ b/treemap/app/src/util.js @@ -11,7 +11,7 @@ /** @template {string} T @typedef {import('typed-query-selector/parser').ParseSelector} ParseSelector */ /** @template T @typedef {import('../../../report/renderer/i18n').I18n} I18n */ -export const UIStrings = { +const UIStrings = { /** Label for a button that alternates between showing or hiding a table. */ toggleTableButtonLabel: 'Toggle Table', /** Text for an option in a dropdown menu. When selected, the app shows information for all scripts that were found in a web page. */ @@ -30,7 +30,7 @@ export const UIStrings = { duplicateModulesLabel: 'Duplicate Modules', }; -export class TreemapUtil { +class TreemapUtil { /** @type {I18n} */ // @ts-expect-error: Is set in main. static i18n = null; @@ -216,3 +216,8 @@ TreemapUtil.COLOR_HUES = [ 15.9, 199.5, ]; + +export { + TreemapUtil, + UIStrings, +}; diff --git a/viewer/.eslintrc.cjs b/viewer/.eslintrc.cjs index 8e460494ad..03870169c5 100644 --- a/viewer/.eslintrc.cjs +++ b/viewer/.eslintrc.cjs @@ -23,5 +23,7 @@ module.exports = { ], 'newlines-between': 'always', }], + 'import/group-exports': 2, + 'import/exports-last': 2, }, }; diff --git a/viewer/app/src/psi-api.js b/viewer/app/src/psi-api.js index 09092b50f0..56c79ee413 100644 --- a/viewer/app/src/psi-api.js +++ b/viewer/app/src/psi-api.js @@ -9,7 +9,7 @@ const PSI_URL = 'https://www.googleapis.com/pagespeedonline/v5/runPagespeed'; const PSI_KEY = 'AIzaSyAjcDRNN9CX9dCazhqI4lGR7yyQbkd_oYE'; -export const PSI_DEFAULT_CATEGORIES = [ +const PSI_DEFAULT_CATEGORIES = [ 'performance', 'accessibility', 'seo', @@ -29,7 +29,7 @@ export const PSI_DEFAULT_CATEGORIES = [ /** * Wrapper around the PSI API for fetching LHR. */ -export class PSIApi { +class PSIApi { /** * @param {PSIParams} params * @return {Promise} @@ -49,3 +49,8 @@ export class PSIApi { return fetch(apiUrl.href).then(res => res.json()); } } + +export { + PSI_DEFAULT_CATEGORIES, + PSIApi, +}; diff --git a/viewer/test/test-helpers.js b/viewer/test/test-helpers.js index fc25833b67..8cc87774ee 100644 --- a/viewer/test/test-helpers.js +++ b/viewer/test/test-helpers.js @@ -16,7 +16,7 @@ import {LH_ROOT} from '../../root.js'; const PAGE = fs.readFileSync(path.join(LH_ROOT, 'viewer/app/index.html'), 'utf8'); -export function setupJsDomGlobals() { +function setupJsDomGlobals() { const {window} = new jsdom.JSDOM(PAGE); global.document = window.document; global.window = window; @@ -24,8 +24,13 @@ export function setupJsDomGlobals() { global.logger.hide = () => {/* noop */}; } -export function cleanupJsDomGlobals() { +function cleanupJsDomGlobals() { global.document = undefined; global.window = undefined; global.logger = undefined; } + +export { + setupJsDomGlobals, + cleanupJsDomGlobals, +};