Skip to content

Commit

Permalink
chore: run linter
Browse files Browse the repository at this point in the history
  • Loading branch information
harlan-zw committed Feb 29, 2024
1 parent db34a45 commit ab51451
Show file tree
Hide file tree
Showing 21 changed files with 146 additions and 179 deletions.
6 changes: 0 additions & 6 deletions .eslintignore

This file was deleted.

9 changes: 0 additions & 9 deletions .eslintrc

This file was deleted.

2 changes: 1 addition & 1 deletion docs/components/docs/DocsAsideLinks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function mapContentLinks(links: NavItem[]) {
</UVerticalNavigation>
</template>
<div v-else class="space-y-3">
<div v-for="(group2, index) in group.children" :key="index">
<div v-for="(group2, idx2) in group.children" :key="idx2">
<p class="text-sm font-semibold text-gray-900 dark:text-gray-200 truncate leading-6">
{{ group2.title }}
</p>
Expand Down
1 change: 0 additions & 1 deletion docs/content/2.integrations/1.ci.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ unlighthouse-ci --site <your-site> --reporter lighthouseServer
export default {
ci: {
reporter: 'lighthouseServer'

}
}
```
Expand Down
8 changes: 8 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,13 @@ import antfu from '@antfu/eslint-config'
export default antfu({
rules: {
'no-use-before-define': 'off',
'node/prefer-global/process': 'off',
'ts/no-use-before-define': 'off',
},
// exclude examples dir
ignores: [
'test/*',
'examples/*',
'examples/**/*.*',
],
})
16 changes: 8 additions & 8 deletions packages/cli/src/ci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { CiOptions } from './types'
import { pickOptions, validateHost, validateOptions } from './util'
import createCli from './createCli'
import { generateReportPayload, outputReport } from './reporters'
import { ReporterConfig } from './reporters/types'
import type { ReporterConfig } from './reporters/types'

async function run() {
const startTime = new Date()
Expand All @@ -18,7 +18,7 @@ async function run() {
cli.option('--budget <budget>', 'Budget (1-100), the minimum score which can pass.')
cli.option('--build-static <build-static>', 'Build a static website for the reports which can be uploaded.')
cli.option('--reporter <reporter>', 'The report to generate from results. Options: csv, csvExpanded, json, jsonExpanded or false. Default: json.')
cli.option('--lhci-host <lhci-host>', 'URL of your LHCI server.')
cli.option('--lhci-host <lhci-host>', 'URL of your LHCI server.')
cli.option('--lhci-build-token <lhci-build-token>', 'LHCI build token, used to add data.')

const { options } = cli.parse() as unknown as { options: CiOptions }
Expand All @@ -33,8 +33,8 @@ async function run() {
reporter: options.reporter || 'jsonSimple',
reporterConfig: {
lhciHost: options.lhciHost,
lhciBuildToken: options.lhciBuildToken
}
lhciBuildToken: options.lhciBuildToken,
},

}

Expand Down Expand Up @@ -95,15 +95,15 @@ async function run() {
const reporter = resolvedConfig.ci.reporter
const reporterConfig: ReporterConfig = {
columns: resolvedConfig.client.columns,
...(resolvedConfig.ci?.reporterConfig || {})
...(resolvedConfig.ci?.reporterConfig || {}),

}
// @ts-expect-error untyped
const payload = await Promise.resolve<Promise<any>>(generateReportPayload(reporter, worker.reports(), reporterConfig))
let path = ''
if(payload){
path = `\`./${relative(resolvedConfig.root, await outputReport(reporter, resolvedConfig, payload))}\``
}
if (payload)
path = `\`./${relative(resolvedConfig.root, await outputReport(reporter, resolvedConfig, payload))}\``

logger.success(`Generated \`${resolvedConfig.ci.reporter}\` report`, path)
}

Expand Down
3 changes: 1 addition & 2 deletions packages/cli/src/reporters/csvExpanded.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

import { get } from 'lodash-es'
import type { UnlighthouseRouteReport } from '../types'
import { csvSimpleFormat } from './csvSimple'
import { ReporterConfig } from './types'
import type { ReporterConfig } from './types'

export function reportCSVExpanded(reports: UnlighthouseRouteReport[], { columns }: ReporterConfig): string {
const { headers, body } = csvSimpleFormat(reports)
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/reporters/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { join } from 'node:path'
import fse from 'fs-extra'
import type { ResolvedUserConfig, UnlighthouseColumn, UnlighthouseRouteReport, UnlighthouseTabs } from '@unlighthouse/core'
import type { ResolvedUserConfig, UnlighthouseRouteReport } from '@unlighthouse/core'
import { reportJsonSimple } from './jsonSimple'
import { reportJsonExpanded } from './jsonExpanded'
import type { ReportJsonExpanded, ReportJsonSimple, ReporterConfig } from './types'
Expand All @@ -27,9 +27,9 @@ export function generateReportPayload(reporter: string, reports: UnlighthouseRou
if (reporter === 'csvExpanded')
return reportCSVExpanded(sortedReporters, config)
}
if (reporter === 'lighthouseServer') {
if (reporter === 'lighthouseServer')
return reportLighthouseServer(sortedReporters, config)
}

throw new Error(`Unsupported reporter: ${reporter}.`)
}

Expand Down
8 changes: 4 additions & 4 deletions packages/cli/src/reporters/jsonExpanded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function extractCategoriesFromRoutes(routes: ExpandedRouteReport[]) {
const categoriesWithAllScores = routes.reduce((prev, curr) => {
return Object.keys(curr.categories).reduce((target, categoryKey) => {
const scores = target[categoryKey] ? target[categoryKey].scores : []
const { score, ...strippedCategory } = curr.categories[categoryKey]
const { ...strippedCategory } = curr.categories[categoryKey]
return {
...target,
[categoryKey]: {
Expand All @@ -121,7 +121,7 @@ function extractCategoriesFromRoutes(routes: ExpandedRouteReport[]) {
) / categoriesWithAllScores[key].scores.length
).toFixed(2),
)
const { scores, ...strippedCategory } = categoriesWithAllScores[key]
const { ...strippedCategory } = categoriesWithAllScores[key]
return { ...prev, [key]: { ...strippedCategory, averageScore } }
},
{} as {
Expand All @@ -136,7 +136,7 @@ function extractMetricsFromRoutes(routes: ExpandedRouteReport[]) {
const numericValues = target[metricKey]
? target[metricKey].numericValues
: []
const { numericValue, displayValue, ...strippedMetric } = curr.metrics[metricKey]
const { ...strippedMetric } = curr.metrics[metricKey]
return {
...target,
[metricKey]: {
Expand All @@ -158,7 +158,7 @@ function extractMetricsFromRoutes(routes: ExpandedRouteReport[]) {
) / metricsWithAllNumericValues[key].numericValues.length
).toFixed(2),
)
const { numericValues, ...strippedMetric }
const { ...strippedMetric }
= metricsWithAllNumericValues[key]
return { ...prev, [key]: { ...strippedMetric, averageNumericValue } }
},
Expand Down
53 changes: 27 additions & 26 deletions packages/cli/src/reporters/lighthouseServer.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
import type { UnlighthouseRouteReport } from "../types";
import ApiClient from "@lhci/utils/src/api-client.js";
import ApiClient from '@lhci/utils/src/api-client.js'
import {
getCommitMessage,
getAncestorHash,
getAuthor,
getAvatarUrl,
getExternalBuildUrl,
getCommitMessage,
getCommitTime,
getCurrentHash,
getCurrentBranch,
getAncestorHash,
} from "@lhci/utils/src/build-context.js";
import fs from "fs-extra";
import { ReporterConfig } from "./types";
import { handleError } from "../errors";
getCurrentHash,
getExternalBuildUrl,
} from '@lhci/utils/src/build-context.js'
import fs from 'fs-extra'
import type { UnlighthouseRouteReport } from '../types'
import { handleError } from '../errors'
import type { ReporterConfig } from './types'

export async function reportLighthouseServer(
reports: UnlighthouseRouteReport[],
{ lhciBuildToken, lhciHost }: ReporterConfig
{ lhciBuildToken, lhciHost }: ReporterConfig,
): Promise<void> {
try {
const api = new ApiClient({ fetch, rootURL: lhciHost });
api.setBuildToken(lhciBuildToken);
const project = await api.findProjectByToken(lhciBuildToken);
const baseBranch = project.baseBranch || "master";
const hash = getCurrentHash();
const branch = getCurrentBranch();
const ancestorHash = getAncestorHash("HEAD", baseBranch);
const api = new ApiClient({ fetch, rootURL: lhciHost })
api.setBuildToken(lhciBuildToken)
const project = await api.findProjectByToken(lhciBuildToken)
const baseBranch = project.baseBranch || 'master'
const hash = getCurrentHash()
const branch = getCurrentBranch()
const ancestorHash = getAncestorHash('HEAD', baseBranch)
const build = await api.createBuild({
projectId: project.id,
lifecycle: "unsealed",
hash: hash,
lifecycle: 'unsealed',
hash,
branch,
ancestorHash,
commitMessage: getCommitMessage(hash),
Expand All @@ -41,23 +41,24 @@ export async function reportLighthouseServer(
ancestorCommittedAt: ancestorHash
? getCommitTime(ancestorHash)
: undefined,
});
})

for (const report of reports) {
const lighthouseResult = await fs.readJson(
`${report.artifactPath}/lighthouse.json`
);
`${report.artifactPath}/lighthouse.json`,
)

await api.createRun({
projectId: project.id,
buildId: build.id,
representative: false,
url: `${report.route.url}${report.route.path}`,
lhr: JSON.stringify(lighthouseResult),
});
})
}
await api.sealBuild(build.projectId, build.id);
} catch (e) {
await api.sealBuild(build.projectId, build.id)
}
catch (e) {
handleError(e)
}
}
2 changes: 1 addition & 1 deletion packages/cli/src/reporters/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UnlighthouseTabs, UnlighthouseColumn } from "../../../core/src"
import type { UnlighthouseColumn, UnlighthouseTabs } from '../../../core/src'

export interface CategoryScore {
key: string
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ReporterConfig, UnlighthouseRouteReport, ValidReportTypes } from '@unlighthouse/core'
import type { UnlighthouseRouteReport, ValidReportTypes } from '@unlighthouse/core'

export interface CliOptions {
host?: string
Expand Down Expand Up @@ -39,7 +39,6 @@ export interface CiOptions extends CliOptions {
lhciHost?: string
lhciBuildToken?: string


}

export { UnlighthouseRouteReport }
22 changes: 11 additions & 11 deletions packages/cli/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ export function validateOptions(resolvedOptions: UserConfig) {
if (!isValidUrl(resolvedOptions.site))
return handleError('Please provide a valid site URL.')

if(resolvedOptions?.ci?.reporter === 'lighthouseServer'){
if (!resolvedOptions?.ci?.reporterConfig?.lhciBuildToken) {
handleError(
"Please provide the lighthouse server build token with --lhci-build-token."
);
}
if (!resolvedOptions?.ci?.reporterConfig?.lhciHost) {
handleError(
"Please provide the lighthouse server build token with --lhci-host."
);
}
if (resolvedOptions?.ci?.reporter === 'lighthouseServer') {
if (!resolvedOptions?.ci?.reporterConfig?.lhciBuildToken) {
handleError(
'Please provide the lighthouse server build token with --lhci-build-token.',
)
}
if (!resolvedOptions?.ci?.reporterConfig?.lhciHost) {
handleError(
'Please provide the lighthouse server build token with --lhci-host.',
)
}
}
}

export function pickOptions(options: CiOptions | CliOptions): UserConfig {
Expand Down
Loading

0 comments on commit ab51451

Please sign in to comment.