Skip to content

Commit 830ed10

Browse files
committed
dev: run prettier in precommit, style: run prettier again
1 parent 92bc838 commit 830ed10

File tree

22 files changed

+378
-270
lines changed

22 files changed

+378
-270
lines changed

.github/workflows/static.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- run: bun install --frozen-lockfile
2121
- run: bun check
2222
- run: biome lint .
23-
- run: biome format .
23+
- run: bun prettier --check .
2424
nix-checks:
2525
name: Nix checks
2626
runs-on: ubuntu-latest

.helix/languages.toml

+2-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# [language-server]
2-
# deno = { command = "deno", args = ["lsp"] }
3-
41
[[language]]
52
name = "nix"
63
formatter.command = "alejandra"
@@ -26,17 +23,9 @@ language-servers = [
2623

2724
[[language]]
2825
name = "svelte"
29-
formatter = { command = "biome", args = [
30-
"format",
31-
"--stdin-file-path",
32-
"a.svelte",
33-
] }
26+
formatter = { command = "prettier", args = ["--parser=svelte"] }
3427
language-servers = ["tailwindcss-ls", "svelteserver"]
3528

3629
[[language]]
3730
name = "typescript"
38-
formatter = { command = "biome", args = [
39-
"format",
40-
"--stdin-file-path",
41-
"a.ts",
42-
] }
31+
formatter = { command = "prettier", args = ["--parser=typescript"] }

biome.jsonc

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"ignore": [],
1111
},
1212
"formatter": {
13-
"enabled": true, // HTML-ish support when?
13+
"enabled": false, // HTML-ish support when?
1414
"lineWidth": 120,
1515
"indentStyle": "space",
1616
"indentWidth": 2,

lefthook.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ pre-commit:
2929
run: cd service; bun run cf-typegen
3030
stage_fixed: true
3131
# JS
32-
biome-fmt:
32+
prettier:
3333
tags: js style
34-
glob: "*.{js,ts,svelte,html,md}"
35-
run: biome format {staged_files} --fix
34+
glob: "*.{js,ts,svelte,json,jsonc,yaml,html,md}"
35+
run: bun prettier {staged_files} --write
3636
stage_fixed: true
3737
biome-lint:
3838
tags: js lint

service/features/auth/index.ts

+38-8
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ type AuthInfo = {
2828
info: NoAuth;
2929
};
3030

31-
export async function signup(c: Context, auth: AuthInfo): Promise<SelectAccount> {
31+
export async function signup(
32+
c: Context,
33+
auth: AuthInfo,
34+
): Promise<SelectAccount> {
3235
const browser_id = await getBrowserID(c);
3336
const prev = await _findAccount(c, auth);
3437
if (prev) {
@@ -45,36 +48,63 @@ export async function signup(c: Context, auth: AuthInfo): Promise<SelectAccount>
4548
})
4649
.returning()
4750
)[0];
48-
if (!account) throw new HTTPException(500, { message: "Failed to create account" });
51+
if (!account)
52+
throw new HTTPException(500, { message: "Failed to create account" });
4953
return account;
5054
}
5155

5256
// TODO: implement authentication
53-
export async function login(c: Context, auth: AuthInfo): Promise<SelectAccount> {
57+
export async function login(
58+
c: Context,
59+
auth: AuthInfo,
60+
): Promise<SelectAccount> {
5461
const acc = await _findAccount(c, auth);
5562
if (acc) {
56-
setSignedCookie(c, cookie_identifier__browser_id, acc.browser_id, GET_COOKIE_SIGN(c), cookieOptions);
63+
setSignedCookie(
64+
c,
65+
cookie_identifier__browser_id,
66+
acc.browser_id,
67+
GET_COOKIE_SIGN(c),
68+
cookieOptions,
69+
);
5770
return acc;
5871
}
5972
throw new HTTPException(404, { message: "account not found" });
6073
}
6174

6275
// creates new one if necessary.
6376
export async function getBrowserID(c: Context): Promise<string> {
64-
const cookie = await getSignedCookie(c, GET_COOKIE_SIGN(c), cookie_identifier__browser_id);
77+
const cookie = await getSignedCookie(
78+
c,
79+
GET_COOKIE_SIGN(c),
80+
cookie_identifier__browser_id,
81+
);
6582
if (cookie) {
6683
return cookie;
6784
}
6885
const browser_id = crypto.randomUUID();
69-
await setSignedCookie(c, cookie_identifier__browser_id, browser_id, GET_COOKIE_SIGN(c), cookieOptions);
86+
await setSignedCookie(
87+
c,
88+
cookie_identifier__browser_id,
89+
browser_id,
90+
GET_COOKIE_SIGN(c),
91+
cookieOptions,
92+
);
7093
return browser_id;
7194
}
7295

7396
// TODO: implement authentication
74-
async function _findAccount(c: Context, auth: AuthInfo): Promise<SelectAccount | undefined> {
97+
async function _findAccount(
98+
c: Context,
99+
auth: AuthInfo,
100+
): Promise<SelectAccount | undefined> {
75101
switch (auth.kind) {
76102
case "none": {
77-
const accountsResult = await db(c).select().from(accounts).where(eq(accounts.name, auth.info.name)).limit(1);
103+
const accountsResult = await db(c)
104+
.select()
105+
.from(accounts)
106+
.where(eq(accounts.name, auth.info.name))
107+
.limit(1);
78108
return accountsResult[0]; // findUnique をしたかった
79109
}
80110
default:

service/lib.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,20 @@ import type { Context } from "hono";
22
import { env as _env } from "hono/adapter";
33
import { panic } from "share/lib.ts";
44

5-
export function env(ctx: Context, name: string, options: { fallback?: string } = {}) {
6-
return _env(ctx)?.[name] ?? options.fallback ?? panic(`env var "${name}" not found in environment!`);
5+
export function env(
6+
ctx: Context,
7+
name: string,
8+
options: { fallback?: string } = {},
9+
) {
10+
return (
11+
_env(ctx)?.[name] ??
12+
options.fallback ??
13+
panic(`env var "${name}" not found in environment!`)
14+
);
715
}
816

917
export function process_env(name: string) {
10-
return process.env[name] ?? panic(`env var "${name}" not found in environment!`);
18+
return (
19+
process.env[name] ?? panic(`env var "${name}" not found in environment!`)
20+
);
1121
}

service/routes/projects/index.ts

+57-23
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ import { and, eq, exists } from "drizzle-orm";
22
import { Hono } from "hono";
33
import { HTTPException } from "hono/http-exception";
44
import { db } from "service/db/client.ts";
5-
import { matches, participants, projects, ratings, roles } from "service/db/schema.ts";
5+
import {
6+
matches,
7+
participants,
8+
projects,
9+
ratings,
10+
roles,
11+
} from "service/db/schema.ts";
612
import { getBrowserID } from "service/features/auth/index.ts";
713
import type { HonoOptions } from "service/types.ts";
814
import { json, param } from "service/validator/hono.ts";
@@ -42,7 +48,11 @@ const route = new Hono<HonoOptions>()
4248
async (c) => {
4349
const browser_id = await getBrowserID(c);
4450
const projectId = c.req.valid("param").projectId;
45-
const project_resp = db(c).select().from(projects).where(eq(projects.id, projectId)).execute();
51+
const project_resp = db(c)
52+
.select()
53+
.from(projects)
54+
.where(eq(projects.id, projectId))
55+
.execute();
4656
const project = project_resp.then((it) => {
4757
const project = it[0];
4858
if (!project) {
@@ -108,7 +118,8 @@ const route = new Hono<HonoOptions>()
108118
])
109119
.returning()
110120
)[0];
111-
if (!project_resp) throw new HTTPException(500, { message: "failed to create project" });
121+
if (!project_resp)
122+
throw new HTTPException(500, { message: "failed to create project" });
112123
await db(c)
113124
.insert(participants)
114125
.values([
@@ -138,23 +149,32 @@ const route = new Hono<HonoOptions>()
138149
roles: roles_resp,
139150
});
140151
})
141-
.delete("/:projectId", param({ projectId: v.pipe(v.string(), v.uuid()) }), async (c) => {
142-
const browser_id = await getBrowserID(c);
143-
const { projectId: project_id } = c.req.valid("param");
144-
const d = db(c);
145-
await d.delete(projects).where(
146-
and(
147-
eq(projects.id, project_id),
148-
exists(
149-
d
150-
.select()
151-
.from(participants)
152-
.where(and(eq(participants.browser_id, browser_id), eq(participants.is_admin, 1))),
152+
.delete(
153+
"/:projectId",
154+
param({ projectId: v.pipe(v.string(), v.uuid()) }),
155+
async (c) => {
156+
const browser_id = await getBrowserID(c);
157+
const { projectId: project_id } = c.req.valid("param");
158+
const d = db(c);
159+
await d.delete(projects).where(
160+
and(
161+
eq(projects.id, project_id),
162+
exists(
163+
d
164+
.select()
165+
.from(participants)
166+
.where(
167+
and(
168+
eq(participants.browser_id, browser_id),
169+
eq(participants.is_admin, 1),
170+
),
171+
),
172+
),
153173
),
154-
),
155-
);
156-
return c.json({ ok: true }, 200);
157-
})
174+
);
175+
return c.json({ ok: true }, 200);
176+
},
177+
)
158178

159179
.put("/:projectId/finalize", param({ projectId: v.string() }), async (c) => {
160180
const browser_id = await getBrowserID(c);
@@ -165,7 +185,10 @@ const route = new Hono<HonoOptions>()
165185
const participant_resp = await db(c)
166186
.select()
167187
.from(participants)
168-
.where(eq(participants.browser_id, browser_id) && eq(participants.project_id, c.req.param("projectId")));
188+
.where(
189+
eq(participants.browser_id, browser_id) &&
190+
eq(participants.project_id, c.req.param("projectId")),
191+
);
169192
if (participant_resp[0]?.is_admin !== 1) {
170193
return c.json({ message: "Unauthorized" }, 401);
171194
}
@@ -183,7 +206,10 @@ const route = new Hono<HonoOptions>()
183206
.where(eq(ratings.project_id, projectId))
184207
.orderBy(ratings.participant_id, ratings.role_id);
185208

186-
const ratingsByParticipant = Map.groupBy(participantsData, (item) => item.participant_id);
209+
const ratingsByParticipant = Map.groupBy(
210+
participantsData,
211+
(item) => item.participant_id,
212+
);
187213

188214
const ratingsArray: number[][] = []; // TODO: 型付けをマシにする
189215
const participantIndexIdMap: string[] = [];
@@ -193,13 +219,21 @@ const route = new Hono<HonoOptions>()
193219
participantIndexIdMap.push(r[0]?.participant_id ?? "-");
194220
});
195221

196-
const roleConstraints = await db(c).select().from(roles).where(eq(roles.project_id, projectId)).orderBy(roles.id);
222+
const roleConstraints = await db(c)
223+
.select()
224+
.from(roles)
225+
.where(eq(roles.project_id, projectId))
226+
.orderBy(roles.id);
197227
const minMaxConstraints = roleConstraints.map((role) => ({
198228
min: role.min,
199229
max: role.max,
200230
}));
201231

202-
const result = assignRoles(ratingsArray, at(ratingsArray, 0).length, minMaxConstraints);
232+
const result = assignRoles(
233+
ratingsArray,
234+
at(ratingsArray, 0).length,
235+
minMaxConstraints,
236+
);
203237

204238
await db(c)
205239
.insert(matches)

service/routes/projects/preferences.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,20 @@ const route = new Hono<HonoOptions>()
8686
.set({
8787
name: body.participantName,
8888
})
89-
.where(and(eq(participants.browser_id, browser_id), eq(participants.is_admin, 0)))
89+
.where(
90+
and(
91+
eq(participants.browser_id, browser_id),
92+
eq(participants.is_admin, 0),
93+
),
94+
)
9095
.returning({ id: participants.id })
9196
)[0];
92-
if (!participant) throw new HTTPException(500, { message: "failed to find participant" });
97+
if (!participant)
98+
throw new HTTPException(500, { message: "failed to find participant" });
9399

94-
await db(c).delete(ratings).where(eq(ratings.participant_id, participant.id));
100+
await db(c)
101+
.delete(ratings)
102+
.where(eq(ratings.participant_id, participant.id));
95103
await db(c)
96104
.insert(ratings)
97105
.values(

service/validator/hono.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { vValidator } from "@hono/valibot-validator";
2-
import { type BaseIssue, type BaseSchema, type ObjectEntries, object } from "valibot";
2+
import {
3+
type BaseIssue,
4+
type BaseSchema,
5+
type ObjectEntries,
6+
object,
7+
} from "valibot";
38

49
export function param<T extends ObjectEntries>(values: T) {
510
return vValidator("param", object(values));
@@ -9,6 +14,8 @@ export function query<T extends ObjectEntries>(values: T) {
914
return vValidator("param", object(values));
1015
}
1116

12-
export function json<T extends BaseSchema<unknown, unknown, BaseIssue<unknown>>>(schema: T) {
17+
export function json<
18+
T extends BaseSchema<unknown, unknown, BaseIssue<unknown>>,
19+
>(schema: T) {
1320
return vValidator("json", schema);
1421
}

share/lib.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export function assert(cond: boolean, message?: string) {
1616
}
1717
export function at<T>(list: T[], idx: number): T {
1818
const elem = list[idx];
19-
if (elem === undefined) throw new Error(`elemAt: item not found at index ${idx} in list`);
19+
if (elem === undefined)
20+
throw new Error(`elemAt: item not found at index ${idx} in list`);
2021
return elem;
2122
}

share/logic/min-flow.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ export function assignRoles(
2424
sumMax += minMaxConstraints[j]?.max ?? 0;
2525
}
2626
if (sumMin > P) {
27-
throw new Error("割当可能な participant 数が制約を満たしません(sum(min) > participants.length)");
27+
throw new Error(
28+
"割当可能な participant 数が制約を満たしません(sum(min) > participants.length)",
29+
);
2830
}
2931

3032
// 拡張用配列:dummy role を追加するかどうか
@@ -55,7 +57,11 @@ export function assignRoles(
5557
// distribution: dist[0..M_ext-1] で、各 extended role j に割り当てる参加者数
5658
// 条件: extendedConstraints[j].min <= d[j] <= extendedConstraints[j].max, ∑ d[j] = P
5759
const distributions: number[][] = [];
58-
function enumerateDistribution(index: number, current: number[], remaining: number) {
60+
function enumerateDistribution(
61+
index: number,
62+
current: number[],
63+
remaining: number,
64+
) {
5965
if (index === M_ext) {
6066
if (remaining === 0) {
6167
distributions.push(current.slice());
@@ -129,7 +135,10 @@ export function assignRoles(
129135
const result: { participant: number; role: number }[] = [];
130136
for (let i = 0; i < P; i++) {
131137
// const assignedRole = bestMatching.roleForColumn[bestMatching.assignment[i]];
132-
const assignedRole = at(bestMatching.roleForColumn, at(bestMatching.assignment, i));
138+
const assignedRole = at(
139+
bestMatching.roleForColumn,
140+
at(bestMatching.assignment, i),
141+
);
133142
// dummy roleの場合は -1 として返す(必要に応じて処理してください)
134143
result.push({ participant: i, role: assignedRole < M ? assignedRole : -1 });
135144
}

0 commit comments

Comments
 (0)