Skip to content

Commit 8a6061c

Browse files
authored
chore: update linter
update golangci-lint to v1.53.3
1 parent c10e468 commit 8a6061c

File tree

13 files changed

+202
-129
lines changed

13 files changed

+202
-129
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ on:
77
pull_request:
88

99
env:
10-
GO_VERSION: 1.19
11-
GOLANGCI_LINT_VERSION: v1.47.1
10+
GO_VERSION: '1.20'
11+
GOLANGCI_LINT_VERSION: v1.53.3
1212

1313
jobs:
1414

.golangci.toml

Lines changed: 0 additions & 92 deletions
This file was deleted.

.golangci.yml

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
run:
2+
timeout: 10m
3+
skip-files: []
4+
5+
linters-settings:
6+
govet:
7+
check-shadowing: false
8+
gocyclo:
9+
min-complexity: 12
10+
maligned:
11+
suggest-new: true
12+
goconst:
13+
min-len: 3
14+
min-occurrences: 3
15+
funlen:
16+
lines: -1
17+
statements: 50
18+
misspell:
19+
locale: US
20+
depguard:
21+
rules:
22+
main:
23+
files:
24+
- $all
25+
allow:
26+
- $gostd
27+
- github.com/traefik/yaegi
28+
tagalign:
29+
align: false
30+
order:
31+
- xml
32+
- json
33+
- yaml
34+
- yml
35+
- toml
36+
- mapstructure
37+
- url
38+
godox:
39+
keywords:
40+
- FIXME
41+
gocritic:
42+
enabled-tags:
43+
- diagnostic
44+
- style
45+
- performance
46+
disabled-checks:
47+
- paramTypeCombine # already handle by gofumpt.extra-rules
48+
- whyNoLint # already handle by nonolint
49+
- unnamedResult
50+
- hugeParam
51+
- sloppyReassign
52+
- rangeValCopy
53+
- octalLiteral
54+
- ptrToRefParam
55+
- appendAssign
56+
- ruleguard
57+
- httpNoBody
58+
- exposedSyncMutex
59+
- importShadow # TODO should be fixed
60+
- commentedOutCode # TODO should be fixed
61+
revive:
62+
rules:
63+
- name: struct-tag
64+
- name: blank-imports
65+
- name: context-as-argument
66+
- name: context-keys-type
67+
- name: dot-imports
68+
- name: error-return
69+
- name: error-strings
70+
- name: error-naming
71+
- name: exported
72+
disabled: true
73+
- name: if-return
74+
- name: increment-decrement
75+
- name: var-naming
76+
- name: var-declaration
77+
- name: package-comments
78+
disabled: true
79+
- name: range
80+
- name: receiver-naming
81+
- name: time-naming
82+
- name: unexported-return
83+
- name: indent-error-flow
84+
- name: errorf
85+
- name: empty-block
86+
- name: superfluous-else
87+
- name: unused-parameter
88+
disabled: true
89+
- name: unreachable-code
90+
- name: redefines-builtin-id
91+
92+
linters:
93+
enable-all: true
94+
disable:
95+
- deadcode # deprecated
96+
- exhaustivestruct # deprecated
97+
- golint # deprecated
98+
- ifshort # deprecated
99+
- interfacer # deprecated
100+
- maligned # deprecated
101+
- nosnakecase # deprecated
102+
- scopelint # deprecated
103+
- structcheck # deprecated
104+
- varcheck # deprecated
105+
- cyclop # duplicate of gocyclo
106+
- sqlclosecheck # not relevant (SQL)
107+
- rowserrcheck # not relevant (SQL)
108+
- execinquery # not relevant (SQL)
109+
- lll
110+
- gas
111+
- dupl
112+
- prealloc
113+
- gocyclo
114+
- cyclop
115+
- gochecknoinits
116+
- gochecknoglobals
117+
- wsl
118+
- nlreturn
119+
- godox
120+
- funlen
121+
- gocognit
122+
- stylecheck
123+
- gomnd
124+
- testpackage
125+
- paralleltest
126+
- tparallel
127+
- goerr113
128+
- wrapcheck
129+
- nestif
130+
- exhaustive
131+
- exhaustruct
132+
- forbidigo
133+
- ifshort
134+
- forcetypeassert
135+
- varnamelen
136+
- nosnakecase
137+
- nonamedreturns
138+
- nilnil
139+
- maintidx
140+
- dupword # false positives
141+
- errorlint # TODO: must be reactivate after fixes
142+
143+
issues:
144+
exclude-use-default: false
145+
max-per-linter: 0
146+
max-same-issues: 0
147+
exclude: []
148+
exclude-rules:
149+
- path: .+_test\.go
150+
linters:
151+
- goconst
152+
- path: .+_test\.go
153+
text: 'var-declaration:'
154+
- path: interp/interp.go
155+
text: '`in` can be `io.Reader`'
156+
- path: interp/interp.go
157+
text: '`out` can be `io.Writer`'
158+
- path: interp/interp.go
159+
text: '`Panic` should conform to the `XxxError` format'
160+
- path: interp/interp_eval_test.go
161+
linters:
162+
- thelper
163+
- path: interp/debugger.go
164+
linters:
165+
- containedctx

example/pkg/pkg_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func TestPackages(t *testing.T) {
128128
if test.topImport != "" {
129129
topImport = test.topImport
130130
}
131-
if _, err = i.Eval(fmt.Sprintf(`import "%s"`, topImport)); err != nil {
131+
if _, err = i.Eval(fmt.Sprintf(`import %q`, topImport)); err != nil {
132132
t.Fatal(err)
133133
}
134134
value, err := i.Eval(`pkg.NewSample()`)

extract/extract.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ func matchList(name string, list []string) (match bool, err error) {
130130
return
131131
}
132132

133+
// Extractor creates a package with all the symbols from a dependency package.
134+
type Extractor struct {
135+
Dest string // The name of the created package.
136+
License string // License text to be included in the created package, optional.
137+
Exclude []string // Comma separated list of regexp matching symbols to exclude.
138+
Include []string // Comma separated list of regexp matching symbols to include.
139+
Tag []string // Comma separated of build tags to be added to the created package.
140+
}
141+
133142
func (e *Extractor) genContent(importPath string, p *types.Package) ([]byte, error) {
134143
prefix := "_" + importPath + "_"
135144
prefix = strings.NewReplacer("/", "_", "-", "_", ".", "_", "~", "_").Replace(prefix)
@@ -283,11 +292,11 @@ func (e *Extractor) genContent(importPath string, p *types.Package) ([]byte, err
283292
}
284293

285294
for _, t := range e.Tag {
286-
if len(t) != 0 {
295+
if t != "" {
287296
buildTags += "," + t
288297
}
289298
}
290-
if len(buildTags) != 0 && buildTags[0] == ',' {
299+
if buildTags != "" && buildTags[0] == ',' {
291300
buildTags = buildTags[1:]
292301
}
293302

@@ -340,7 +349,7 @@ func fixConst(name string, val constant.Value, imports map[string]bool) string {
340349
str = f.Text('g', int(f.Prec()))
341350
case constant.Complex:
342351
// TODO: not sure how to parse this case
343-
fallthrough
352+
fallthrough //nolint:gocritic // Empty Fallthrough is expected.
344353
default:
345354
return name
346355
}
@@ -351,15 +360,6 @@ func fixConst(name string, val constant.Value, imports map[string]bool) string {
351360
return fmt.Sprintf("constant.MakeFromLiteral(%q, token.%s, 0)", str, tok)
352361
}
353362

354-
// Extractor creates a package with all the symbols from a dependency package.
355-
type Extractor struct {
356-
Dest string // The name of the created package.
357-
License string // License text to be included in the created package, optional.
358-
Exclude []string // Comma separated list of regexp matching symbols to exclude.
359-
Include []string // Comma separated list of regexp matching symbols to include.
360-
Tag []string // Comma separated of build tags to be added to the created package.
361-
}
362-
363363
// importPath checks whether pkgIdent is an existing directory relative to
364364
// e.WorkingDir. If yes, it returns the actual import path of the Go package
365365
// located in the directory. If it is definitely a relative path, but it does not

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module github.com/traefik/yaegi
22

3-
go 1.18
3+
go 1.19

interp/interp.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,14 @@ type opt struct {
184184
noRun bool // compile, but do not run
185185
fastChan bool // disable cancellable chan operations
186186
specialStdio bool // allows os.Stdin, os.Stdout, os.Stderr to not be file descriptors
187-
unrestricted bool // allow use of non sandboxed symbols
187+
unrestricted bool // allow use of non-sandboxed symbols
188188
}
189189

190190
// Interpreter contains global resources and state.
191191
type Interpreter struct {
192-
// id is an atomic counter counter used for run cancellation,
192+
// id is an atomic counter used for run cancellation,
193193
// only accessed via runid/stop
194-
// Located at start of struct to ensure proper alignment on 32 bit
194+
// Located at start of struct to ensure proper alignment on 32-bit
195195
// architectures.
196196
id uint64
197197

interp/interp_consistent_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package interp_test
22

33
import (
4+
"bytes"
45
"go/build"
56
"io"
67
"os"
@@ -176,7 +177,7 @@ func TestInterpConsistencyBuild(t *testing.T) {
176177
t.Fatal(err)
177178
}
178179

179-
if string(outInterp) != string(outRun) {
180+
if !bytes.Equal(outInterp, outRun) {
180181
t.Errorf("\nGot: %q,\n want: %q", string(outInterp), string(outRun))
181182
}
182183
})
@@ -288,8 +289,8 @@ func TestInterpErrorConsistency(t *testing.T) {
288289

289290
for _, test := range testCases {
290291
t.Run(test.fileName, func(t *testing.T) {
291-
if len(test.expectedInterp) == 0 && len(test.expectedExec) == 0 {
292-
t.Fatal("at least expectedInterp must be define")
292+
if test.expectedInterp == "" && test.expectedExec == "" {
293+
t.Fatal("at least expectedInterp must be defined")
293294
}
294295

295296
filePath := filepath.Join("..", "_test", test.fileName)
@@ -315,7 +316,7 @@ func TestInterpErrorConsistency(t *testing.T) {
315316
t.Fatal("An error is expected but got none.")
316317
}
317318

318-
if len(test.expectedExec) == 0 && !strings.Contains(string(outRun), test.expectedInterp) {
319+
if test.expectedExec == "" && !strings.Contains(string(outRun), test.expectedInterp) {
319320
t.Errorf("got %q, want: %q", string(outRun), test.expectedInterp)
320321
} else if !strings.Contains(string(outRun), test.expectedExec) {
321322
t.Errorf("got %q, want: %q", string(outRun), test.expectedExec)

0 commit comments

Comments
 (0)