Skip to content

Commit c14d339

Browse files
committed
ci: refactor linter configurations and update GitHub workflows
- Update golangci-lint-action to version 7 in GitHub workflow - Specify version v2.0 for golangci-lint-action in GitHub workflow - Set golangci.yml version to "2" - Change linter configuration to "default: none" in golangci.yml - Replace multiple linter settings with a single "settings" entry in golangci.yml - Add exclusions and presets for generated code in golangci.yml - Add paths exclusions for third_party, builtin, and examples in golangci.yml - Enable gofmt, gofumpt, and goimports formatters in golangci.yml - Replace ioutil with io in size_test.go Signed-off-by: Bo-Yi Wu <[email protected]>
1 parent c9fe096 commit c14d339

File tree

3 files changed

+45
-34
lines changed

3 files changed

+45
-34
lines changed

.github/workflows/go.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ jobs:
2323
go-version-file: go.mod
2424
check-latest: true
2525
- name: Setup golangci-lint
26-
uses: golangci/golangci-lint-action@v6
26+
uses: golangci/golangci-lint-action@v7
2727
with:
28+
version: v2.0
2829
args: --verbose
2930
test:
3031
strategy:

.golangci.yml

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
1+
version: "2"
12
linters:
2-
enable-all: false
3-
disable-all: true
4-
fast: false
3+
default: none
54
enable:
65
- bodyclose
76
- depguard
87
- dogsled
98
- dupl
109
- errcheck
11-
- exportloopref
1210
- exhaustive
1311
- gochecknoinits
1412
- goconst
1513
- gocritic
1614
- gocyclo
17-
- gofmt
18-
- goimports
1915
- goprintffuncname
2016
- gosec
21-
- gosimple
2217
- govet
2318
- ineffassign
2419
- lll
@@ -28,31 +23,46 @@ linters:
2823
- nolintlint
2924
- rowserrcheck
3025
- staticcheck
31-
- stylecheck
32-
- typecheck
3326
- unconvert
3427
- unparam
3528
- unused
3629
- whitespace
30+
settings:
31+
depguard:
32+
rules:
33+
Main:
34+
files:
35+
- $all
36+
- '!$test'
37+
allow:
38+
- $gostd
39+
- github.com/gin-gonic/gin
40+
Test:
41+
files:
42+
- $test
43+
allow:
44+
- $gostd
45+
- github.com/gin-gonic/gin
46+
- github.com/stretchr/testify
47+
exclusions:
48+
generated: lax
49+
presets:
50+
- comments
51+
- common-false-positives
52+
- legacy
53+
- std-error-handling
54+
paths:
55+
- third_party$
56+
- builtin$
57+
- examples$
58+
formatters:
59+
enable:
60+
- gofmt
3761
- gofumpt
38-
39-
linters-settings:
40-
depguard:
41-
rules:
42-
Main:
43-
files:
44-
- $all
45-
- "!$test"
46-
allow:
47-
- $gostd
48-
- github.com/gin-gonic/gin
49-
Test:
50-
files:
51-
- $test
52-
allow:
53-
- $gostd
54-
- github.com/gin-gonic/gin
55-
- github.com/stretchr/testify
56-
57-
run:
58-
timeout: 3m
62+
- goimports
63+
exclusions:
64+
generated: lax
65+
paths:
66+
- third_party$
67+
- builtin$
68+
- examples$

size_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package limits
22

33
import (
44
"bytes"
5-
"io/ioutil"
5+
"io"
66
"net/http"
77
"net/http/httptest"
88
"testing"
@@ -14,7 +14,7 @@ func TestRequestSizeLimiterOK(t *testing.T) {
1414
router := gin.New()
1515
router.Use(RequestSizeLimiter(10))
1616
router.POST("/test_ok", func(c *gin.Context) {
17-
_, _ = ioutil.ReadAll(c.Request.Body)
17+
_, _ = io.ReadAll(c.Request.Body)
1818
if len(c.Errors) > 0 {
1919
return
2020
}
@@ -32,7 +32,7 @@ func TestRequestSizeLimiterOver(t *testing.T) {
3232
router := gin.New()
3333
router.Use(RequestSizeLimiter(10))
3434
router.POST("/test_large", func(c *gin.Context) {
35-
_, _ = ioutil.ReadAll(c.Request.Body)
35+
_, _ = io.ReadAll(c.Request.Body)
3636
if len(c.Errors) > 0 {
3737
return
3838
}

0 commit comments

Comments
 (0)