Skip to content

Commit 51c9259

Browse files
committed
ref: to golangci lint v2
1 parent ab7c2cb commit 51c9259

13 files changed

Lines changed: 91 additions & 129 deletions

File tree

.github/workflows/go.yml

Lines changed: 37 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ name: Go
55

66
on:
77
push:
8-
branches: [ "master" ]
8+
branches: ["master"]
99
pull_request:
10-
branches: [ "master" ]
10+
branches: ["master"]
1111

1212
permissions:
1313
contents: read
@@ -17,42 +17,38 @@ jobs:
1717
build:
1818
runs-on: ubuntu-latest
1919
steps:
20-
- uses: actions/checkout@v3
21-
22-
- name: Set up Go
23-
uses: actions/setup-go@v4
24-
with:
25-
go-version: '1.21'
26-
27-
- name: Build
28-
run: go build -v ./...
29-
30-
- name: Go Format
31-
run: gofmt -s -w . && git diff --exit-code
32-
33-
- name: Go Tidy
34-
run: go mod tidy && git diff --exit-code
35-
36-
- name: Go mod verify
37-
run: go mod verify
38-
39-
- name: Run linter
40-
uses: golangci/golangci-lint-action@v3
41-
with:
42-
version: latest
43-
skip-cache: true
44-
skip-pkg-cache: true
45-
skip-build-cache: true
46-
args: --timeout 3m --verbose
47-
48-
- name: Test
49-
run: go test -v ./...
50-
51-
- name: Update coverage report
52-
uses: ncruces/go-coverage-report@v0
53-
with:
54-
report: true
55-
chart: true
56-
amend: true
57-
if: github.event_name == 'push'
58-
continue-on-error: true
20+
- uses: actions/checkout@v4
21+
22+
- name: Set up Go
23+
uses: actions/setup-go@v5
24+
with:
25+
go-version: "1.25"
26+
27+
- name: Build
28+
run: go build -v ./...
29+
30+
- name: Go Format
31+
run: gofmt -s -w . && git diff --exit-code
32+
33+
- name: Go Tidy
34+
run: go mod tidy && git diff --exit-code
35+
36+
- name: Go mod verify
37+
run: go mod verify
38+
39+
- name: Run linter
40+
uses: golangci/golangci-lint-action@v9
41+
with:
42+
args: --timeout 3m --verbose
43+
44+
- name: Test
45+
run: go test -v ./... -count=10
46+
47+
- name: Update coverage report
48+
uses: ncruces/go-coverage-report@v0
49+
with:
50+
report: true
51+
chart: true
52+
amend: true
53+
if: github.event_name == 'push'
54+
continue-on-error: true

.golangci.yml

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,42 @@
11
# More info on config here: https://github.com/golangci/golangci-lint#config-file
2+
version: "2"
3+
24
run:
3-
deadline: 10s
4-
issues-exit-code: 1
5+
timeout: 10s
56
tests: true
6-
skip-dirs-use-default: true
7-
skip-dirs:
8-
- bin
9-
- vendor
10-
- tests
117

128
output:
13-
format: colored-line-number
14-
print-issued-lines: true
15-
print-linter-name: true
16-
17-
linters-settings:
18-
govet:
19-
check-shadowing: true
20-
golint:
21-
min-confidence: 0
22-
dupl:
23-
threshold: 100
24-
goconst:
25-
min-len: 2
26-
min-occurrences: 2
27-
9+
formats:
10+
text:
11+
path: stdout
12+
print-linter-name: true
13+
colors: true
2814

2915
linters:
30-
disable-all: true
16+
default: none
3117
enable:
3218
- unused
33-
- stylecheck
34-
- gosimple
3519
- govet
3620
- errcheck
3721
- ineffassign
38-
- typecheck
3922
- dupl
4023
- goconst
41-
- goimports
42-
- megacheck
4324
- gosec
4425
- gocritic
4526
- staticcheck
27+
settings:
28+
govet:
29+
enable:
30+
- shadow
31+
dupl:
32+
threshold: 100
33+
goconst:
34+
min-len: 2
35+
min-occurrences: 2
36+
37+
formatters:
38+
enable:
39+
- goimports
4640

4741
issues:
4842
exclude-use-default: false

bik/bik_test.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ func TestValidate(t *testing.T) {
4040
}
4141

4242
for i, tc := range testCases {
43-
tc := tc
44-
4543
isValid, err := Validate(tc.Code)
4644
if err != nil {
4745
require.ErrorAs(t, err, &tc.Error, fmt.Sprintf("invalid test case %d: input: %s", i, tc.Code))
@@ -87,8 +85,6 @@ func TestValidate(t *testing.T) {
8785
},
8886
}
8987
for i, tc := range testCases {
90-
tc := tc
91-
9288
isValid, err := Validate(tc.Code)
9389
if err != nil {
9490
require.ErrorAs(t, err, &tc.Error, fmt.Sprintf("invalid test case %d: input: %s", i, tc.Code))
@@ -102,7 +98,7 @@ func TestValidate(t *testing.T) {
10298
}
10399

104100
func Test_Generate(t *testing.T) {
105-
for i := 0; i < 10; i++ {
101+
for range 10 {
106102
bik := Generate()
107103
isValid, err := Validate(bik)
108104
require.NoError(t, err, fmt.Sprintf("invalid bik value: %s", bik))
@@ -119,12 +115,12 @@ func Test_Exists(t *testing.T) {
119115
}
120116

121117
func BenchmarkValidateCorrect(b *testing.B) {
122-
for i := 0; i < b.N; i++ {
118+
for b.Loop() {
123119
_, _ = Validate("044525225")
124120
}
125121
}
126122
func BenchmarkGenerate(b *testing.B) {
127-
for i := 0; i < b.N; i++ {
123+
for b.Loop() {
128124
Generate()
129125
}
130126
}

inn/inn_test.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ func TestValidate(t *testing.T) {
4040
},
4141
}
4242
for i, tc := range testCases {
43-
tc := tc
44-
4543
isValid, err := Validate(tc.Code)
4644
assert.Equal(t, tc.IsValid, isValid, tc.Code)
4745
if err != nil {
@@ -83,8 +81,6 @@ func TestValidate(t *testing.T) {
8381
},
8482
}
8583
for i, tc := range testCases {
86-
tc := tc
87-
8884
isValid, err := Validate(tc.Code)
8985
assert.Equal(t, tc.IsValid, isValid, tc.Code)
9086
if err != nil {
@@ -102,7 +98,7 @@ func TestGenerate(t *testing.T) {
10298
t.Run("generate legal inn", func(t *testing.T) {
10399
var inn string
104100

105-
for i := 0; i < 10; i++ {
101+
for range 10 {
106102
inn = GenerateLegal()
107103
isValid, err := Validate(inn)
108104
require.NoError(t, err, inn)
@@ -114,7 +110,7 @@ func TestGenerate(t *testing.T) {
114110
t.Run("generate physical inn", func(t *testing.T) {
115111
var inn string
116112

117-
for i := 0; i < 10; i++ {
113+
for range 10 {
118114
inn = GeneratePhysical()
119115
isValid, err := Validate(inn)
120116
require.NoError(t, err, inn)
@@ -126,7 +122,7 @@ func TestGenerate(t *testing.T) {
126122
t.Run("generate random inn", func(t *testing.T) {
127123
var inn string
128124

129-
for i := 0; i < 10; i++ {
125+
for range 10 {
130126
inn = Generate()
131127
isValid, err := Validate(inn)
132128
require.NoError(t, err, inn)
@@ -137,31 +133,31 @@ func TestGenerate(t *testing.T) {
137133
}
138134

139135
func BenchmarkValidateCorrectLegal(b *testing.B) {
140-
for i := 0; i < b.N; i++ {
136+
for b.Loop() {
141137
_, _ = Validate("7707083893")
142138
}
143139
}
144140

145141
func BenchmarkValidateCorrectPhysical(b *testing.B) {
146-
for i := 0; i < b.N; i++ {
142+
for b.Loop() {
147143
_, _ = Validate("526317984689")
148144
}
149145
}
150146

151147
func BenchmarkGenerate(b *testing.B) {
152-
for i := 0; i < b.N; i++ {
148+
for b.Loop() {
153149
Generate()
154150
}
155151
}
156152

157153
func BenchmarkGenerateLegal(b *testing.B) {
158-
for i := 0; i < b.N; i++ {
154+
for b.Loop() {
159155
GenerateLegal()
160156
}
161157
}
162158

163159
func BenchmarkGeneratePhysical(b *testing.B) {
164-
for i := 0; i < b.N; i++ {
160+
for b.Loop() {
165161
GeneratePhysical()
166162
}
167163
}

kpp/kpp_test.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ func TestValidate(t *testing.T) {
4444
},
4545
}
4646
for i, tc := range testCases {
47-
tc := tc
48-
4947
isValid, err := Validate(tc.Code)
5048
assert.Equal(t, isValid, tc.IsValid, fmt.Sprintf("invalid test case %d: input: %s", i, tc.Code))
5149
if err != nil {
@@ -86,8 +84,6 @@ func TestValidate(t *testing.T) {
8684
},
8785
}
8886
for i, tc := range testCases {
89-
tc := tc
90-
9187
isValid, err := Validate(tc.Code)
9288
assert.Equal(t, isValid, tc.IsValid, fmt.Sprintf("invalid test case %d: input: %s", i, tc.Code))
9389
if err != nil {
@@ -116,8 +112,6 @@ func TestValidate(t *testing.T) {
116112
},
117113
}
118114
for i, tc := range testCases {
119-
tc := tc
120-
121115
isValid, err := Validate(tc.Code)
122116
assert.Equal(t, isValid, tc.IsValid, fmt.Sprintf("invalid test case %d: input: %s", i, tc.Code))
123117
if err != nil {
@@ -130,7 +124,7 @@ func TestValidate(t *testing.T) {
130124
}
131125

132126
func Test_Generate(t *testing.T) {
133-
for i := 0; i < 10; i++ {
127+
for range 10 {
134128
kpp := Generate()
135129
isValid, err := Validate(kpp)
136130
require.NoError(t, err, fmt.Sprintf("invalid kpp value: %s", kpp))
@@ -140,12 +134,12 @@ func Test_Generate(t *testing.T) {
140134
}
141135

142136
func BenchmarkValidateCorrect(b *testing.B) {
143-
for i := 0; i < b.N; i++ {
137+
for b.Loop() {
144138
_, _ = Validate("775001001")
145139
}
146140
}
147141
func BenchmarkGenerate(b *testing.B) {
148-
for i := 0; i < b.N; i++ {
142+
for b.Loop() {
149143
Generate()
150144
}
151145
}

ogrn/models.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ func ParseOGRN(requiredType OGRNType, ogrn string) (*OGRNStruct, error) {
175175
}
176176

177177
if requiredType == Physical && len(ogrn) != physicalLength {
178-
fmt.Println(requiredType, len(ogrn))
179178
return nil, &models.CommonError{
180179
Method: packageName,
181180
Err: models.ErrInvalidLength,

ogrn/ogrn_test.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ func TestValidate(t *testing.T) {
3939
},
4040
}
4141
for i, tc := range testCases {
42-
tc := tc
43-
4442
isValid, err := Validate(tc.Code)
4543
assert.Equal(t, tc.IsValid, isValid, tc.Code)
4644
if err != nil {
@@ -81,8 +79,6 @@ func TestValidate(t *testing.T) {
8179
}
8280

8381
for i, tc := range testCases {
84-
tc := tc
85-
8682
isValid, err := Validate(tc.Code)
8783
assert.Equal(t, tc.IsValid, isValid, tc.Code)
8884
if err != nil {
@@ -95,7 +91,7 @@ func TestValidate(t *testing.T) {
9591
}
9692

9793
func Test_Generate(t *testing.T) {
98-
for i := 0; i < 10; i++ {
94+
for range 10 {
9995
ogrn := Generate()
10096
isValid, err := Validate(ogrn)
10197
require.NoError(t, err, fmt.Sprintf("invalid ogrn value: %s", ogrn))
@@ -105,12 +101,12 @@ func Test_Generate(t *testing.T) {
105101
}
106102

107103
func BenchmarkValidateCorrect(b *testing.B) {
108-
for i := 0; i < b.N; i++ {
104+
for b.Loop() {
109105
_, _ = Validate("1027700132195")
110106
}
111107
}
112108
func BenchmarkGenerate(b *testing.B) {
113-
for i := 0; i < b.N; i++ {
109+
for b.Loop() {
114110
Generate()
115111
}
116112
}

0 commit comments

Comments
 (0)