Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add golangci-lint and fix linting issues #111

Merged
merged 1 commit into from Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
@@ -0,0 +1 @@
*.go text eol=lf
19 changes: 19 additions & 0 deletions .github/workflows/lint.yml
@@ -0,0 +1,19 @@
name: golangci-lint
on: push
jobs:
golangci:
strategy:
matrix:
go-version: [1.15.x]
os: [macos-latest, windows-latest, ubuntu-latest]
name: lint
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: 1.17
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.44.2
20 changes: 3 additions & 17 deletions .github/workflows/ci.yml → .github/workflows/test.yml
@@ -1,35 +1,21 @@
name: Continuous Integration
on: push

jobs:

linux:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v2
with:
go-version: 1.17
- run: sudo apt-get install pass gnome-keyring dbus-x11
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- run: go test -race ./...
- run: go vet ./...

mac:
runs-on: macOS-latest
runs-on: macos-latest
steps:
- uses: actions/setup-go@v2
with:
go-version: 1.17
- run: brew install pass gnupg
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- run: go test -race ./...
- run: go vet ./...

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v2
with:
go-version: 1.17
- uses: actions/checkout@v1
- run: diff -u <(echo -n) <(gofmt -s -d .)
39 changes: 39 additions & 0 deletions .golangci.yml
@@ -0,0 +1,39 @@
linters:
enable:
- bodyclose
- contextcheck
- deadcode
- depguard
- durationcheck
- dupl
- errcheck
- errchkjson
- errname
- exhaustive
- exportloopref
- gocritic
- gofmt
- goimports
- gosimple
- govet
- ineffassign
- makezero
- misspell
- nakedret
- nilerr
- nilnil
- noctx
- prealloc
- revive
- rowserrcheck
- staticcheck
- structcheck
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- unused
- varcheck
- wastedassign
- whitespace
12 changes: 6 additions & 6 deletions array.go
Expand Up @@ -2,13 +2,13 @@ package keyring

// ArrayKeyring is a mock/non-secure backend that meets the Keyring interface.
// It is intended to be used to aid unit testing of code that relies on the package.
// NOTE: Do not use in production code
// NOTE: Do not use in production code.
type ArrayKeyring struct {
items map[string]Item
}

// NewArrayKeyring returns an ArrayKeyring, optionally constructed with an initial slice
// of items
// of items.
func NewArrayKeyring(initial []Item) *ArrayKeyring {
kr := &ArrayKeyring{}
for _, i := range initial {
Expand All @@ -17,15 +17,15 @@ func NewArrayKeyring(initial []Item) *ArrayKeyring {
return kr
}

// Get returns an Item matching Key
// Get returns an Item matching Key.
func (k *ArrayKeyring) Get(key string) (Item, error) {
if i, ok := k.items[key]; ok {
return i, nil
}
return Item{}, ErrKeyNotFound
}

// Set will store an item on the mock Keyring
// Set will store an item on the mock Keyring.
func (k *ArrayKeyring) Set(i Item) error {
if k.items == nil {
k.items = map[string]Item{}
Expand All @@ -34,13 +34,13 @@ func (k *ArrayKeyring) Set(i Item) error {
return nil
}

// Remove will delete an Item from the Keyring
// Remove will delete an Item from the Keyring.
func (k *ArrayKeyring) Remove(key string) error {
delete(k.items, key)
return nil
}

// Keys provides a slice of all Item keys on the Keyring
// Keys provides a slice of all Item keys on the Keyring.
func (k *ArrayKeyring) Keys() ([]string, error) {
var keys = []string{}
for key := range k.items {
Expand Down
1 change: 1 addition & 0 deletions cmd/keyring/main.go
Expand Up @@ -104,5 +104,6 @@ func hasBackend(key string) bool {
return true
}
}

return false
}
2 changes: 1 addition & 1 deletion config.go
@@ -1,6 +1,6 @@
package keyring

// Config contains configuration for keyring
// Config contains configuration for keyring.
type Config struct {
// AllowedBackends is a whitelist of backend providers that can be used. Nil means all available.
AllowedBackends []BackendType
Expand Down
7 changes: 7 additions & 0 deletions docker-compose.yml
@@ -0,0 +1,7 @@
version: "3.9"
services:
keyring:
image: golang:1.17
volumes:
- .:/usr/local/src/keyring
working_dir: /usr/local/src/keyring
3 changes: 1 addition & 2 deletions go.mod
Expand Up @@ -10,14 +10,13 @@ require (
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c
github.com/mtibben/percent v0.2.1
github.com/stretchr/testify v1.7.0
golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838
golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.3.0 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
8 changes: 0 additions & 8 deletions go.sum
Expand Up @@ -26,20 +26,12 @@ github.com/stretchr/objx v0.3.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoH
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838 h1:71vQrMauZZhcTVK6KdYM+rklehEEwb3E+ZhaE5jrPrE=
golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210819135213-f52c844e1c1c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a h1:ppl5mZgokTT8uPkmYOyEUmPTr3ypaKkg5eFOGrAmxxE=
golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b h1:QRR6H1YWRnHb4Y/HeNFCTJLFVxaq6wH4YuVdsUOr75U=
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
24 changes: 13 additions & 11 deletions keychain_test.go
Expand Up @@ -14,7 +14,7 @@ import (

func TestOSXKeychainKeyringSet(t *testing.T) {
path := tempPath()
defer deleteKeychain(path, t)
defer deleteKeychain(t, path)

k := &keychain{
path: path,
Expand Down Expand Up @@ -43,18 +43,18 @@ func TestOSXKeychainKeyringSet(t *testing.T) {
t.Fatalf("Data stored was not the data retrieved: %q vs %q", v.Data, item.Data)
}

if string(v.Key) != item.Key {
if v.Key != item.Key {
t.Fatalf("Key stored was not the data retrieved: %q vs %q", v.Key, item.Key)
}

if string(v.Description) != item.Description {
if v.Description != item.Description {
t.Fatalf("Description stored was not the data retrieved: %q vs %q", v.Description, item.Description)
}
}

func TestOSXKeychainKeyringOverwrite(t *testing.T) {
path := tempPath()
defer deleteKeychain(path, t)
defer deleteKeychain(t, path)

k := &keychain{
path: path,
Expand Down Expand Up @@ -106,7 +106,7 @@ func TestOSXKeychainKeyringOverwrite(t *testing.T) {

func TestOSXKeychainKeyringListKeysWhenEmpty(t *testing.T) {
path := tempPath()
defer deleteKeychain(path, t)
defer deleteKeychain(t, path)

k := &keychain{
path: path,
Expand All @@ -126,7 +126,7 @@ func TestOSXKeychainKeyringListKeysWhenEmpty(t *testing.T) {

func TestOSXKeychainKeyringListKeysWhenNotEmpty(t *testing.T) {
path := tempPath()
defer deleteKeychain(path, t)
defer deleteKeychain(t, path)

k := &keychain{
path: path,
Expand Down Expand Up @@ -158,7 +158,9 @@ func TestOSXKeychainKeyringListKeysWhenNotEmpty(t *testing.T) {
}
}

func deleteKeychain(path string, t *testing.T) {
func deleteKeychain(t *testing.T, path string) {
t.Helper()

if _, err := os.Stat(path); os.IsExist(err) {
_ = os.Remove(path)
}
Expand All @@ -172,7 +174,7 @@ func deleteKeychain(path string, t *testing.T) {

func TestOSXKeychainGetKeyWhenEmpty(t *testing.T) {
path := tempPath()
defer deleteKeychain(path, t)
defer deleteKeychain(t, path)

k := &keychain{
path: path,
Expand All @@ -189,7 +191,7 @@ func TestOSXKeychainGetKeyWhenEmpty(t *testing.T) {

func TestOSXKeychainGetKeyWhenNotEmpty(t *testing.T) {
path := tempPath()
defer deleteKeychain(path, t)
defer deleteKeychain(t, path)

k := &keychain{
path: path,
Expand Down Expand Up @@ -219,7 +221,7 @@ func TestOSXKeychainGetKeyWhenNotEmpty(t *testing.T) {

func TestOSXKeychainRemoveKeyWhenEmpty(t *testing.T) {
path := tempPath()
defer deleteKeychain(path, t)
defer deleteKeychain(t, path)

k := &keychain{
path: path,
Expand All @@ -236,7 +238,7 @@ func TestOSXKeychainRemoveKeyWhenEmpty(t *testing.T) {

func TestOSXKeychainRemoveKeyWhenNotEmpty(t *testing.T) {
path := tempPath()
defer deleteKeychain(path, t)
defer deleteKeychain(t, path)

k := &keychain{
path: path,
Expand Down