Skip to content

Commit d8b1c3f

Browse files
authored
Merge pull request #45 from covalenthq/precommit
precommit hook for running golangci-lint
2 parents 63966a3 + 192bd16 commit d8b1c3f

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

.githooks/pre-commit

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/sh
2+
3+
STAGED_GO_FILES=$(git diff --cached --name-only | grep ".go$")
4+
5+
if [[ "$STAGED_GO_FILES" = "" ]]; then
6+
exit 0
7+
fi
8+
9+
10+
if ! command -v golangci-lint &> /dev/null; then
11+
printf "installing golangci-lint"
12+
brew install golangci-lint
13+
fi
14+
15+
16+
PASS=true
17+
18+
for FILE in $STAGED_GO_FILES
19+
do
20+
golangci-lint run $FILE
21+
if [[ $? == 1 ]]; then
22+
PASS=false
23+
fi
24+
done
25+
26+
if ! $PASS; then
27+
printf "COMMIT FAILED\n"
28+
exit 1
29+
else
30+
printf "COMMIT SUCCEEDED\n"
31+
fi
32+
33+
exit 0

docs/CONTRIBUTING.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* [Development Procedure](#dev_procedure)
66
* [Dependencies](#dependencies)
77
* [Testing](#testing)
8+
* [Linting](#linting)
89
* [Branching Model and Release](#braching_model_and_release)
910
* [PR Targeting](#pr_targeting)
1011
* [Pull Requests](#pull_requests)
@@ -88,6 +89,16 @@ on `go mod tidy -v`.
8889

8990
Covalent uses [GitHub Actions](https://github.com/features/actions) for automated [integration testing](https://github.com/covalenthq/bsp-agent/actions).
9091

92+
### <spand id="linting">Linting</span>
93+
94+
The repo uses `golangci-lint` to run linters and enforce coding standards. There are two ways to run this:
95+
- run `golangci-lint run` or `golangci-lint run <filename>`
96+
- or configure the git hooks path:
97+
```bash
98+
git config core.hooksPath .githooks
99+
```
100+
This will run `golanci-lint` automatically before committing.
101+
91102
### <span id="braching_model_and_release">Branching Model and Release</span>
92103

93104
User-facing repos should adhere to the [trunk based development branching model](https://trunkbaseddevelopment.com/).
@@ -129,4 +140,4 @@ All PRs require two Reviews before merge. When reviewing PRs, please use the fol
129140

130141
1. Ensure pull branch is rebased on `main`.
131142
2. Ensure that all CI tests pass.
132-
3. Squash merge pull request.
143+
3. Squash merge pull request.

0 commit comments

Comments
 (0)