chore: add pre-commit hook (#59)

* chore: add pre-commit-hook

* doc(contribute): add pre-commit setup guide

* doc(contribute.md): add pre-commit doc url

* chore(pre-commit): add gofmt custom hook

* fix: fix syntax

* chore(pre-commit): rename gofmt as gofmt-fixer

* chore(pre-commit): add config reference

* chore(pre-commit): add golangci-lint
This commit is contained in:
Kevin Yu 2023-04-23 13:24:05 +08:00 committed by GitHub
parent 80ae760ebf
commit 064bf1ebbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 0 deletions

30
.pre-commit-config.yaml Normal file
View File

@ -0,0 +1,30 @@
# reference: https://verdantfox.com/blog/view/how-to-use-git-pre-commit-hooks-the-hard-way-and-the-easy-way
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-json
- id: check-yaml
args:
- --unsafe
- id: double-quote-string-fixer
- id: end-of-file-fixer
- repo: https://github.com/golangci/golangci-lint
rev: v1.52.2
hooks:
- id: golangci-lint
- repo: local
hooks:
- id: gofmt-fixer
name: gofmt
entry: gofmt -w .
language: golang
types: [go]
# - id: check-x
# name: Check X
# entry: ./bin/check-x.sh
# language: script
# files: \.x$

View File

@ -14,6 +14,17 @@ Before you start any Pull Request, `it is recommended that you create an issue`
`Pull Requests` can only be merged once all status checks are green. `Pull Requests` can only be merged once all status checks are green.
### Pre-commit Hook
This repo uses [pre-commit hook](https://github.com/pre-commit/pre-commit-hooks) to apply linting check prior to writing commit to local git history. To set up pre-commit, do the followings:
```bash
# install pre-commit
pip3 install pre-commit
# install pre-commit hooks
pre-commit install
```
### How to make a clean pull request ### How to make a clean pull request
- Create a `personal fork` of the project on Github. - Create a `personal fork` of the project on Github.