Skip to content
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
38 changes: 31 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,39 @@
version: 2
version: 2.1

jobs:
build:
docker:
- image: circleci/golang:1.9
working_directory: /go/src/github.com/powerman/check
- image: circleci/golang:1
environment:
GOLANGCI_LINT_VER: 1.12.2
steps:
- checkout
- run: go get -v -t -d ./...
- run: go test -v -race ./...
- run:
name: Report coverage
name: Initialize
command: |
rmdir /go/*/ # fix owner/permission
env | grep _VER | sort > /tmp/tools.ver
- restore_cache:
keys:
- v1-{{ checksum "/tmp/tools.ver" }}-{{ checksum "go.mod" }}-{{ .Branch }}
- v1-{{ checksum "/tmp/tools.ver" }}-{{ checksum "go.mod" }}-
- v1-{{ checksum "/tmp/tools.ver" }}-
- v1-
- run:
name: Install tools
command: |
cd /
golangci-lint --version | tee /dev/stderr | grep -wq $GOLANGCI_LINT_VER ||
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b /go/bin v$GOLANGCI_LINT_VER
go get -v github.com/mattn/goveralls
goveralls -service=circle-ci
- run: go test -mod=readonly -v -race ./...
- run: golangci-lint run
- run: goveralls -service=circle-ci
- save_cache:
when: always
key: v1-{{ checksum "/tmp/tools.ver" }}-{{ checksum "go.mod" }}-{{ .Branch }}
paths:
- /go/bin/
- /go/pkg/
- /go/src/
- ~/.cache/go-build/
67 changes: 67 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
linters-settings:
errcheck:
check-type-assertions: false
check-blank: false
govet:
check-shadowing: true
golint:
min-confidence: 0 # 0.8
gocyclo:
min-complexity: 12 # 30
maligned:
suggest-new: false
dupl:
threshold: 150
goconst:
min-len: 3
min-occurrences: 3
unused:
check-exported: false
unparam:
algo: cha
check-exported: false
nakedret:
max-func-lines: 30
prealloc:
simple: true
range-loops: true
for-loops: false
gocritic:
enabled-checks:
- appendAssign
- appendCombine
- assignOp
- boolExprSimplify
- caseOrder
- defaultCaseOrder
- deprecatedComment
- dupArg
- dupBranchBody
- dupCase
- flagDeref
- ifElseChain
- indexAlloc
- methodExprCall
- rangeExprCopy
# - rangeValCopy
- regexpMust
- singleCaseSwitch
- sloppyLen
# - switchTrue
- typeSwitchVar
- underef
# - unlabelStmt
- unlambda
- unslice

linters:
enable-all: true
disable:
- gofmt
- goimports
- depguard
- dupl
- gochecknoglobals
- gochecknoinits
- lll
- scopelint
10 changes: 6 additions & 4 deletions check.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,12 @@ func (t *C) report2(actual, expected interface{}, msg []interface{}, ok bool) bo
func (t *C) report3(actual, expected1, expected2 interface{}, msg []interface{}, ok bool) bool {
t.Helper()
checker, arg2Name, arg3Name := callerFuncName(1), "arg1", "arg2"
if strings.Contains(checker, "Between") {
switch {
case strings.Contains(checker, "Between"):
arg2Name, arg3Name = "Min", "Max"
} else if strings.Contains(checker, "Delta") {
case strings.Contains(checker, "Delta"):
arg2Name, arg3Name = nameExpected, "Delta"
} else if strings.Contains(checker, "SMAPE") {
case strings.Contains(checker, "SMAPE"):
arg2Name, arg3Name = nameExpected, "SMAPE"
}
return t.report(ok, msg,
Expand Down Expand Up @@ -398,8 +399,9 @@ func isEqual(actual, expected interface{}) bool {
switch actual := actual.(type) {
case time.Time:
return actual.Equal(expected.(time.Time))
default:
return actual == expected
}
return actual == expected
}

// EQ is a synonym for Equal.
Expand Down
5 changes: 2 additions & 3 deletions check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1249,8 +1249,7 @@ func TestCheckerApprox(t *testing.T) {
}

func half(v interface{}) interface{} {
switch v := v.(type) {
case time.Duration:
if v, ok := v.(time.Duration); ok {
return v / 2
}
switch val := reflect.ValueOf(v); val.Kind() {
Expand Down Expand Up @@ -1336,7 +1335,7 @@ func TestCheckerSubstring(t *testing.T) {
{[]byte("Sunday"), []byte("Monday")},
{[]rune("Sunday"), []rune("Monday")},
{time.Sunday, time.Monday},
{errors.New("Sunday"), errors.New("Monday")},
{errors.New("Sunday"), errors.New("Monday")}, // nolint:golint
}

t.Run("HasPrefix", func(tt *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (v dump) diff(expected dump) string {
// - []byte: same as string instead of hexdump for valid utf8
// - []rune: use quoted char instead of number for valid runes in list
// - json.RawMessage: indent, then same as string
func newDump(i interface{}) (d dump) {
func newDump(i interface{}) (d dump) { // nolint:gocyclo
d.dump = spewCfg.Sdump(i)

if i == nil {
Expand Down