From 2f98594fa35c670196ad5df3bd6426704b0eb2f8 Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Wed, 22 May 2024 21:09:59 -0500 Subject: [PATCH] golangci-lint: enable containedctx --- .github/workflows/pull-request-main.yml | 4 +- .github/workflows/push-main.yml | 4 +- .golangci.yml | 121 ++++++++++++++++++++++++ Makefile | 20 ++++ 4 files changed, 145 insertions(+), 4 deletions(-) create mode 100644 .golangci.yml create mode 100644 Makefile diff --git a/.github/workflows/pull-request-main.yml b/.github/workflows/pull-request-main.yml index 3d4f42e..ab5464f 100644 --- a/.github/workflows/pull-request-main.yml +++ b/.github/workflows/pull-request-main.yml @@ -1,10 +1,10 @@ -name: pull-request-master +name: pull-request-main on: merge_group: pull_request: branches: - - master + - main # Only run 1 of this workflow at a time per PR concurrency: group: chainlink-vrf-${{ github.ref }} diff --git a/.github/workflows/push-main.yml b/.github/workflows/push-main.yml index 72731af..5e24f74 100644 --- a/.github/workflows/push-main.yml +++ b/.github/workflows/push-main.yml @@ -1,9 +1,9 @@ -name: push-master +name: push-main on: push: branches: - - master + - main env: PACKAGES: "./..." diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..5edaee7 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,121 @@ +run: + timeout: 10m0s +linters: + enable: + - exhaustive + - exportloopref + - revive + - goimports + - gosec + - misspell + - rowserrcheck + - errorlint + - unconvert + - sqlclosecheck + - noctx + - whitespace + - depguard + - containedctx +linters-settings: + exhaustive: + default-signifies-exhaustive: true + goimports: + local-prefixes: github.com/smartcontractkit/chainlink-vrf + golint: + min-confidence: 1.0 + gosec: + excludes: + - G101 + - G104 + # - G204 + # - G304 + # - G404 + govet: + # report about shadowed variables + check-shadowing: true + errorlint: + # Allow formatting of errors without %w + errorf: false + revive: + confidence: 0.8 + rules: + - name: blank-imports + - name: context-as-argument + - name: context-keys-type + - name: dot-imports + - name: error-return + - name: error-strings + - name: error-naming + - name: exported + - name: if-return + - name: increment-decrement + - name: var-naming + - name: var-declaration + - name: package-comments + - name: range + - name: receiver-naming + - name: time-naming + # - name: unexported-return + - name: indent-error-flow + - name: errorf + - name: empty-block + - name: superfluous-else + # - name: unused-parameter + - name: unreachable-code + - name: redefines-builtin-id + - name: waitgroup-by-value + - name: unconditional-recursion + - name: struct-tag + # - name: string-format + - name: string-of-int + - name: range-val-address + - name: range-val-in-closure + - name: modifies-value-receiver + - name: modifies-parameter + - name: identical-branches + - name: get-return + # - name: flag-parameter + - name: early-return + - name: defer + - name: constant-logical-expr + # - name: confusing-naming + # - name: confusing-results + - name: bool-literal-in-expr + - name: atomic + depguard: + rules: + main: + list-mode: lax + deny: + - pkg: "cosmossdk.io/errors" + desc: Use the standard library instead + - pkg: "github.com/ethereum/go-ethereum" + desc: This is a chain-agnostic repo + - pkg: "github.com/go-gorm/gorm" + desc: Use github.com/jmoiron/sqlx directly instead + - pkg: "github.com/gofrs/uuid" + desc: Use github.com/google/uuid instead + - pkg: "github.com/pkg/errors" + desc: Use the standard library instead, for example https://pkg.go.dev/errors#Join + - pkg: "github.com/satori/go.uuid" + desc: Use github.com/google/uuid instead + - pkg: "github.com/test-go/testify/assert" + desc: Use github.com/stretchr/testify/assert instead + - pkg: "github.com/test-go/testify/mock" + desc: Use github.com/stretchr/testify/mock instead + - pkg: "github.com/test-go/testify/require" + desc: Use github.com/stretchr/testify/require instead + - pkg: "go.uber.org/multierr" + desc: Use the standard library instead, for example https://pkg.go.dev/errors#Join + - pkg: "gopkg.in/guregu/null.v1" + desc: Use gopkg.in/guregu/null.v4 instead + - pkg: "gopkg.in/guregu/null.v2" + desc: Use gopkg.in/guregu/null.v4 instead + - pkg: "gopkg.in/guregu/null.v3" + desc: Use gopkg.in/guregu/null.v4 instead +issues: + exclude-rules: + - path: test + text: "^G404:" + linters: + - gosec \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a26bcbc --- /dev/null +++ b/Makefile @@ -0,0 +1,20 @@ +SHELL=/bin/bash -o pipefail + +.PHONY: all +all: build + +.PHONY: build +build: + go build ./... + +.PHONY: test +test: + go test ./... + +.PHONY: lint +lint: + golangci-lint run ./... + +.PHONY: tidy +tidy: + go mod tidy