Integrate GolangCI-Lint (#90)
* Use plugin orb for ci * Add golangci-lint config and fix issues * Simplify circleci config * Drop unparam * Drop maligned * Ignore varcheck in server/manifest.go
This commit is contained in:
parent
ebbd3cdaad
commit
f5e50c1e17
5 changed files with 81 additions and 63 deletions
|
@ -1,27 +1,12 @@
|
|||
version: 2.1
|
||||
executors:
|
||||
default:
|
||||
docker:
|
||||
- image: circleci/golang:1.14-node
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
executor:
|
||||
name: default
|
||||
steps:
|
||||
- checkout
|
||||
- run: make check-style
|
||||
|
||||
test:
|
||||
executor:
|
||||
name: default
|
||||
steps:
|
||||
- checkout
|
||||
- run: make test
|
||||
orbs:
|
||||
plugin-ci: mattermost/plugin-ci@0.1.0
|
||||
|
||||
workflows:
|
||||
version: 2
|
||||
untagged-build:
|
||||
ci:
|
||||
jobs:
|
||||
- lint
|
||||
- test
|
||||
- plugin-ci/lint
|
||||
- plugin-ci/test
|
||||
- plugin-ci/build
|
||||
|
|
60
.golangci.yml
Normal file
60
.golangci.yml
Normal file
|
@ -0,0 +1,60 @@
|
|||
run:
|
||||
timeout: 5m
|
||||
modules-download-mode: readonly
|
||||
|
||||
linters-settings:
|
||||
goconst:
|
||||
min-len: 2
|
||||
min-occurrences: 2
|
||||
gofmt:
|
||||
simplify: true
|
||||
goimports:
|
||||
local-prefixes: github.com/mattermost/mattermost-starter-template
|
||||
golint:
|
||||
min-confidence: 0
|
||||
govet:
|
||||
check-shadowing: true
|
||||
enable-all: true
|
||||
misspell:
|
||||
locale: US
|
||||
|
||||
linters:
|
||||
disable-all: true
|
||||
enable:
|
||||
- bodyclose
|
||||
- deadcode
|
||||
- errcheck
|
||||
- goconst
|
||||
- gocritic
|
||||
- gofmt
|
||||
- goimports
|
||||
- golint
|
||||
- gosec
|
||||
- gosimple
|
||||
- govet
|
||||
- ineffassign
|
||||
- interfacer
|
||||
- misspell
|
||||
- nakedret
|
||||
- staticcheck
|
||||
- structcheck
|
||||
- stylecheck
|
||||
- typecheck
|
||||
- unconvert
|
||||
- unused
|
||||
- varcheck
|
||||
- whitespace
|
||||
|
||||
issues:
|
||||
exclude-rules:
|
||||
- path: server/manifest.go
|
||||
linters:
|
||||
- unused
|
||||
- varcheck
|
||||
- path: server/configuration.go
|
||||
linters:
|
||||
- unused
|
||||
- path: _test\.go
|
||||
linters:
|
||||
- goconst
|
||||
- scopelint # https://github.com/kyoh86/scopelint/issues/4
|
52
Makefile
52
Makefile
|
@ -30,54 +30,25 @@ all: check-style test dist
|
|||
apply:
|
||||
./build/bin/manifest apply
|
||||
|
||||
## Runs govet and gofmt against all packages.
|
||||
## Runs golangci-lint and eslint.
|
||||
.PHONY: check-style
|
||||
check-style: webapp/.npminstall gofmt govet golint
|
||||
check-style: webapp/.npminstall golangci-lint
|
||||
@echo Checking for style guide compliance
|
||||
|
||||
ifneq ($(HAS_WEBAPP),)
|
||||
cd webapp && npm run lint
|
||||
endif
|
||||
|
||||
## Runs gofmt against all packages.
|
||||
.PHONY: gofmt
|
||||
gofmt:
|
||||
ifneq ($(HAS_SERVER),)
|
||||
@echo Running gofmt
|
||||
@for package in $$(go list ./...); do \
|
||||
echo "Checking "$$package; \
|
||||
files=$$(go list -f '{{range .GoFiles}}{{$$.Dir}}/{{.}} {{end}}' $$package); \
|
||||
if [ "$$files" ]; then \
|
||||
gofmt_output=$$(gofmt -d -s $$files 2>&1); \
|
||||
if [ "$$gofmt_output" ]; then \
|
||||
echo "$$gofmt_output"; \
|
||||
echo "Gofmt failure"; \
|
||||
exit 1; \
|
||||
fi; \
|
||||
fi; \
|
||||
done
|
||||
@echo Gofmt success
|
||||
endif
|
||||
## Run golangci-lint on codebase.
|
||||
.PHONY: golangci-lint
|
||||
golangci-lint:
|
||||
@if ! [ -x "$$(command -v golangci-lint)" ]; then \
|
||||
echo "golangci-lint is not installed. Please see https://github.com/golangci/golangci-lint#install for installation instructions."; \
|
||||
exit 1; \
|
||||
fi; \
|
||||
|
||||
## Runs govet against all packages.
|
||||
.PHONY: govet
|
||||
govet:
|
||||
ifneq ($(HAS_SERVER),)
|
||||
@echo Running govet
|
||||
@# Workaround because you can't install binaries without adding them to go.mod
|
||||
env GO111MODULE=off $(GO) get golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow
|
||||
$(GO) vet ./...
|
||||
$(GO) vet -vettool=$(GOPATH)/bin/shadow ./...
|
||||
@echo Govet success
|
||||
endif
|
||||
|
||||
## Runs golint against all packages.
|
||||
.PHONY: golint
|
||||
golint:
|
||||
@echo Running lint
|
||||
env GO111MODULE=off $(GO) get golang.org/x/lint/golint
|
||||
$(GOPATH)/bin/golint -set_exit_status ./...
|
||||
@echo lint success
|
||||
@echo Running golangci-lint
|
||||
golangci-lint run ./...
|
||||
|
||||
## Builds the server, if it exists, including support for multiple architectures.
|
||||
.PHONY: server
|
||||
|
@ -104,6 +75,7 @@ ifneq ($(HAS_WEBAPP),)
|
|||
endif
|
||||
|
||||
## Builds the webapp in debug mode, if it exists.
|
||||
.PHONY: webapp-debug
|
||||
webapp-debug: webapp/.npminstall
|
||||
ifneq ($(HAS_WEBAPP),)
|
||||
cd webapp && \
|
||||
|
|
|
@ -85,13 +85,13 @@ func uploadPlugin(client *model.Client4, pluginID, bundlePath string) error {
|
|||
log.Print("Uploading plugin via API.")
|
||||
_, resp := client.UploadPluginForced(pluginBundle)
|
||||
if resp.Error != nil {
|
||||
return fmt.Errorf("Failed to upload plugin bundle: %s", resp.Error.Error())
|
||||
return errors.Wrap(resp.Error, "failed to upload plugin bundle")
|
||||
}
|
||||
|
||||
log.Print("Enabling plugin.")
|
||||
_, resp = client.EnablePlugin(pluginID)
|
||||
if resp.Error != nil {
|
||||
return fmt.Errorf("Failed to enable plugin: %s", resp.Error.Error())
|
||||
return errors.Wrap(resp.Error, "Failed to enable plugin")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -19,6 +19,7 @@ func TestServeHTTP(t *testing.T) {
|
|||
|
||||
result := w.Result()
|
||||
assert.NotNil(result)
|
||||
defer result.Body.Close()
|
||||
bodyBytes, err := ioutil.ReadAll(result.Body)
|
||||
assert.Nil(err)
|
||||
bodyString := string(bodyBytes)
|
||||
|
|
Reference in a new issue