From 4f52d86d9720f759d2bf7d56fa7e062b23377a1a Mon Sep 17 00:00:00 2001 From: Esteban Maya Date: Thu, 21 Mar 2024 15:51:54 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Add=20documentation=20for=20pre-?= =?UTF-8?q?commit=20and=20code=20linting=20(#718)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sebastián Ramírez --- development.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/development.md b/development.md index a62c6b2..857a4e0 100644 --- a/development.md +++ b/development.md @@ -23,6 +23,7 @@ In that case, you will need to use a fake local domain (`dev.example.com`) and m If you have a custom domain like that, you need to add it to the list in the variable `BACKEND_CORS_ORIGINS` in the `.env` file. * Open your `hosts` file with administrative privileges using a text editor: + * **Note for Windows**: If you are in Windows, open the main Windows menu, search for "notepad", right click on it, and select the option "open as Administrator" or similar. Then click the "File" menu, "Open file", go to the directory `c:\Windows\System32\Drivers\etc\`, select the option to show "All files" instead of only "Text (.txt) files", and open the `hosts` file. * **Note for Mac and Linux**: Your `hosts` file is probably located at `/etc/hosts`, you can edit it in a terminal running `sudo nano /etc/hosts`. @@ -91,6 +92,52 @@ Depending on your workflow, you could want to exclude it from Git, for example i One way to do it could be to add each environment variable to your CI/CD system, and updating the `docker-compose.yml` file to read that specific env var instead of reading the `.env` file. +### Pre-commits and code linting + +we are using a tool called [pre-commit](https://pre-commit.com/) for code linting and formatting. + +When you install it, it runs right before making a commit in git. This way it ensures that the code is consistent and formatted even before it is committed. + +You can find a file `.pre-commit-config.yaml` with configurations at the root of the project. + +#### Install pre-commit to run automatically + +`pre-commit` is already part of the dependencies of the project, but you could also install it globally if you prefer to, following [the official pre-commit docs](https://pre-commit.com/). + +After having the `pre-commit` tool installed and available, you need to "install" it in the local repository, so that it runs automatically before each commit. + +Using Poetry, you could do it with: + +```bash +❯ poetry run pre-commit install +pre-commit installed at .git/hooks/pre-commit +``` + +Now whenever you try to commit, e.g. with: + +```bash +git commit +``` + +...pre-commit will run and check and format the code you are about to commit, and will ask you to add that code (stage it) with git again before committing. + +Then you can `git add` the modified/fixed files again and now you can commit. + +#### Running pre-commit hooks manually + +you can also run `pre-commit` manually on all the files, you can do it using Poetry with: + +```bash +❯ poetry run pre-commit run --all-files +check for added large files..............................................Passed +check toml...............................................................Passed +check yaml...............................................................Passed +ruff.....................................................................Passed +ruff-format..............................................................Passed +eslint...................................................................Passed +prettier.................................................................Passed +``` + ## URLs The production or staging URLs would use these same paths, but with your own domain.