Skip to content

Commit

Permalink
Use golangci-lint for linting (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
ob-stripe committed Aug 2, 2019
1 parent f0887ec commit d2c89f3
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 35 deletions.
18 changes: 18 additions & 0 deletions .golangci.yml
@@ -0,0 +1,18 @@
run:
tests: false

linters:
goimports:
local-prefixes: github.com/stripe/stripe-cli

linters:
enable-all: true
disable:
- errcheck
- gochecknoglobals
- gochecknoinits
- gosec
- lll
- maligned
- unparam
- stylecheck
15 changes: 8 additions & 7 deletions .travis.yml
@@ -1,18 +1,19 @@
dist: bionic

language: go

go:
- 1.12.x
go: '1.12.x'

addons:
apt:
packages:
- rpm

env:
global:
- GO111MODULE=on
- GOBIN="${GOPATH}/bin"
- PATH="${GOBIN}:${PATH}"
install:
- make setup

script:
- make ci

deploy:
- provider: script
Expand Down
7 changes: 7 additions & 0 deletions .vscode/settings.json
Expand Up @@ -5,6 +5,13 @@
"editor.formatOnSave": false,

"go.formatTool": "goimports",
"go.formatFlags": [
"-local", "github.com/stripe/stripe-cli",
],
"go.lintTool": "golangci-lint",
"go.lintFlags": [
"--fast",
],
"[go]": {
"editor.formatOnSave": true
},
Expand Down
88 changes: 60 additions & 28 deletions Makefile
@@ -1,50 +1,80 @@
SOURCE_FILES?=./...
TEST_PATTERN?=.
TEST_OPTIONS?=

export GO111MODULE := on
export GOBIN := $(shell pwd)/bin
export PATH := $(GOBIN):$(PATH)
export GOPROXY := https://gocenter.io

all: test
# Install all the build and lint dependencies
setup:
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh
curl -L https://git.io/misspell | sh
go mod download
.PHONY: setup

install-deps:
go get
.PHONY: install-deps
# Run all the tests
test:
go test $(TEST_OPTIONS) -failfast -race -coverpkg=./... -covermode=atomic -coverprofile=coverage.txt $(SOURCE_FILES) -run $(TEST_PATTERN) -timeout=2m
.PHONY: test

update-deps:
go get -u
.PHONY: update-deps
# Run all the tests and opens the coverage report
cover: test
go tool cover -html=coverage.txt
.PHONY: cover

update-openapi-spec:
rm -f ./api/openapi-spec/spec3.sdk.json
wget https://raw.githubusercontent.com/stripe/openapi/master/openapi/spec3.sdk.json -P ./api/openapi-spec
.PHONY: update-openapi-spec
# gofmt and goimports all go files
fmt:
find . -name '*.go' | while read -r file; do gofmt -w -s "$$file"; goimports -w "$$file"; done
.PHONY: fmt

# Run all the linters
lint:
# In travis, we need to install golint explicitly. Don't do this in other
# environments
ifeq ($(ENVIRONMENT), travis)
go get golang.org/x/lint/golint
git checkout .
endif
golint -set_exit_status ./...
# TODO: fix tests and disabled linter issues
./bin/golangci-lint run ./...
./bin/misspell -error **/*.go
.PHONY: lint

vet:
go vet $(shell go list ./... | grep -v /vendor/)
.PHONY: vet
# Clean go.mod
go-mod-tidy:
@go mod tidy -v
@git diff HEAD
@git diff-index --quiet HEAD
.PHONY: go-mod-tidy

test: install-deps lint vet
go test -race -cover -v ./...
@echo '\o/ yay, we did it!'
.PHONY: test
# Run all the tests and code checks
ci: build test lint go-mod-tidy
.PHONY: ci

# Build a beta version of stripe
build:
go mod download
go generate ./...
go build -o stripe -ldflags "-s -w" cmd/stripe/main.go
go build -o stripe cmd/stripe/main.go
.PHONY: build

# Show to-do items per file
todo:
@grep \
--exclude-dir=vendor \
--exclude-dir=node_modules \
--exclude=Makefile \
--text \
--color \
-nRo -E ' TODO:.*|SkipNow' .
.PHONY: todo

# Updates the OpenAPI spec
update-openapi-spec:
rm -f ./api/openapi-spec/spec3.sdk.json
wget https://raw.githubusercontent.com/stripe/openapi/master/openapi/spec3.sdk.json -P ./api/openapi-spec
.PHONY: update-openapi-spec

# Releases a new version
release:
# This does not release anything from your local machine but creates a tag
# for our CI to handle it
release:

git pull origin master

# Makefile's execute each line in its own subshell so variables don't
Expand All @@ -54,3 +84,5 @@ release:
git tag $$version
git push --tags
.PHONY: release

.DEFAULT_GOAL := build

0 comments on commit d2c89f3

Please sign in to comment.