jenkins: update to golangci-lint 1.21.0 (#3289)

* jenkins: update to golint-1.21.0
* don't use underscores in var
* make handles private to satisfy linter

lib\uplinkc\universe.go:32:39: exported method Add returns unexported type storj.io/storj/lib/uplinkc._Ctype_long, which can be annoying to use (golint)
   func (m *Universe) Add(x interface{}) Handle {

* disable wsl explicitly
This commit is contained in:
Egon Elbre 2019-10-17 10:42:22 +03:00 committed by GitHub
parent 863e4cacbe
commit edf8318c0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 110 additions and 109 deletions

View File

@ -33,6 +33,7 @@ linters:
#TODO#- gosec #TODO#- gosec
disable: disable:
- godox - godox
- wsl # too much noise
- goimports # disabled, because it's slow, using scripts/check-imports.go instead. - goimports # disabled, because it's slow, using scripts/check-imports.go instead.
- goconst # check for things that could be replaced by constants - goconst # check for things that could be replaced by constants
- gocyclo # needs tweaking - gocyclo # needs tweaking

View File

@ -27,7 +27,7 @@ RUN unzip /tmp/protoc.zip -d "$HOME"/protoc
# Linters # Linters
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b ${GOPATH}/bin v1.19.1 RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b ${GOPATH}/bin v1.21.0
RUN go get github.com/ckaznocha/protoc-gen-lint RUN go get github.com/ckaznocha/protoc-gen-lint
RUN go get github.com/nilslice/protolock/cmd/protolock RUN go get github.com/nilslice/protolock/cmd/protolock
RUN go get github.com/josephspurrier/goversioninfo RUN go get github.com/josephspurrier/goversioninfo

View File

@ -46,7 +46,7 @@ build-dev-deps: ## Install dependencies for builds
go get golang.org/x/tools/cover go get golang.org/x/tools/cover
go get github.com/modocache/gover go get github.com/modocache/gover
go get github.com/go-bindata/go-bindata/go-bindata go get github.com/go-bindata/go-bindata/go-bindata
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b ${GOPATH}/bin v1.19.1 curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b ${GOPATH}/bin v1.21.0
.PHONY: lint .PHONY: lint
lint: check-copyrights ## Analyze and find programs in source code lint: check-copyrights ## Analyze and find programs in source code

58
lib/uplinkc/handles.go Normal file
View File

@ -0,0 +1,58 @@
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"sync"
)
import "C"
// handle is a generic handle.
type handle = C.long
// handles stores different Go values that need to be accessed from Go side.
type handles struct {
lock sync.Mutex
nextid handle
values map[handle]interface{}
}
// newHandles creates a place to store go files by handle.
func newHandles() *handles {
return &handles{
values: make(map[handle]interface{}),
}
}
// Add adds a value to the table.
func (m *handles) Add(x interface{}) handle {
m.lock.Lock()
defer m.lock.Unlock()
m.nextid++
m.values[m.nextid] = x
return m.nextid
}
// Get gets a value.
func (m *handles) Get(x handle) interface{} {
m.lock.Lock()
defer m.lock.Unlock()
return m.values[x]
}
// Del deletes the value
func (m *handles) Del(x handle) {
m.lock.Lock()
defer m.lock.Unlock()
delete(m.values, x)
}
// Empty returns whether the handles is empty.
func (m *handles) Empty() bool {
m.lock.Lock()
defer m.lock.Unlock()
return len(m.values) == 0
}

View File

@ -0,0 +1,39 @@
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestUniverse(t *testing.T) {
{
handles := newHandles()
str := "testing 123"
handle := handles.Add(str)
got := handles.Get(handle)
assert.Equal(t, str, got)
handles.Del(handle)
assert.True(t, handles.Empty())
}
{
handles := newHandles()
str := "testing 123"
handle := handles.Add(&str)
got := handles.Get(handle)
assert.Equal(t, str, *got.(*string))
handles.Del(handle)
assert.True(t, handles.Empty())
assert.Nil(t, handles.Get(handle))
}
}

View File

@ -42,7 +42,7 @@ func TestC(t *testing.T) {
ctx := testcontext.NewWithTimeout(t, 5*time.Minute) ctx := testcontext.NewWithTimeout(t, 5*time.Minute)
defer ctx.Cleanup() defer ctx.Cleanup()
libuplink_include := ctx.CompileShared(t, "uplink", "storj.io/storj/lib/uplinkc") libuplinkInclude := ctx.CompileShared(t, "uplink", "storj.io/storj/lib/uplinkc")
currentdir, err := os.Getwd() currentdir, err := os.Getwd()
require.NoError(t, err) require.NoError(t, err)
@ -65,7 +65,7 @@ func TestC(t *testing.T) {
Dest: testName, Dest: testName,
Sources: []string{ctest}, Sources: []string{ctest},
Includes: []testcontext.Include{ Includes: []testcontext.Include{
libuplink_include, libuplinkInclude,
definition, definition,
testcontext.CLibMath, testcontext.CLibMath,
}, },

View File

@ -1,66 +0,0 @@
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"sync"
)
import "C"
var universe = NewUniverse()
// Handle is a generic handle.
type Handle = C.long
// Universe stores different Go values that need to be accessed from Go side.
type Universe struct {
lock sync.Mutex
nextid Handle
values map[Handle]interface{}
}
// NewUniverse creates a place to store go files by handle.
func NewUniverse() *Universe {
return &Universe{
values: make(map[Handle]interface{}),
}
}
// Add adds a value to the table.
func (m *Universe) Add(x interface{}) Handle {
m.lock.Lock()
defer m.lock.Unlock()
m.nextid++
m.values[m.nextid] = x
return m.nextid
}
// Get gets a value.
func (m *Universe) Get(x Handle) interface{} {
m.lock.Lock()
defer m.lock.Unlock()
return m.values[x]
}
// Del deletes the value
func (m *Universe) Del(x Handle) {
m.lock.Lock()
defer m.lock.Unlock()
delete(m.values, x)
}
// Empty returns whether the universe is empty.
func (m *Universe) Empty() bool {
m.lock.Lock()
defer m.lock.Unlock()
return len(m.values) == 0
}
//export internal_UniverseIsEmpty
// internal_UniverseIsEmpty returns true if nothing is stored in the global map.
func internal_UniverseIsEmpty() bool {
return universe.Empty()
}

View File

@ -1,39 +0,0 @@
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestUniverse(t *testing.T) {
{
universe := NewUniverse()
str := "testing 123"
handle := universe.Add(str)
got := universe.Get(handle)
assert.Equal(t, str, got)
universe.Del(handle)
assert.True(t, universe.Empty())
}
{
universe := NewUniverse()
str := "testing 123"
handle := universe.Add(&str)
got := universe.Get(handle)
assert.Equal(t, str, *got.(*string))
universe.Del(handle)
assert.True(t, universe.Empty())
assert.Nil(t, universe.Get(handle))
}
}

View File

@ -12,6 +12,14 @@ import (
"storj.io/storj/lib/uplink" "storj.io/storj/lib/uplink"
) )
var universe = newHandles()
//export internal_UniverseIsEmpty
// internal_UniverseIsEmpty returns true if nothing is stored in the global map.
func internal_UniverseIsEmpty() bool {
return universe.Empty()
}
// Uplink is a scoped uplink.Uplink. // Uplink is a scoped uplink.Uplink.
type Uplink struct { type Uplink struct {
scope scope