Skip to content

Commit

Permalink
golangci-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
joshblum committed Aug 26, 2019
1 parent b3b9e2c commit 29d4a07
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 36 deletions.
11 changes: 11 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
linters-settings:
gocritic:
disabled-checks:
- ifElseChain
- elseif

linters:
enable:
- gofmt
- gocritic
- unconvert
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ before_install:
- go get golang.org/x/lint/golint

script:
- if [[ "$(go version)" =~ go1.1[12] ]]; then go get honnef.co/go/tools/cmd/staticcheck && staticcheck ./... && echo "staticcheck complete"; fi
- go vet ./...
- golint ./...
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.16.0
- golangci-lint run
- go test -tags skipsecretserviceintegrationtests ./...

go:
Expand Down
4 changes: 2 additions & 2 deletions bind/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ func GenericPasswordTest(t Test, service string, accessGroup string) {
item2 := keychain.NewGenericPassword(service, account2, "", []byte("toomanysecrets2"), accessGroup)

// Cleanup
defer keychain.DeleteItem(item)
defer keychain.DeleteItem(item2)
defer func() { _ = keychain.DeleteItem(item) }()
defer func() { _ = keychain.DeleteItem(item2) }()

// Test account names empty
accounts, err := keychain.GetGenericPasswordAccounts(service)
Expand Down
39 changes: 20 additions & 19 deletions corefoundation.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ func MapToCFDictionary(m map[C.CFTypeRef]C.CFTypeRef) (C.CFDictionaryRef, error)
keysPointer = &keys[0]
valuesPointer = &values[0]
}
cfDict := C.CFDictionaryCreateSafe2(C.kCFAllocatorDefault, keysPointer, valuesPointer, C.CFIndex(numValues), &C.kCFTypeDictionaryKeyCallBacks, &C.kCFTypeDictionaryValueCallBacks)
cfDict := C.CFDictionaryCreateSafe2(C.kCFAllocatorDefault, keysPointer, valuesPointer, C.CFIndex(numValues),
&C.kCFTypeDictionaryKeyCallBacks, &C.kCFTypeDictionaryValueCallBacks) // nolint
if cfDict == 0 {
return 0, fmt.Errorf("CFDictionaryCreate failed")
}
Expand Down Expand Up @@ -149,7 +150,7 @@ func ArrayToCFArray(a []C.CFTypeRef) C.CFArrayRef {
if numValues > 0 {
valuesPointer = &values[0]
}
return C.CFArrayCreateSafe2(C.kCFAllocatorDefault, valuesPointer, C.CFIndex(numValues), &C.kCFTypeArrayCallBacks)
return C.CFArrayCreateSafe2(C.kCFAllocatorDefault, valuesPointer, C.CFIndex(numValues), &C.kCFTypeArrayCallBacks) // nolint
}

// CFArrayToArray converts a CFArrayRef to an array of CFTypes.
Expand Down Expand Up @@ -203,7 +204,7 @@ func ConvertMapToCFDictionary(attr map[string]interface{}) (C.CFDictionaryRef, e
if err != nil {
return 0, err
}
valueRef = C.CFTypeRef(convertedRef)
valueRef = convertedRef
defer Release(valueRef)
}
keyRef, err := StringToCFString(key)
Expand Down Expand Up @@ -267,7 +268,7 @@ func Convert(ref C.CFTypeRef) (interface{}, error) {

// ConvertCFDictionary converts a CFDictionary to map (deep).
func ConvertCFDictionary(d C.CFDictionaryRef) (map[interface{}]interface{}, error) {
m := CFDictionaryToMap(C.CFDictionaryRef(d))
m := CFDictionaryToMap(d)
result := make(map[interface{}]interface{})

for k, v := range m {
Expand All @@ -292,66 +293,66 @@ func CFNumberToInterface(cfNumber C.CFNumberRef) interface{} {
switch typ {
case C.kCFNumberSInt8Type:
var sint C.SInt8
C.CFNumberGetValue(cfNumber, typ, unsafe.Pointer(&sint))
C.CFNumberGetValue(cfNumber, typ, unsafe.Pointer(&sint)) // nolint
return int8(sint)
case C.kCFNumberSInt16Type:
var sint C.SInt16
C.CFNumberGetValue(cfNumber, typ, unsafe.Pointer(&sint))
C.CFNumberGetValue(cfNumber, typ, unsafe.Pointer(&sint)) // nolint
return int16(sint)
case C.kCFNumberSInt32Type:
var sint C.SInt32
C.CFNumberGetValue(cfNumber, typ, unsafe.Pointer(&sint))
C.CFNumberGetValue(cfNumber, typ, unsafe.Pointer(&sint)) // nolint
return int32(sint)
case C.kCFNumberSInt64Type:
var sint C.SInt64
C.CFNumberGetValue(cfNumber, typ, unsafe.Pointer(&sint))
C.CFNumberGetValue(cfNumber, typ, unsafe.Pointer(&sint)) // nolint
return int64(sint)
case C.kCFNumberFloat32Type:
var float C.Float32
C.CFNumberGetValue(cfNumber, typ, unsafe.Pointer(&float))
C.CFNumberGetValue(cfNumber, typ, unsafe.Pointer(&float)) // nolint
return float32(float)
case C.kCFNumberFloat64Type:
var float C.Float64
C.CFNumberGetValue(cfNumber, typ, unsafe.Pointer(&float))
C.CFNumberGetValue(cfNumber, typ, unsafe.Pointer(&float)) // nolint
return float64(float)
case C.kCFNumberCharType:
var char C.char
C.CFNumberGetValue(cfNumber, typ, unsafe.Pointer(&char))
C.CFNumberGetValue(cfNumber, typ, unsafe.Pointer(&char)) // nolint
return byte(char)
case C.kCFNumberShortType:
var short C.short
C.CFNumberGetValue(cfNumber, typ, unsafe.Pointer(&short))
C.CFNumberGetValue(cfNumber, typ, unsafe.Pointer(&short)) // nolint
return int16(short)
case C.kCFNumberIntType:
var i C.int
C.CFNumberGetValue(cfNumber, typ, unsafe.Pointer(&i))
C.CFNumberGetValue(cfNumber, typ, unsafe.Pointer(&i)) // nolint
return int32(i)
case C.kCFNumberLongType:
var long C.long
C.CFNumberGetValue(cfNumber, typ, unsafe.Pointer(&long))
C.CFNumberGetValue(cfNumber, typ, unsafe.Pointer(&long)) // nolint
return int(long)
case C.kCFNumberLongLongType:
// This is the only type that may actually overflow us
var longlong C.longlong
C.CFNumberGetValue(cfNumber, typ, unsafe.Pointer(&longlong))
C.CFNumberGetValue(cfNumber, typ, unsafe.Pointer(&longlong)) // nolint
return int64(longlong)
case C.kCFNumberFloatType:
var float C.float
C.CFNumberGetValue(cfNumber, typ, unsafe.Pointer(&float))
C.CFNumberGetValue(cfNumber, typ, unsafe.Pointer(&float)) // nolint
return float32(float)
case C.kCFNumberDoubleType:
var double C.double
C.CFNumberGetValue(cfNumber, typ, unsafe.Pointer(&double))
C.CFNumberGetValue(cfNumber, typ, unsafe.Pointer(&double)) // nolint
return float64(double)
case C.kCFNumberCFIndexType:
// CFIndex is a long
var index C.CFIndex
C.CFNumberGetValue(cfNumber, typ, unsafe.Pointer(&index))
C.CFNumberGetValue(cfNumber, typ, unsafe.Pointer(&index)) // nolint
return int(index)
case C.kCFNumberNSIntegerType:
// We don't have a definition of NSInteger, but we know it's either an int or a long
var nsInt C.long
C.CFNumberGetValue(cfNumber, typ, unsafe.Pointer(&nsInt))
C.CFNumberGetValue(cfNumber, typ, unsafe.Pointer(&nsInt)) // nolint
return int(nsInt)
}
panic("Unknown CFNumber type")
Expand Down
3 changes: 1 addition & 2 deletions datetime.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ func unixToAbsoluteTime(s int64, ns int64) C.CFAbsoluteTime {
// isn't much earlier than the Core Foundation absolute
// reference date).
abs := s - absoluteTimeIntervalSince1970()
// Need to cast CFTimeInterval to CFAbsoluteTime for go 1.9.x.
return C.CFAbsoluteTime(abs) + C.CFAbsoluteTime(C.CFTimeInterval(ns))/nsPerSec
return C.CFAbsoluteTime(abs) + C.CFTimeInterval(ns)/nsPerSec
}

func absoluteTimeToUnix(abs C.CFAbsoluteTime) (int64, int64) {
Expand Down
2 changes: 1 addition & 1 deletion keychain.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ func QueryItemRef(item Item) (C.CFTypeRef, error) {
defer Release(C.CFTypeRef(cfDict))

var resultsRef C.CFTypeRef
errCode := C.SecItemCopyMatching(cfDict, &resultsRef)
errCode := C.SecItemCopyMatching(cfDict, &resultsRef) // nolint
if Error(errCode) == ErrorItemNotFound {
return 0, nil
}
Expand Down
12 changes: 6 additions & 6 deletions macos.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func createAccess(label string, trustedApplications []string) (C.CFTypeRef, erro
if createErr != nil {
return 0, createErr
}
defer C.CFRelease(C.CFTypeRef(trustedApplicationRef))
defer C.CFRelease(trustedApplicationRef)
trustedApplicationsRefs = append(trustedApplicationsRefs, trustedApplicationRef)
}

Expand All @@ -66,7 +66,7 @@ func createAccess(label string, trustedApplications []string) (C.CFTypeRef, erro
}

var access C.SecAccessRef
errCode := C.SecAccessCreate(labelRef, trustedApplicationsArray, &access)
errCode := C.SecAccessCreate(labelRef, trustedApplicationsArray, &access) // nolint
err = checkError(errCode)
if err != nil {
return 0, err
Expand All @@ -85,7 +85,7 @@ func createTrustedApplication(trustedApplication string) (C.CFTypeRef, error) {
}

var trustedApplicationRef C.SecTrustedApplicationRef
errCode := C.SecTrustedApplicationCreateFromPath(trustedApplicationCStr, &trustedApplicationRef)
errCode := C.SecTrustedApplicationCreateFromPath(trustedApplicationCStr, &trustedApplicationRef) // nolint
err := checkError(errCode)
if err != nil {
return 0, err
Expand Down Expand Up @@ -151,11 +151,11 @@ func newKeychain(path, password string, promptUser bool) (Keychain, error) {
var kref C.SecKeychainRef

if promptUser {
errCode = C.SecKeychainCreate(pathRef, C.UInt32(0), nil, C.Boolean(1), 0, &kref)
errCode = C.SecKeychainCreate(pathRef, C.UInt32(0), nil, C.Boolean(1), 0, &kref) // nolint
} else {
passwordRef := C.CString(password)
defer C.free(unsafe.Pointer(passwordRef))
errCode = C.SecKeychainCreate(pathRef, C.UInt32(len(password)), unsafe.Pointer(passwordRef), C.Boolean(0), 0, &kref)
errCode = C.SecKeychainCreate(pathRef, C.UInt32(len(password)), unsafe.Pointer(passwordRef), C.Boolean(0), 0, &kref) //nolint
}

if err := checkError(errCode); err != nil {
Expand Down Expand Up @@ -196,7 +196,7 @@ func openKeychainRef(path string) (C.SecKeychainRef, error) {
defer C.free(unsafe.Pointer(pathName))

var kref C.SecKeychainRef
if err := checkError(C.SecKeychainOpen(pathName, &kref)); err != nil {
if err := checkError(C.SecKeychainOpen(pathName, &kref)); err != nil { // nolint
return 0, err
}

Expand Down
5 changes: 0 additions & 5 deletions staticcheck.conf

This file was deleted.

0 comments on commit 29d4a07

Please sign in to comment.