Skip to content

Commit

Permalink
chore: update linter
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Jul 2, 2023
1 parent c10e468 commit 85abb50
Show file tree
Hide file tree
Showing 13 changed files with 202 additions and 129 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ on:
pull_request:

env:
GO_VERSION: 1.19
GOLANGCI_LINT_VERSION: v1.47.1
GO_VERSION: '1.20'
GOLANGCI_LINT_VERSION: v1.53.3

jobs:

Expand Down
92 changes: 0 additions & 92 deletions .golangci.toml

This file was deleted.

165 changes: 165 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
run:
timeout: 10m
skip-files: []

linters-settings:
govet:
check-shadowing: false
gocyclo:
min-complexity: 12
maligned:
suggest-new: true
goconst:
min-len: 3
min-occurrences: 3
funlen:
lines: -1
statements: 50
misspell:
locale: US
depguard:
rules:
main:
files:
- $all
allow:
- $gostd
- github.com/traefik/yaegi
tagalign:
align: false
order:
- xml
- json
- yaml
- yml
- toml
- mapstructure
- url
godox:
keywords:
- FIXME
gocritic:
enabled-tags:
- diagnostic
- style
- performance
disabled-checks:
- paramTypeCombine # already handle by gofumpt.extra-rules
- whyNoLint # already handle by nonolint
- unnamedResult
- hugeParam
- sloppyReassign
- rangeValCopy
- octalLiteral
- ptrToRefParam
- appendAssign
- ruleguard
- httpNoBody
- exposedSyncMutex
- importShadow # TODO should be fixed
- commentedOutCode # TODO should be fixed
revive:
rules:
- name: struct-tag
- name: blank-imports
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: error-return
- name: error-strings
- name: error-naming
- name: exported
disabled: true
- name: if-return
- name: increment-decrement
- name: var-naming
- name: var-declaration
- name: package-comments
disabled: true
- name: range
- name: receiver-naming
- name: time-naming
- name: unexported-return
- name: indent-error-flow
- name: errorf
- name: empty-block
- name: superfluous-else
- name: unused-parameter
disabled: true
- name: unreachable-code
- name: redefines-builtin-id

linters:
enable-all: true
disable:
- deadcode # deprecated
- exhaustivestruct # deprecated
- golint # deprecated
- ifshort # deprecated
- interfacer # deprecated
- maligned # deprecated
- nosnakecase # deprecated
- scopelint # deprecated
- structcheck # deprecated
- varcheck # deprecated
- cyclop # duplicate of gocyclo
- sqlclosecheck # not relevant (SQL)
- rowserrcheck # not relevant (SQL)
- execinquery # not relevant (SQL)
- lll
- gas
- dupl
- prealloc
- gocyclo
- cyclop
- gochecknoinits
- gochecknoglobals
- wsl
- nlreturn
- godox
- funlen
- gocognit
- stylecheck
- gomnd
- testpackage
- paralleltest
- tparallel
- goerr113
- wrapcheck
- nestif
- exhaustive
- exhaustruct
- forbidigo
- ifshort
- forcetypeassert
- varnamelen
- nosnakecase
- nonamedreturns
- nilnil
- maintidx
- dupword # false positives
- errorlint # TODO: must be reactivate after fixes

issues:
exclude-use-default: false
max-per-linter: 0
max-same-issues: 0
exclude: []
exclude-rules:
- path: .+_test\.go
linters:
- goconst
- path: .+_test\.go
text: 'var-declaration:'
- path: interp/interp.go
text: '`in` can be `io.Reader`'
- path: interp/interp.go
text: '`out` can be `io.Writer`'
- path: interp/interp.go
text: '`Panic` should conform to the `XxxError` format'
- path: interp/interp_eval_test.go
linters:
- thelper
- path: interp/debugger.go
linters:
- containedctx
2 changes: 1 addition & 1 deletion example/pkg/pkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func TestPackages(t *testing.T) {
if test.topImport != "" {
topImport = test.topImport
}
if _, err = i.Eval(fmt.Sprintf(`import "%s"`, topImport)); err != nil {
if _, err = i.Eval(fmt.Sprintf(`import %q`, topImport)); err != nil {
t.Fatal(err)
}
value, err := i.Eval(`pkg.NewSample()`)
Expand Down
24 changes: 12 additions & 12 deletions extract/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ func matchList(name string, list []string) (match bool, err error) {
return
}

// Extractor creates a package with all the symbols from a dependency package.
type Extractor struct {
Dest string // The name of the created package.
License string // License text to be included in the created package, optional.
Exclude []string // Comma separated list of regexp matching symbols to exclude.
Include []string // Comma separated list of regexp matching symbols to include.
Tag []string // Comma separated of build tags to be added to the created package.
}

func (e *Extractor) genContent(importPath string, p *types.Package) ([]byte, error) {
prefix := "_" + importPath + "_"
prefix = strings.NewReplacer("/", "_", "-", "_", ".", "_", "~", "_").Replace(prefix)
Expand Down Expand Up @@ -283,11 +292,11 @@ func (e *Extractor) genContent(importPath string, p *types.Package) ([]byte, err
}

for _, t := range e.Tag {
if len(t) != 0 {
if t != "" {
buildTags += "," + t
}
}
if len(buildTags) != 0 && buildTags[0] == ',' {
if buildTags != "" && buildTags[0] == ',' {
buildTags = buildTags[1:]
}

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

// Extractor creates a package with all the symbols from a dependency package.
type Extractor struct {
Dest string // The name of the created package.
License string // License text to be included in the created package, optional.
Exclude []string // Comma separated list of regexp matching symbols to exclude.
Include []string // Comma separated list of regexp matching symbols to include.
Tag []string // Comma separated of build tags to be added to the created package.
}

// importPath checks whether pkgIdent is an existing directory relative to
// e.WorkingDir. If yes, it returns the actual import path of the Go package
// located in the directory. If it is definitely a relative path, but it does not
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/traefik/yaegi

go 1.18
go 1.19
6 changes: 3 additions & 3 deletions interp/interp.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,14 @@ type opt struct {
noRun bool // compile, but do not run
fastChan bool // disable cancellable chan operations
specialStdio bool // allows os.Stdin, os.Stdout, os.Stderr to not be file descriptors
unrestricted bool // allow use of non sandboxed symbols
unrestricted bool // allow use of non-sandboxed symbols
}

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

Expand Down
9 changes: 5 additions & 4 deletions interp/interp_consistent_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package interp_test

import (
"bytes"
"go/build"
"io"
"os"
Expand Down Expand Up @@ -176,7 +177,7 @@ func TestInterpConsistencyBuild(t *testing.T) {
t.Fatal(err)
}

if string(outInterp) != string(outRun) {
if !bytes.Equal(outInterp, outRun) {
t.Errorf("\nGot: %q,\n want: %q", string(outInterp), string(outRun))
}
})
Expand Down Expand Up @@ -288,8 +289,8 @@ func TestInterpErrorConsistency(t *testing.T) {

for _, test := range testCases {
t.Run(test.fileName, func(t *testing.T) {
if len(test.expectedInterp) == 0 && len(test.expectedExec) == 0 {
t.Fatal("at least expectedInterp must be define")
if test.expectedInterp == "" && test.expectedExec == "" {
t.Fatal("at least expectedInterp must be defined")
}

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

if len(test.expectedExec) == 0 && !strings.Contains(string(outRun), test.expectedInterp) {
if test.expectedExec == "" && !strings.Contains(string(outRun), test.expectedInterp) {
t.Errorf("got %q, want: %q", string(outRun), test.expectedInterp)
} else if !strings.Contains(string(outRun), test.expectedExec) {
t.Errorf("got %q, want: %q", string(outRun), test.expectedExec)
Expand Down
Loading

0 comments on commit 85abb50

Please sign in to comment.