Skip to content

Commit

Permalink
chore(sdk): update linters
Browse files Browse the repository at this point in the history
Signed-off-by: Andrii Holovko <[email protected]>
  • Loading branch information
aholovko committed Jan 8, 2025
1 parent 6ffe938 commit ce55ec4
Show file tree
Hide file tree
Showing 49 changed files with 302 additions and 206 deletions.
33 changes: 15 additions & 18 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,33 @@

run:
concurrency: 4
deadline: 3m
timeout: 3m
issues-exit-code: 1
tests: true
build-tags: [""]
skip-dirs: [""]

output:
format: colored-line-number
formats:
- format: colored-line-number
print-issued-lines: true
print-linter-name: true

linters-settings:
errcheck:
check-type-assertions: true
check-blank: true
ignore: fmt:.*,io/ioutil:^Read.*
exclude-functions:
- fmt:.*
- io/ioutil:^Read.*
govet:
check-shadowing: true
golint:
min-confidence: 0.6
enable:
- shadow
gofmt:
simplify: true
goimports:
local-prefixes: github.com/trustbloc/agent-sdk
gocyclo:
min-complexity: 10
maligned:
suggest-new: true
dupl:
threshold: 100
goconst:
Expand All @@ -46,8 +45,6 @@ linters-settings:
lll:
line-length: 120
tab-width: 1
unused:
check-exported: false
unparam:
check-exported: false
nakedret:
Expand All @@ -73,17 +70,11 @@ linters-settings:
linters:
enable-all: true
disable:
- maligned
- prealloc
- goerr113 # not good: https://github.com/Djarvur/go-err113/issues/10
- err113 # not good: https://github.com/Djarvur/go-err113/issues/10
- paralleltest
- exhaustivestruct
# - tparallel
- interfacer # deprecated by the author https://github.com/mvdan/interfacer#interfacer
- scopelint # deprecated by the author https://github.com/kyoh86/scopelint#obsoleted
- maligned # deprecated by the author https://github.com/mdempsky/maligned
- cyclop # TODO consider replacing gocyclo with cyclop
- ifshort # TODO enable
- wrapcheck # TODO enable
- forbidigo # TODO enable
- gci # giving spurious errors for imports of syscall/js
Expand All @@ -92,6 +83,10 @@ linters:
- tagliatelle # JSON tags using camel-case required by the specs we implement
- varnamelen # This linter prevents us from using "i" as an index variable or "vc" for a variable name for a Verifiable Credential, both of which are very common in our code
- depguard # TODO consider enabling in the future
- exportloopref
- revive
- perfsprint
- thelper

issues:
exclude-use-default: false
Expand All @@ -101,6 +96,8 @@ issues:
- dupl
- funlen
- maintidx
max-issues-per-linter: 0
max-same-issues: 0

exclude:
# Allow package logger variables (for now)
Expand Down
6 changes: 3 additions & 3 deletions cmd/wallet-sdk-gomobile/api/activitylogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (p *Params) GetString(key string) (string, error) {
func (p *Params) GetStringArray(key string) (*StringArray, error) {
value, exists := p.params[key]
if !exists {
return nil, fmt.Errorf(noValueFoundErrMsg)
return nil, errors.New(noValueFoundErrMsg)
}

return interfaceAsStringArray(value)
Expand Down Expand Up @@ -218,7 +218,7 @@ func getType(value interface{}) (string, error) {
// This function checks to see if the []interface{} value is really a []string, and if so,
// returns "[]string" (which matches what fmt.Sprintf("%T", value) returns for a []string).
func getTypeOfInterfaceArray(typedValue []interface{}) (string, error) {
for i := 0; i < len(typedValue); i++ {
for i := range typedValue {
_, ok := typedValue[i].(string)
if !ok {
return "", errors.New(unsupportedTypeErrMsg)
Expand All @@ -237,7 +237,7 @@ func interfaceAsStringArray(value interface{}) (*StringArray, error) {
}

strings := make([]string, len(valueAsInterfaceArray))
for i := 0; i < len(valueAsInterfaceArray); i++ {
for i := range valueAsInterfaceArray {
strings[i], ok = valueAsInterfaceArray[i].(string)
if !ok {
return nil, errors.New(valueNotStringArrayErrMsg)
Expand Down
2 changes: 1 addition & 1 deletion cmd/wallet-sdk-gomobile/api/activitylogger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func checkActivity(t *testing.T, activity *api.Activity) {

require.Equal(t, 2, keyValuePairs.Length())

for i := 0; i < keyValuePairs.Length(); i++ {
for i := range keyValuePairs.Length() {
var stringCaseChecked, stringArrayCaseChecked bool

keyValuePair := keyValuePairs.AtIndex(i)
Expand Down
1 change: 1 addition & 0 deletions cmd/wallet-sdk-gomobile/attestation/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ func createGoAPIClientConfig(args *CreateClientArgs) (*attestationgoapi.ClientCo
dlHTTPClient := wrapper.NewHTTPClient(args.httpTimeout, api.Headers{}, args.disableHTTPClientTLSVerification)

var err error

goAPIClientConfig.DocumentLoader, err = common.CreateJSONLDDocumentLoader(dlHTTPClient, legacy.NewProvider())
if err != nil {
return nil, err
Expand Down
3 changes: 2 additions & 1 deletion cmd/wallet-sdk-gomobile/credential/inquirer.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func NewInquirer(opts *InquirerOpts) (*Inquirer, error) {
}

var err error

goAPIDocumentLoader, err = common.CreateJSONLDDocumentLoader(httpClient, legacy.NewProvider())
if err != nil {
return nil, wrapper.ToMobileError(err)
Expand Down Expand Up @@ -112,7 +113,7 @@ func unwrapQuery(query []byte) (*presexch.PresentationDefinition, error) {
func unwrapVCs(vcs *verifiable.CredentialsArray) []*afgoverifiable.Credential {
var credentials []*afgoverifiable.Credential

for i := 0; i < vcs.Length(); i++ {
for i := range vcs.Length() {
credentials = append(credentials, vcs.AtIndex(i).VC)
}

Expand Down
68 changes: 34 additions & 34 deletions cmd/wallet-sdk-gomobile/credential/inquirer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,25 +91,25 @@ func TestInstance_GetSubmissionRequirements(t *testing.T) {
requirements, err := query.GetSubmissionRequirements(multiInputPD, createCredJSONArray(t, contents))

require.NoError(t, err)
require.Equal(t, requirements.Len(), 1)
require.Equal(t, 1, requirements.Len())
req1 := requirements.AtIndex(0)
require.Equal(t, req1.DescriptorLen(), 3)
require.Equal(t, req1.Name(), "Information")
require.Equal(t, req1.Purpose(), "test purpose")
require.Equal(t, req1.Rule(), "pick")
require.Equal(t, 3, req1.DescriptorLen())
require.Equal(t, "Information", req1.Name())
require.Equal(t, "test purpose", req1.Purpose())
require.Equal(t, "pick", req1.Rule())
require.Nil(t, requirements.AtIndex(1))

require.Equal(t, req1.Count(), 1)
require.Equal(t, req1.Min(), 0)
require.Equal(t, req1.Max(), 0)
require.Equal(t, req1.NestedRequirementLength(), 0)
require.Equal(t, 1, req1.Count())
require.Equal(t, 0, req1.Min())
require.Equal(t, 0, req1.Max())
require.Equal(t, 0, req1.NestedRequirementLength())

desc1 := req1.DescriptorAtIndex(0)

require.Equal(t, desc1.ID, "VerifiedEmployee")
require.Equal(t, desc1.Name, "Verified Employee")
require.Equal(t, desc1.Purpose, "test purpose")
require.Equal(t, desc1.MatchedVCs.Length(), 1)
require.Equal(t, "VerifiedEmployee", desc1.ID)
require.Equal(t, "Verified Employee", desc1.Name)
require.Equal(t, "test purpose", desc1.Purpose)
require.Equal(t, 1, desc1.MatchedVCs.Length())
require.Equal(t, 0, desc1.Schemas().Length())
require.Nil(t, desc1.Schemas().AtIndex(0))
require.Equal(t, "VerifiedEmployee", desc1.TypeConstraint())
Expand All @@ -124,26 +124,26 @@ func TestInstance_GetSubmissionRequirements(t *testing.T) {
requirements, err := query.GetSubmissionRequirements(nestedRequirementsPD, createCredJSONArray(t, contents))

require.NoError(t, err)
require.Equal(t, requirements.Len(), 1)
require.Equal(t, 1, requirements.Len())
req1 := requirements.AtIndex(0)
require.Equal(t, req1.DescriptorLen(), 0)
require.Equal(t, req1.Name(), "Nested requirements")
require.Equal(t, req1.Rule(), "all")
require.Equal(t, 0, req1.DescriptorLen())
require.Equal(t, "Nested requirements", req1.Name())
require.Equal(t, "all", req1.Rule())

require.Equal(t, req1.Count(), 2)
require.Equal(t, req1.Min(), 0)
require.Equal(t, req1.Max(), 0)
require.Equal(t, req1.NestedRequirementLength(), 2)
require.Equal(t, 2, req1.Count())
require.Equal(t, 0, req1.Min())
require.Equal(t, 0, req1.Max())
require.Equal(t, 2, req1.NestedRequirementLength())

nestedReq1 := req1.NestedRequirementAtIndex(0)

require.Equal(t, nestedReq1.DescriptorLen(), 2)
require.Equal(t, 2, nestedReq1.DescriptorLen())

desc1 := nestedReq1.DescriptorAtIndex(0)

require.Equal(t, desc1.ID, "VerifiedEmployee")
require.Equal(t, desc1.Name, "Verified Employee")
require.Equal(t, desc1.MatchedVCs.Length(), 1)
require.Equal(t, "VerifiedEmployee", desc1.ID)
require.Equal(t, "Verified Employee", desc1.Name)
require.Equal(t, 1, desc1.MatchedVCs.Length())

require.Nil(t, req1.NestedRequirementAtIndex(2))
})
Expand All @@ -155,7 +155,7 @@ func TestInstance_GetSubmissionRequirements(t *testing.T) {
requirements, err := query.GetSubmissionRequirements(schemaPD, createCredJSONArray(t, contents))

require.NoError(t, err)
require.Equal(t, requirements.Len(), 1)
require.Equal(t, 1, requirements.Len())
req1 := requirements.AtIndex(0)

desc1 := req1.DescriptorAtIndex(0)
Expand All @@ -178,7 +178,7 @@ func TestInstance_GetSubmissionRequirements(t *testing.T) {
requirements, err := query.GetSubmissionRequirements(schemaPD, nil)

require.NoError(t, err)
require.Equal(t, requirements.Len(), 1)
require.Equal(t, 1, requirements.Len())
req1 := requirements.AtIndex(0)

desc1 := req1.DescriptorAtIndex(0)
Expand Down Expand Up @@ -238,18 +238,18 @@ func TestInstance_GetSubmissionRequirementsCitizenship(t *testing.T) {
requirements, err := query.GetSubmissionRequirements(citizenshipPD, createCredJSONArray(t, contents))

require.NoError(t, err)
require.Equal(t, requirements.Len(), 1)
require.Equal(t, 1, requirements.Len())
req1 := requirements.AtIndex(0)
require.Equal(t, req1.DescriptorLen(), 1)
require.Equal(t, 1, req1.DescriptorLen())

require.Equal(t, req1.Count(), 1)
require.Equal(t, req1.Min(), 0)
require.Equal(t, req1.Max(), 0)
require.Equal(t, req1.NestedRequirementLength(), 0)
require.Equal(t, 1, req1.Count())
require.Equal(t, 0, req1.Min())
require.Equal(t, 0, req1.Max())
require.Equal(t, 0, req1.NestedRequirementLength())

desc1 := req1.DescriptorAtIndex(0)

require.Equal(t, desc1.MatchedVCs.Length(), 1)
require.Equal(t, 1, desc1.MatchedVCs.Length())
})
}

Expand Down
5 changes: 2 additions & 3 deletions cmd/wallet-sdk-gomobile/did/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ SPDX-License-Identifier: Apache-2.0
package did

import (
"github.com/trustbloc/wallet-sdk/pkg/did/resolver"

"github.com/trustbloc/wallet-sdk/cmd/wallet-sdk-gomobile/api"
// helps gomobile bind api.DIDResolver interface to Resolver implementation in ios-bindings.
_ "github.com/trustbloc/wallet-sdk/cmd/wallet-sdk-gomobile/api"
"github.com/trustbloc/wallet-sdk/cmd/wallet-sdk-gomobile/wrapper"
"github.com/trustbloc/wallet-sdk/pkg/did/resolver"
)

// Resolver supports DID resolution.
Expand Down
7 changes: 4 additions & 3 deletions cmd/wallet-sdk-gomobile/did/wellknown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"net/http/httptest"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/trustbloc/did-go/doc/did"
"github.com/trustbloc/did-go/method/httpbinding"
Expand Down Expand Up @@ -121,11 +122,11 @@ func TestValidate(t *testing.T) {
}

testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
require.Equal(t, "/"+testDID, req.URL.String())
assert.Equal(t, "/"+testDID, req.URL.String())
res.Header().Add("Content-type", "application/did+ld+json")
res.WriteHeader(http.StatusOK)
_, err := res.Write([]byte(resolutionResponse))
require.NoError(t, err)
assert.NoError(t, err)
}))

defer func() { testServer.Close() }()
Expand All @@ -148,7 +149,7 @@ func TestValidate(t *testing.T) {
t.Run("DID service validation failure", func(t *testing.T) {
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, _ *http.Request) {
_, err := res.Write([]byte(didCfg))
require.NoError(t, err)
assert.NoError(t, err)
}))

defer func() { testServer.Close() }()
Expand Down
10 changes: 5 additions & 5 deletions cmd/wallet-sdk-gomobile/display/credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,19 @@ type Credential struct {
}

// LocalizedOverviewsLength returns the number of different locales supported for the credential displays.
func (d *Credential) LocalizedOverviewsLength() int {
return len(d.credentialDisplay.LocalizedOverview)
func (c *Credential) LocalizedOverviewsLength() int {
return len(c.credentialDisplay.LocalizedOverview)
}

// LocalizedOverviewAtIndex returns the number of different locales supported for the issuer displays.
// If the index passed in is out of bounds, then nil is returned.
func (d *Credential) LocalizedOverviewAtIndex(index int) *Overview {
maxIndex := len(d.credentialDisplay.LocalizedOverview) - 1
func (c *Credential) LocalizedOverviewAtIndex(index int) *Overview {
maxIndex := len(c.credentialDisplay.LocalizedOverview) - 1
if index > maxIndex || index < 0 {
return nil
}

return &Overview{overview: &d.credentialDisplay.LocalizedOverview[index]}
return &Overview{overview: &c.credentialDisplay.LocalizedOverview[index]}
}

// SubjectsLength returns the number of credential subject displays contained within this Credential object.
Expand Down
11 changes: 8 additions & 3 deletions cmd/wallet-sdk-gomobile/display/displaydata.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,14 @@ func (c *Attachment) ID() string {
}

// Type returns the attachment Type. This could be "EmbeddedAttachment", "RemoteAttachment" or "AttachmentEvidence".
// For EmbeddedAttachment, the uri will be a data URI. Hash and HashAlg will provide the hash value of the data along with Hash algorithm used to generate the hash.
// For RemoteAttachment, the uri will be a remote HTTP URL. Hash and HashAlg will provide the hash value of the data along with Hash algorithm used to generate the hash. Consumer of this API need to validate the hash value against the hash of the data object retrieved from the remote url
// For AttachmentEvidence, the uri will be empty. But the hash and hashAlg will provide the hash value of the data along with Hash algorithm used to generate the hash. Consumer of this API need to validate the hash value against the hash of the data object retrieved from the out of band.
// For EmbeddedAttachment, the uri will be a data URI. Hash and HashAlg will provide the hash value of the data
// along with Hash algorithm used to generate the hash.
// For RemoteAttachment, the uri will be a remote HTTP URL. Hash and HashAlg will provide the hash value of the data
// along with Hash algorithm used to generate the hash. Consumer of this API need to validate the hash value against the
// hash of the data object retrieved from the remote url.
// For AttachmentEvidence, the uri will be empty. But the hash and hashAlg will provide the hash value of the data
// along with Hash algorithm used to generate the hash. Consumer of this API need to validate the hash value against the
// hash of the data object retrieved from the out of band.
func (c *Attachment) Type() string {
if len(c.attachment.Type) == 0 {
return ""
Expand Down
Loading

0 comments on commit ce55ec4

Please sign in to comment.