Skip to content

Commit

Permalink
Switching to golangci (#17)
Browse files Browse the repository at this point in the history
* Switching to golangci

* Dropping support for go 1.8 and 1.9

* Adding .editorconfig
  • Loading branch information
yazgazan authored May 7, 2019
1 parent 1a8f74f commit 959328e
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 20 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true


[*.go]
indent_style = tab
indent_size = 2

46 changes: 46 additions & 0 deletions .golangci.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[run]
concurrency = 4
tests = false

[linters-settings]
[linters-settings.gocyclo]
min-complexity = 10

[linters-settings.goconst]
min-len = 2
min-occurrences = 2

[linters-settings.misspell]
locale = "US"

[linters]
# White-listing, to be more CI safe.
disable-all = true

# @see https://github.com/golangci/golangci-lint#enabled-by-default-linters
enable = [
"staticcheck",
"gosimple",
"ineffassign",
"typecheck",
"govet",
"errcheck",
"unused",
"structcheck",
"varcheck",
"deadcode",

"stylecheck",
"gosec",
"interfacer",
"unconvert",
"goconst",
"gocyclo",
"maligned",
"depguard",
"misspell",
"unparam",
"prealloc",
"scopelint", # Would like to ignore *_test.go files, but can't atm.
"gocritic",
]
7 changes: 2 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
language: go
go:
- 1.8
- 1.9
- "1.10"
- 1.11
- 1.12

before_install:
- go get -u golang.org/x/tools/cmd/cover
- go get -u github.com/mattn/goveralls
- go get -u gopkg.in/alecthomas/gometalinter.v2
- gometalinter.v2 --install
- curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sudo sh -s -- -b $(go env GOPATH)/bin v1.14.0

script:
- go build
- gometalinter.v2 -e '_test.go' -e 'should have comment or be unexported' -e 'error return value not checked.+fmt\.Fprintf' -D gosec ./...
- golangci-lint run
- go test -v ./...
- go test -v -covermode=count -coverprofile=coverage.out ./diff
- ./tests.sh
Expand Down
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ A JSON diff utility.

## From source

- Have go 1.8 or greater installed: [golang.org](https://golang.org/doc/install)
- Have go 1.10 or greater installed: [golang.org](https://golang.org/doc/install)
- run `go get -u github.com/yazgazan/jaydiff`

# Usage
Expand Down
2 changes: 1 addition & 1 deletion diff/cyclic_detection.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type visited struct {

// push will try to add the value's pointers to the list. It will return an error
// if the value is already in the list.
// visited.remove should be called whether an error occured or not.
// visited.remove should be called whether an error occurred or not.
func (v *visited) push(lhs, rhs reflect.Value) error {
if canAddr(lhs) && !isEmptyMapOrSlice(lhs) {
if inPointers(v.lhs, lhs.Pointer()) {
Expand Down
2 changes: 1 addition & 1 deletion diff/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (m mapDiff) mapKeyString(key interface{}, conf Output) string {
}

func (m mapDiff) Walk(path string, fn WalkFn) error {
var keys []interface{}
keys := make([]interface{}, 0, len(m.diffs))

for k := range m.diffs {
keys = append(keys, k)
Expand Down
27 changes: 15 additions & 12 deletions diff/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ type Output struct {
func (o Output) red(v interface{}) string {
var s string

if o.ShowTypes {
switch {
default:
s = fmt.Sprintf("%v", v)
case o.ShowTypes:
s = fmt.Sprintf("%T %v", v, v)
} else if o.JSONValues {
case o.JSONValues:
s = jsonString(v)
} else {
s = fmt.Sprintf("%v", v)
}

if !o.Colorized {
Expand All @@ -37,12 +38,13 @@ func (o Output) red(v interface{}) string {
func (o Output) green(v interface{}) string {
var s string

if o.ShowTypes {
switch {
default:
s = fmt.Sprintf("%v", v)
case o.ShowTypes:
s = fmt.Sprintf("%T %v", v, v)
} else if o.JSONValues {
case o.JSONValues:
s = jsonString(v)
} else {
s = fmt.Sprintf("%v", v)
}

if !o.Colorized {
Expand All @@ -55,12 +57,13 @@ func (o Output) green(v interface{}) string {
func (o Output) white(v interface{}) string {
var s string

if o.ShowTypes {
switch {
default:
s = fmt.Sprintf("%v", v)
case o.ShowTypes:
s = fmt.Sprintf("%T %v", v, v)
} else if o.JSONValues {
case o.JSONValues:
s = jsonString(v)
} else {
s = fmt.Sprintf("%v", v)
}

return s
Expand Down

0 comments on commit 959328e

Please sign in to comment.