Skip to content

Commit 8aa0f9f

Browse files
authored
feat: enable type-aware no-base-to-string rule, fix 56 violations (#22750)
1 parent c802695 commit 8aa0f9f

26 files changed

Lines changed: 87 additions & 55 deletions

File tree

.oxlintrc.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/nicolo-ribaudo/oxc-project.github.io/refs/heads/json-schema/src/public/.oxlintrc.schema.json",
3+
"options": {
4+
"typeAware": true
5+
},
36
"categories": {
47
"suspicious": "warn"
58
},
69
"rules": {
10+
"typescript/no-base-to-string": "warn",
711
// Effect uses `function*` with Effect.gen/Effect.fnUntraced that don't always yield
812
"require-yield": "off",
913
// SolidJS uses `let ref: T | undefined` for JSX ref bindings assigned at runtime

packages/console/app/src/routes/workspace/[id]/billing/black-section.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ const createSessionUrl = action(async (workspaceID: string, returnUrl: string) =
116116

117117
const setUseBalance = action(async (form: FormData) => {
118118
"use server"
119-
const workspaceID = form.get("workspaceID")?.toString()
119+
const workspaceID = form.get("workspaceID") as string | null
120120
if (!workspaceID) return { error: formError.workspaceRequired }
121-
const useBalance = form.get("useBalance")?.toString() === "true"
121+
const useBalance = (form.get("useBalance") as string | null) === "true"
122122

123123
return json(
124124
await withActor(async () => {

packages/console/app/src/routes/workspace/[id]/billing/monthly-limit-section.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import { formError, localizeError } from "~/lib/form-error"
1010

1111
const setMonthlyLimit = action(async (form: FormData) => {
1212
"use server"
13-
const limit = form.get("limit")?.toString()
13+
const limit = form.get("limit") as string | null
1414
if (!limit) return { error: formError.limitRequired }
1515
const numericLimit = parseInt(limit)
1616
if (numericLimit < 0) return { error: formError.monthlyLimitInvalid }
17-
const workspaceID = form.get("workspaceID")?.toString()
17+
const workspaceID = form.get("workspaceID") as string | null
1818
if (!workspaceID) return { error: formError.workspaceRequired }
1919
return json(
2020
await withActor(

packages/console/app/src/routes/workspace/[id]/billing/reload-section.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { formError, formErrorReloadAmountMin, formErrorReloadTriggerMin, localiz
1212

1313
const reload = action(async (form: FormData) => {
1414
"use server"
15-
const workspaceID = form.get("workspaceID")?.toString()
15+
const workspaceID = form.get("workspaceID") as string | null
1616
if (!workspaceID) return { error: formError.workspaceRequired }
1717
return json(await withActor(() => Billing.reload(), workspaceID), {
1818
revalidate: queryBillingInfo.key,
@@ -21,11 +21,11 @@ const reload = action(async (form: FormData) => {
2121

2222
const setReload = action(async (form: FormData) => {
2323
"use server"
24-
const workspaceID = form.get("workspaceID")?.toString()
24+
const workspaceID = form.get("workspaceID") as string | null
2525
if (!workspaceID) return { error: formError.workspaceRequired }
26-
const reloadValue = form.get("reload")?.toString() === "true"
27-
const amountStr = form.get("reloadAmount")?.toString()
28-
const triggerStr = form.get("reloadTrigger")?.toString()
26+
const reloadValue = (form.get("reload") as string | null) === "true"
27+
const amountStr = form.get("reloadAmount") as string | null
28+
const triggerStr = form.get("reloadTrigger") as string | null
2929

3030
const reloadAmount = amountStr && amountStr.trim() !== "" ? parseInt(amountStr) : null
3131
const reloadTrigger = triggerStr && triggerStr.trim() !== "" ? parseInt(triggerStr) : null
@@ -91,8 +91,8 @@ export function ReloadSection() {
9191
const info = billingInfo()!
9292
setStore("show", true)
9393
setStore("reload", true)
94-
setStore("reloadAmount", info.reloadAmount.toString())
95-
setStore("reloadTrigger", info.reloadTrigger.toString())
94+
setStore("reloadAmount", String(info.reloadAmount))
95+
setStore("reloadTrigger", String(info.reloadTrigger))
9696
}
9797

9898
function hide() {
@@ -152,11 +152,11 @@ export function ReloadSection() {
152152
data-component="input"
153153
name="reloadAmount"
154154
type="number"
155-
min={billingInfo()?.reloadAmountMin.toString()}
155+
min={String(billingInfo()?.reloadAmountMin ?? "")}
156156
step="1"
157157
value={store.reloadAmount}
158158
onInput={(e) => setStore("reloadAmount", e.currentTarget.value)}
159-
placeholder={billingInfo()?.reloadAmount.toString()}
159+
placeholder={String(billingInfo()?.reloadAmount ?? "")}
160160
disabled={!store.reload}
161161
/>
162162
</div>
@@ -166,11 +166,11 @@ export function ReloadSection() {
166166
data-component="input"
167167
name="reloadTrigger"
168168
type="number"
169-
min={billingInfo()?.reloadTriggerMin.toString()}
169+
min={String(billingInfo()?.reloadTriggerMin ?? "")}
170170
step="1"
171171
value={store.reloadTrigger}
172172
onInput={(e) => setStore("reloadTrigger", e.currentTarget.value)}
173-
placeholder={billingInfo()?.reloadTrigger.toString()}
173+
placeholder={String(billingInfo()?.reloadTrigger ?? "")}
174174
disabled={!store.reload}
175175
/>
176176
</div>

packages/console/app/src/routes/workspace/[id]/go/lite-section.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ const createSessionUrl = action(async (workspaceID: string, returnUrl: string) =
120120

121121
const setLiteUseBalance = action(async (form: FormData) => {
122122
"use server"
123-
const workspaceID = form.get("workspaceID")?.toString()
123+
const workspaceID = form.get("workspaceID") as string | null
124124
if (!workspaceID) return { error: formError.workspaceRequired }
125-
const useBalance = form.get("useBalance")?.toString() === "true"
125+
const useBalance = (form.get("useBalance") as string | null) === "true"
126126

127127
return json(
128128
await withActor(async () => {

packages/console/app/src/routes/workspace/[id]/keys/key-section.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ import { formError, localizeError } from "~/lib/form-error"
1212

1313
const removeKey = action(async (form: FormData) => {
1414
"use server"
15-
const id = form.get("id")?.toString()
15+
const id = form.get("id") as string | null
1616
if (!id) return { error: formError.idRequired }
17-
const workspaceID = form.get("workspaceID")?.toString()
17+
const workspaceID = form.get("workspaceID") as string | null
1818
if (!workspaceID) return { error: formError.workspaceRequired }
1919
return json(await withActor(() => Key.remove({ id }), workspaceID), { revalidate: listKeys.key })
2020
}, "key.remove")
2121

2222
const createKey = action(async (form: FormData) => {
2323
"use server"
24-
const name = form.get("name")?.toString().trim()
24+
const name = (form.get("name") as string | null)?.trim()
2525
if (!name) return { error: formError.nameRequired }
26-
const workspaceID = form.get("workspaceID")?.toString()
26+
const workspaceID = form.get("workspaceID") as string | null
2727
if (!workspaceID) return { error: formError.workspaceRequired }
2828
return json(
2929
await withActor(

packages/console/app/src/routes/workspace/[id]/members/member-section.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ const listMembers = query(async (workspaceID: string) => {
2424

2525
const inviteMember = action(async (form: FormData) => {
2626
"use server"
27-
const email = form.get("email")?.toString().trim()
27+
const email = (form.get("email") as string | null)?.trim()
2828
if (!email) return { error: formError.emailRequired }
29-
const workspaceID = form.get("workspaceID")?.toString()
29+
const workspaceID = form.get("workspaceID") as string | null
3030
if (!workspaceID) return { error: formError.workspaceRequired }
31-
const role = form.get("role")?.toString() as (typeof UserRole)[number]
31+
const role = form.get("role") as (typeof UserRole)[number] | null
3232
if (!role) return { error: formError.roleRequired }
33-
const limit = form.get("limit")?.toString()
33+
const limit = form.get("limit") as string | null
3434
const monthlyLimit = limit && limit.trim() !== "" ? parseInt(limit) : null
3535
if (monthlyLimit !== null && monthlyLimit < 0) return { error: formError.monthlyLimitInvalid }
3636
return json(
@@ -47,9 +47,9 @@ const inviteMember = action(async (form: FormData) => {
4747

4848
const removeMember = action(async (form: FormData) => {
4949
"use server"
50-
const id = form.get("id")?.toString()
50+
const id = form.get("id") as string | null
5151
if (!id) return { error: formError.idRequired }
52-
const workspaceID = form.get("workspaceID")?.toString()
52+
const workspaceID = form.get("workspaceID") as string | null
5353
if (!workspaceID) return { error: formError.workspaceRequired }
5454
return json(
5555
await withActor(
@@ -66,13 +66,13 @@ const removeMember = action(async (form: FormData) => {
6666
const updateMember = action(async (form: FormData) => {
6767
"use server"
6868

69-
const id = form.get("id")?.toString()
69+
const id = form.get("id") as string | null
7070
if (!id) return { error: formError.idRequired }
71-
const workspaceID = form.get("workspaceID")?.toString()
71+
const workspaceID = form.get("workspaceID") as string | null
7272
if (!workspaceID) return { error: formError.workspaceRequired }
73-
const role = form.get("role")?.toString() as (typeof UserRole)[number]
73+
const role = form.get("role") as (typeof UserRole)[number] | null
7474
if (!role) return { error: formError.roleRequired }
75-
const limit = form.get("limit")?.toString()
75+
const limit = form.get("limit") as string | null
7676
const monthlyLimit = limit && limit.trim() !== "" ? parseInt(limit) : null
7777
if (monthlyLimit !== null && monthlyLimit < 0) return { error: formError.monthlyLimitInvalid }
7878

@@ -118,7 +118,7 @@ function MemberRow(props: {
118118
}
119119
setStore("editing", true)
120120
setStore("selectedRole", props.member.role)
121-
setStore("limit", props.member.monthlyLimit?.toString() ?? "")
121+
setStore("limit", props.member.monthlyLimit != null ? String(props.member.monthlyLimit) : "")
122122
}
123123

124124
function hide() {

packages/console/app/src/routes/workspace/[id]/model-section.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ const getModelsInfo = query(async (workspaceID: string) => {
6767

6868
const updateModel = action(async (form: FormData) => {
6969
"use server"
70-
const model = form.get("model")?.toString()
70+
const model = form.get("model") as string | null
7171
if (!model) return { error: formError.modelRequired }
72-
const workspaceID = form.get("workspaceID")?.toString()
72+
const workspaceID = form.get("workspaceID") as string | null
7373
if (!workspaceID) return { error: formError.workspaceRequired }
74-
const enabled = form.get("enabled")?.toString() === "true"
74+
const enabled = (form.get("enabled") as string | null) === "true"
7575
return json(
7676
withActor(async () => {
7777
if (enabled) {
@@ -163,7 +163,7 @@ export function ModelSection() {
163163
<form action={updateModel} method="post">
164164
<input type="hidden" name="model" value={id} />
165165
<input type="hidden" name="workspaceID" value={params.id} />
166-
<input type="hidden" name="enabled" value={isEnabled().toString()} />
166+
<input type="hidden" name="enabled" value={String(isEnabled())} />
167167
<label data-slot="model-toggle-label">
168168
<input
169169
type="checkbox"

packages/console/app/src/routes/workspace/[id]/provider-section.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ function maskCredentials(credentials: string) {
2121

2222
const removeProvider = action(async (form: FormData) => {
2323
"use server"
24-
const provider = form.get("provider")?.toString()
24+
const provider = form.get("provider") as string | null
2525
if (!provider) return { error: formError.providerRequired }
26-
const workspaceID = form.get("workspaceID")?.toString()
26+
const workspaceID = form.get("workspaceID") as string | null
2727
if (!workspaceID) return { error: formError.workspaceRequired }
2828
return json(await withActor(() => Provider.remove({ provider }), workspaceID), {
2929
revalidate: listProviders.key,
@@ -32,11 +32,11 @@ const removeProvider = action(async (form: FormData) => {
3232

3333
const saveProvider = action(async (form: FormData) => {
3434
"use server"
35-
const provider = form.get("provider")?.toString()
36-
const credentials = form.get("credentials")?.toString()
35+
const provider = form.get("provider") as string | null
36+
const credentials = form.get("credentials") as string | null
3737
if (!provider) return { error: formError.providerRequired }
3838
if (!credentials) return { error: formError.apiKeyRequired }
39-
const workspaceID = form.get("workspaceID")?.toString()
39+
const workspaceID = form.get("workspaceID") as string | null
4040
if (!workspaceID) return { error: formError.workspaceRequired }
4141
return json(
4242
await withActor(
@@ -59,10 +59,13 @@ function ProviderRow(props: { provider: Provider }) {
5959
const params = useParams()
6060
const i18n = useI18n()
6161
const providers = createAsync(() => listProviders(params.id!))
62-
const saveSubmission = useSubmission(saveProvider, ([fd]) => fd.get("provider")?.toString() === props.provider.key)
62+
const saveSubmission = useSubmission(
63+
saveProvider,
64+
([fd]) => (fd.get("provider") as string | null) === props.provider.key,
65+
)
6366
const removeSubmission = useSubmission(
6467
removeProvider,
65-
([fd]) => fd.get("provider")?.toString() === props.provider.key,
68+
([fd]) => (fd.get("provider") as string | null) === props.provider.key,
6669
)
6770
const [store, setStore] = createStore({ editing: false })
6871

packages/console/app/src/routes/workspace/[id]/settings/settings-section.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ const getWorkspaceInfo = query(async (workspaceID: string) => {
3030

3131
const updateWorkspace = action(async (form: FormData) => {
3232
"use server"
33-
const name = form.get("name")?.toString().trim()
33+
const name = (form.get("name") as string | null)?.trim()
3434
if (!name) return { error: formError.workspaceNameRequired }
3535
if (name.length > 255) return { error: formError.nameTooLong }
36-
const workspaceID = form.get("workspaceID")?.toString()
36+
const workspaceID = form.get("workspaceID") as string | null
3737
if (!workspaceID) return { error: formError.workspaceRequired }
3838
return json(
3939
await withActor(

0 commit comments

Comments
 (0)