From 6666aa3502dba7e4093f6f8e8729aea1999fa9a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20Gon=C3=A7alves?= Date: Sun, 21 Jan 2024 08:59:27 +0000 Subject: [PATCH] Add Prettier config and GitHub workflow --- .github/workflows/prettier-check.yml | 39 ++++++++++++++++++++++++++++ backend/.prettierrc | 11 ++++++++ backend/package-lock.json | 24 ++++++++++++++++- backend/package.json | 7 +++-- frontend/.prettierrc | 16 ++++++++++++ frontend/package-lock.json | 22 ++++++++++++++++ frontend/package.json | 7 +++-- 7 files changed, 121 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/prettier-check.yml create mode 100644 backend/.prettierrc create mode 100644 frontend/.prettierrc diff --git a/.github/workflows/prettier-check.yml b/.github/workflows/prettier-check.yml new file mode 100644 index 0000000..4e10d4e --- /dev/null +++ b/.github/workflows/prettier-check.yml @@ -0,0 +1,39 @@ +name: Prettier Check + +on: + push: + branches: + - main + +jobs: + prettier-check: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Use Node.js 20 + uses: actions/setup-node@v3 + with: + node-version: 20 + + - name: Install frontend dependencies + run: | + cd frontend + npm install -D + + - name: Install backend dependencies + run: | + cd backend + npm install -D + + - name: Frontend Prettier check + run: | + cd frontend + npm run prettier:check + + - name: Backend Prettier check + run: | + cd backend + npm run prettier:check diff --git a/backend/.prettierrc b/backend/.prettierrc new file mode 100644 index 0000000..c3f0748 --- /dev/null +++ b/backend/.prettierrc @@ -0,0 +1,11 @@ +{ + "printWidth": 100, + "tabWidth": 2, + "useTabs": false, + "semi": true, + "singleQuote": false, + "trailingComma": "all", + "bracketSpacing": true, + "arrowParens": "always", + "endOfLine": "lf" +} diff --git a/backend/package-lock.json b/backend/package-lock.json index 7704a06..16ef689 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -30,7 +30,8 @@ "winston": "^3.11.0" }, "devDependencies": { - "nodemon": "^2.0.22" + "nodemon": "^2.0.22", + "prettier": "3.2.4" } }, "node_modules/@colors/colors": { @@ -2557,6 +2558,21 @@ "node": ">= 0.8.0" } }, + "node_modules/prettier": { + "version": "3.2.4", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.2.4.tgz", + "integrity": "sha512-FWu1oLHKCrtpO1ypU6J0SbK2d9Ckwysq6bHj/uaCP26DxrPpppCLQRGVuqAxSTvhF00AcvDRyYrLNW7ocBhFFQ==", + "dev": true, + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/pretty": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/pretty/-/pretty-2.0.0.tgz", @@ -5587,6 +5603,12 @@ "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz", "integrity": "sha512-ESF23V4SKG6lVSGZgYNpbsiaAkdab6ZgOxe52p7+Kid3W3u3bxR4Vfd/o21dmN7jSt0IwgZ4v5MUd26FEtXE9w==" }, + "prettier": { + "version": "3.2.4", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.2.4.tgz", + "integrity": "sha512-FWu1oLHKCrtpO1ypU6J0SbK2d9Ckwysq6bHj/uaCP26DxrPpppCLQRGVuqAxSTvhF00AcvDRyYrLNW7ocBhFFQ==", + "dev": true + }, "pretty": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/pretty/-/pretty-2.0.0.tgz", diff --git a/backend/package.json b/backend/package.json index ca77d07..b546565 100644 --- a/backend/package.json +++ b/backend/package.json @@ -5,7 +5,9 @@ "main": "index.js", "scripts": { "start": "nodemon src/index.js", - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "prettier:check": "prettier --check \"**/*.{js,json,md}\"", + "prettier:format": "prettier --write \"**/*.{js,json,md}\"" }, "repository": { "type": "git", @@ -39,6 +41,7 @@ "winston": "^3.11.0" }, "devDependencies": { - "nodemon": "^2.0.22" + "nodemon": "^2.0.22", + "prettier": "3.2.4" } } diff --git a/frontend/.prettierrc b/frontend/.prettierrc new file mode 100644 index 0000000..65acff7 --- /dev/null +++ b/frontend/.prettierrc @@ -0,0 +1,16 @@ +{ + "printWidth": 100, + "tabWidth": 2, + "useTabs": false, + "semi": true, + "singleQuote": false, + "quoteProps": "as-needed", + "jsxSingleQuote": false, + "trailingComma": "es5", + "bracketSpacing": true, + "bracketSameLine": false, + "arrowParens": "avoid", + "endOfLine": "lf", + "embeddedLanguageFormatting": "auto", + "singleAttributePerLine": false +} diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 0602955..370778a 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -28,6 +28,7 @@ "eslint-plugin-react": "^7.32.2", "eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-react-refresh": "^0.3.4", + "prettier": "3.2.4", "vite": ">=4.5.2" } }, @@ -4997,6 +4998,21 @@ "node": ">= 0.8.0" } }, + "node_modules/prettier": { + "version": "3.2.4", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.2.4.tgz", + "integrity": "sha512-FWu1oLHKCrtpO1ypU6J0SbK2d9Ckwysq6bHj/uaCP26DxrPpppCLQRGVuqAxSTvhF00AcvDRyYrLNW7ocBhFFQ==", + "dev": true, + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/probe-image-size": { "version": "7.2.3", "resolved": "https://registry.npmjs.org/probe-image-size/-/probe-image-size-7.2.3.tgz", @@ -9815,6 +9831,12 @@ "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", "dev": true }, + "prettier": { + "version": "3.2.4", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.2.4.tgz", + "integrity": "sha512-FWu1oLHKCrtpO1ypU6J0SbK2d9Ckwysq6bHj/uaCP26DxrPpppCLQRGVuqAxSTvhF00AcvDRyYrLNW7ocBhFFQ==", + "dev": true + }, "probe-image-size": { "version": "7.2.3", "resolved": "https://registry.npmjs.org/probe-image-size/-/probe-image-size-7.2.3.tgz", diff --git a/frontend/package.json b/frontend/package.json index f1973a7..8896394 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -7,7 +7,9 @@ "dev": "vite --host", "build": "vite build", "lint": "eslint src --ext js,jsx --report-unused-disable-directives --max-warnings 0", - "preview": "vite preview" + "preview": "vite preview", + "prettier:check": "prettier --check \"**/*.{js,json,md,jsx,html,css}\"", + "prettier:format": "prettier --write \"**/*.{js,json,md,jsx,html,css}\"" }, "dependencies": { "@emotion/react": "^11.11.0", @@ -15,8 +17,8 @@ "@mui/icons-material": "^5.11.16", "@mui/material": "^5.13.2", "axios": "^1.6.0", - "plotly.js": "^2.25.2", "notistack": "^3.0.1", + "plotly.js": "^2.25.2", "react": "^18.2.0", "react-dom": "^18.2.0", "react-plotly.js": "^2.6.0", @@ -30,6 +32,7 @@ "eslint-plugin-react": "^7.32.2", "eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-react-refresh": "^0.3.4", + "prettier": "3.2.4", "vite": ">=4.5.2" } }