diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 2a08e65..9bbe5cb 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -1,30 +1,32 @@ -name: Check +name: CI on: - push: - branches: [ master ] pull_request: - branches: [ master ] + branches: + - main + +env: + CI_GITHUB_TOKEN: ${{ secrets.CI_GITHUB_TOKEN }} jobs: - check: - name: Check + unit-test: + name: Unit Tests runs-on: ubuntu-latest steps: - - name: Set up Go - uses: actions/setup-go@v2 + - uses: actions/setup-go@v4 with: - go-version: 1.17 - id: go - - - name: Check out code - uses: actions/checkout@v2 - - - name: Get dependencies - run: go get -v -t -d ./... - - - name: Unit Test - run: make test + go-version: "1.21" + - uses: actions/checkout@v3 + - run: git config --global url.https://ci:$CI_GITHUB_TOKEN@github.com/.insteadOf https://github.com/ + - run: make unit-tests - - name: Lint - run: make lint + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - run: git config --global url.https://ci:$CI_GITHUB_TOKEN@github.com/.insteadOf https://github.com/ + - uses: golangci/golangci-lint-action@v3 + with: + version: v1.55.2 + args: --timeout=5m diff --git a/.golangci.yml b/.golangci.yml index 0aba96c..bb12eac 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,102 +1,215 @@ -service: - golangci-lint-version: 1.38.x - -run: - tests: false - modules-download-mode: readonly - linters-settings: + cyclop: + max-complexity: 20 + # the maximal average package complexity. If it's higher than 0.0 (float) the check is enabled (default 0.0) + package-average: 0.0 + skip-tests: false + dogsled: + # checks assignments with too many blank identifiers; default is 2 + max-blank-identifiers: 2 + dupl: + threshold: 100 errcheck: - check-type-assertions: true - check-blank: true + check-type-assertions: false + check-blank: false + errorlint: + errorf: false + asserts: true + comparison: true + forbidigo: + # Forbid the following identifiers (identifiers are written using regexp): + forbid: + - ^print.*$ + - 'fmt\.Print.*' + exclude_godoc_examples: true funlen: - lines: 100 - statements: 75 + lines: 60 + statements: 60 + gocognit: + min-complexity: 35 + goconst: + min-len: 3 + min-occurrences: 3 + ignore-tests: true + match-constant: true + numbers: false + min: 3 + max: 3 + ignore-calls: true + gocritic: + # Which checks should be disabled; can't be combined with 'enabled-checks' + disabled-checks: + - regexpMust + gocyclo: + min-complexity: 20 + godot: + # comments to be checked: `declarations`, `toplevel`, or `all` + scope: all + capital: false + gofmt: + # simplify code: gofmt with `-s` option + simplify: true gofumpt: - extra-rules: true + # Select the Go version to target + lang-version: "1.21" + extra-rules: false + goimports: + # put imports beginning with prefix after 3rd-party packages; + # it's a comma-separated list of prefixes + local-prefixes: github.com/trustwallet + gomnd: + settings: + mnd: + # the list of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description. + checks: + - argument + - case + - condition + - operation + - return + - assign + ignored-numbers: 10,1000 + gomoddirectives: + replace-local: false + gosec: + # To select a subset of rules to run. + # Available rules: https://github.com/securego/gosec#available-rules + includes: + - G401 + - G306 + - G101 + gosimple: + # Select the Go version to target + go: "1.21" + # https://staticcheck.io/docs/options#checks + checks: [ "all" ] govet: check-shadowing: true - enable-all: true - disable: - - fieldalignment + composites: false + ifshort: + # Maximum length of variable declaration measured in number of lines, after which linter won't suggest using short syntax. + # Has higher priority than max-decl-chars. + max-decl-lines: 1 + # Maximum length of variable declaration measured in number of characters, after which linter won't suggest using short syntax. + max-decl-chars: 30 + importas: + golibsGin: github:com/trustwallet/go-common/gin + + lll: + # max line length + line-length: 120 + tab-width: 1 misspell: locale: US - nolintlint: - allow-unused: false - allow-leading-space: true - gci: - local-prefixes: github.com/trustwallet - unparam: - check-exported: true + # ignore-words: + revive: + # see https://github.com/mgechev/revive#available-rules for details. + ignore-generated-header: true + severity: warning + rules: + - name: indent-error-flow + severity: warning + - name: time-naming + severity: warn + - name: errorf + severity: warn + - name: blank-imports + sevetiry: warn + # The error return parameter should be last + - name: error-return + severity: error + # Redundant if when returning an error + - name: if-return + severity: warn + # Warns when there are heading or trailing newlines in a block + - name: empty-lines + severity: error + staticcheck: + # Select the Go version to target + go: "1.21" + # https://staticcheck.io/docs/options#checks + checks: [ "all" ] + stylecheck: + # Select the Go version to target + go: "1.21" + # https://staticcheck.io/docs/options#checks + checks: [ "all", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022" ] + # https://staticcheck.io/docs/options#dot_import_whitelist + dot-import-whitelist: + - fmt + # https://staticcheck.io/docs/options#initialisms + initialisms: [ "ACL", "API", "ASCII", "CPU", "CSS", "DNS", "EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID", "IP", "JSON", "QPS", "RAM", "RPC", "SLA", "SMTP", "SQL", "SSH", "TCP", "TLS", "TTL", "UDP", "UI", "GID", "UID", "UUID", "URI", "URL", "UTF8", "VM", "XML", "XMPP", "XSRF", "XSS" ] + # https://staticcheck.io/docs/options#http_status_code_whitelist + http-status-code-whitelist: [ "200", "400", "404", "500" ] unused: - check-exported: true - errorlint: - errorf: true - gocyclo: - min-complexity: 25 - wrapcheck: - ignorePackageGlobs: - - github.com/trustwallet/* -issues: - new: false + # Select the Go version to target + go: "1.21" + whitespace: + multi-if: true # Enforces newlines (or comments) after every multi-line if statement + multi-func: false # Enforces newlines (or comments) after every multi-line function signature + wsl: + # See https://github.com/bombsimon/wsl/blob/master/doc/configuration.md for + # documentation of available settings + allow-assign-and-anything: false + allow-assign-and-call: true + allow-cuddle-declarations: false + allow-multiline-assign: true + allow-separated-leading-comment: false + allow-trailing-comment: false + force-case-trailing-whitespace: 0 + force-err-cuddling: false + force-short-decl-cuddling: false + strict-append: true + linters: disable-all: true enable: - - deadcode - - errcheck - - gosimple - - govet - - ineffassign - - staticcheck - - structcheck - - typecheck - - unused - - varcheck - - asciicheck - - bodyclose + # - deadcode + # - depguard - dogsled - dupl - - durationcheck - - errorlint - - exhaustive + - errcheck - exportloopref - - forcetypeassert - - funlen - - gci - - gochecknoglobals - - gochecknoinits - - gocognit - goconst - gocritic - - gocyclo - # - goerr113 - gofmt - - gofumpt - goimports - # - gomnd - goprintffuncname - gosec - - importas - - lll - - makezero + - gosimple + - ineffassign - misspell - nakedret - - nestif - - nilerr - - nlreturn - - nolintlint - - paralleltest - - prealloc - - predeclared - - revive + - noctx - rowserrcheck - - sqlclosecheck - - stylecheck - - testpackage - - thelper - - tparallel + - staticcheck + # - structcheck + - typecheck - unconvert - unparam - - wastedassign + - unused + # - varcheck - whitespace - # - wrapcheck \ No newline at end of file + - asciicheck + - gocognit + - nestif + - testpackage + +run: + timeout: 2m + issues-exit-code: 1 + tests: false + skip-dirs: + - ide + - local + skip-dirs-use-default: true + modules-download-mode: readonly + allow-parallel-runners: false + +output: + format: colored-line-number + print-issued-lines: true + print-linter-name: true + uniq-by-line: true + path-prefix: "" + sort-results: true diff --git a/Makefile b/Makefile index 76aeec9..832552c 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ GOFMT_FILES?=$$(find . -name '*.go' | grep -v vendor) all: fmt lint test -test: +unit-tests: @echo " > Running unit tests" GOBIN=$(GOBIN) go test -cover -race -coverprofile=coverage.txt -covermode=atomic -v ./... diff --git a/client/assets-manager/client.go b/client/assets-manager/client.go index f6c76b4..9d92b5c 100644 --- a/client/assets-manager/client.go +++ b/client/assets-manager/client.go @@ -1,6 +1,7 @@ package assetsmanager import ( + "context" "time" "github.com/trustwallet/go-common/client" @@ -17,13 +18,19 @@ func InitClient(url string, errorHandler client.HttpErrorHandler) Client { } func (c *Client) ValidateAssetInfo(req *AssetValidationReq) (result AssetValidationResp, err error) { - err = c.req.Post(&result, "/v1/validate/asset_info", req) + request := client.NewReqBuilder(). + Method("POST"). + PathStatic("/api/v1/validate/asset_info"). + Body(req). + WriteTo(&result).Build() + + _, err = c.req.Execute(context.Background(), request) return result, err } func (c *Client) GetTagValues() (result TagValuesResp, err error) { - err = c.req.GetWithCache(&result, "/v1/values/tags", nil, time.Hour) + err = c.req.GetWithCache(&result, "/api/v1/values/tags", nil, time.Hour) return result, err } diff --git a/file/path.go b/file/path.go index b6f94f2..0220b03 100644 --- a/file/path.go +++ b/file/path.go @@ -146,7 +146,7 @@ func (p Path) defineFileType(path string) (string, *regexp.Regexp) { func ReadLocalFileStructure(root string, filesToSkip []string) ([]string, error) { paths := []string{"./"} - err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error { + err := filepath.Walk(root, func(path string, _ os.FileInfo, err error) error { if err != nil { return err } diff --git a/go.mod b/go.mod index d1095bf..f03f042 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/trustwallet/assets-go-libs -go 1.18 +go 1.21 require github.com/trustwallet/go-primitives v0.0.76 diff --git a/validation/file.go b/validation/file.go index 67064d0..4ac9af6 100644 --- a/validation/file.go +++ b/validation/file.go @@ -66,6 +66,7 @@ func ValidateFileInPR(path string) error { if strings.Index(path, "assets") > 0 || strings.HasSuffix(path, "allowlist.json") || strings.HasSuffix(path, "validators/list.json") { + return nil } } diff --git a/validation/info/external/trc10.go b/validation/info/external/trc10.go index 9a585f8..e1f3311 100644 --- a/validation/info/external/trc10.go +++ b/validation/info/external/trc10.go @@ -1,3 +1,4 @@ +//nolint:dupl // it's ok package external import ( diff --git a/validation/info/external/trc20.go b/validation/info/external/trc20.go index 3f4c228..69d6f16 100644 --- a/validation/info/external/trc20.go +++ b/validation/info/external/trc20.go @@ -1,3 +1,4 @@ +//nolint:dupl // it's ok package external import (