Skip to content

Commit

Permalink
Merge branch 'master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Bai-Yingjie authored Jul 3, 2023
2 parents 5fe181a + 8a6061c commit 0fd7e46
Show file tree
Hide file tree
Showing 15 changed files with 226 additions and 131 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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ It powers executable Go scripts and plugins, in embedded interpreters or interac
* Works everywhere Go works
* All Go & runtime resources accessible from script (with control)
* Security: `unsafe` and `syscall` packages neither used nor exported by default
* Support Go 1.18 and Go 1.19 (the latest 2 major releases)
* Support the latest 2 major releases of Go (Go 1.19 and Go 1.20)

## Install

Expand All @@ -30,7 +30,7 @@ import "github.com/traefik/yaegi/interp"
### Command-line executable

```bash
go get -u github.com/traefik/yaegi/cmd/yaegi
go install github.com/traefik/yaegi/cmd/yaegi@latest
```

Note that you can use [rlwrap](https://github.com/hanslub42/rlwrap) (install with your favorite package manager),
Expand Down
20 changes: 20 additions & 0 deletions _test/issue-1571.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

type A struct {
*B[string]
}

type B[T any] struct {
data T
}

func main() {
_ = &A{
B: &B[string]{},
}

println("PASS")
}

// Output:
// PASS
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
Loading

0 comments on commit 0fd7e46

Please sign in to comment.