Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add linting + CI #3

Merged
merged 3 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]

- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/[email protected]

- name: Install golangci-lint
run: go install github.com/golangci/golangci-lint/cmd/[email protected]

- 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
98 changes: 98 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -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'
27 changes: 27 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading