From f2b91ab7734b0dceddca68c02cb4292e072d86ed Mon Sep 17 00:00:00 2001 From: Chris Hager Date: Tue, 14 Nov 2023 10:28:19 +0100 Subject: [PATCH 1/3] add linting --- .github/workflows/checks.yml | 42 ++++++++++++++++ .golangci.yaml | 98 ++++++++++++++++++++++++++++++++++++ Makefile | 27 ++++++++++ 3 files changed, 167 insertions(+) create mode 100644 .github/workflows/checks.yml create mode 100644 .golangci.yaml create mode 100644 Makefile diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml new file mode 100644 index 0000000..0222ea7 --- /dev/null +++ b/.github/workflows/checks.yml @@ -0,0 +1,42 @@ +name: Checks + +on: + push: + branches: + - main + pull_request: + +jobs: + checks: + name: Lint and Test + runs-on: ubuntu-latest + steps: + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: ^1.21 + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + + - name: Install gofumpt + run: go install mvdan.cc/gofumpt@v0.4.0 + + - name: Install staticcheck + run: go install honnef.co/go/tools/cmd/staticcheck@v0.4.2 + + - name: Install golangci-lint + run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.0 + + - name: Run tests + run: make test + + - name: Lint + run: make lint + + - name: Ensure go mod tidy runs without changes + run: | + go mod tidy + git update-index -q --really-refresh + git diff-index HEAD diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..e6dd602 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,98 @@ +linters: + enable-all: true + disable: + - cyclop + - forbidigo + - funlen + - gochecknoglobals + - gochecknoinits + - gocritic + - godot + - godox + - gomnd + - lll + - nestif + - nilnil + - nlreturn + - noctx + - nonamedreturns + - nosnakecase + - paralleltest + - revive + - testpackage + - unparam + - varnamelen + - wrapcheck + - wsl + - deadcode + - varcheck + - exhaustruct + - depguard + - gomoddirectives + - goerr113 + + # + # Disabled because of generics: + # + - contextcheck + - rowserrcheck + - sqlclosecheck + - structcheck + - wastedassign + + # + # Disabled because deprecated: + # + - exhaustivestruct + - golint + - ifshort + - interfacer + - maligned + - scopelint + +linters-settings: + # + # The G108 rule throws a false positive. We're not actually vulnerable. If + # you're not careful the profiling endpoint is automatically exposed on + # /debug/pprof if you import net/http/pprof. See this link: + # + # https://mmcloughlin.com/posts/your-pprof-is-showing + # + gosec: + excludes: + - G108 + + tagliatelle: + case: + rules: + json: snake + + gofumpt: + extra-rules: true + + exhaustruct: + exclude: + # + # Because it's easier to read without the other fields. + # + - 'GetPayloadsFilters' + + # + # Structures outside our control that have a ton of settings. It doesn't + # make sense to specify all of the fields. + # + - 'cobra.Command' + - 'database.*Entry' + - 'http.Server' + - 'logrus.*Formatter' + - 'Options' # redis + + # + # Excluded because there are private fields (not capitalized) that are + # not initialized. If possible, I think these should be altered. + # + - 'Datastore' + - 'Housekeeper' + - 'MockBeaconClient' + - 'RelayAPI' + - 'Webserver' diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0eb58e9 --- /dev/null +++ b/Makefile @@ -0,0 +1,27 @@ +VERSION := $(shell git describe --tags --always --dirty="-dev") + +.PHONY: clean +clean: + rm -rf out/ + +.PHONY: test +test: + go test ./framework/... + +.PHONY: lint +lint: + gofmt -d -s examples/ framework/ + gofumpt -d -extra examples/ framework/ + go vet ./examples/... ./framework/... + staticcheck ./examples/... ./framework/... + golangci-lint run + +.PHONY: fmt +fmt: + gofmt -s -w examples/ framework/ + gofumpt -extra -w examples/ framework/ + gci write examples/ framework/ + go mod tidy + +.PHONY: lt +lt: lint test From 6f61867befc66fba461d2adedda72f6584b860d9 Mon Sep 17 00:00:00 2001 From: Chris Hager Date: Wed, 15 Nov 2023 12:05:53 +0100 Subject: [PATCH 2/3] fix framework --- framework/framework.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/framework.go b/framework/framework.go index 2341423..1a273b0 100644 --- a/framework/framework.go +++ b/framework/framework.go @@ -124,7 +124,7 @@ func ensureTransactionSuccess(txn *sdk.TransactionResult) (*types.Receipt, error // DeployAndTransact is a helper function that deploys a suapp // and inmediately executes a function on it with a confidential request. -func DeployAndTransact(path string, funcName string) { +func DeployAndTransact(path, funcName string) { contract, err := DeployContract(path) if err != nil { fmt.Printf("failed to deploy contract: %v", err) From 340be5aa732546d4b2cf5c7932f86645047cba7b Mon Sep 17 00:00:00 2001 From: Chris Hager Date: Wed, 15 Nov 2023 12:12:29 +0100 Subject: [PATCH 3/3] update tooling --- .github/workflows/checks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 0222ea7..ada3336 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -24,7 +24,7 @@ jobs: run: go install mvdan.cc/gofumpt@v0.4.0 - name: Install staticcheck - run: go install honnef.co/go/tools/cmd/staticcheck@v0.4.2 + run: go install honnef.co/go/tools/cmd/staticcheck@v0.4.5 - name: Install golangci-lint run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.0