Add precommit hooks (#2119)

This commit is contained in:
Marta Sanchez 2023-06-10 22:23:51 +02:00 committed by GitHub
parent 5ebf4ee963
commit 93904eb24b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 30 deletions

18
.pre-commit-config.yaml Normal file
View file

@ -0,0 +1,18 @@
repos:
- repo: local
hooks:
- id: fmt
name: fmt
description: Format files with cargo fmt.
entry: cargo fmt
language: system
types: [rust]
args: ["--all", "--", "--check"]
- id: clippy
name: clippy
description: Lint rust sources
entry: cargo clippy
language: system
args: ["--", "-W", "warnings"]
types: [rust]
pass_filenames: false

View file

@ -121,41 +121,47 @@ For the initial start, fork the project and use git clone command to download th
git clone https://github.com/surrealdb/surrealdb git clone https://github.com/surrealdb/surrealdb
``` ```
1. Pull all changes from the upstream `main` branch, before creating a new branch - to ensure that your `main` branch is up-to-date with the latest changes: (Optional): Install [pre-commit](https://pre-commit.com/#install) to run the checks before each commit and run:
```bash
pre-commit install
```
2. Pull all changes from the upstream `main` branch, before creating a new branch - to ensure that your `main` branch is up-to-date with the latest changes:
```bash ```bash
git pull git pull
``` ```
2. Create new branch from `main` like: `bugfix-548-ensure-queries-execute-sequentially`: 3. Create new branch from `main` like: `bugfix-548-ensure-queries-execute-sequentially`:
```bash ```bash
git checkout -b "[the name of your branch]" git checkout -b "[the name of your branch]"
``` ```
3. Make changes to the code, and ensure all code changes are formatted correctly: 4. Make changes to the code, and ensure all code changes are formatted correctly:
```bash ```bash
cargo fmt cargo fmt
``` ```
4. Commit your changes when finished: 5. Commit your changes when finished:
```bash ```bash
git add -A git add -A
git commit -m "[your commit message]" git commit -m "[your commit message]"
``` ```
5. Push changes to GitHub: 6. Push changes to GitHub:
```bash ```bash
git push origin "[the name of your branch]" git push origin "[the name of your branch]"
``` ```
6. Submit your changes for review, by going to your repository on GitHub and clicking the `Compare & pull request` button. 7. Submit your changes for review, by going to your repository on GitHub and clicking the `Compare & pull request` button.
7. Ensure that you have entered a commit message which details about the changes, and what the pull request is for. 8. Ensure that you have entered a commit message which details about the changes, and what the pull request is for.
8. Now submit the pull request by clicking the `Create pull request` button. 9. Now submit the pull request by clicking the `Create pull request` button.
9. Wait for code review and approval. 10. Wait for code review and approval.
10. After approval, merge your pull request. 11. After approval, merge your pull request.
## Other Ways to Help ## Other Ways to Help

View file

@ -115,7 +115,7 @@
hardeningDisable = [ "fortify" ]; hardeningDisable = [ "fortify" ];
depsBuildBuild = buildSpec.depsBuildBuild or [ ] depsBuildBuild = buildSpec.depsBuildBuild or [ ]
++ [ rustToolchain ] ++ (with pkgs; [ nixfmt cargo-watch wasm-pack ]); ++ [ rustToolchain ] ++ (with pkgs; [ nixfmt cargo-watch wasm-pack pre-commit]);
inherit (util) SURREAL_BUILD_METADATA; inherit (util) SURREAL_BUILD_METADATA;
})) util.platforms); })) util.platforms);