From fb9478ae7f4af575b27c1dff481fda7ca2323349 Mon Sep 17 00:00:00 2001 From: Jakub Nowakowski Date: Fri, 24 Nov 2023 00:45:31 +0100 Subject: [PATCH 1/3] Define prettier in the repository root Define prettier to ensure consistent formatting in the root directory. Exclude sub-packages that have their own formatting configuration. --- .pre-commit-config.yaml | 7 +++++++ .prettierignore | 7 +++++++ .prettierrc.js | 3 +++ core/.prettierrc.js | 2 +- dapp/.prettierrc.js | 2 +- dapp/package.json | 1 - package.json | 10 +++++++++- pnpm-lock.yaml | 15 ++++++++------- website/.prettierrc.js | 2 +- website/package.json | 1 - 10 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 .prettierignore create mode 100644 .prettierrc.js diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e55db32ed..3abedc120 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,13 @@ repos: - repo: local hooks: + # Root + - id: root-lint + name: "lint root" + entry: /usr/bin/env bash -c "npm run format" + exclude: (^core/|^dapp/|^website/) + language: script + description: "Checks code according to the package's linter configuration" # Core - id: core-lint-sol name: "lint core sol" diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 000000000..db08b3da8 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,7 @@ +# Packages that have own prettier configuration. +core/ +dapp/ +website/ + +# Auto-generated files. +pnpm-lock.yaml diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 000000000..3c35d0a49 --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1,3 @@ +module.exports = { + ...require("@thesis/prettier-config"), +} diff --git a/core/.prettierrc.js b/core/.prettierrc.js index bf24da7e5..a31367f16 100644 --- a/core/.prettierrc.js +++ b/core/.prettierrc.js @@ -1,5 +1,5 @@ module.exports = { - ...require("@thesis-co/prettier-config"), + ...require("../.prettierrc.js"), plugins: ["prettier-plugin-solidity"], overrides: [ { diff --git a/dapp/.prettierrc.js b/dapp/.prettierrc.js index 5eea77223..15dafbe4b 100644 --- a/dapp/.prettierrc.js +++ b/dapp/.prettierrc.js @@ -1,3 +1,3 @@ module.exports = { - ...require("@thesis-co/prettier-config"), + ...require("../.prettierrc.js"), } diff --git a/dapp/package.json b/dapp/package.json index abe517062..571a3152d 100644 --- a/dapp/package.json +++ b/dapp/package.json @@ -28,7 +28,6 @@ }, "devDependencies": { "@thesis-co/eslint-config": "^0.6.1", - "@thesis/prettier-config": "github:thesis/prettier-config", "@types/react": "^18.2.15", "@types/react-dom": "^18.2.7", "@typescript-eslint/eslint-plugin": "^6.10.0", diff --git a/package.json b/package.json index 4dc406476..55251ea20 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,12 @@ { "private": true, - "packageManager": "pnpm@8.10.5" + "packageManager": "pnpm@8.10.5", + "scripts": { + "format": "prettier --check .", + "format:fix": "prettier --write ." + }, + "devDependencies": { + "@thesis/prettier-config": "github:thesis/prettier-config", + "prettier": "^3.1.0" + } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c5e48aef0..846ac9212 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,7 +6,14 @@ settings: importers: - .: {} + .: + devDependencies: + '@thesis/prettier-config': + specifier: github:thesis/prettier-config + version: github.com/thesis/prettier-config/daeaac564056a7885e4366ce12bfde6fd823fc90(prettier@3.1.0) + prettier: + specifier: ^3.1.0 + version: 3.1.0 core: devDependencies: @@ -128,9 +135,6 @@ importers: '@thesis-co/eslint-config': specifier: ^0.6.1 version: 0.6.1(eslint@8.54.0)(prettier@3.1.0)(typescript@5.3.2) - '@thesis/prettier-config': - specifier: github:thesis/prettier-config - version: github.com/thesis/prettier-config/daeaac564056a7885e4366ce12bfde6fd823fc90(prettier@3.1.0) '@types/react': specifier: ^18.2.15 version: 18.2.38 @@ -174,9 +178,6 @@ importers: '@thesis-co/eslint-config': specifier: ^0.6.1 version: 0.6.1(eslint@8.54.0)(prettier@3.1.0)(typescript@5.3.2) - '@thesis/prettier-config': - specifier: github:thesis/prettier-config - version: github.com/thesis/prettier-config/daeaac564056a7885e4366ce12bfde6fd823fc90(prettier@3.1.0) '@types/node': specifier: ^20.3.3 version: 20.9.4 diff --git a/website/.prettierrc.js b/website/.prettierrc.js index c22abd03a..6d44c572e 100644 --- a/website/.prettierrc.js +++ b/website/.prettierrc.js @@ -1,3 +1,3 @@ module.exports = { - ...require("@thesis-co/prettier-config"), + ...require("../.prettierrc.js"), } diff --git a/website/package.json b/website/package.json index ee47d0022..d01776ddd 100644 --- a/website/package.json +++ b/website/package.json @@ -26,7 +26,6 @@ }, "devDependencies": { "@thesis-co/eslint-config": "^0.6.1", - "@thesis/prettier-config": "github:thesis/prettier-config", "@types/node": "^20.3.3", "@types/react": "^18.2.14", "@types/react-dom": "^18.2.6", From 0976ac1b09b7257fe74389bafe94697059a07aed Mon Sep 17 00:00:00 2001 From: Jakub Nowakowski Date: Fri, 24 Nov 2023 00:52:54 +0100 Subject: [PATCH 2/3] Run format:fix in the root directory This is a result of running the format:fix script. --- README.md | 16 +++++++++------- package.json | 20 ++++++++++---------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 86f06997e..18d15124c 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ please see the [documentation](https://pnpm.io/installation). #### Package Dependencies To install the packages dependencies run: + ```sh pnpm install ``` @@ -30,19 +31,21 @@ automatically discover code issues, before they submit the code. To setup the hooks follow the steps: 1. Install `pre-commit` tool: - ```sh - brew install pre-commit - ``` + + ```sh + brew install pre-commit + ``` 2. Install the hooks for the repository: - ```sh - pre-commit install - ``` + ```sh + pre-commit install + ``` #### Testing To test the pre-commit hooks configuration you can invoke them with one of the commands: + ```sh # Execute hooks for all files: pre-commit run --all-files @@ -50,4 +53,3 @@ pre-commit run --all-files # Execute hooks for specific files (e.g. Acre.sol): pre-commit run --files ./core/contracts/Acre.sol ``` - diff --git a/package.json b/package.json index 55251ea20..32355e52a 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,12 @@ { - "private": true, - "packageManager": "pnpm@8.10.5", - "scripts": { - "format": "prettier --check .", - "format:fix": "prettier --write ." - }, - "devDependencies": { - "@thesis/prettier-config": "github:thesis/prettier-config", - "prettier": "^3.1.0" - } + "private": true, + "packageManager": "pnpm@8.10.5", + "scripts": { + "format": "prettier --check .", + "format:fix": "prettier --write ." + }, + "devDependencies": { + "@thesis/prettier-config": "github:thesis/prettier-config", + "prettier": "^3.1.0" + } } From 18b873e3fa873ea0ae151bb531be5019713ad7e7 Mon Sep 17 00:00:00 2001 From: Jakub Nowakowski Date: Fri, 24 Nov 2023 00:53:58 +0100 Subject: [PATCH 3/3] Add format:fix result to git blame ignore --- .git-blame-ignore-revs | 1 + 1 file changed, 1 insertion(+) diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index b4f1cac41..ec9afb3e3 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -1,2 +1,3 @@ # Auto-fix linting d2a058fe6cfbab6f82d0d977d1b2d8bd9f494df1 +0976ac1b09b7257fe74389bafe94697059a07aed