diff --git a/. prettierignore b/. prettierignore new file mode 100644 index 0000000..75afcdd --- /dev/null +++ b/. prettierignore @@ -0,0 +1,3 @@ +node_modules +.yarn +.next diff --git a/.eslintrc.json b/.eslintrc.json index bffb357..f4c762f 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,3 +1,24 @@ { - "extends": "next/core-web-vitals" + "env": { + "browser": true, + "es2021": true + }, + "extends": [ + "next/core-web-vitals", + "eslint:recommended", + "plugin:@typescript-eslint/recommended", + "prettier" + ], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaVersion": "latest", + "sourceType": "module" + }, + "plugins": ["@typescript-eslint"], + "rules": { + "@typescript-eslint/no-unused-vars": "error", + "@typescript-eslint/consistent-type-definitions": "error", + "react-hooks/rules-of-hooks": "error", + "react-hooks/exhaustive-deps": "error" + } } diff --git a/components/Form.tsx b/components/Form.tsx index 4d96512..7653b5a 100644 --- a/components/Form.tsx +++ b/components/Form.tsx @@ -28,28 +28,31 @@ export function Form({ setLoading, setError, setParsedText }: FormProps) { setClearing(false); setFile(undefined); setParsedText(''); - }, []); + }, [setParsedText]); - const validateFile = useCallback((file: File) => { - if (file.type !== 'application/pdf') { - setError( - "The file you've selected is not a PDF file. Please select a PDF file." - ); - setLoading(false); + const validateFile = useCallback( + (file: File) => { + if (file.type !== 'application/pdf') { + setError( + "The file you've selected is not a PDF file. Please select a PDF file." + ); + setLoading(false); - return false; - } + return false; + } - // This limit is caused by the project being deployed on Vercel using a free tier, with limited resources for the cloud functions (it can be commented out if running locally) - if (file.size > 1024 * 1024) { - setError('The file must be smaller than 1MB.'); - setLoading(false); + // This limit is caused by the project being deployed on Vercel using a free tier, with limited resources for the cloud functions (it can be commented out if running locally) + if (file.size > 1024 * 1024) { + setError('The file must be smaller than 1MB.'); + setLoading(false); - return false; - } + return false; + } - return true; - }, []); + return true; + }, + [setError, setLoading] + ); const uploadFile = useCallback(async () => { if (!file) return; @@ -76,7 +79,7 @@ export function Form({ setLoading, setError, setParsedText }: FormProps) { setClearing(true); setLoading(false); } - }, [file, validateFile]); + }, [file, validateFile, setError, setParsedText, setClearing, setLoading]); const handleUpload = useCallback(() => { setLoading(true); @@ -84,7 +87,7 @@ export function Form({ setLoading, setError, setParsedText }: FormProps) { setParsedText(''); uploadFile(); - }, [uploadFile]); + }, [uploadFile, setLoading, setError, setParsedText]); function renderForm() { if (clearing) { diff --git a/package.json b/package.json index 09ce7f7..feeac01 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "build": "next build", "start": "next start", "lint": "next lint", - "format": "prettier --config .prettierrc 'app/' --write", + "format": "prettier --config .prettierrc '**/*.{ts,tsx,json}' --write", "typecheck": "tsc --noEmit", "prepare": "husky install" }, @@ -40,10 +40,10 @@ "typescript": "^5" }, "lint-staged": { - "*.ts": [ - "eslint --quiet --fix" + "*.{ts,tsx}": [ + "eslint" ], - "*.{json,ts}": [ + "*.{json,ts,tsx}": [ "prettier --write --ignore-unknown" ] } diff --git a/tailwind.config.ts b/tailwind.config.ts index 7e4bd91..6299298 100644 --- a/tailwind.config.ts +++ b/tailwind.config.ts @@ -1,20 +1,20 @@ -import type { Config } from "tailwindcss"; +import type { Config } from 'tailwindcss'; const config: Config = { content: [ - "./pages/**/*.{js,ts,jsx,tsx,mdx}", - "./components/**/*.{js,ts,jsx,tsx,mdx}", - "./app/**/*.{js,ts,jsx,tsx,mdx}", + './pages/**/*.{js,ts,jsx,tsx,mdx}', + './components/**/*.{js,ts,jsx,tsx,mdx}', + './app/**/*.{js,ts,jsx,tsx,mdx}' ], theme: { extend: { backgroundImage: { - "gradient-radial": "radial-gradient(var(--tw-gradient-stops))", - "gradient-conic": - "conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))", - }, - }, + 'gradient-radial': 'radial-gradient(var(--tw-gradient-stops))', + 'gradient-conic': + 'conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))' + } + } }, - plugins: [], + plugins: [] }; export default config; diff --git a/utils/parser.ts b/utils/parser.ts index c20cec8..af78f32 100644 --- a/utils/parser.ts +++ b/utils/parser.ts @@ -2,7 +2,7 @@ import PdfParse from 'pdf-parse'; export async function parser(file: File) { const chunks = []; - for await (const chunk of file.stream() as any) { + for await (const chunk of file.stream() as unknown as AsyncIterable) { chunks.push(chunk); }