Fix lint failures: unused vars, eqeqeq, toSorted
- Remove unused seededSet/unseededSet variables in test - Replace != null with !== null && !== undefined (eqeqeq rule) - Replace .sort() with .toSorted() in simulator and route (unicorn/no-array-sort) https://claude.ai/code/session_01WZ6FjMmC2eBeZ1564M9Ruz
This commit is contained in:
parent
585dc9e112
commit
64e8024c62
3 changed files with 6 additions and 12 deletions
|
|
@ -195,7 +195,7 @@ export default function AdminSportsSeasonDartsElo() {
|
||||||
const initial: Record<string, string> = {};
|
const initial: Record<string, string> = {};
|
||||||
participants.forEach(p => {
|
participants.forEach(p => {
|
||||||
const d = existingData[p.id];
|
const d = existingData[p.id];
|
||||||
if (d?.elo != null) initial[p.id] = d.elo.toString();
|
if (d?.elo !== null && d?.elo !== undefined) initial[p.id] = d.elo.toString();
|
||||||
});
|
});
|
||||||
return initial;
|
return initial;
|
||||||
});
|
});
|
||||||
|
|
@ -204,7 +204,7 @@ export default function AdminSportsSeasonDartsElo() {
|
||||||
const initial: Record<string, string> = {};
|
const initial: Record<string, string> = {};
|
||||||
participants.forEach(p => {
|
participants.forEach(p => {
|
||||||
const d = existingData[p.id];
|
const d = existingData[p.id];
|
||||||
if (d?.ranking != null) initial[p.id] = d.ranking.toString();
|
if (d?.ranking !== null && d?.ranking !== undefined) initial[p.id] = d.ranking.toString();
|
||||||
});
|
});
|
||||||
return initial;
|
return initial;
|
||||||
});
|
});
|
||||||
|
|
@ -292,7 +292,7 @@ export default function AdminSportsSeasonDartsElo() {
|
||||||
const isSubmitting = navigation.state === 'submitting';
|
const isSubmitting = navigation.state === 'submitting';
|
||||||
|
|
||||||
// Sort participants for display: by current rank (ascending), then unranked alphabetically
|
// Sort participants for display: by current rank (ascending), then unranked alphabetically
|
||||||
const sortedParticipants = [...participants].sort((a, b) => {
|
const sortedParticipants = [...participants].toSorted((a, b) => {
|
||||||
const rankA = rankValues[a.id] ? parseInt(rankValues[a.id], 10) : null;
|
const rankA = rankValues[a.id] ? parseInt(rankValues[a.id], 10) : null;
|
||||||
const rankB = rankValues[b.id] ? parseInt(rankValues[b.id], 10) : null;
|
const rankB = rankValues[b.id] ? parseInt(rankValues[b.id], 10) : null;
|
||||||
if (rankA !== null && rankB !== null) return rankA - rankB;
|
if (rankA !== null && rankB !== null) return rankA - rankB;
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@ describe("getSeededMatchOrder", () => {
|
||||||
it("for n=32, contains all seeds 1–32 exactly once", () => {
|
it("for n=32, contains all seeds 1–32 exactly once", () => {
|
||||||
const order = getSeededMatchOrder(32);
|
const order = getSeededMatchOrder(32);
|
||||||
expect(order).toHaveLength(32);
|
expect(order).toHaveLength(32);
|
||||||
const sorted = [...order].sort((a, b) => a - b);
|
const sorted = [...order].toSorted((a, b) => a - b);
|
||||||
expect(sorted).toEqual(Array.from({ length: 32 }, (_, i) => i + 1));
|
expect(sorted).toEqual(Array.from({ length: 32 }, (_, i) => i + 1));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -140,11 +140,7 @@ describe("buildR1Bracket", () => {
|
||||||
const allPlayers = pairs.flat();
|
const allPlayers = pairs.flat();
|
||||||
expect(allPlayers).toHaveLength(128);
|
expect(allPlayers).toHaveLength(128);
|
||||||
|
|
||||||
const seededSet = new Set(seeded);
|
|
||||||
const unseededSet = new Set(unseeded);
|
|
||||||
for (const [a, b] of pairs) {
|
for (const [a, b] of pairs) {
|
||||||
// Each pair has one seeded and one unseeded (first 32 pairs),
|
|
||||||
// or two unseeded (last 32 pairs).
|
|
||||||
expect(a).toBeTruthy();
|
expect(a).toBeTruthy();
|
||||||
expect(b).toBeTruthy();
|
expect(b).toBeTruthy();
|
||||||
}
|
}
|
||||||
|
|
@ -162,8 +158,6 @@ describe("buildR1Bracket", () => {
|
||||||
|
|
||||||
it("each of the 32 seeded players faces an unseeded opponent in their R1 match", () => {
|
it("each of the 32 seeded players faces an unseeded opponent in their R1 match", () => {
|
||||||
const pairs = buildR1Bracket(seeded, unseeded);
|
const pairs = buildR1Bracket(seeded, unseeded);
|
||||||
const unseededSet = new Set(unseeded);
|
|
||||||
const seededSet = new Set(seeded);
|
|
||||||
|
|
||||||
// First 32 pairs: seeded vs unseeded
|
// First 32 pairs: seeded vs unseeded
|
||||||
for (let i = 0; i < 32; i++) {
|
for (let i = 0; i < 32; i++) {
|
||||||
|
|
@ -429,7 +423,7 @@ describe("DartsSimulator.simulate() — Path B (pre-bracket)", () => {
|
||||||
const sim = new DartsSimulator();
|
const sim = new DartsSimulator();
|
||||||
const results = await sim.simulate("season-1");
|
const results = await sim.simulate("season-1");
|
||||||
|
|
||||||
const sorted = [...results].sort((a, b) => b.probabilities.probFirst - a.probabilities.probFirst);
|
const sorted = [...results].toSorted((a, b) => b.probabilities.probFirst - a.probabilities.probFirst);
|
||||||
// player-1 is world #1 with the highest Elo — should have highest win probability
|
// player-1 is world #1 with the highest Elo — should have highest win probability
|
||||||
expect(sorted[0].participantId).toBe("player-1");
|
expect(sorted[0].participantId).toBe("player-1");
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -461,7 +461,7 @@ export class DartsSimulator implements Simulator {
|
||||||
|
|
||||||
// Sort participants by world ranking (ascending). Fall back to Elo order (descending) for
|
// Sort participants by world ranking (ascending). Fall back to Elo order (descending) for
|
||||||
// any without a ranking, then alphabetical as a final tiebreak.
|
// any without a ranking, then alphabetical as a final tiebreak.
|
||||||
const sorted = [...allParticipants].sort((a, b) => {
|
const sorted = [...allParticipants].toSorted((a, b) => {
|
||||||
const rankA = rankingMap.get(a.id);
|
const rankA = rankingMap.get(a.id);
|
||||||
const rankB = rankingMap.get(b.id);
|
const rankB = rankingMap.get(b.id);
|
||||||
if (rankA !== undefined && rankB !== undefined) return rankA - rankB;
|
if (rankA !== undefined && rankB !== undefined) return rankA - rankB;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue