Skip to content

Commit d4ef23b

Browse files
committed
feat: making updates to linting, docs and hooks
1 parent df8be93 commit d4ef23b

11 files changed

Lines changed: 114 additions & 48 deletions

.cz.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
commitizen:
2+
name: cz_customize
3+
customize:
4+
message_template: "{{change_type}}:{% if show_message %} {{message}}{% endif %}"
5+
example: 'feature: this feature enable customize through config file'
6+
schema: "<type>: <body>"
7+
schema_pattern: "(feature|bug fix):(\\s.*)"
8+
bump_pattern: "^(break|new|fix|hotfix)"
9+
commit_parser: "^(?P<change_type>feature|bug fix):\\s(?P<message>.*)?"
10+
changelog_pattern: "^(feature|bug fix)?(!)?"
11+
change_type_map:
12+
feature: Feat
13+
bug fix: Fix
14+
bump_map:
15+
break: MAJOR
16+
new: MINOR
17+
fix: PATCH
18+
hotfix: PATCH
19+
change_type_order: ["BREAKING CHANGE", "feat", "fix", "refactor", "perf"]
20+
info_path: cz_customize_info.txt
21+
info: This is customized info
22+
questions:
23+
- type: list
24+
name: change_type
25+
choices:
26+
- value: feat
27+
name: 'feat: A new feature.'
28+
- value: fix
29+
name: 'fix: A bug fix.'
30+
- value: refactor
31+
name: 'refactor: A code change that neither fixes a bug nor adds a feature.'
32+
- value: perf
33+
name: 'perf: A code change that improves performance.'
34+
- value: test
35+
name: 'test: Adding missing tests or correcting existing tests.'
36+
- value: docs
37+
name: 'docs: Documentation only changes.'
38+
- value: chore
39+
name: 'chore: Changes that don''t modify src or test files.'
40+
- value: cicd
41+
name: 'cicd: Changes to CI/CD configuration files and scripts.'
42+
message: Select the type of change you are committing
43+
- type: input
44+
name: message
45+
message: Body.
46+
- type: confirm
47+
name: show_message
48+
message: Do you want to add body message in commit?

.pre-commit-config.yaml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,33 @@ repos:
1414
'--exclude-files',
1515
'(_test\.go$|/testdata/)',
1616
]
17-
- repo: https://github.com/sqlfluff/sqlfluff
18-
rev: 3.2.4
19-
hooks:
20-
- id: sqlfluff-fix
17+
- repo: https://github.com/mrtazz/checkmake.git
18+
rev: 0.2.2
19+
hooks:
20+
- id: checkmake
2121
- repo: https://github.com/pre-commit/pre-commit-hooks
2222
rev: v5.0.0
2323
hooks:
2424
- id: check-json
2525
- id: check-merge-conflict
2626
- id: check-yaml
27+
- id: end-of-file-fixer
28+
- id: check-symlinks
29+
- repo: https://github.com/markdownlint/markdownlint
30+
rev: v0.12.0
31+
hooks:
32+
- id: markdownlint
33+
- repo: https://github.com/commitizen-tools/commitizen
34+
rev: v3.30.1
35+
hooks:
36+
- id: commitizen
37+
- id: commitizen-branch
38+
stages: [push]
39+
- repo: local
40+
hooks:
41+
- id: makefile
42+
name: Run Makefile Lint
43+
entry: make
44+
args: [pre-commit]
45+
language: system
46+
pass_filenames: false

.secrets.baseline

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "1.1.2",
2+
"version": "1.5.0",
33
"plugins_used": [
44
{
55
"name": "ArtifactoryDetector"
@@ -72,10 +72,18 @@
7272
{
7373
"path": "detect_secrets.filters.allowlist.is_line_allowlisted"
7474
},
75+
{
76+
"path": "detect_secrets.filters.common.is_baseline_file",
77+
"filename": ".secrets.baseline"
78+
},
7579
{
7680
"path": "detect_secrets.filters.common.is_ignored_due_to_verification_policies",
7781
"min_level": 2
7882
},
83+
{
84+
"path": "detect_secrets.filters.gibberish.should_exclude_secret",
85+
"limit": 3.7
86+
},
7987
{
8088
"path": "detect_secrets.filters.heuristic.is_indirect_reference"
8189
},
@@ -99,8 +107,14 @@
99107
},
100108
{
101109
"path": "detect_secrets.filters.heuristic.is_templated_secret"
110+
},
111+
{
112+
"path": "detect_secrets.filters.regex.should_exclude_file",
113+
"pattern": [
114+
"(_test\\.go/testdata/)"
115+
]
102116
}
103117
],
104118
"results": {},
105-
"generated_at": "2021-12-19T18:30:03Z"
119+
"generated_at": "2024-11-15T15:19:50Z"
106120
}

Makefile

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,29 @@ all: build tidy lint fmt test
55
# ------------------------------------------------------------------------
66
env=CGO_ENABLED=1
77
op= op run --env-file="./.env" --
8+
SHELL := $(shell which bash)
9+
fuzzsh=https://raw.githubusercontent.com/devnw/workflows/refs/heads/main/fuzz.sh
10+
11+
pre-commit: update upgrade tidy fmt lint build test
812

913
test:
1014
CGO_ENABLED=1 go test -v -cover -failfast -race ./...
1115

1216
fuzz:
13-
@fuzzTime=$${FUZZ_TIME:-10}; \
14-
files=$$(grep -r --include='**_test.go' --files-with-matches 'func Fuzz' .); \
15-
for file in $$files; do \
16-
funcs=$$(grep -o 'func Fuzz\w*' $$file | sed 's/func //'); \
17-
for func in $$funcs; do \
18-
echo "Fuzzing $$func in $$file"; \
19-
parentDir=$$(dirname $$file); \
20-
go test $$parentDir -run=$$func -fuzz=$$func -fuzztime=$${fuzzTime}s; \
21-
if [ $$? -ne 0 ]; then \
22-
echo "Fuzzing $$func in $$file failed"; \
23-
exit 1; \
24-
fi; \
25-
done; \
26-
done
17+
curl -fsSL $(fuzzsh) | $(SHELL)
2718

2819
bench:
2920
go test -bench=. -benchmem ./...
3021

3122
test-all: test fuzz
3223

33-
lint:
24+
fmt:
25+
nixfmt flake.nix
3426
goimports -w .
27+
gofmt -s -w .
28+
29+
lint:
3530
golangci-lint run
36-
pre-commit run --all-files
3731

3832
gomod2nix:
3933
gomod2nix generate
@@ -51,17 +45,11 @@ upgrade:
5145
update:
5246
git submodule update --recursive
5347

54-
fmt:
55-
gofmt -s -w .
56-
5748
tidy: fmt
5849
go mod tidy
5950

6051
release:
61-
if [ -z "$(tag)" ]; then \
62-
echo "tag is required"; \
63-
exit 1; \
64-
fi
52+
if [ -z "$(tag)" ]; then echo "tag is required"; exit 1; fi
6553
git tag -a ${tag} -m "${tag}"
6654
git push origin ${tag}
6755

@@ -102,4 +90,4 @@ FORCE:
10290
# Phony targets
10391
#-------------------------------------------------------------------------
10492

105-
.PHONY: build test lint fuzz
93+
.PHONY: build test lint fuzz all clean FORCE

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
# Bridgekeeper - What is your (Re)Quest?
2-
3-
## HTTP Request Limiter and Retrier
1+
# Bridgekeeper - HTTP Request Limiter and Retrier
42

53
[![Build & Test](https://github.com/devnw/bridgekeeper/actions/workflows/build.yml/badge.svg)](https://github.com/devnw/bridgekeeper/actions/workflows/build.yml)
64
[![Go Reference](https://pkg.go.dev/badge/go.devnw.com/bk/v2.svg)](https://pkg.go.dev/go.devnw.com/bk)
75
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
86

9-
### Using Bridgekeeper
7+
## Using Bridgekeeper
108

119
```go
1210
go get -u go.devnw.com/bk/v2@latest
@@ -29,6 +27,7 @@ go get -u go.devnw.com/bk/v2@latest
2927
log.Fatal(err)
3028
}
3129
```
30+
3231
### HTTP Round Tripper Example
3332

3433
```go

bk.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (k *Keeper) handleRequest(req *requestWrapper) {
109109

110110
// Execute a call against the endpoint handling any potential panics from
111111
// the http client
112-
resp, err := k.execute(req)
112+
resp, err := k.execute(req) //nolint:bodyclose // upstream responsibility
113113
if resp == nil {
114114
select {
115115
case <-req.ctx.Done():

bk_mocks_test.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func (client *httpclient) RoundTrip(r *http.Request) (*http.Response, error) {
2424
return client.Do(r)
2525
}
2626

27-
func (client *httpclient) Do(r *http.Request) (*http.Response, error) {
27+
func (client *httpclient) Do(*http.Request) (*http.Response, error) {
2828
if client.delay > 0 {
2929
time.Sleep(client.delay)
3030
}
@@ -46,8 +46,8 @@ func (client *httpclient) Do(r *http.Request) (*http.Response, error) {
4646

4747
type fakeReadCloser struct{}
4848

49-
func (rc *fakeReadCloser) Read(p []byte) (n int, err error) { return 0, io.EOF }
50-
func (rc *fakeReadCloser) Close() error { return nil }
49+
func (rc *fakeReadCloser) Read([]byte) (int, error) { return 0, io.EOF }
50+
func (rc *fakeReadCloser) Close() error { return nil }
5151

5252
type badclient struct {
5353
panic bool
@@ -63,7 +63,7 @@ func (client *badclient) RoundTrip(r *http.Request) (*http.Response, error) {
6363
return client.Do(r)
6464
}
6565

66-
func (client *badclient) Do(r *http.Request) (*http.Response, error) {
66+
func (client *badclient) Do(*http.Request) (*http.Response, error) {
6767
if client.panic {
6868
panic("panic")
6969
}
@@ -75,11 +75,7 @@ type tstruct struct {
7575
error bool
7676
}
7777

78-
func (t *tstruct) correct(err error, paniced bool) error {
79-
if paniced {
80-
return errors.New("unexpected panic")
81-
}
82-
78+
func (t *tstruct) correct(err error, _ bool) error {
8379
if t.error && err == nil {
8480
return errors.New("expected error but success instead")
8581
}

bk_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type tcase struct {
1414
success tstruct
1515
}
1616

17-
func cases(t *testing.T, req func() *http.Request) map[string]tcase {
17+
func cases(_ *testing.T, req func() *http.Request) map[string]tcase {
1818
return map[string]tcase{
1919
"ValidWValidClient": {
2020
&httpclient{

bk_test_rt.go

Lines changed: 0 additions & 1 deletion
This file was deleted.

flake.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
automake
5656
act
5757
gcc
58+
ruby
59+
commitizen
5860

5961
python
6062

0 commit comments

Comments
 (0)