Skip to content

Commit

Permalink
Merge pull request #45 from form3tech-oss/nvloff-lint
Browse files Browse the repository at this point in the history
fix: updates & cleanups
  • Loading branch information
nvloff-f3 authored Feb 28, 2024
2 parents 28e514d + dd115f7 commit 362f1e2
Show file tree
Hide file tree
Showing 535 changed files with 34,229 additions and 8,178 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
on: [push]
jobs:
Test:
runs-on: ubuntu-latest
steps:
- uses: "actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608" # v4.1.0
with:
fetch-depth: 0
fetch-tags: true
- uses: "actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491" # v5.0.0
- name: test
run: |
make lint
make build
make test
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ pacttesting/logs
pact/
pacttesting/log/pact.log
pacttesting/logs/pact.log
build/
build/
/tools
99 changes: 99 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Using golangci-lint@v1.56.2
run:
timeout: 5m
tests: true
skip-dirs:
- vendor$
build-tags:
- all
output:
print-linter-name: true
linters:
enable-all: true
fast: false
disable:
# Deprecated (see https://golangci-lint.run/usage/linters/)
- deadcode
- golint
- ifshort
- interfacer
- maligned
- nosnakecase
- scopelint
- structcheck
- varcheck
- exhaustivestruct

# Style guides that are very subjective
- funlen
- nlreturn
- wsl
- cyclop
- varnamelen
- maintidx
- gocognit
- godot
- gocyclo
- nestif
- nilnil
- tagliatelle
- ireturn
- gomnd

# Dynamic errors are OK here
- goerr113

# We don't need to limit dependencies or replacements
- gomoddirectives

# Too many false positives for structs with optional fields
- exhaustruct

# Requires massive test rewrite
- testpackage

# Most tests can't run in parallel
- paralleltest

linters-settings:
depguard:
rules:
main:
deny:
- pkg: "github.com/pkg/errors"
desc: Use standard library errors package
exhaustive:
default-signifies-exhaustive: true
errcheck:
check-blank: false
gci:
sections:
- standard
- default
- prefix(github.com/form3tech-oss)
- prefix(github.com/form3tech-oss/go-pact-testing)
issues:
max-issues-per-linter: 0
max-same-issues: 0
exclude-rules:
- path: _test\.go
linters:
- unparam
- errcheck
- bodyclose
- path: _test\.go
# ST1003: Poorly chosen identifiers (https://staticcheck.io/docs/checks/#ST1003)
# This is to allow identifiers to be snake_cased in favor of BDD integration tests
text: "ST1003"
linters:
- stylecheck
- path: _test\.go
# This is to allow identifiers to be snake_cased in favor of BDD integration tests
text: "var-naming: don't use underscores in Go names;"
linters:
- revive
- path: _test\.go
# This is to allow stages to be private strcts
text: "unexported-return: exported func"
linters:
- revive
48 changes: 22 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,50 +1,46 @@
.DEFAULT_GOAL := default

GOLANGCI_VERSION := 1.56.2

platform := $(shell uname)
pact_version := "1.88.51"

GOFMT_FILES?=$$(find ./ -name '*.go' | grep -v vendor)

default: build test

default: lint build test

ifeq (${platform},Darwin)
pact_filename := "pact-${pact_version}-osx.tar.gz"
else
pact_filename := "pact-${pact_version}-linux-x86_64.tar.gz"
endif

build: goimportscheck vet install-pact-go
.PHONY: build
build: install-pact-go
go install ./pacttesting

.PHONY: test
test:
@echo "executing tests..."
@go test -count=1 -v github.com/form3tech-oss/go-pact-testing/v2/pacttesting

install-pact-go:
@if [ ! -d ./pact ]; then \
echo "pact-go not installed, installing..."; \
wget https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v${pact_version}/${pact_filename} -O /tmp/pactserver.tar.gz && tar -xvf /tmp/pactserver.tar.gz -C .; \
fi

install-goimports:
@go get golang.org/x/tools/cmd/goimports

test: goimportscheck
@echo "executing tests..."
@go test -v github.com/form3tech-oss/go-pact-testing/v2/pacttesting

vet:
@echo "go vet ."
@go vet $$(go list ./... | grep -v vendor/) ; if [ $$? -eq 1 ]; then \
echo ""; \
echo "Vet found suspicious constructs. Please check the reported constructs"; \
echo "and fix them if necessary before submitting the code for review."; \
exit 1; \
fi

goimports:
goimports:
goimports -w $(GOFMT_FILES)

goimportscheck:
@sh -c "'$(CURDIR)/scripts/goimportscheck.sh'"
.PHONY: lint
lint: tools/golangci-lint
@echo "==> Running golangci-lint..."
@tools/golangci-lint run

.PHONY: lint-fix
lint-fix: tools/golangci-lint
@echo "==> Running golangci-lint with autofix..."
@tools/golangci-lint run --fix

.PHONY: build test vet goimports goimportscheck errcheck package
.PHONY: tools/golangci-lint
tools/golangci-lint:
@echo "==> Installing golangci-lint..."
@./scripts/install-golangci-lint.sh $(GOLANGCI_VERSION)
37 changes: 20 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,34 @@ module github.com/form3tech-oss/go-pact-testing/v2
go 1.20

require (
github.com/avast/retry-go/v4 v4.3.3
github.com/pact-foundation/pact-go v1.7.0
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.0
github.com/spf13/viper v1.15.0
github.com/stretchr/testify v1.8.2
github.com/avast/retry-go/v4 v4.5.1
github.com/pact-foundation/pact-go v1.8.0
github.com/sirupsen/logrus v1.9.3
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.8.4
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/hashicorp/go-version v1.5.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/text v0.5.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 362f1e2

Please sign in to comment.