From 24bcc58483a535c6acc4d007e423f8df2ff0baef Mon Sep 17 00:00:00 2001 From: egenerse Date: Tue, 17 Dec 2024 14:04:26 +0300 Subject: [PATCH 1/5] feat: add general prettier formatter to the monorepo --- .prettierrc | 9 +++++++++ library/lib/index.ts | 2 +- library/vite.config.ts | 6 +++--- standalone/server/src/server.ts | 14 +++++++------- standalone/webapp/vite.config.ts | 6 +++--- 5 files changed, 23 insertions(+), 14 deletions(-) create mode 100644 .prettierrc diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..49a058d --- /dev/null +++ b/.prettierrc @@ -0,0 +1,9 @@ +{ + "printWidth": 80, + "tabWidth": 2, + "singleQuote": false, + "semi": false, + "trailingComma": "es5", + "arrowParens": "always", + "bracketSpacing": true +} diff --git a/library/lib/index.ts b/library/lib/index.ts index 7556fd5..c56baa8 100644 --- a/library/lib/index.ts +++ b/library/lib/index.ts @@ -1,3 +1,3 @@ export function calculateSomething(first: number, second: number): number { - return first + second; + return first + second } diff --git a/library/vite.config.ts b/library/vite.config.ts index a46cef3..6821f54 100644 --- a/library/vite.config.ts +++ b/library/vite.config.ts @@ -1,5 +1,5 @@ -import { defineConfig } from "vite"; -import react from "@vitejs/plugin-react"; +import { defineConfig } from "vite" +import react from "@vitejs/plugin-react" export default defineConfig({ plugins: [react()], @@ -10,4 +10,4 @@ export default defineConfig({ fileName: (format) => `@apollon2/library.${format}.js`, }, }, -}); +}) diff --git a/standalone/server/src/server.ts b/standalone/server/src/server.ts index 7918b76..bbad475 100644 --- a/standalone/server/src/server.ts +++ b/standalone/server/src/server.ts @@ -1,13 +1,13 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import express from "express"; +import express from "express" -const app = express(); -const port = 3000; +const app = express() +const port = 3000 app.get("/", (req: any, res: any) => { - res.send("Hello from Backend!"); -}); + res.send("Hello from Backend!") +}) app.listen(port, () => { - console.log(`Server running on http://localhost:${port}`); -}); + console.log(`Server running on http://localhost:${port}`) +}) diff --git a/standalone/webapp/vite.config.ts b/standalone/webapp/vite.config.ts index 0e43ae8..afe0e3d 100644 --- a/standalone/webapp/vite.config.ts +++ b/standalone/webapp/vite.config.ts @@ -1,7 +1,7 @@ -import { defineConfig } from "vite"; -import react from "@vitejs/plugin-react"; +import { defineConfig } from "vite" +import react from "@vitejs/plugin-react" // https://vite.dev/config/ export default defineConfig({ plugins: [react()], -}); +}) From 7bd80a37955469eaad97f60336a751eafe88f5fe Mon Sep 17 00:00:00 2001 From: egenerse Date: Tue, 17 Dec 2024 14:05:27 +0300 Subject: [PATCH 2/5] fix: format .tsx files as well --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index dbcb275..13932b3 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,8 @@ "lint:lib": "npm run lint --workspace=@apollon2/library", "lint:server": "npm run lint --workspace=@apollon2/server", "lint:webapp": "npm run lint --workspace=@apollon2/webapp", - "format": "prettier --ignore-path .gitignore --write \"**/*.+(js|ts|json)\"", - "format:fix": "prettier --write \"**/*.+(js|ts|json)\"", + "format": "prettier --ignore-path .gitignore --write \"**/*.+(js|ts|tsx|json)\"", + "format:fix": "prettier --write \"**/*.+(js|ts|tsx|json)\"", "preview": "husky" }, "license": "MIT", From 6f9ed5ab234d39d96804c8c3d91481e0e9bbdb10 Mon Sep 17 00:00:00 2001 From: egenerse Date: Tue, 17 Dec 2024 14:11:59 +0300 Subject: [PATCH 3/5] feat: run format:check script in pre commit stage --- .husky/pre-commit | 2 +- package.json | 4 ++-- standalone/webapp/src/App.tsx | 8 ++++---- standalone/webapp/src/main.tsx | 14 +++++++------- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index 3932801..9c9f69b 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1 +1 @@ -npm run format +npm run format:check diff --git a/package.json b/package.json index 13932b3..85d5ff1 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,8 @@ "lint:lib": "npm run lint --workspace=@apollon2/library", "lint:server": "npm run lint --workspace=@apollon2/server", "lint:webapp": "npm run lint --workspace=@apollon2/webapp", - "format": "prettier --ignore-path .gitignore --write \"**/*.+(js|ts|tsx|json)\"", - "format:fix": "prettier --write \"**/*.+(js|ts|tsx|json)\"", + "format": "prettier --ignore-path .gitignore --write \"**/*.+(js,ts,tsx,json)\"", + "format:check": "prettier --ignore-path .gitignore --check \"**/*.{js,ts,tsx,json}\"", "preview": "husky" }, "license": "MIT", diff --git a/standalone/webapp/src/App.tsx b/standalone/webapp/src/App.tsx index f33097b..2281fc1 100644 --- a/standalone/webapp/src/App.tsx +++ b/standalone/webapp/src/App.tsx @@ -1,14 +1,14 @@ -import { useState } from "react"; +import { useState } from "react" function App() { - const [count, setCount] = useState(0); + const [count, setCount] = useState(0) return (
{count}
- ); + ) } -export default App; +export default App diff --git a/standalone/webapp/src/main.tsx b/standalone/webapp/src/main.tsx index eed9ab8..93e648c 100644 --- a/standalone/webapp/src/main.tsx +++ b/standalone/webapp/src/main.tsx @@ -1,15 +1,15 @@ -import { StrictMode } from 'react'; -import { createRoot } from 'react-dom/client'; -import App from './App.tsx'; +import { StrictMode } from "react" +import { createRoot } from "react-dom/client" +import App from "./App.tsx" -const rootElement = document.getElementById('root'); +const rootElement = document.getElementById("root") if (rootElement) { createRoot(rootElement).render( - , - ); + + ) } else { - console.error('Root element not found'); + console.error("Root element not found") } From 75122a67910a859fa61cc780dafc8879c4c21c3d Mon Sep 17 00:00:00 2001 From: egenerse Date: Tue, 17 Dec 2024 16:15:44 +0300 Subject: [PATCH 4/5] docs: add format scripts to readme --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 98c7dd0..21a0b24 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,14 @@ Here are the commonly used scripts defined in the monorepo: ```bash npm run start ``` +- **Format the project:** + ```bash + npm run format + ``` +- **Check formatting of the project:** + ```bash + npm run format:check + ``` ## Troubleshooting From c1b1a1cc41c25d034d9c151e27989f2359ba6e19 Mon Sep 17 00:00:00 2001 From: egenerse Date: Tue, 17 Dec 2024 17:12:54 +0300 Subject: [PATCH 5/5] docs: add small descriptions to readme script --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7b692e5..300ad4c 100644 --- a/README.md +++ b/README.md @@ -122,11 +122,11 @@ Here are the commonly used scripts defined in the monorepo: ```bash npm run lint ``` -- **Format the project:** +- **Fixes formatting issues :** ```bash npm run format ``` -- **Check formatting of the project:** +- **Checks formatting issues without fixing them :** ```bash npm run format:check ```