👷 Add pre-commit workflow (#2056)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
Motov Yurii
2025-12-26 17:16:14 +01:00
committed by GitHub
parent ac9319d841
commit 2059d2e271
6 changed files with 146 additions and 133 deletions

View File

@@ -134,48 +134,51 @@ One way to do it could be to add each environment variable to your CI/CD system,
## Pre-commits and code linting
we are using a tool called [pre-commit](https://pre-commit.com/) for code linting and formatting.
we are using a tool called [prek](https://prek.j178.dev/) (modern alternative to [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
#### Install prek 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/).
`prek` is already part of the dependencies of the project.
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.
After having the `prek` tool installed and available, you need to "install" it in the local repository, so that it runs automatically before each commit.
Using `uv`, you could do it with:
Using `uv`, you could do it with (make sure you are inside `backend` folder):
```bash
uv run pre-commit install
pre-commit installed at .git/hooks/pre-commit
uv run prek install -f
prek installed at `../.git/hooks/pre-commit`
```
The `-f` flag forces the installation, in case there was already a `pre-commit` hook previously installed.
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.
...prek 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
#### Running prek hooks manually
you can also run `pre-commit` manually on all the files, you can do it using `uv` with:
you can also run `prek` manually on all the files, you can do it using `uv` with:
```bash
uv run pre-commit run --all-files
uv run prek run --all-files
check for added large files..............................................Passed
check toml...............................................................Passed
check yaml...............................................................Passed
fix end of files.........................................................Passed
trim trailing whitespace.................................................Passed
ruff.....................................................................Passed
ruff-format..............................................................Passed
eslint...................................................................Passed
prettier.................................................................Passed
biome check..............................................................Passed
```
## URLs