Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Commit

Permalink
chore: apply linter for better quality code (#55)
Browse files Browse the repository at this point in the history
* apply linter

* update makefile

* update travis yml
  • Loading branch information
bxcodec authored Feb 1, 2019
1 parent 40420f9 commit 6e28510
Show file tree
Hide file tree
Showing 12 changed files with 355 additions and 34 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ cover.html
.glide/
faker
vendor/

coverage.txt
bin/
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ language: go
go:
- "1.11"

env:
- env GO111MODULE=on

before_install:
- go get -t -v ./...

script:
- go test -race -coverprofile=coverage.txt -covermode=atomic
- make lint-prepare
- make lint
- make test

after_success:
- bash <(curl -s https://codecov.io/bash)
29 changes: 21 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
BINARY=faker
TESTS=go test $$(go list ./... | grep -v /vendor/) -cover

build:
${TESTS}
go build -o ${BINARY}
build: test
@go build ./...

install:
${TESTS}
go build -o ${BINARY}
test:
@go test -v ./... -cover -race -coverprofile=coverage.txt -covermode=atomic

unittest:
go test -short $$(go list ./... | grep -v /vendor/)
@go test -v -short ./...

# Linter
lint-prepare:
@echo "Installing golangci-lint"
# @go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s v1.13.2

lint:
./bin/golangci-lint run \
--exclude="cyclomatic complexity" \
--exclude-use-default=false \
--enable=golint \
--enable=gocyclo \
--enable=goconst \
--enable=unconvert \
./...
clean:
if [ -f ${BINARY} ] ; then rm ${BINARY} ; fi

.PHONY: lint lint-prepare clean build unittest
4 changes: 2 additions & 2 deletions address.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (i Address) Latitude(v reflect.Value) (interface{}, error) {
kind := v.Kind()
val := i.latitute()
if kind == reflect.Float32 {
return float32(val), nil
return val, nil
}
return float64(val), nil
}
Expand All @@ -55,7 +55,7 @@ func (i Address) Longitude(v reflect.Value) (interface{}, error) {
kind := v.Kind()
val := i.longitude()
if kind == reflect.Float32 {
return float32(val), nil
return val, nil
}
return float64(val), nil
}
5 changes: 4 additions & 1 deletion datetime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ func TestUnixTimeValueValid(t *testing.T) {
}{
some: 1212,
}
d.UnixTime(reflect.ValueOf(&ref.some).Elem())
_, err := d.UnixTime(reflect.ValueOf(&ref.some).Elem())
if err != nil {
t.Error("function Date need return valid value")
}

if time.Now().Unix() <= ref.some {
t.Error("UnixTime should return time <= now")
Expand Down
2 changes: 1 addition & 1 deletion faker.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func getValue(t reflect.Type) (reflect.Value, error) {
}
return v, nil
case reflect.Int:
return reflect.ValueOf(int(rand.Intn(100))), nil
return reflect.ValueOf(rand.Intn(100)), nil
case reflect.Int8:
return reflect.ValueOf(int8(rand.Intn(100))), nil
case reflect.Int16:
Expand Down
12 changes: 9 additions & 3 deletions faker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,10 @@ type SampleStruct struct {
Age int
}

func (s SampleStruct) GetName() string {
return s.name
}

func TestUnexportedFieldStruct(t *testing.T) {
// This test is to ensure that the faker won't panic if trying to fake data on struct that has unexported field
a := new(SampleStruct)
Expand Down Expand Up @@ -559,12 +563,14 @@ func TestTagWithPointer(t *testing.T) {
School *School `faker:"school"`
}
// With custom provider
AddProvider("school", func(v reflect.Value) (interface{}, error) {
err := AddProvider("school", func(v reflect.Value) (interface{}, error) {
return &School{Location: "Jakarta"}, nil
})

if err != nil {
t.Error("Expected Not Error, But Got: ", err)
}
var sample TestStruct
err := FakeData(&sample)
err = FakeData(&sample)
if err != nil {
t.Error("Expected Not Error, But Got: ", err)
}
Expand Down
48 changes: 48 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1 +1,49 @@
module github.com/bxcodec/faker/v3

require (
github.com/OpenPeeDeeP/depguard v0.0.0-20181229194401-1f388ab2d810 // indirect
github.com/StackExchange/wmi v0.0.0-20181212234831-e0a55b97c705 // indirect
github.com/coreos/etcd v3.3.11+incompatible // indirect
github.com/fatih/color v1.7.0 // indirect
github.com/go-critic/go-critic v0.3.4 // indirect
github.com/go-ole/go-ole v1.2.2 // indirect
github.com/go-toolsmith/astcast v1.0.0 // indirect
github.com/go-toolsmith/astcopy v1.0.0 // indirect
github.com/go-toolsmith/astfmt v1.0.0 // indirect
github.com/go-toolsmith/astp v1.0.0 // indirect
github.com/go-toolsmith/pkgload v1.0.0 // indirect
github.com/go-toolsmith/typep v1.0.0 // indirect
github.com/gogo/protobuf v1.2.0 // indirect
github.com/golang/mock v1.2.0 // indirect
github.com/golangci/errcheck v0.0.0-20181223084120-ef45e06d44b6 // indirect
github.com/golangci/go-tools v0.0.0-20180902103155-93eecd106a0b // indirect
github.com/golangci/gocyclo v0.0.0-20180528144436-0a533e8fa43d // indirect
github.com/golangci/gofmt v0.0.0-20181222123516-0b8337e80d98 // indirect
github.com/golangci/golangci-lint v1.13.2 // indirect
github.com/golangci/lint-1 v0.0.0-20181222135242-d2cdd8c08219 // indirect
github.com/golangci/revgrep v0.0.0-20180812185044-276a5c0a1039 // indirect
github.com/golangci/tools v0.0.0-20190108095906-d95fd85c147a // indirect
github.com/kr/pty v1.1.3 // indirect
github.com/mattn/go-isatty v0.0.4 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d // indirect
github.com/onsi/ginkgo v1.7.0 // indirect
github.com/onsi/gomega v1.4.3 // indirect
github.com/pkg/errors v0.8.1 // indirect
github.com/shirou/gopsutil v2.18.12+incompatible // indirect
github.com/shurcooL/go v0.0.0-20190121191506-3fef8c783dec // indirect
github.com/sirupsen/logrus v1.3.0 // indirect
github.com/spf13/afero v1.2.1 // indirect
github.com/spf13/cobra v0.0.3 // indirect
github.com/spf13/viper v1.3.1 // indirect
github.com/stretchr/testify v1.3.0 // indirect
github.com/ugorji/go/codec v0.0.0-20190128213124-ee1426cffec0 // indirect
golang.org/x/crypto v0.0.0-20190131182504-b8fe1690c613 // indirect
golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3 // indirect
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 // indirect
golang.org/x/sys v0.0.0-20190130150945-aca44879d564 // indirect
golang.org/x/tools v0.0.0-20190131163942-067a2f313b69 // indirect
mvdan.cc/unparam v0.0.0-20190131163057-1679b9996abd // indirect
sourcegraph.com/sourcegraph/go-diff v0.5.0 // indirect
sourcegraph.com/sqs/pbtypes v1.0.0 // indirect
)
Loading

0 comments on commit 6e28510

Please sign in to comment.