From 687aa17a8965dd060aa0313789b0ff8981b9d7e9 Mon Sep 17 00:00:00 2001 From: Daniel Lee <142878302+tw-daniel@users.noreply.github.com> Date: Fri, 24 May 2024 13:45:14 +0900 Subject: [PATCH] Revert "Update assets manager client path (#111)" This reverts commit 2cceecb49bd8094237cbd50f85570ba5d9035d74. --- .github/workflows/check.yml | 44 +++-- .golangci.yml | 263 +++++++++--------------------- Makefile | 2 +- client/assets-manager/client.go | 11 +- file/path.go | 2 +- go.mod | 2 +- validation/file.go | 1 - validation/info/external/trc10.go | 1 - validation/info/external/trc20.go | 1 - 9 files changed, 101 insertions(+), 226 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 9bbe5cb..2a08e65 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -1,32 +1,30 @@ -name: CI +name: Check on: + push: + branches: [ master ] pull_request: - branches: - - main - -env: - CI_GITHUB_TOKEN: ${{ secrets.CI_GITHUB_TOKEN }} + branches: [ master ] jobs: - unit-test: - name: Unit Tests + check: + name: Check runs-on: ubuntu-latest steps: - - uses: actions/setup-go@v4 + - name: Set up Go + uses: actions/setup-go@v2 with: - 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 + go-version: 1.17 + id: go - 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 + - name: Check out code + uses: actions/checkout@v2 + + - name: Get dependencies + run: go get -v -t -d ./... + + - name: Unit Test + run: make test + + - name: Lint + run: make lint diff --git a/.golangci.yml b/.golangci.yml index bb12eac..0aba96c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,215 +1,102 @@ +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: 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 + check-type-assertions: true + check-blank: true funlen: - 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 + lines: 100 + statements: 75 gofumpt: - # 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" ] + extra-rules: true govet: check-shadowing: true - 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 + enable-all: true + disable: + - fieldalignment misspell: locale: US - # 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" ] + nolintlint: + allow-unused: false + allow-leading-space: true + gci: + local-prefixes: github.com/trustwallet + unparam: + check-exported: true unused: - # 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 - + check-exported: true + errorlint: + errorf: true + gocyclo: + min-complexity: 25 + wrapcheck: + ignorePackageGlobs: + - github.com/trustwallet/* +issues: + new: false linters: disable-all: true enable: - # - deadcode - # - depguard + - deadcode + - errcheck + - gosimple + - govet + - ineffassign + - staticcheck + - structcheck + - typecheck + - unused + - varcheck + - asciicheck + - bodyclose - dogsled - dupl - - errcheck + - durationcheck + - errorlint + - exhaustive - exportloopref + - forcetypeassert + - funlen + - gci + - gochecknoglobals + - gochecknoinits + - gocognit - goconst - gocritic + - gocyclo + # - goerr113 - gofmt + - gofumpt - goimports + # - gomnd - goprintffuncname - gosec - - gosimple - - ineffassign + - importas + - lll + - makezero - misspell - nakedret - - noctx + - nestif + - nilerr + - nlreturn + - nolintlint + - paralleltest + - prealloc + - predeclared + - revive - rowserrcheck - - staticcheck - # - structcheck - - typecheck + - sqlclosecheck + - stylecheck + - testpackage + - thelper + - tparallel - unconvert - unparam - - unused - # - varcheck + - wastedassign - whitespace - - 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 + # - wrapcheck \ No newline at end of file diff --git a/Makefile b/Makefile index 832552c..76aeec9 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ GOFMT_FILES?=$$(find . -name '*.go' | grep -v vendor) all: fmt lint test -unit-tests: +test: @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 3cf9c85..34a7f95 100644 --- a/client/assets-manager/client.go +++ b/client/assets-manager/client.go @@ -1,7 +1,6 @@ package assetsmanager import ( - "context" "time" "github.com/trustwallet/go-libs/client" @@ -18,19 +17,13 @@ func InitClient(url string, errorHandler client.HttpErrorHandler) Client { } func (c *Client) ValidateAssetInfo(req *AssetValidationReq) (result AssetValidationResp, err error) { - request := client.NewReqBuilder(). - Method("POST"). - PathStatic("/api/v1/validate/asset_info"). - Body(req). - WriteTo(&result).Build() - - _, err = c.req.Execute(context.Background(), request) + err = c.req.Post(&result, "/v1/validate/asset_info", req) return result, err } func (c *Client) GetTagValues() (result TagValuesResp, err error) { - err = c.req.GetWithCache(&result, "/api/v1/values/tags", nil, time.Hour) + err = c.req.GetWithCache(&result, "/v1/values/tags", nil, time.Hour) return result, err } diff --git a/file/path.go b/file/path.go index 0220b03..b6f94f2 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, _ os.FileInfo, err error) error { + err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error { if err != nil { return err } diff --git a/go.mod b/go.mod index 1eaf13d..adfe5fa 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/trustwallet/assets-go-libs -go 1.21 +go 1.18 require github.com/trustwallet/go-primitives v0.0.76 diff --git a/validation/file.go b/validation/file.go index 4ac9af6..67064d0 100644 --- a/validation/file.go +++ b/validation/file.go @@ -66,7 +66,6 @@ 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 e1f3311..9a585f8 100644 --- a/validation/info/external/trc10.go +++ b/validation/info/external/trc10.go @@ -1,4 +1,3 @@ -//nolint:dupl // it's ok package external import ( diff --git a/validation/info/external/trc20.go b/validation/info/external/trc20.go index 69d6f16..3f4c228 100644 --- a/validation/info/external/trc20.go +++ b/validation/info/external/trc20.go @@ -1,4 +1,3 @@ -//nolint:dupl // it's ok package external import (