From 031145dce63a89313734d26c7fb30eac1dd4adfb Mon Sep 17 00:00:00 2001 From: Erik Taubeneck Date: Mon, 10 Jun 2024 11:02:03 -0700 Subject: [PATCH] Prettier config (#38) * Add prettier formatting * apply prettier fixes * add git-blame-ignore-revs * add prettier to pre commit hood, add pre-commit local setup to readme * add comments to .prettierignore explaining why files are ignored * typo in README * apply prettier to middleware.ts * one more formatting commit to ignore with blame --- .git-blame-ignore-revs | 3 +++ .pre-commit-config.yaml | 6 ++++++ README.md | 6 ++++++ server/.prettierignore | 13 +++++++++++++ server/.prettierrc | 1 + server/app/alert.tsx | 4 +++- server/app/query/haikunator.tsx | 20 +++++++++++--------- server/middleware.ts | 27 ++++++++++++++++----------- server/package-lock.json | 16 ++++++++++++++++ server/package.json | 1 + 10 files changed, 76 insertions(+), 21 deletions(-) create mode 100644 .git-blame-ignore-revs create mode 100644 server/.prettierignore create mode 100644 server/.prettierrc diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 0000000..aa8417c --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1,3 @@ +# Prettier formatting errors +32743cbd2f5dead77fd6ef7be25105f33c370f29 +be76190dd8ca29e9e7b63a3cd1126386b2fe5917 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6c648c9..680eff9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -32,3 +32,9 @@ repos: files: ^server/ types_or: [javascript, jsx, ts, tsx] pass_filenames: false + - id: prettier + name: prettier + entry: npx --prefix server prettier --config=server/.prettierrc --ignore-path=server/.prettierignore --check server + language: system + files: ^server/ + types_or: [javascript, jsx, ts, tsx] diff --git a/README.md b/README.md index f314637..7c185c1 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,12 @@ Requirements: 3. [Supabase CLI](https://supabase.com/docs/guides/cli/getting-started) 4. Docker + +#### Pre-commit Hooks + +Github is set up to run pre-commit hooks specified in .pre-commit-config.yaml. If you want to use it locally, in the virtual environment, run `pre-commit install`. + + #### macOS install prerequisites ```brew install python3``` diff --git a/server/.prettierignore b/server/.prettierignore new file mode 100644 index 0000000..be8e1c7 --- /dev/null +++ b/server/.prettierignore @@ -0,0 +1,13 @@ +# Auto-generated file +data/supabaseTypes.ts +postcss.config.js +supabase/.temp* +tailwind.config.ts +.next/* + +# Config files +next.config.js +tsconfig.json + +# Not JS +README.md diff --git a/server/.prettierrc b/server/.prettierrc new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/server/.prettierrc @@ -0,0 +1 @@ +{} diff --git a/server/app/alert.tsx b/server/app/alert.tsx index 7a6f375..be49468 100644 --- a/server/app/alert.tsx +++ b/server/app/alert.tsx @@ -14,7 +14,9 @@ export default function QueryStartedAlert({ queryId }: { queryId: string }) {

Successfully started Query: {queryId}. Redirecting to - /query/view/{queryId} .{" "} + + /query/view/{queryId}{" "} + .{" "}

diff --git a/server/app/query/haikunator.tsx b/server/app/query/haikunator.tsx index 61847a4..11f4eae 100644 --- a/server/app/query/haikunator.tsx +++ b/server/app/query/haikunator.tsx @@ -6,16 +6,18 @@ const haikunator = new Haikunator({ nouns: nouns, }); -function getCurrentTimestamp() { - const now = new Date(); - const year = now.getFullYear(); - const month = (now.getMonth() + 1).toString().padStart(2, '0'); - const day = now.getDate().toString().padStart(2, '0'); - const hours = now.getHours().toString().padStart(2, '0'); - const minutes = now.getMinutes().toString().padStart(2, '0'); - return `${year}-${month}-${day}T${hours}${minutes}`; +function getCurrentTimestamp() { + const now = new Date(); + const year = now.getFullYear(); + const month = (now.getMonth() + 1).toString().padStart(2, "0"); + const day = now.getDate().toString().padStart(2, "0"); + const hours = now.getHours().toString().padStart(2, "0"); + const minutes = now.getMinutes().toString().padStart(2, "0"); + return `${year}-${month}-${day}T${hours}${minutes}`; } export default function NewQueryId(): string { - return encodeURIComponent(haikunator.haikunate({tokenLength: 0}) + getCurrentTimestamp()); + return encodeURIComponent( + haikunator.haikunate({ tokenLength: 0 }) + getCurrentTimestamp(), + ); } diff --git a/server/middleware.ts b/server/middleware.ts index ae4e880..6ca76ca 100644 --- a/server/middleware.ts +++ b/server/middleware.ts @@ -54,26 +54,31 @@ export async function middleware(request: NextRequest) { }, ); - if (process.env.NODE_ENV === "development" && process.env.BYPASS_AUTH === "true") { + if ( + process.env.NODE_ENV === "development" && + process.env.BYPASS_AUTH === "true" + ) { const dummyEmail: string = process.env.DUMMY_EMAIL!; - const dummyPassword:string = process.env.DUMMY_PASSWORD!; - const { data, error: signInError } = await supabase.auth.signInWithPassword({ - email: dummyEmail, - password: dummyPassword, - }) + const dummyPassword: string = process.env.DUMMY_PASSWORD!; + const { data, error: signInError } = await supabase.auth.signInWithPassword( + { + email: dummyEmail, + password: dummyPassword, + }, + ); if (signInError) { const { error: signUpError } = await supabase.auth.signUp({ email: dummyEmail, - password: dummyPassword + password: dummyPassword, }); if (signUpError) { - console.error('Sign-in error:', signInError); - console.error('Sign-up error:', signUpError); - throw new Error('Failed to handle local development auth bypass.'); + console.error("Sign-in error:", signInError); + console.error("Sign-up error:", signUpError); + throw new Error("Failed to handle local development auth bypass."); } } - return response + return response; } const { data: { user }, diff --git a/server/package-lock.json b/server/package-lock.json index 61cb9b4..c6fc8c9 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -32,6 +32,7 @@ "eslint": "^8", "eslint-config-next": "14.0.3", "postcss": "^8", + "prettier": "3.3.1", "tailwindcss": "^3.3.0", "typescript": "^5" } @@ -4323,6 +4324,21 @@ "node": ">= 0.8.0" } }, + "node_modules/prettier": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.1.tgz", + "integrity": "sha512-7CAwy5dRsxs8PHXT3twixW9/OEll8MLE0VRPCJyl7CkS6VHGPSlsVaWTiASPTyGyYRyApxlaWTzwUxVNrhcwDg==", + "dev": true, + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/prop-types": { "version": "15.8.1", "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.8.1.tgz", diff --git a/server/package.json b/server/package.json index 0159572..176c5ec 100644 --- a/server/package.json +++ b/server/package.json @@ -33,6 +33,7 @@ "eslint": "^8", "eslint-config-next": "14.0.3", "postcss": "^8", + "prettier": "3.3.1", "tailwindcss": "^3.3.0", "typescript": "^5" }