Skip to content

Commit

Permalink
ESLint
Browse files Browse the repository at this point in the history
  • Loading branch information
rbtying committed Dec 3, 2024
1 parent 21ddcb5 commit 4dada04
Show file tree
Hide file tree
Showing 31 changed files with 173 additions and 109 deletions.
21 changes: 21 additions & 0 deletions frontend/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// @ts-check

import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';

export default tseslint.config(
eslint.configs.recommended,
tseslint.configs.recommended,
{
ignores: ["**/generated/**"]
},
{
rules: {
"@typescript-eslint/no-unused-vars": [
"error",
{ argsIgnorePattern: "^_", varsIgnorePattern: "^_" },
],
"@typescript-eslint/no-explicit-any": "off",
}
}
);
2 changes: 1 addition & 1 deletion frontend/src/AppStateProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const appState: State<AppState> = combineState({
roomName: noPersistence(() => window.location.hash.slice(1, 17)),
name: stringLocalStorageState("name"),
changeLogLastViewed: numberLocalStorageState("change_log_last_viewed"),
gameState: noPersistence<GameState>(() => null),
gameState: noPersistence<GameState | null>(() => null),
headerMessages: noPersistence<string[]>(() => []),
errors: noPersistence<string[]>(() => []),
messages: noPersistence<Message[]>(() => []),
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ const computeCanvasBounds = (font: string, dpr: number): TextMetrics => {
c.style.display = "none";
document.body.appendChild(c);
const ctx = c.getContext("2d");
if (ctx === null) {
throw new Error("Could not get 2d context");
}
ctx.scale(dpr, dpr);
ctx.font = font;
const text = "🂠";
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/Cards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const Cards = (props: IProps): JSX.Element => {
const handleUnselect = (card: string) => () => {
if (selectedCards !== undefined) {
const index = selectedCards.indexOf(card);
if (index >= 0) {
if (index >= 0 && props.onSelect) {
props.onSelect(ArrayUtils.minus(selectedCards, [card]));
}
}
Expand Down
22 changes: 12 additions & 10 deletions frontend/src/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,19 @@ const Chat = (props: IProps): JSX.Element => {
const handleSubmit = (message: string): void => send({ Message: message });

return (
!settings.hideChatBox && (
<div className="chat">
<div className="messages">
{props.messages.map((m, idx) => (
<ChatMessage message={m} key={idx} />
))}
<div className="chat-anchor" ref={anchor} />
<>
{!settings.hideChatBox && (
<div className="chat">
<div className="messages">
{props.messages.map((m, idx) => (
<ChatMessage message={m} key={idx} />
))}
<div className="chat-anchor" ref={anchor} />
</div>
<ChatInput onSubmit={handleSubmit} />
</div>
<ChatInput onSubmit={handleSubmit} />
</div>
)
)}
</>
);
};

Expand Down
8 changes: 4 additions & 4 deletions frontend/src/ChatMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const renderMessage = (message: Message): JSX.Element => {
case "MadeBid":
return (
<span>
{message.data.actor_name} bid{" "}
{message.data?.actor_name} bid{" "}
{ArrayUtil.range(variant.count, (i) => (
<InlineCard card={variant.card} key={i} />
))}
Expand All @@ -26,7 +26,7 @@ const renderMessage = (message: Message): JSX.Element => {
case "PlayedCards":
return (
<span>
{message.data.actor_name} played{" "}
{message.data?.actor_name} played{" "}
{variant.cards.map((card, i) => (
<InlineCard card={card} key={i} />
))}
Expand Down Expand Up @@ -119,11 +119,11 @@ const renderScoringMessage = (message: Message): JSX.Element => {
}
return (
<span>
{message.data.actor_name} updated the scoring parameters: {changes}
{message.data?.actor_name} updated the scoring parameters: {changes}
</span>
);
} else {
return null;
return <></>;
}
};

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/Confetti.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const Confetti = (props: IProps): JSX.Element => {
particleCount: particleCount,
origin: { x: randomInRange(0.2, 0.8), y: Math.random() - 0.2 },
angle: randomInRange(65, 115),
}).then(
})!.then(
() => {},
() => {},
);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/DebugInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from "react";
import { AppStateContext } from "./AppStateProvider";

export const DebugInfo = (_props: {}): JSX.Element => {
export const DebugInfo = (_props: unknown): JSX.Element => {
const appState = React.useContext(AppStateContext);

return (
Expand Down
22 changes: 13 additions & 9 deletions frontend/src/Draw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,29 +151,29 @@ class Draw extends React.Component<IDrawProps, IDrawState> {
/>
<BidArea
bids={this.props.state.bids}
autobid={this.props.state.autobid}
autobid={this.props.state.autobid!}
hands={this.props.state.hands}
epoch={0}
name={this.props.name}
trump={trump}
landlord={landlord}
landlord={landlord!}
players={this.props.state.propagated.players}
bidPolicy={this.props.state.propagated.bid_policy}
bidPolicy={this.props.state.propagated.bid_policy!}
bidReinforcementPolicy={
this.props.state.propagated.bid_reinforcement_policy
this.props.state.propagated.bid_reinforcement_policy!
}
jokerBidPolicy={this.props.state.propagated.joker_bid_policy}
jokerBidPolicy={this.props.state.propagated.joker_bid_policy!}
numDecks={this.props.state.num_decks}
header={
<>
<h2>
Bids ({this.props.state.deck.length} cards remaining in the
deck)
</h2>
{this.props.state.removed_cards.length > 0 ? (
{this.props.state.removed_cards!.length > 0 ? (
<p>
Note:{" "}
{this.props.state.removed_cards.map((c) => (
{this.props.state.removed_cards!.map((c) => (
<InlineCard key={c} card={c} />
))}{" "}
have been removed from the deck
Expand Down Expand Up @@ -212,7 +212,11 @@ class Draw extends React.Component<IDrawProps, IDrawState> {
this.props.state.deck.length > 0 ||
(this.props.state.bids.length === 0 &&
this.props.state.autobid === null &&
!(landlord !== null && players[landlord].level === "NT")) ||
!(
landlord !== null &&
landlord !== undefined &&
players[landlord].level === "NT"
)) ||
(landlord !== null && landlord !== playerId) ||
(landlord === null &&
((this.props.state.propagated
Expand All @@ -235,7 +239,7 @@ class Draw extends React.Component<IDrawProps, IDrawState> {
this.props.state.deck.length > 0 ||
this.props.state.bids.length > 0 ||
this.props.state.autobid !== null ||
this.props.state.revealed_cards >=
(this.props.state.revealed_cards || 0) >=
this.props.state.kitty.length ||
(landlord !== null &&
landlord !== undefined &&
Expand Down
24 changes: 12 additions & 12 deletions frontend/src/Exchange.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class Exchange extends React.Component<IExchangeProps, IExchangeState> {
</>
) : null;

const lastBid = this.props.state.bids[this.props.state.bids.length - 1];
const lastBid = this.props.state.bids![this.props.state.bids!.length - 1];
const startGame = (
<button
onClick={this.startGame}
Expand All @@ -209,24 +209,24 @@ class Exchange extends React.Component<IExchangeProps, IExchangeState> {
kittyTheftEnabled &&
this.props.state.finalized &&
this.props.state.autobid === null &&
(!isExchanger || lastBid.epoch + 1 !== this.props.state.epoch) ? (
(!isExchanger || lastBid.epoch! + 1 !== this.props.state.epoch) ? (
<>
<BidArea
bids={this.props.state.bids}
bids={this.props.state.bids!}
autobid={this.props.state.autobid}
hands={this.props.state.hands}
epoch={this.props.state.epoch}
epoch={this.props.state.epoch!}
name={this.props.name}
landlord={this.props.state.propagated.landlord}
landlord={this.props.state.propagated.landlord!}
players={this.props.state.propagated.players}
bidPolicy={this.props.state.propagated.bid_policy}
bidPolicy={this.props.state.propagated.bid_policy!}
bidReinforcementPolicy={
this.props.state.propagated.bid_reinforcement_policy
this.props.state.propagated.bid_reinforcement_policy!
}
jokerBidPolicy={this.props.state.propagated.joker_bid_policy}
jokerBidPolicy={this.props.state.propagated.joker_bid_policy!}
numDecks={this.props.state.num_decks}
header={
<h2>Bids (round {this.props.state.epoch + 1} of bidding)</h2>
<h2>Bids (round {this.props.state.epoch! + 1} of bidding)</h2>
}
suffixButtons={
<>
Expand Down Expand Up @@ -274,7 +274,7 @@ class Exchange extends React.Component<IExchangeProps, IExchangeState> {
friend={friend}
trump={this.props.state.trump}
friend_selection_policy={
this.props.state.propagated.friend_selection_policy
this.props.state.propagated.friend_selection_policy!
}
num_decks={this.props.state.num_decks}
/>
Expand All @@ -300,10 +300,10 @@ class Exchange extends React.Component<IExchangeProps, IExchangeState> {
name={this.props.name}
/>
<Trump trump={this.props.state.trump} />
{this.props.state.removed_cards.length > 0 ? (
{(this.props.state.removed_cards || []).length > 0 ? (
<p>
Note:{" "}
{this.props.state.removed_cards.map((c) => (
{(this.props.state.removed_cards || []).map((c) => (
<InlineCard key={c} card={c} />
))}{" "}
have been removed from the deck
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/FriendSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const FriendSelect = (props: IProps): JSX.Element => {
initial_skip: parseInt(select.value, 10),
}));

const rank: string | null =
const rank: string | null | undefined =
"Standard" in props.trump
? props.trump.Standard.number
: props.trump.NoTrump.number;
Expand Down Expand Up @@ -75,7 +75,7 @@ const FriendSelect = (props: IProps): JSX.Element => {
);
},
Unrestricted: (c: ICardInfo) => notTrumpFilter(c),
TrumpsIncluded: (c: ICardInfo) => true,
TrumpsIncluded: (_) => true,
};
const policyFilter: (c: ICardInfo) => boolean =
policyFilters[props.friend_selection_policy];
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/Friends.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const Friends = (props: IProps): JSX.Element => {
</div>
);
} else {
return null;
return <></>;
}
};

Expand Down
10 changes: 5 additions & 5 deletions frontend/src/Initialize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ const ScoringSettings = (props: IScoringSettings): JSX.Element => {
style={{ content: contentStyle }}
>
<GameScoringSettings
params={props.state.propagated.game_scoring_parameters}
params={props.state.propagated.game_scoring_parameters!}
decks={props.decks}
/>
</ReactModal>
Expand Down Expand Up @@ -570,7 +570,7 @@ const UncommonSettings = (props: IUncommonSettings): JSX.Element => {
</label>
</div>
<TractorRequirementsE
tractorRequirements={props.state.propagated.tractor_requirements}
tractorRequirements={props.state.propagated.tractor_requirements!}
numDecks={props.numDecksEffective}
onChange={(req) => props.setTractorRequirements(req)}
/>
Expand Down Expand Up @@ -808,7 +808,7 @@ const Initialize = (props: IProps): JSX.Element => {
props.state.propagated.num_decks > 0
? props.state.propagated.num_decks
: Math.max(Math.floor(props.state.propagated.players.length / 2), 1);
const decks = [...props.state.propagated.special_decks];
const decks = [...(props.state.propagated.special_decks || [])];
while (decks.length < decksEffective) {
decks.push({
exclude_big_joker: false,
Expand Down Expand Up @@ -1100,7 +1100,7 @@ const Initialize = (props: IProps): JSX.Element => {
JSON.stringify(props.state.propagated),
);
});
} catch (err) {
} catch {
localStorage.setItem(
"gameSettingsInLocalStorage",
JSON.stringify(props.state.propagated),
Expand Down Expand Up @@ -1345,7 +1345,7 @@ const Initialize = (props: IProps): JSX.Element => {
<button
className="normal"
onClick={() => {
showPicker ? setShowPicker(false) : setShowPicker(true);
setShowPicker(!showPicker);
}}
>
{showPicker ? "Hide" : "Pick"}
Expand Down
8 changes: 5 additions & 3 deletions frontend/src/InlineCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const InlineCardBase = styled.span`
padding-right: 0.1em;
`;

function Suit(className: string): React.FunctionComponent<{}> {
const component = (props: {}): JSX.Element => {
function Suit(className: string): React.FunctionComponent<object> {
const component = (props: object): JSX.Element => {
const settings = React.useContext(SettingsContext);
return (
<InlineCardBase
Expand All @@ -37,7 +37,9 @@ const LittleJoker = Suit("🃟");
const BigJoker = Suit("🃏");
const Unknown = Suit("🂠");

const suitComponent = (suitCard: ISuitCard): React.FunctionComponent<{}> => {
const suitComponent = (
suitCard: ISuitCard,
): React.FunctionComponent<object> => {
switch (suitCard.suit) {
case "diamonds":
return Diamonds;
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/Kicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ const Kicker = (props: IProps): JSX.Element => {
</select>
<button
className="normal"
onClick={() => props.onKick(selection)}
onClick={() => {
if (selection) {
props.onKick(selection);
}
}}
disabled={selection === null}
>
Kick
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/KittySizeSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import WasmContext from "./WasmContext";
interface IProps {
numPlayers: number;
decks: Deck[];
kittySize: number | null;
kittySize: number | null | undefined;
onChange: (newKittySize: number | null) => void;
}

Expand Down
Loading

0 comments on commit 4dada04

Please sign in to comment.