From c51ca39fa7d34739b1e46552c726f2e9b061b087 Mon Sep 17 00:00:00 2001 From: Max Leiter Date: Sat, 7 Jan 2023 14:52:27 -0800 Subject: [PATCH] Eslint changes and linting (no-mix-spaces) --- .eslintrc.json | 5 +- package.json | 2 +- .../new/components/description/index.tsx | 2 +- src/app/(posts)/new/components/new.tsx | 2 - .../components/header/post-buttons/index.tsx | 2 +- .../[id]/components/header/title/index.tsx | 6 +-- .../post-files/password-modal-wrapper.tsx | 51 ++++++++++--------- .../post-files/view-document/index.tsx | 2 - src/app/components/badges/badge.tsx | 2 +- .../badges/visibility-control/index.tsx | 19 ++++--- src/app/components/button/index.tsx | 17 ++++--- src/app/components/input/index.tsx | 3 +- src/app/components/post-list/list-item.tsx | 48 ++++++++--------- src/app/hooks/swr/use-api-tokens.ts | 4 +- src/app/lib/copy-to-clipboard.ts | 4 +- src/app/mine/page.tsx | 2 +- src/app/page.tsx | 4 +- .../settings/components/sections/api-keys.tsx | 5 +- .../settings/components/sections/profile.tsx | 2 +- src/lib/server/auth.ts | 4 +- src/pages/api/post/[id].ts | 2 +- src/pages/api/user/tokens.ts | 2 +- 22 files changed, 103 insertions(+), 87 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index ca79b343..93ac1eb2 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -7,5 +7,8 @@ "parser": "@typescript-eslint/parser", "plugins": ["@typescript-eslint"], "root": true, - "ignorePatterns": ["node_modules/", "__tests__/"] + "ignorePatterns": ["node_modules/", "__tests__/"], + "rules": { + "no-mixed-spaces-and-tabs": ["off"] + } } diff --git a/package.json b/package.json index 0080dba7..79b97ded 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "dev": "next dev --port 3000", "build": "next build", "start": "next start --port 3000", - "lint": "next lint && prettier --list-different --config .prettierrc '{components,lib,app,pages}/**/*.{ts,tsx}' --write", + "lint": "next lint && prettier --list-different --config .prettierrc 'src/{components,lib,app,pages}/**/*.{ts,tsx}' --write", "analyze": "cross-env ANALYZE=true next build", "find:unused": "next-unused", "prisma": "prisma", diff --git a/src/app/(posts)/new/components/description/index.tsx b/src/app/(posts)/new/components/description/index.tsx index ac77bbf6..bd62b237 100644 --- a/src/app/(posts)/new/components/description/index.tsx +++ b/src/app/(posts)/new/components/description/index.tsx @@ -1,5 +1,5 @@ import Input from "@components/input" -import { ChangeEvent, memo } from "react" +import { ChangeEvent } from "react" import styles from "../post.module.css" diff --git a/src/app/(posts)/new/components/new.tsx b/src/app/(posts)/new/components/new.tsx index 7b26c2dc..0a97a97d 100644 --- a/src/app/(posts)/new/components/new.tsx +++ b/src/app/(posts)/new/components/new.tsx @@ -55,7 +55,6 @@ const Post = ({ title: doc.title, content: doc.content, id: doc.id - // eslint-disable-next-line no-mixed-spaces-and-tabs })) : [emptyDoc] @@ -285,7 +284,6 @@ const Post = ({ } ]) }} - type="default" style={{ flex: 1 }} diff --git a/src/app/(posts)/post/[id]/components/header/post-buttons/index.tsx b/src/app/(posts)/post/[id]/components/header/post-buttons/index.tsx index 55ff885c..54227fba 100644 --- a/src/app/(posts)/post/[id]/components/header/post-buttons/index.tsx +++ b/src/app/(posts)/post/[id]/components/header/post-buttons/index.tsx @@ -13,7 +13,7 @@ export const PostButtons = ({ files, loading, postId, - parentId, + parentId }: { title: string files?: Pick["files"] diff --git a/src/app/(posts)/post/[id]/components/header/title/index.tsx b/src/app/(posts)/post/[id]/components/header/title/index.tsx index ec2bb776..6d12b678 100644 --- a/src/app/(posts)/post/[id]/components/header/title/index.tsx +++ b/src/app/(posts)/post/[id]/components/header/title/index.tsx @@ -21,9 +21,9 @@ export const PostTitle = ({ visibility, createdAt, expiresAt, - loading, - // authorId -}: TitleProps) => { + loading +}: // authorId +TitleProps) => { return (

{ ? undefined : session?.user && session?.user?.id === authorId const [isPasswordModalOpen, setIsPasswordModalOpen] = useState(false) - const onSubmit = useCallback(async (password: string) => { - const res = await fetch(`/api/post/${postId}?password=${password}`, { - method: "GET", - headers: { - "Content-Type": "application/json" - } - }) - - if (!res.ok) { - setToast({ - type: "error", - message: "Wrong password" + const onSubmit = useCallback( + async (password: string) => { + const res = await fetch(`/api/post/${postId}?password=${password}`, { + method: "GET", + headers: { + "Content-Type": "application/json" + } }) - return - } - const data = await res.json() - if (data) { - if (data.error) { + if (!res.ok) { setToast({ - message: data.error, - type: "error" + type: "error", + message: "Wrong password" }) - } else { - setIsPasswordModalOpen(false) - setPost(data.post) + return } - } - }, [postId, setPost, setToast]) + + const data = await res.json() + if (data) { + if (data.error) { + setToast({ + message: data.error, + type: "error" + }) + } else { + setIsPasswordModalOpen(false) + setPost(data.post) + } + } + }, + [postId, setPost, setToast] + ) const onClose = () => { setIsPasswordModalOpen(false) diff --git a/src/app/(posts)/post/[id]/components/post-files/view-document/index.tsx b/src/app/(posts)/post/[id]/components/post-files/view-document/index.tsx index c6eac4e2..a5555662 100644 --- a/src/app/(posts)/post/[id]/components/post-files/view-document/index.tsx +++ b/src/app/(posts)/post/[id]/components/post-files/view-document/index.tsx @@ -21,11 +21,9 @@ type SharedProps = { type Props = ( | { skeleton?: true - // eslint-disable-next-line no-mixed-spaces-and-tabs } | { skeleton?: false - // eslint-disable-next-line no-mixed-spaces-and-tabs } ) & SharedProps diff --git a/src/app/components/badges/badge.tsx b/src/app/components/badges/badge.tsx index ac92b6ec..84584be4 100644 --- a/src/app/components/badges/badge.tsx +++ b/src/app/components/badges/badge.tsx @@ -6,7 +6,7 @@ type BadgeProps = { } & React.HTMLAttributes const Badge = React.forwardRef( - ({ type, children, ...rest}: BadgeProps, ref) => { + ({ type, children, ...rest }: BadgeProps, ref) => { return (
diff --git a/src/app/components/badges/visibility-control/index.tsx b/src/app/components/badges/visibility-control/index.tsx index 893c246d..382464f7 100644 --- a/src/app/components/badges/visibility-control/index.tsx +++ b/src/app/components/badges/visibility-control/index.tsx @@ -15,7 +15,11 @@ type Props = { visibility: string } -const VisibilityControl = ({ authorId, postId, visibility: postVisibility }: Props) => { +const VisibilityControl = ({ + authorId, + postId, + visibility: postVisibility +}: Props) => { const { data: session } = useSession() const isAuthor = session?.user && session?.user?.id === authorId const [visibility, setVisibility] = useState(postVisibility) @@ -23,7 +27,7 @@ const VisibilityControl = ({ authorId, postId, visibility: postVisibility }: Pro const [isSubmitting, setSubmitting] = useState() const [passwordModalVisible, setPasswordModalVisible] = useState(false) const { setToast } = useToasts() - const router = useRouter(); + const router = useRouter() const sendRequest = useCallback( async (visibility: string, password?: string) => { @@ -43,7 +47,6 @@ const VisibilityControl = ({ authorId, postId, visibility: postVisibility }: Pro message: "Visibility updated", type: "success" }) - } else { setToast({ message: "An error occurred", @@ -84,10 +87,12 @@ const VisibilityControl = ({ authorId, postId, visibility: postVisibility }: Pro return ( <> - +
- {!hideActions ? - {post.parentId && ( - + {!hideActions ? ( + + {post.parentId && ( + +
{post.description && ( diff --git a/src/app/hooks/swr/use-api-tokens.ts b/src/app/hooks/swr/use-api-tokens.ts index aed8d1c0..3d418db3 100644 --- a/src/app/hooks/swr/use-api-tokens.ts +++ b/src/app/hooks/swr/use-api-tokens.ts @@ -50,10 +50,10 @@ export function useApiTokens({ userId, initialTokens }: UseApiTokens) { throw new Error(response.error) return } - + mutate([...(data || []), response]) - return response as SerializedApiToken + return response as SerializedApiToken } const expireToken = async (id: string) => { diff --git a/src/app/lib/copy-to-clipboard.ts b/src/app/lib/copy-to-clipboard.ts index 670e47af..0e9e9a50 100644 --- a/src/app/lib/copy-to-clipboard.ts +++ b/src/app/lib/copy-to-clipboard.ts @@ -1,3 +1,3 @@ -export async function copyToClipboard(text: string ) { - await navigator.clipboard.writeText(text) +export async function copyToClipboard(text: string) { + await navigator.clipboard.writeText(text) } diff --git a/src/app/mine/page.tsx b/src/app/mine/page.tsx index 6db4da9f..ef2dce82 100644 --- a/src/app/mine/page.tsx +++ b/src/app/mine/page.tsx @@ -24,4 +24,4 @@ export default async function Mine() { ) } -export const revalidate = 0; \ No newline at end of file +export const revalidate = 0 diff --git a/src/app/page.tsx b/src/app/page.tsx index 943fe4fd..2332dfa7 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -68,7 +68,9 @@ export default async function Page() {

Recent public posts

} + fallback={ + + } > {/* @ts-expect-error because of async RSC */} diff --git a/src/app/settings/components/sections/api-keys.tsx b/src/app/settings/components/sections/api-keys.tsx index b5372312..b69d7016 100644 --- a/src/app/settings/components/sections/api-keys.tsx +++ b/src/app/settings/components/sections/api-keys.tsx @@ -5,7 +5,10 @@ import Input from "@components/input" import Note from "@components/note" import { Spinner } from "@components/spinner" import { useToasts } from "@components/toasts" -import { SerializedApiToken, useApiTokens } from "src/app/hooks/swr/use-api-tokens" +import { + SerializedApiToken, + useApiTokens +} from "src/app/hooks/swr/use-api-tokens" import { copyToClipboard } from "src/app/lib/copy-to-clipboard" import { useSession } from "next-auth/react" import { useState } from "react" diff --git a/src/app/settings/components/sections/profile.tsx b/src/app/settings/components/sections/profile.tsx index 23c76452..c579bd69 100644 --- a/src/app/settings/components/sections/profile.tsx +++ b/src/app/settings/components/sections/profile.tsx @@ -19,7 +19,7 @@ const Profile = () => { setName(session?.user.name || "") } }, [name, session]) - + const handleNameChange = (e: React.ChangeEvent) => { setName(e.target.value) } diff --git a/src/lib/server/auth.ts b/src/lib/server/auth.ts index b1a45e38..ad7a5ab6 100644 --- a/src/lib/server/auth.ts +++ b/src/lib/server/auth.ts @@ -146,7 +146,7 @@ export const authOptions: NextAuthOptions = { if (config.enable_admin && totalUsers === 1) { await prisma.user.update({ where: { - id: user.id, + id: user.id }, data: { role: "admin" @@ -161,7 +161,7 @@ export const authOptions: NextAuthOptions = { }, data: { username: user.name, - displayName: user.name, + displayName: user.name } }) } diff --git a/src/pages/api/post/[id].ts b/src/pages/api/post/[id].ts index 65aac540..89e0cc3b 100644 --- a/src/pages/api/post/[id].ts +++ b/src/pages/api/post/[id].ts @@ -68,7 +68,7 @@ async function handleGet(req: NextApiRequest, res: NextApiResponse) { post: { id: post.id, visibility: post.visibility, - authorId: post.authorId, + authorId: post.authorId } }) } diff --git a/src/pages/api/user/tokens.ts b/src/pages/api/user/tokens.ts index 0193e4b2..4cf763fe 100644 --- a/src/pages/api/user/tokens.ts +++ b/src/pages/api/user/tokens.ts @@ -25,7 +25,7 @@ export default async function handle( expiresAt: true, name: true } - }); + }) console.log(tokens)