Skip to content

Commit baa9fcd

Browse files
committed
Fix remaining Biome lints
1 parent 1c9bc6e commit baa9fcd

File tree

13 files changed

+77
-56
lines changed

13 files changed

+77
-56
lines changed

badgers-web/src/app/codeberg/release/[owner]/[repo]/route.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ export async function GET(request: NextRequest, { params: { owner, repo } }: Par
1515

1616
const shortestName = (() => {
1717
if (release === null) { return null }
18-
return [release?.tag_name, release?.name]
19-
.filter(Boolean)
20-
.reduce((a, b) => a!.length < b!.length ? a : b)
18+
return [release.tag_name, release.name]
19+
.reduce((a, b) => a.length < b.length ? a : b)
2120
})()
2221

2322
return await Badge.generate(request, 'release', shortestName ?? 'None', {
24-
color: !!shortestName ? 'blue' : 'yellow'
23+
color: shortestName ? 'blue' : 'yellow'
2524
})
2625
}
2726

badgers-web/src/app/codeberg/stars/[owner]/[repo]/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export async function GET(request: NextRequest, { params: { owner, repo } }: Par
1515
const stargazers = repository?.stars_count
1616

1717
return await Badge.generate(request, 'stars', stargazers?.toString() ?? 'None', {
18-
color: !!stargazers ? 'blue' : 'yellow'
18+
color: stargazers ? 'blue' : 'yellow'
1919
})
2020
}
2121

badgers-web/src/app/github/contributors/[owner]/[repo]/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ export async function GET(request: NextRequest, { params: { owner, repo } }: Par
1414
const resp = await GitHub.wrapRequest(
1515
octokit => octokit.repos.listContributors({ owner, repo })
1616
)
17-
if (resp.data === undefined) return await Badge.error(request, 'github')
18-
return await Badge.generate(request, 'contributors', resp.data!.length.toString())
17+
if (!resp.data) return await Badge.error(request, 'github')
18+
return await Badge.generate(request, 'contributors', resp.data.length.toString())
1919
}

badgers-web/src/app/github/license/[owner]/[repo]/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ export async function GET(request: NextRequest, { params: { owner, repo } }: Par
1616
)
1717
const licenseName = resp.data?.license?.spdx_id ?? resp.data?.license?.name
1818
return await Badge.generate(request, 'license', licenseName ?? 'unknown', {
19-
color: !!licenseName ? 'blue' : 'gray'
19+
color: licenseName ? 'blue' : 'gray'
2020
})
2121
}

badgers-web/src/app/icons/IconShelf.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client'
22

3-
import { useMemo, useState } from "react"
3+
import { Fragment, useMemo, useState } from "react"
44

55
import type { IconSetList } from "./page"
66

@@ -32,13 +32,13 @@ export default function IconShelf({ icons }: Props) {
3232
)}
3333
{Object.entries(icons).map(([name, data]) => {
3434
return (
35-
<>
35+
<Fragment key={name}>
3636
<div className="flex justify-center items-center bg-gray-700 rounded-md w-8 h-8">
3737
{/* eslint-disable-next-line @next/next/no-img-element */}
3838
<img width="20" height="20" alt={name} src={data} />
3939
</div>
4040
<div className="text-gray-800">{name}</div>
41-
</>
41+
</Fragment>
4242
)
4343
})}
4444
</div>

badgers-web/src/app/layout.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ import type { Metadata, Viewport } from "next";
1010

1111
const inter = Inter({ subsets: ["latin"] });
1212

13+
const metadataBase = (() => {
14+
const proto = process.env.NEXT_PUBLIC_WEB_PROTO
15+
const host = process.env.NEXT_PUBLIC_WEB_HOST
16+
if (!proto || !host) {
17+
throw new Error("Missing environment variables: NEXT_PUBLIC_WEB_PROTO, NEXT_PUBLIC_WEB_HOST")
18+
}
19+
return new URL(`${proto}://${host}`)
20+
})()
21+
1322
export const metadata: Metadata = {
1423
title: "SpaceBadgers",
1524
applicationName: "SpaceBadgers",
@@ -24,7 +33,7 @@ export const metadata: Metadata = {
2433
],
2534
authors: [{ name: "Marco Quinten", url: "https://github.com/splittydev" }],
2635
creator: "Marco Quinten",
27-
metadataBase: new URL(`${process.env.NEXT_PUBLIC_WEB_PROTO!}://${process.env.NEXT_PUBLIC_WEB_HOST!}`),
36+
metadataBase,
2837
}
2938

3039
export const viewport: Viewport = {

badgers-web/src/components/Path.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Fragment } from "react"
2+
13
type Props = {
24
value: string,
35
}
@@ -50,7 +52,7 @@ export default function Path({ value }: Props) {
5052
value,
5153
className: getPathColor(value, isQueryParam ? queryParamCount - 1 : isDynamic ? dynamicIndex++ : staticIndex++, isProtocol, isQueryParam),
5254
isQuery: isQueryParam,
53-
renderAmpersand: queryParamCount == 2
55+
renderAmpersand: queryParamCount === 2
5456
}
5557
})
5658
}
@@ -60,15 +62,15 @@ export default function Path({ value }: Props) {
6062
return (
6163
<div className="flex flex-wrap whitespace-pre-wrap text-gray-400 font-mono">
6264
{parts.map(({ value, className, isQuery, renderAmpersand }, i) => (
63-
<>
64-
{!isQuery && (!containsProtocol || (containsProtocol && i != 0)) && (
65-
<div key={`sep-${value}`}>/</div>
65+
<Fragment key={value}>
66+
{!isQuery && (!containsProtocol || (containsProtocol && i !== 0)) && (
67+
<div>/</div>
6668
)}
6769
{renderAmpersand && <div className={className}>&amp;</div>}
68-
<div key={value} className={className}>
70+
<div className={className}>
6971
{value}
7072
</div>
71-
</>
73+
</Fragment>
7274
))}
7375
</div>
7476
)

badgers-web/src/utils/Badge.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { type NextRequest, NextResponse } from "next/server"
22

3-
const pick = (obj: any, keys: string[]) => Object.fromEntries(keys.map(key => [key, obj[key]]))
4-
53
interface BadgeOverrides {
64
labelColor?: string,
75
color?: string,
@@ -13,7 +11,7 @@ interface BadgeOverrides {
1311
*
1412
* Uses the Spacebadgers worker to generate badges.
1513
*/
16-
export default class Badge {
14+
const Badge = {
1715

1816
/**
1917
* Generate a badge.
@@ -24,7 +22,7 @@ export default class Badge {
2422
* @param overrides Badge overrides.
2523
* @returns The badge response.
2624
*/
27-
static async generate(request: NextRequest, label: string, status: string, overrides: BadgeOverrides = {}): Promise<NextResponse> {
25+
async generate(request: NextRequest, label: string, status: string, overrides: BadgeOverrides = {}): Promise<NextResponse> {
2826
// Get API configuration from env
2927
const api = {
3028
proto: process.env.NEXT_PUBLIC_API_PROTO,
@@ -43,8 +41,9 @@ export default class Badge {
4341
.replace(/^\?+/gm, '').split('&')
4442
.reduce((acc, pair) => {
4543
const [key, value] = pair.split('=')
46-
return {...acc, [key]: value}
47-
}, {})
44+
acc[key] = value
45+
return acc
46+
}, {} as Record<string, string>)
4847
const unifiedQueryOverrides = {...systemQueryOverrides, ...userQueryOverrides}
4948
const queryParams = Object
5049
.entries(unifiedQueryOverrides)
@@ -74,13 +73,13 @@ export default class Badge {
7473
statusText: resp.statusText,
7574
headers,
7675
})
77-
}
76+
},
7877

79-
static async error(request: NextRequest, subsystem: string): Promise<NextResponse> {
78+
async error(request: NextRequest, subsystem: string): Promise<NextResponse> {
8079
return await Badge.generate(request, subsystem, 'error', { color: 'gray' })
81-
}
80+
},
8281

83-
static async passThrough(request: NextRequest): Promise<NextResponse> {
82+
async passThrough(request: NextRequest): Promise<NextResponse> {
8483
const api = {
8584
proto: process.env.NEXT_PUBLIC_API_PROTO,
8685
host: process.env.NEXT_PUBLIC_API_HOST,
@@ -102,5 +101,7 @@ export default class Badge {
102101
statusText: resp.statusText,
103102
headers,
104103
})
105-
}
104+
},
106105
}
106+
107+
export default Badge

badgers-web/src/utils/Codeberg.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class CodebergClient {
2525
this.token = token
2626
}
2727

28-
buildUrl(path: string, query: Record<string, any> = {}): string {
28+
buildUrl(path: string, query: Record<string, string | number | boolean> = {}): string {
2929
const queryArgs = {
3030
...query,
3131
token: this.token,
@@ -47,7 +47,7 @@ class CodebergClient {
4747
return await resp.json() as Repository
4848
}
4949

50-
async getIssuesCount({ owner, repo }: ProjectInfo, query: Record<string, any> = {}): Promise<number | null> {
50+
async getIssuesCount({ owner, repo }: ProjectInfo, query: Record<string, string | number | boolean> = {}): Promise<number | null> {
5151
const repoId = `${owner}/${repo}`
5252
const url = this.buildUrl(`repos/${repoId}/issues`, query)
5353
const resp = await fetch(url)
@@ -67,8 +67,10 @@ class CodebergClient {
6767
}
6868
}
6969

70-
export default class Codeberg {
71-
static getClient(): CodebergClient {
70+
const Codeberg = {
71+
getClient(): CodebergClient {
7272
return new CodebergClient(process.env.CODEBERG_TOKEN as string)
73-
}
73+
},
7474
}
75+
76+
export default Codeberg

badgers-web/src/utils/Crates.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@ import { CratesIO } from 'crates.io'
22

33
type WrappedCratesRequest<T> = (arg0: CratesIO) => Promise<T>
44

5-
export default class Crates {
6-
static getCratesClient(): CratesIO {
5+
const Crates = {
6+
getCratesClient(): CratesIO {
77
return new CratesIO()
8-
}
8+
},
99

10-
static async wrapRequest<T>(request: WrappedCratesRequest<T>): Promise<T | null> {
10+
async wrapRequest<T>(request: WrappedCratesRequest<T>): Promise<T | null> {
1111
try {
1212
return await request(Crates.getCratesClient())
1313
} catch (error) {
1414
return null
1515
}
16-
}
16+
},
1717
}
1818

19+
export default Crates
20+
1921
// Disable Vercel data cache for all requests.
2022
// This is a temporary solution. Once we can serve all routes via fetch,
2123
// we can remove this and use the next revalidate feature.

0 commit comments

Comments
 (0)