From fb16db64e7c0a57074ec4a54e3d064d87151233b Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 5 Apr 2026 20:26:20 +0000 Subject: [PATCH] =?UTF-8?q?Fix=20oxlint=20errors:=20non-null=20assertions,?= =?UTF-8?q?=20sort=E2=86=92toSorted,=20unused=20vars?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - cs-major-simulator.ts: replace 5 non-null assertions (!) with safe optional chaining / if-guards; replace 6 .sort() with .toSorted() - cs2-major-stage.ts: remove unused `inArray` import - cs2-setup.tsx: remove unused `assignedIds` variable https://claude.ai/code/session_019w21Nkf5TvTZHH6oVHaQXR --- app/models/cs2-major-stage.ts | 2 +- ...-seasons.$id.events.$eventId.cs2-setup.tsx | 3 -- .../simulations/cs-major-simulator.ts | 32 +++++++++---------- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/app/models/cs2-major-stage.ts b/app/models/cs2-major-stage.ts index 57d34b4..6a30bc5 100644 --- a/app/models/cs2-major-stage.ts +++ b/app/models/cs2-major-stage.ts @@ -14,7 +14,7 @@ import { database } from "~/database/context"; import { cs2MajorStageResults, participants } from "~/database/schema"; -import { eq, and, inArray, sql } from "drizzle-orm"; +import { eq, and, sql } from "drizzle-orm"; export interface Cs2StageResult { id: string; diff --git a/app/routes/admin.sports-seasons.$id.events.$eventId.cs2-setup.tsx b/app/routes/admin.sports-seasons.$id.events.$eventId.cs2-setup.tsx index c438ef8..4051206 100644 --- a/app/routes/admin.sports-seasons.$id.events.$eventId.cs2-setup.tsx +++ b/app/routes/admin.sports-seasons.$id.events.$eventId.cs2-setup.tsx @@ -119,9 +119,6 @@ export default function AdminCs2Setup() { const navigation = useNavigation(); const isSubmitting = navigation.state === 'submitting'; - // Build maps from existing stage results - const assignedIds = new Set(stageResults.map(r => r.participantId)); - // Stage assignment state (local, submitted via form) const [stageSelections, setStageSelections] = useState>(() => { const initial: Record = {}; diff --git a/app/services/simulations/cs-major-simulator.ts b/app/services/simulations/cs-major-simulator.ts index f9d72e8..425606a 100644 --- a/app/services/simulations/cs-major-simulator.ts +++ b/app/services/simulations/cs-major-simulator.ts @@ -120,7 +120,7 @@ export function sampleField( pool: TeamWithElo[], fieldSize: number = FIELD_SIZE ): TeamWithElo[] { - const sorted = [...pool].sort((a, b) => a.rank - b.rank); + const sorted = [...pool].toSorted((a, b) => a.rank - b.rank); if (sorted.length <= fieldSize) return sorted; @@ -146,8 +146,8 @@ function weightedSampleWithoutReplacement( ): T[] { const keys = weights.map((w) => -Math.log(Math.random()) / w); const indexed = items.map((item, i) => ({ item, key: keys[i] })); - indexed.sort((a, b) => a.key - b.key); - return indexed.slice(0, count).map((x) => x.item); + const sortedIndexed = indexed.toSorted((a, b) => a.key - b.key); + return sortedIndexed.slice(0, count).map((x) => x.item); } // ─── Swiss stage simulation ─────────────────────────────────────────────────── @@ -213,13 +213,13 @@ export function simulateSwiss(teams: TeamWithElo[], bo3: boolean): SwissResult { if ((wins.get(winnerId) ?? 0) >= 3) { advancedIds.add(winnerId); - const t = teamById.get(winnerId)!; - advanced.push({ id: t.id, elo: t.elo, rank: t.rank }); + const t = teamById.get(winnerId); + if (t) advanced.push({ id: t.id, elo: t.elo, rank: t.rank }); } if ((losses.get(loserId) ?? 0) >= 3) { eliminatedIds.add(loserId); - const t = teamById.get(loserId)!; - eliminated.push({ id: t.id, elo: t.elo, rank: t.rank, wins: wins.get(loserId) ?? 0 }); + const t = teamById.get(loserId); + if (t) eliminated.push({ id: t.id, elo: t.elo, rank: t.rank, wins: wins.get(loserId) ?? 0 }); } } } @@ -237,7 +237,7 @@ function groupByRecord( for (const t of active) { const key = `${wins.get(t.id) ?? 0}-${losses.get(t.id) ?? 0}`; if (!groups.has(key)) groups.set(key, []); - groups.get(key)!.push(t); + groups.get(key)?.push(t); } return groups; } @@ -287,7 +287,7 @@ export function simulateChampionsStage(teams: TeamWithElo[]): ChampionsResult { } // Seed by rank ascending - const seeded = [...teams].sort((a, b) => a.rank - b.rank); + const seeded = [...teams].toSorted((a, b) => a.rank - b.rank); // Standard 8-team seeding: 1v8, 4v5, 3v6, 2v7 const bracket: [TeamWithElo, TeamWithElo][] = [ [seeded[0], seeded[7]], @@ -353,12 +353,12 @@ function calcStage3ExitQP( const byWins = new Map(); for (const t of elimTeams) { if (!byWins.has(t.wins)) byWins.set(t.wins, []); - byWins.get(t.wins)!.push(t.id); + byWins.get(t.wins)?.push(t.id); } // Assign placement slots 9–16 from highest wins first const result = new Map(); - const winsGroups = [...byWins.entries()].sort((a, b) => b[0] - a[0]); // descending wins + const winsGroups = [...byWins.entries()].toSorted((a, b) => b[0] - a[0]); // descending wins let slotStart = 9; for (const [, ids] of winsGroups) { @@ -415,10 +415,10 @@ export class CSMajorSimulator implements Simulator { const pool: TeamWithElo[] = participantIds .filter((id) => eloMap.has(id)) .map((id) => { - const e = eloMap.get(id)!; - return { id, elo: e.elo, rank: e.rank }; + const e = eloMap.get(id); + return { id, elo: e?.elo ?? FALLBACK_ELO, rank: e?.rank ?? 9999 }; }) - .sort((a, b) => a.rank - b.rank); + .toSorted((a, b) => a.rank - b.rank); if (pool.length === 0) { throw new Error( @@ -497,7 +497,7 @@ export class CSMajorSimulator implements Simulator { } // Rank all participants by total QP descending. - const ranked = [...simQP.entries()].sort((a, b) => b[1] - a[1]); + const ranked = [...simQP.entries()].toSorted((a, b) => b[1] - a[1]); for (let rank = 0; rank < Math.min(8, ranked.length); rank++) { const [pid] = ranked[rank]; const idx = idToIndex.get(pid); @@ -564,7 +564,7 @@ function simulateOneMajor( stage3Direct = s3; } else { const field = sampleField(pool, FIELD_SIZE); - const sorted = [...field].sort((a, b) => a.rank - b.rank); + const sorted = field.toSorted((a, b) => a.rank - b.rank); stage3Direct = sorted.slice(0, 8); stage2Direct = sorted.slice(8, 16); stage1Teams = sorted.slice(16, 32);