Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add import and style sorting config + capabilities. #132

Merged
merged 14 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions packages/webapp/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ const config = {
extends: ["next/core-web-vitals", "plugin:@typescript-eslint/recommended", "prettier"],
parser: "@typescript-eslint/parser",
parserOptions: {
project: "./tsconfig.json",
},
plugins: ["@typescript-eslint"],
project: "./tsconfig.json",
"sourceType": "module",
"ecmaVersion": "latest",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's with the weird indentation here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't seem to appear on my local repo. 😶

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's because of mixed tabs and spaces. We should add .cjs and .mjs files to the list of those who get formatted by prettier, cand you do that?

},
plugins: ["@typescript-eslint", "simple-import-sort"],
root: true,
ignorePatterns: ["node_modules", "src/hooks/useScrollBox.ts"],
rules: {
Expand All @@ -26,6 +28,31 @@ const config = {
caughtErrorsIgnorePattern: "^_",
},
],
"import/first": "error",
"import/newline-after-import": "error",
"import/no-duplicates": "error",
"simple-import-sort/imports": [
"error",
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird alignment, is this not caught by the formatter?

"groups": [
// Packages. `react` related packages come first.
[
"^react",
"^next",
],
// Internal packages.
["^@?\\w"],
// Parent imports. Put `..` last.
["^\\.\\.(?!/?$)", "^\\.\\./?$"],
// Other relative imports. Put same-folder imports and `.` last.
["^\\./(?=.*/)(?!/?$)", "^\\.(?!/?$)", "^\\./?$"],
// Style imports.
["^.+\\.s?css$"],
// Side effect imports.
["^\\u0000"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One rule that would be great is to make sure the internal imports, which we prefix with src/ are in their own separate section (after the "internal packages" would be ideal — we should also change that comment to actually say "external packages" (stuff like wagmi etc))

]
}
]
},
}

Expand Down
3 changes: 2 additions & 1 deletion packages/webapp/.prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"singleQuote": false,
"tabWidth": 4,
"useTabs": false,
"printWidth": 120
"printWidth": 120,
"plugins": ["prettier-plugin-tailwindcss"]
}
6 changes: 5 additions & 1 deletion packages/webapp/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"javascript.validate.enable": false,
"typescript.validate.enable": false
"typescript.validate.enable": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
"eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"]
}
1 change: 1 addition & 0 deletions packages/webapp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ check:

# Runs prettier formatting across webapp files with specified file extensions.
format:
pnpm eslint . --fix
pnpm prettier --write "**/*.{js,jsx,ts,tsx,json,css}"
.PHONY: format
6 changes: 4 additions & 2 deletions packages/webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"connectkit": "^1.5.3",
"eslint-config-prettier": "^9.1.0",
"jotai": "^2.4.3",
"jotai-devtools": "^0.7.0",
"lodash": "^4.17.21",
Expand Down Expand Up @@ -52,8 +51,11 @@
"autoprefixer": "^10.4.16",
"eslint": "^8.52.0",
"eslint-config-next": "^13.5.6",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-simple-import-sort": "^12.0.0",
"postcss": "^8.4.31",
"prettier": "2.8.8",
"prettier-plugin-tailwindcss": "^0.5.11",
ultraviolet10 marked this conversation as resolved.
Show resolved Hide resolved
"tailwindcss": "^3.3.3",
"typescript": "^5.2.2"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/webapp/src/actions/concede.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { defaultErrorHandling } from "src/actions/errors"
import { checkFresh, freshWrap } from "src/store/checkFresh"
import { contractWriteThrowing } from "src/actions/libContractWrite"
import { Address } from "src/chain"
import { deployment } from "src/deployment"
import { gameABI } from "src/generated"
import { checkFresh, freshWrap } from "src/store/checkFresh"

// =================================================================================================

Expand Down
2 changes: 1 addition & 1 deletion packages/webapp/src/actions/defend.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { defaultErrorHandling } from "src/actions/errors"
import { checkFresh, freshWrap } from "src/store/checkFresh"
import { contractWriteThrowing } from "src/actions/libContractWrite"
import { Address } from "src/chain"
import { deployment } from "src/deployment"
import { gameABI } from "src/generated"
import { checkFresh, freshWrap } from "src/store/checkFresh"

// =================================================================================================

Expand Down
12 changes: 6 additions & 6 deletions packages/webapp/src/actions/drawCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import { defaultErrorHandling } from "src/actions/errors"
import { contractWriteThrowing } from "src/actions/libContractWrite"
import { Address, type HexString } from "src/chain"
import { CancellationHandler } from "src/components/modals/loadingModal"
import { DRAW_CARD_PROOF_TIMEOUT } from "src/constants"
import { deployment } from "src/deployment"
import { packCards } from "src/game/fableProofs"
import { gameABI } from "src/generated"
import { getOrInitPrivateInfo, setPrivateInfo } from "src/store/write"
import { checkFresh, freshWrap } from "src/store/checkFresh"
import {
getCards,
getCurrentPlayerAddress,
Expand All @@ -21,12 +23,10 @@ import {
getPlayerAddress,
} from "src/store/read"
import { GameStep, PrivateInfo } from "src/store/types"
import { FAKE_PROOF, proveInWorker, SHOULD_GENERATE_PROOFS } from "src/utils/zkproofs"
import { bigintToHexString } from "src/utils/js-utils"
import { getOrInitPrivateInfo, setPrivateInfo } from "src/store/write"
import { mimcHash } from "src/utils/hashing"
import { DRAW_CARD_PROOF_TIMEOUT } from "src/constants"
import { CancellationHandler } from "src/components/modals/loadingModal"
import { checkFresh, freshWrap } from "src/store/checkFresh"
import { bigintToHexString } from "src/utils/js-utils"
import { FAKE_PROOF, proveInWorker, SHOULD_GENERATE_PROOFS } from "src/utils/zkproofs"

// =================================================================================================

Expand Down
2 changes: 1 addition & 1 deletion packages/webapp/src/actions/endTurn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { contractWriteThrowing } from "src/actions/libContractWrite"
import { Address } from "src/chain"
import { deployment } from "src/deployment"
import { gameABI } from "src/generated"
import { checkFresh, freshWrap } from "src/store/checkFresh"
import { getCurrentPlayerAddress, getGameData, getGameID, getPlayerAddress } from "src/store/read"
import { GameStep } from "src/store/types"
import { checkFresh, freshWrap } from "src/store/checkFresh"

// =================================================================================================

Expand Down
6 changes: 2 additions & 4 deletions packages/webapp/src/actions/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@
* @module actions/errors
*/

import { ContractFunctionRevertedError, UserRejectedRequestError } from "viem"

import { ContractWriteError } from "src/actions/libContractWrite"
import { GIT_ISSUES } from "src/constants"
import { setError } from "src/store/write"

import { StaleError } from "src/store/checkFresh"
import { setError } from "src/store/write"
import { TimeoutError } from "src/utils/errors"
import { ProofCancelled, ProofError, ProofTimeoutError } from "src/utils/zkproofs/proofs"
import { ContractFunctionRevertedError, UserRejectedRequestError } from "viem"

// =================================================================================================
// ERRORS
Expand Down
24 changes: 12 additions & 12 deletions packages/webapp/src/actions/joinGame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
* @module action/joinGame
*/

import { decodeEventLog } from "viem"

import { defaultErrorHandling, FableRequestTimeout, InconsistentGameStateError } from "src/actions/errors"
import { contractWriteThrowing } from "src/actions/libContractWrite"
import { Address } from "src/chain"
import { CancellationHandler } from "src/components/modals/loadingModal"
import { DRAW_HAND_PROOF_TIMEOUT } from "src/constants"
import { deployment } from "src/deployment"
import { NUM_CARDS_FOR_PROOF } from "src/game/constants"
import { drawInitialHand } from "src/game/drawInitialHand"
import { packCards } from "src/game/fableProofs"
import { gameABI } from "src/generated"
import { waitForUpdate } from "src/store/update"
import { getOrInitPrivateInfo, setGameID, setPrivateInfo } from "src/store/write"
import { checkFresh, freshWrap } from "src/store/checkFresh"
import { getPlayerHand } from "src/store/derive"
import {
getCards,
getDeck,
Expand All @@ -26,13 +28,10 @@ import {
isGameReadyToStart,
} from "src/store/read"
import { FetchedGameData, GameStatus, PlayerData, PrivateInfo } from "src/store/types"
import { SHOULD_GENERATE_PROOFS, FAKE_PROOF, ProofOutput, proveInWorker } from "src/utils/zkproofs"
import { NUM_CARDS_FOR_PROOF } from "src/game/constants"
import { packCards } from "src/game/fableProofs"
import { DRAW_HAND_PROOF_TIMEOUT } from "src/constants"
import { CancellationHandler } from "src/components/modals/loadingModal"
import { checkFresh, freshWrap } from "src/store/checkFresh"
import { getPlayerHand } from "src/store/derive"
import { waitForUpdate } from "src/store/update"
import { getOrInitPrivateInfo, setGameID, setPrivateInfo } from "src/store/write"
import { FAKE_PROOF, ProofOutput, proveInWorker,SHOULD_GENERATE_PROOFS } from "src/utils/zkproofs"
import { decodeEventLog } from "viem"

// =================================================================================================

Expand Down Expand Up @@ -85,7 +84,8 @@ async function joinGameImpl(args: JoinGameArgs): Promise<boolean> {
if (gameStatus < GameStatus.JOINED) {
// we can skip the join step if already performed
const promise = doJoinGameTransaction(args, privateInfo.saltHash)
if (gameID === null) await promise // gameID starts null and the call will set it
if (gameID === null)
await promise // gameID starts null and the call will set it
else checkFresh(await freshWrap(promise))
}

Expand Down
4 changes: 1 addition & 3 deletions packages/webapp/src/actions/libContractWrite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* @module ui/libContractWrite
*/

import type { Address, Hash } from "src/chain"
import {
Abi,
ContractFunctionExecutionError,
Expand All @@ -13,11 +14,8 @@ import {
TransactionExecutionError,
TransactionReceipt,
} from "viem"

import { prepareWriteContract, waitForTransaction, writeContract } from "wagmi/actions"

import type { Address, Hash } from "src/chain"

// =================================================================================================

/** Arguments to {@link contractWrite}. */
Expand Down
12 changes: 6 additions & 6 deletions packages/webapp/src/actions/playCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
import { defaultErrorHandling } from "src/actions/errors"
import { contractWriteThrowing } from "src/actions/libContractWrite"
import { Address, type HexString } from "src/chain"
import { CancellationHandler } from "src/components/modals/loadingModal"
import { PLAY_CARD_PROOF_TIMEOUT } from "src/constants"
import { deployment } from "src/deployment"
import { packCards } from "src/game/fableProofs"
import { gameABI } from "src/generated"
import { getOrInitPrivateInfo, setPrivateInfo } from "src/store/write"
import { checkFresh, freshWrap } from "src/store/checkFresh"
import { getCards, getCurrentPlayerAddress, getGameData, getGameID, getPlayerAddress } from "src/store/read"
import { GameStep, PrivateInfo } from "src/store/types"
import { FAKE_PROOF, proveInWorker, SHOULD_GENERATE_PROOFS } from "src/utils/zkproofs"
import { bigintToHexString } from "src/utils/js-utils"
import { getOrInitPrivateInfo, setPrivateInfo } from "src/store/write"
import { mimcHash } from "src/utils/hashing"
import { PLAY_CARD_PROOF_TIMEOUT } from "src/constants"
import { CancellationHandler } from "src/components/modals/loadingModal"
import { checkFresh, freshWrap } from "src/store/checkFresh"
import { bigintToHexString } from "src/utils/js-utils"
import { FAKE_PROOF, proveInWorker, SHOULD_GENERATE_PROOFS } from "src/utils/zkproofs"

// =================================================================================================

Expand Down
3 changes: 1 addition & 2 deletions packages/webapp/src/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
*/

import { getDefaultConfig, getDefaultConnectors } from "connectkit"
import { BurnerConnector } from "src/wagmi/BurnerConnector"
import { type Chain, createConfig } from "wagmi"
import { localhost } from "wagmi/chains"

import { BurnerConnector } from "src/wagmi/BurnerConnector"

// =================================================================================================

/** The list of chains supported by the app. */
Expand Down
18 changes: 9 additions & 9 deletions packages/webapp/src/components/cards/boardCard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { forwardRef, useState } from "react"
import React, { forwardRef, useState } from "react"
import Image from "next/image"
import React from "react"

import { testCards } from "src/utils/card-list"

interface BoardCardProps {
Expand All @@ -12,14 +12,14 @@ const BoardCard = forwardRef<HTMLDivElement, BoardCardProps>(({ id }, ref) => {

return (
<div
className="relative w-full h-full"
className="relative h-full w-full"
ref={ref}
onMouseEnter={() => setShowCardName(true)}
onMouseLeave={() => setShowCardName(false)}
>
<Image
alt={`${id}`}
className="pointer-events-none rounded-xl border select-none"
className="pointer-events-none select-none rounded-xl border"
src={testCards[id]?.image}
width={200}
height={200}
Expand All @@ -29,19 +29,19 @@ const BoardCard = forwardRef<HTMLDivElement, BoardCardProps>(({ id }, ref) => {
/>
{showCardName && (
<>
<div className="flex w-full justify-between p-2 absolute top-0 left-0 right-0">
<div className="flex items-center justify-center h-8 w-8 rounded-full bg-yellow-400 text-gray-900 font-bold text-lg select-none">
<div className="absolute left-0 right-0 top-0 flex w-full justify-between p-2">
<div className="flex h-8 w-8 select-none items-center justify-center rounded-full bg-yellow-400 text-lg font-bold text-gray-900">
{`${testCards[id]?.attack}`}
</div>
<div className="flex items-center justify-center h-8 w-8 rounded-full bg-red-600 text-gray-900 font-bold text-lg select-none">
<div className="flex h-8 w-8 select-none items-center justify-center rounded-full bg-red-600 text-lg font-bold text-gray-900">
{`${testCards[id]?.defense}`}
</div>
</div>

<span
className={`absolute w-[90%] bottom-0 left-1/2 transform -translate-x-1/2 font-serif text-[14px] font-bold text-slate-200 text-center pb-2.5 select-none truncate transition-opacity duration-1000 ${
className={`absolute bottom-0 left-1/2 w-[90%] -translate-x-1/2 transform select-none truncate pb-2.5 text-center font-serif text-[14px] font-bold text-slate-200 transition-opacity duration-1000 ${
showCardName ? "opacity-100" : "opacity-0"
} hover:whitespace-normal hover:overflow-visible`}
} hover:overflow-visible hover:whitespace-normal`}
>
{`${testCards[id]?.name}`}
</span>
Expand Down
12 changes: 7 additions & 5 deletions packages/webapp/src/components/cards/cardContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import React from "react"
import { CardPlacement } from "src/store/types"

import { useSortable } from "@dnd-kit/sortable"
import DraggedCard from "./draggedCard"
import BoardCard from "./boardCard"
import HandCard from "./handCard"
import { CSS } from "@dnd-kit/utilities"
import { CardPlacement } from "src/store/types"
import { convertStringToSafeNumber } from "src/utils/js-utils"

import BoardCard from "./boardCard"
import DraggedCard from "./draggedCard"
import HandCard from "./handCard"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should use the src/ format. I know it's not formatting related, but could you fix it?

I think we could use this type of rule to prevent them, but I wonder if we'd need to be able to make exception to import files form other packages (e.g. deployment addresses) — I think we could get around that by copying files however. Could you look into it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added this rule, running make check and make format doesn't pop up any errors.


interface BaseCardProps {
id: string
className?: string
Expand Down Expand Up @@ -49,7 +51,7 @@ const CardContainer: React.FC<BaseCardProps> = ({ id, handHovered, placement, ca
}
return (
<div
className={`${"shadow-2xl z-[50] flex max-w-[24rem] cursor-pointer flex-col items-center justify-evenly rounded-lg bg-gray-900 transform translateY-[-50%]"}`}
className={`${"translateY-[-50%] z-[50] flex max-w-[24rem] transform cursor-pointer flex-col items-center justify-evenly rounded-lg bg-gray-900 shadow-2xl"}`}
style={sortableStyle}
ref={setNodeRef}
{...attributes}
Expand Down
5 changes: 3 additions & 2 deletions packages/webapp/src/components/cards/draggedCard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Image from "next/image"
import React, { forwardRef } from "react"
import Image from "next/image"

import { testCards } from "src/utils/card-list"

interface DraggedCardProps {
Expand All @@ -11,7 +12,7 @@ const DraggedCard = forwardRef<HTMLImageElement, DraggedCardProps>(({ id }, ref)
<>
<Image
alt={`${id}`}
className="pointer-events-none rounded-xl border select-none"
className="pointer-events-none select-none rounded-xl border"
src={testCards[id]?.image}
width={200}
height={200}
Expand Down
Loading
Loading