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

Commit

Permalink
chore: add golangci-lint.
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Dec 20, 2018
1 parent c93d194 commit 455d7f5
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 21 deletions.
42 changes: 42 additions & 0 deletions .golangci.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[run]
deadline = "3m"
skip-files = []

[linters-settings]

[linters-settings.govet]
check-shadowing = true

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

[linters-settings.maligned]
suggest-new = true

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

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

[linters]
enable-all = true
disable = [
"maligned",
"lll",
"gas",
"dupl",
"prealloc",
"scopelint",
]

[issues]
exclude-use-default = false
max-per-linter = 0
max-same = 0
exclude = [
"string `(DefaultOwnerNamePointer|INFO)` has (\\d+) occurrences, make it a constant",
"(type )?`(other|unexported|SubSubConfig)` is unused",
"cyclomatic complexity (\\d+) of func `(fillStructRecursive|getDefaultValue|getTypesRecursive)` is high \\(> 12\\)",
]
12 changes: 7 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
language: go

go:
- 1.9.x
- master
- 1.11.x
- 1.x

sudo: false

before_install:
- go get -u golang.org/x/lint/golint
- go get -u honnef.co/go/tools/cmd/{gosimple,staticcheck}
- go get -u github.com/client9/misspell/cmd/misspell
# Download and install dep
- curl -sI https://github.com/golang/dep/releases/latest | grep -Fi Location | tr -d '\r' | sed "s/tag/download/g" | awk -F " " '{ print $2 "/dep-linux-amd64"}' | wget --output-document=$GOPATH/bin/dep -i -
- chmod +x $GOPATH/bin/dep

# Install linters and misspell
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin v1.12.2
- golangci-lint --version

install:
- make dependencies
- go get github.com/mattn/goveralls
Expand Down
4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
# name = "github.com/x/y"
# version = "2.4.0"

[prune]
non-go = true
go-tests = true
unused-packages = true

[[constraint]]
name = "github.com/ogier/pflag"
Expand Down
14 changes: 2 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
.PHONY: all


PKGS := $(shell go list ./... | grep -v '/vendor/')
GOFILES := $(shell go list -f '{{range $$index, $$element := .GoFiles}}{{$$.Dir}}/{{$$element}}{{"\n"}}{{end}}' ./... | grep -v '/vendor/')
SRCS = $(shell git ls-files '*.go' | grep -v '^vendor/')
TXT_FILES := $(shell find * -type f -not -path 'vendor/**')

default: clean checks lint test build
default: clean checks test build

test: clean
go test -v -cover $(PKGS)
Expand All @@ -20,19 +17,12 @@ clean:
build:
go build

lint:
golint -set_exit_status $(PKGS)

checks: check-fmt
staticcheck $(PKGS)
gosimple $(PKGS)
golangci-lint run

check-fmt: SHELL := /bin/bash
check-fmt:
diff -u <(echo -n) <(gofmt -d $(GOFILES))

misspell:
misspell -source=text -error $(TXT_FILES)

fmt:
gofmt -s -l -w $(SRCS)
9 changes: 5 additions & 4 deletions flaeg.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,12 @@ func getDefaultValue(defaultValue reflect.Value, defaultPointersValue reflect.Va

// objValue a reflect.Value of a not-nil pointer on a struct
func setPointersNil(objValue reflect.Value) (reflect.Value, error) {
if objValue.Kind() != reflect.Ptr {
switch {
case objValue.Kind() != reflect.Ptr:
return objValue, fmt.Errorf("parameters objValue must be a not-nil pointer on a struct, not a %s", objValue.Kind())
} else if objValue.IsNil() {
case objValue.IsNil():
return objValue, errors.New("parameters objValue must be a not-nil pointer")
} else if objValue.Elem().Kind() != reflect.Struct {
case objValue.Elem().Kind() != reflect.Struct:
// fmt.Printf("Parameters objValue must be a not-nil pointer on a struct, not a pointer on a %s\n", objValue.Elem().Kind().String())
return objValue, nil
}
Expand Down Expand Up @@ -362,7 +363,7 @@ func PrintError(err error, flagMap map[string]reflect.StructField, defaultValmap
fmt.Printf("Error: %s\n", err)
}
if !strings.Contains(err.Error(), ":No parser for type") {
PrintHelp(flagMap, defaultValmap, parsers)
_ = PrintHelp(flagMap, defaultValmap, parsers)
}
return err
}
Expand Down

0 comments on commit 455d7f5

Please sign in to comment.