Skip to content

Commit e5d57f1

Browse files
authored
Merge pull request #10 from Bahjat/patch/adds-go-ruleguard
Patch/adds go ruleguard
2 parents a26a0ff + 1d3675f commit e5d57f1

File tree

4 files changed

+94
-61
lines changed

4 files changed

+94
-61
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v2.3.0
3+
rev: v4.3.0
44
hooks:
55
- id: trailing-whitespace
66
- id: check-yaml
7+
- id: check-json
78
- id: end-of-file-fixer
8-
- repo: git://github.com/detailyang/pre-commit-shell
9-
rev: 1.0.5
9+
- repo: https://github.com/koalaman/shellcheck-precommit
10+
rev: v0.8.0
1011
hooks:
11-
- id: shell-lint
12-
args: [--format=json]
12+
- id: shellcheck

.pre-commit-hooks.yaml

Lines changed: 62 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,62 @@
1-
- id: go-fmt-import
2-
name: 'go import/fmt'
3-
entry: run-go-fmt-import.sh
4-
files: '\.go$'
5-
language: 'script'
6-
description: "Runs `goimport,gofmt`, requires golang"
7-
8-
- id: go-vet
9-
name: 'go vet'
10-
entry: run-go-vet.sh
11-
files: '\.go$'
12-
language: 'script'
13-
description: "Runs `go vet`, requires golang"
14-
15-
- id: go-lint
16-
name: 'golint'
17-
entry: run-go-lint.sh
18-
files: '\.go$'
19-
language: 'script'
20-
description: "Runs `go lint`, requires golang"
21-
22-
- id: go-unit-tests
23-
name: 'go unit test'
24-
entry: run-go-unit-tests.sh
25-
files: '\.go$'
26-
language: 'script'
27-
description: "Runs `go test`, requires golang"
28-
29-
- id: gofumpt
30-
name: 'gofumpt'
31-
entry: run-go-gofumpt.sh
32-
files: '\.go$'
33-
language: 'script'
34-
description: "Runs `gofumpt`, requires github.com/mvdan/gofumpt"
35-
36-
- id: go-err-check
37-
name: 'go errcheck'
38-
entry: run-go-err-check.sh
39-
files: '\.go$'
40-
language: 'script'
41-
description: "Runs `errcheck`, requires github.com/kisielk/errcheck"
42-
43-
- id: go-static-check
44-
name: 'go staticcheck'
45-
entry: run-go-static-check.sh
46-
files: '\.go$'
47-
language: 'script'
48-
description: "Runs `staticcheck`, install https://staticcheck.io/docs/"
49-
50-
- id: golangci-lint
51-
name: 'go golangci-lint'
52-
entry: run-golangci-lint.sh
53-
files: '\.go$'
54-
language: 'script'
55-
description: "Runs `golangci-lint`, install https://github.com/golangci/golangci-lint"
1+
- id: go-fmt-import
2+
name: "go import/fmt"
3+
entry: run-go-fmt-import.sh
4+
files: '\.go$'
5+
language: "script"
6+
description: "Runs `goimport,gofmt`, requires golang"
7+
8+
- id: go-vet
9+
name: "go vet"
10+
entry: run-go-vet.sh
11+
files: '\.go$'
12+
language: "script"
13+
description: "Runs `go vet`, requires golang"
14+
15+
- id: go-lint
16+
name: "golint"
17+
entry: run-go-lint.sh
18+
files: '\.go$'
19+
language: "script"
20+
description: "Runs `go lint`, requires golang"
21+
22+
- id: go-unit-tests
23+
name: "go unit test"
24+
entry: run-go-unit-tests.sh
25+
files: '\.go$'
26+
language: "script"
27+
description: "Runs `go test`, requires golang"
28+
29+
- id: gofumpt
30+
name: "gofumpt"
31+
entry: run-go-gofumpt.sh
32+
files: '\.go$'
33+
language: "script"
34+
description: "Runs `gofumpt`, requires github.com/mvdan/gofumpt"
35+
36+
- id: go-err-check
37+
name: "go errcheck"
38+
entry: run-go-err-check.sh
39+
files: '\.go$'
40+
language: "script"
41+
description: "Runs `errcheck`, requires github.com/kisielk/errcheck"
42+
43+
- id: go-static-check
44+
name: "go staticcheck"
45+
entry: run-go-static-check.sh
46+
files: '\.go$'
47+
language: "script"
48+
description: "Runs `staticcheck`, install https://staticcheck.io/docs/"
49+
50+
- id: golangci-lint
51+
name: "go golangci-lint"
52+
entry: run-golangci-lint.sh
53+
files: '\.go$'
54+
language: "script"
55+
description: "Runs `golangci-lint`, install https://github.com/golangci/golangci-lint"
56+
57+
- id: go-ruleguard
58+
name: "go-ruleguard"
59+
entry: run-go-ruleguard.sh
60+
files: '\.go$'
61+
language: "script"
62+
description: "Runs `go-ruleguard`, install https://github.com/quasilyte/go-ruleguard"

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Add a file named `.pre-commit-config.yaml` into the root directory of your repos
2323
```yaml
2424
repos:
2525
- repo: https://github.com/Bahjat/pre-commit-golang
26-
rev: v1.0.1
26+
rev: v1.0.2
2727
hooks:
2828
- id: go-fmt-import
2929
- id: go-vet
@@ -34,6 +34,8 @@ repos:
3434
- id: go-static-check # install https://staticcheck.io/docs/
3535
- id: golangci-lint # requires github.com/golangci/golangci-lint
3636
args: [--config=.github/linters/.golangci.yml] # optional
37+
- id: go-ruleguard # requires
38+
args: [--rules=rules/rules.go] # required https://github.com/quasilyte/go-ruleguard
3739
```
3840
3941
## Contributing

run-go-ruleguard.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
3+
RULE_FILE="$1"
4+
5+
if ! command -v ruleguard 2>&1 /dev/null
6+
then
7+
echo "go-ruleguard could not be found"
8+
exit
9+
fi
10+
11+
PASS=true
12+
13+
for FILE in "$@"
14+
do
15+
16+
if ! ruleguard -c 0 -rules "$RULE_FILE" "$FILE";
17+
then
18+
PASS=false
19+
fi
20+
done
21+
22+
if [ "$PASS" = "false" ]; then
23+
exit 1
24+
fi

0 commit comments

Comments
 (0)