Skip to content

Commit 0228a8d

Browse files
author
Vladimir Smirnov
authored
Merge pull request #312 from go-graphite/feat/add_linters
feat(ci): Added linters
2 parents aab07c9 + 5ab4b6e commit 0228a8d

File tree

38 files changed

+232
-115
lines changed

38 files changed

+232
-115
lines changed

.github/workflows/lint.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Lint
2+
on:
3+
pull_request:
4+
5+
jobs:
6+
golangci:
7+
name: lint
8+
runs-on: ubuntu-22.04
9+
steps:
10+
- uses: actions/checkout@v4
11+
12+
- uses: actions/setup-go@v4
13+
with:
14+
go-version-file: go.mod
15+
16+
- name: Run linter
17+
uses: golangci/golangci-lint-action@v7
18+
with:
19+
version: v2.0.2
20+

.golangci.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
version: "2"
2+
linters:
3+
default: none
4+
enable:
5+
- asasalint
6+
- asciicheck
7+
- bidichk
8+
- bodyclose
9+
# - contextcheck
10+
- decorder
11+
# - dogsled
12+
- durationcheck
13+
# - errcheck
14+
# - errorlint
15+
# - fatcontext
16+
- ginkgolinter
17+
- gocheckcompilerdirectives
18+
- gochecksumtype
19+
# - goconst
20+
# - gocyclo
21+
# - godot
22+
- goheader
23+
- govet
24+
- grouper
25+
# - ineffassign
26+
- loggercheck
27+
# - makezero
28+
# - misspell
29+
# - mnd
30+
# - nilerr
31+
# - noctx
32+
# - nosprintfhostport
33+
- prealloc
34+
# - predeclared
35+
- promlinter
36+
- protogetter
37+
- reassign
38+
# - revive
39+
- rowserrcheck
40+
- sloglint
41+
- spancheck
42+
- sqlclosecheck
43+
# - staticcheck
44+
# - testifylint
45+
- tparallel
46+
- unconvert
47+
# - unparam
48+
# - unused
49+
- usestdlibvars
50+
# - wastedassign
51+
- whitespace
52+
# - wsl
53+
settings:
54+
gocyclo:
55+
min-complexity: 15
56+
govet:
57+
settings:
58+
printf:
59+
funcs:
60+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
61+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
62+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
63+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
64+
unparam:
65+
check-exported: false
66+
exclusions:
67+
generated: lax
68+
presets:
69+
- comments
70+
- common-false-positives
71+
- legacy
72+
- std-error-handling
73+
rules:
74+
- linters:
75+
- errcheck
76+
- contextcheck
77+
- goconst
78+
- mnd
79+
path: _test\.go
80+
- linters:
81+
- godot
82+
path: notifier/registrator.go
83+
paths:
84+
- third_party$
85+
- builtin$
86+
- examples$
87+
formatters:
88+
enable:
89+
- gofmt
90+
# - gofumpt
91+
- goimports
92+
exclusions:
93+
generated: lax
94+
paths:
95+
- third_party$
96+
- builtin$
97+
- examples$

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,7 @@ md5sum:
117117

118118
sha256sum:
119119
sha256sum $(wildcard $(NAME)_$(VERSION)*.deb) $(wildcard $(NAME)-$(VERSION)*.rpm) > sha256sum
120+
121+
.PHONY: lint
122+
lint:
123+
golangci-lint run

cmd/e2e-test/checks.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,6 @@ func verifyRender(ch *Clickhouse, gch *GraphiteClickhouse, check *RenderCheck, d
299299
from := datetime.TimestampTruncate(check.from, defaultPreision)
300300
until := datetime.TimestampTruncate(check.until, defaultPreision)
301301
for _, format := range check.Formats {
302-
303302
var filteringFunctions []*carbonapi_v3_pb.FilteringFunction
304303
if format == client.FormatPb_v3 {
305304
var err error

cmd/e2e-test/clickhouse.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"bytes"
55
"errors"
66
"fmt"
7-
"io/ioutil"
7+
"io"
88
"net/http"
99
"os"
1010
"os/exec"
@@ -14,9 +14,11 @@ import (
1414
"github.com/msaf1980/go-stringutils"
1515
)
1616

17-
var ClickhouseContainerName = "clickhouse-server-gch-test"
18-
var ClickhouseOldImage = "yandex/clickhouse-server"
19-
var ClickhouseDefaultImage = "clickhouse/clickhouse-server"
17+
var (
18+
ClickhouseContainerName = "clickhouse-server-gch-test"
19+
ClickhouseOldImage = "yandex/clickhouse-server"
20+
ClickhouseDefaultImage = "clickhouse/clickhouse-server"
21+
)
2022

2123
type Clickhouse struct {
2224
Version string `toml:"version"`
@@ -168,7 +170,7 @@ func (c *Clickhouse) Exec(sql string) (bool, string) {
168170

169171
func (c *Clickhouse) Query(sql string) (string, error) {
170172
reader := strings.NewReader(sql)
171-
request, err := http.NewRequest("POST", c.URL(), reader)
173+
request, err := http.NewRequest(http.MethodPost, c.URL(), reader)
172174
if err != nil {
173175
return "", err
174176
}
@@ -177,7 +179,9 @@ func (c *Clickhouse) Query(sql string) (string, error) {
177179
if err != nil {
178180
return "", err
179181
}
180-
msg, err := ioutil.ReadAll(resp.Body)
182+
defer resp.Body.Close()
183+
184+
msg, err := io.ReadAll(resp.Body)
181185
if err != nil {
182186
return "", err
183187
}
@@ -195,6 +199,8 @@ func (c *Clickhouse) Alive() bool {
195199
if err != nil {
196200
return false
197201
}
202+
defer req.Body.Close()
203+
198204
return req.StatusCode == http.StatusOK
199205
}
200206

cmd/graphite-clickhouse-client/main.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func main() {
9090
formatFind = client.FormatPb_v3
9191
}
9292

93-
queryRaw, r, respHeader, err := client.MetricsFind(&httpClient, *address, formatFind, *metricsFind, int64(from), int64(until))
93+
queryRaw, r, respHeader, err := client.MetricsFind(&httpClient, *address, formatFind, *metricsFind, from, until)
9494
if respHeader != nil {
9595
fmt.Printf("Responce header: %+v\n", respHeader)
9696
}
@@ -123,7 +123,7 @@ func main() {
123123
if formatTags == client.FormatDefault {
124124
formatTags = client.FormatJSON
125125
}
126-
queryRaw, r, respHeader, err := client.TagsValues(&httpClient, *address, formatTags, *tagsValues, *limit, int64(from), int64(until))
126+
queryRaw, r, respHeader, err := client.TagsValues(&httpClient, *address, formatTags, *tagsValues, *limit, from, until)
127127
if respHeader != nil {
128128
fmt.Printf("Responce header: %+v\n", respHeader)
129129
}
@@ -156,7 +156,7 @@ func main() {
156156
if formatTags == client.FormatDefault {
157157
formatTags = client.FormatJSON
158158
}
159-
queryRaw, r, respHeader, err := client.TagsNames(&httpClient, *address, formatTags, *tagsNames, *limit, int64(from), int64(until))
159+
queryRaw, r, respHeader, err := client.TagsNames(&httpClient, *address, formatTags, *tagsNames, *limit, from, until)
160160
if respHeader != nil {
161161
fmt.Printf("Responce header: %+v\n", respHeader)
162162
}
@@ -178,7 +178,6 @@ func main() {
178178
} else {
179179
fmt.Println("[]")
180180
}
181-
182181
} else {
183182
ec = 1
184183
fmt.Printf("'%s'\n", strings.TrimRight(err.Error(), "\n"))
@@ -190,7 +189,7 @@ func main() {
190189
if formatRender == client.FormatDefault {
191190
formatRender = client.FormatPb_v3
192191
}
193-
queryRaw, r, respHeader, err := client.Render(&httpClient, *address, formatRender, targets, []*carbonapi_v3_pb.FilteringFunction{}, maxDataPoints, int64(from), int64(until))
192+
queryRaw, r, respHeader, err := client.Render(&httpClient, *address, formatRender, targets, []*carbonapi_v3_pb.FilteringFunction{}, maxDataPoints, from, until)
194193
if respHeader != nil {
195194
fmt.Printf("Responce header: %+v\n", respHeader)
196195
}
@@ -216,7 +215,6 @@ func main() {
216215
} else {
217216
fmt.Println("[]")
218217
}
219-
220218
} else {
221219
ec = 1
222220
fmt.Printf("'%s'\n", strings.TrimRight(err.Error(), "\n"))

config/config.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,6 @@ func (ir IndexReverses) Compile() error {
448448
if _, ok := IndexReverse[n.Reverse]; !ok {
449449
return fmt.Errorf("%s is not valid value for index-reverses.reverse", n.Reverse)
450450
}
451-
452451
}
453452
return nil
454453
}
@@ -549,11 +548,9 @@ func Unmarshal(body []byte, exactConfig bool) (cfg *Config, warns []zap.Field, e
549548
decoder.Strict(exactConfig)
550549

551550
err := decoder.Decode(cfg)
552-
553551
if err != nil {
554552
return nil, nil, err
555553
}
556-
557554
}
558555

559556
if cfg.Logging == nil {

find/handler_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ func (m *clickhouseMock) ServeHTTP(w http.ResponseWriter, r *http.Request) {
2222
}
2323

2424
func TestFind(t *testing.T) {
25-
2625
testCase := func(findQuery, expectedClickHouseQuery string) {
2726
requestLog := make(chan []byte, 1)
2827
m := &clickhouseMock{
@@ -38,7 +37,7 @@ func TestFind(t *testing.T) {
3837
handler := NewHandler(cfg)
3938
w := httptest.NewRecorder()
4039
r := httptest.NewRequest(
41-
"GET",
40+
http.MethodGet,
4241
"http://localhost/metrics/find/?local=1&format=pickle&query="+findQuery,
4342
nil,
4443
)

finder/plain_from_tagged_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,4 @@ func TestPlainFromTaggedFinderAbs(t *testing.T) {
3636
for _, c := range table {
3737
assert.Equal(c[1], string(f.Abs([]byte(c[0]))))
3838
}
39-
4039
}

finder/tagged.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,6 @@ func (t *TaggedFinder) whereFilter(terms []TaggedTerm, from int64, until int64)
446446
date.UntilTimestampToDaysFormat(until),
447447
)
448448
} else {
449-
450449
w.Andf(
451450
"Date >='%s'",
452451
date.FromTimestampToDaysFormat(from),
@@ -632,7 +631,6 @@ func (t *TaggedFinder) SetCostsFromCountTable(ctx context.Context, terms []Tagge
632631
date.UntilTimestampToDaysFormat(until),
633632
)
634633
} else {
635-
636634
w.Andf(
637635
"Date >= '%s'",
638636
date.FromTimestampToDaysFormat(from),

0 commit comments

Comments
 (0)