Fix oxlint errors in NHL simulator and tests

- Replace non-null assertions (data!) with optional chaining (data?.x ?? "")
- Move makeEntry helper to module scope to avoid recreating on every call

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Chris Parsons 2026-04-09 01:27:22 +00:00
parent 721b069b1c
commit a67fe32c52
2 changed files with 18 additions and 17 deletions

View file

@ -78,8 +78,8 @@ describe("getTeamData", () => {
]; ];
for (const name of allTeams) { for (const name of allTeams) {
const data = getTeamData(name); const data = getTeamData(name);
expect(validConferences.has(data!.conference), `${name}: invalid conference`).toBe(true); expect(validConferences.has(data?.conference ?? ""), `${name}: invalid conference`).toBe(true);
expect(validDivisions.has(data!.division), `${name}: invalid division`).toBe(true); expect(validDivisions.has(data?.division ?? ""), `${name}: invalid division`).toBe(true);
} }
}); });
@ -122,21 +122,22 @@ describe("eloWinProbability (PARITY_FACTOR = 1000)", () => {
// ─── simulateProjectedPoints ────────────────────────────────────────────────── // ─── simulateProjectedPoints ──────────────────────────────────────────────────
const makeEntry = (overrides: Partial<{
currentPoints: number;
remainingGames: number;
winProb: number;
}> = {}) => ({
id: "test",
name: "Test Team",
data: undefined,
conference: "Western" as const,
division: "Central",
currentPoints: overrides.currentPoints ?? 80,
remainingGames: overrides.remainingGames ?? 10,
winProb: overrides.winProb ?? 0.55,
});
describe("simulateProjectedPoints", () => { describe("simulateProjectedPoints", () => {
const makeEntry = (overrides: Partial<{
currentPoints: number;
remainingGames: number;
winProb: number;
}> = {}) => ({
id: "test",
name: "Test Team",
data: undefined,
conference: "Western" as const,
division: "Central",
currentPoints: overrides.currentPoints ?? 80,
remainingGames: overrides.remainingGames ?? 10,
winProb: overrides.winProb ?? 0.55,
});
it("returns exactly currentPoints when no games remain", () => { it("returns exactly currentPoints when no games remain", () => {
const entry = makeEntry({ currentPoints: 95, remainingGames: 0 }); const entry = makeEntry({ currentPoints: 95, remainingGames: 0 });

View file

@ -245,7 +245,7 @@ function projectTeam(t: TeamEntry): ProjectedTeam {
/** Sort projected teams descending by pts, then by random tiebreaker. Mutates arr. */ /** Sort projected teams descending by pts, then by random tiebreaker. Mutates arr. */
function sortProjected(arr: ProjectedTeam[]): ProjectedTeam[] { function sortProjected(arr: ProjectedTeam[]): ProjectedTeam[] {
return arr.sort((a, b) => b.pts - a.pts || b.tb - a.tb); return arr.toSorted((a, b) => b.pts - a.pts || b.tb - a.tb);
} }
// ─── Simulator ──────────────────────────────────────────────────────────────── // ─── Simulator ────────────────────────────────────────────────────────────────