diff --git a/.golangci.yml b/.golangci.yml index 766c275fa7..a3083aa6bd 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -8,51 +8,115 @@ run: - otelginmetrics/* timeout: 15m skip-files: - - '.*\.abigen\.go$' - - '.*\.metadata\.go$' - - '.*\.pb\.go$' + - '.*\\.abigen\\.go$' + - '.*\\.metadata\\.go$' + - '.*\\.pb\\.go$' - '.*_gen.go$' linters-settings: gofmt: simplify: true govet: + # Don't report about shadowed variables check-shadowing: false misspell: locale: US gocritic: disabled-checks: - appendAssign - cyclop: - max-complexity: 15 - linters: - disable-all: true - enable: - - gofmt - - govet - - gosimple - - staticcheck - - errcheck - - ineffassign - - unused - - gosec - - cyclop - - revive - - stylecheck - - gocritic - - misspell + enable-all: true + disable: + # Global variables are used in many places throughout the code base. + - gochecknoglobals + + # Some lines are over 80 characters on purpose and we don't want to make them + # even longer by marking them as 'nolint'. + - lll + + # We don't care (enough) about misaligned structs to lint that. + - maligned + + # We have long functions, especially in tests. Moving or renaming those would + # trigger funlen problems that we may not want to solve at that time. + - funlen + + # Disable for now as we haven't yet tuned the sensitivity to our codebase + # yet. Enabling by default for example, would also force new contributors to + # potentially extensively refactor code, when they want to smaller change to + # land. - gocyclo - - dupl - - wrapcheck + + # Instances of table driven tests that don't pre-allocate shouldn't trigger + # the linter. + - prealloc + + # Init functions are used by loggers throughout the codebase. + - gochecknoinits + # this messes with formatting + - goimports + # TODO implement paralell tests + - paralleltest + # remove + - wsl + # skip for post set + - exhaustruct + - exhaustivestruct + # if short + - ifshort + # we want to use todo + - godox + # skip new line return until autofix works for it + - nlreturn + # go 1.13 error + - goerr113 + # disable gci + - gci + # disable gofumpt + - gofumpt + # allow magic numbers + - gomnd + # allow println + - forbidigo + # disabled (todo: enable) + - interfacer + # Allow nolint + - nolintlint + # we use external json tags + - tagliatelle + # var name len + - varnamelen + # allow replacements + - gomoddirectives + # no need to disallow returning interfaces + - ireturn + - nonamedreturns + - contextcheck + - nosnakecase + - depguard + # we use core/testsuite.Err() etc that don't get caught by this linter and result in false positives. + - testifylint + # we use metrics.EndSpan and metrics.EndSpanWithErr so this gets triggered falsely + - spancheck + # simply annoying + - perfsprint + # malfunctions on embedded structs + - typecheck + # magic numbers + - mnd + # constants + - goconst + fast: false issues: + # We use dot imports extensively in tests. Usually for testify assertions exclude-rules: - path: _test\.go linters: - revive - stylecheck - dupl + # wrapping errors when exporting for testing is tedious - path: export_test\.go linters: - wrapcheck @@ -76,7 +140,7 @@ issues: - cyclop - path: signoz/* linters: - - mnd + - gomnd - stylecheck - path: example/* linters: diff --git a/tools/.golangci.yml b/tools/.golangci.yml deleted file mode 100644 index e935707bf9..0000000000 --- a/tools/.golangci.yml +++ /dev/null @@ -1,58 +0,0 @@ -# This is the root golangci-lint configuration for the tools package -linters: - enable: - - gofmt - - govet - - staticcheck - - unused - - gosimple - disable: - - deadcode # deprecated - - structcheck # deprecated - - varcheck # deprecated - -linters-settings: - unused: - check-exported: false # Don't warn about exported unused functions in test files - staticcheck: - checks: - - 'all' - - '-SA1019' # Ignore deprecation warnings - govet: - check-shadowing: true - enable-all: true - disable: - - shadow # Too many false positives - -issues: - exclude-rules: - # Exclude unused warnings for test files - - path: _test\.go$ - linters: - - unused - text: 'imported and not used' - # Exclude certain patterns in test files - - path: _test\.go$ - text: 'testify/suite' - linters: - - unused - - path: _test\.go$ - text: 'testify/require' - linters: - - unused - - path: _test\.go$ - text: 'testing' - linters: - - unused - # Exclude file permission checks in test files - - path: _test\.go$ - linters: - - gosec - text: 'G302: Expect file permissions' - -run: - timeout: 5m - tests: true - build-tags: - - integration - - tools diff --git a/tools/abigen/internal/etherscan/ratelimiter.go b/tools/abigen/internal/etherscan/ratelimiter.go index 890135deaa..fe41c63203 100644 --- a/tools/abigen/internal/etherscan/ratelimiter.go +++ b/tools/abigen/internal/etherscan/ratelimiter.go @@ -14,11 +14,16 @@ import ( // fileRateLimiter implements a file based rate limiter for limiting requests across abi generate commands. type fileRateLimiter struct { - mux sync.Mutex // Mutex (40-byte alignment) - waitBetweenRequests time.Duration // Duration (8-byte alignment) - flock *flock.Flock // Pointer (8-byte alignment) - lastRequestFile *os.File // Pointer (8-byte alignment) - lockFolderPath string // String (8-byte alignment) + // lockFolderPath is the path to the rate limiter + lockFolderPath string + // flock is the file locker for recording the last request. This is locked per process to prevent two from running at once + flock *flock.Flock + // waitBetweenRequests is how long to wait before requests + waitBetweenRequests time.Duration + // lastRequestFile is the last request file + lastRequestFile *os.File + // mux prevents duplicate locking + mux sync.Mutex } // fileRateTimeout is how long to wait for file rate limiting. diff --git a/tools/abigen/internal/etherscan/ratelimiter_test.go b/tools/abigen/internal/etherscan/ratelimiter_test.go index bec9ee8262..20228f23bd 100644 --- a/tools/abigen/internal/etherscan/ratelimiter_test.go +++ b/tools/abigen/internal/etherscan/ratelimiter_test.go @@ -1,37 +1,32 @@ package etherscan_test import ( - "context" - "time" - "github.com/Flaque/filet" + . "github.com/stretchr/testify/assert" "github.com/synapsecns/sanguine/tools/abigen/internal/etherscan" + "time" ) -// PLACEHOLDER: EtherscanSuite is defined in suite_test.go +var waitTime = time.Second -// PLACEHOLDER: TestEtherscanSuite function implementation +func (s EtherscanSuite) TestRateLimiter() { + lockPath := filet.TmpDir(s.T(), "") -func (s *EtherscanSuite) TestRateLimiter() { - waitTime := time.Second - lockPath := filet.TmpDir(s.TestSuite.T(), "") - - rateLimiter, err := etherscan.NewFileRateLimiter(context.Background(), lockPath, waitTime) - s.TestSuite.Require().NoError(err) + rateLimiter, err := etherscan.NewFileRateLimiter(s.GetTestContext(), lockPath, waitTime) + Nil(s.T(), err) for lockCount := 0; lockCount < 2; lockCount++ { expectedEndTime := time.Now().Add(waitTime) + // obtain lock obtains the lcok + ok, err := rateLimiter.ObtainLock(s.GetTestContext()) + True(s.T(), ok) + Nil(s.T(), err) - // obtain lock obtains the lock - ok, err := rateLimiter.ObtainLock(context.Background()) - s.TestSuite.Assert().True(ok) - s.TestSuite.Require().NoError(err) - - // release lock releases the lock + // release lock releases the lcok ok, err = rateLimiter.ReleaseLock() - s.TestSuite.Assert().True(ok) - s.TestSuite.Require().NoError(err) + True(s.T(), ok) + Nil(s.T(), err) - s.TestSuite.Assert().GreaterOrEqual(expectedEndTime.UnixNano(), time.Now().UnixNano()) + GreaterOrEqual(s.T(), expectedEndTime.UnixNano(), time.Now().UnixNano()) } }