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:
Ben Schumacher 2020-04-02 20:01:00 +02:00 committed by GitHub
parent ebbd3cdaad
commit f5e50c1e17
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 81 additions and 63 deletions

View file

@ -1,27 +1,12 @@
version: 2.1 version: 2.1
executors:
default:
docker:
- image: circleci/golang:1.14-node
jobs: orbs:
lint: plugin-ci: mattermost/plugin-ci@0.1.0
executor:
name: default
steps:
- checkout
- run: make check-style
test:
executor:
name: default
steps:
- checkout
- run: make test
workflows: workflows:
version: 2 version: 2
untagged-build: ci:
jobs: jobs:
- lint - plugin-ci/lint
- test - plugin-ci/test
- plugin-ci/build

60
.golangci.yml Normal file
View 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

View file

@ -30,54 +30,25 @@ all: check-style test dist
apply: apply:
./build/bin/manifest apply ./build/bin/manifest apply
## Runs govet and gofmt against all packages. ## Runs golangci-lint and eslint.
.PHONY: check-style .PHONY: check-style
check-style: webapp/.npminstall gofmt govet golint check-style: webapp/.npminstall golangci-lint
@echo Checking for style guide compliance @echo Checking for style guide compliance
ifneq ($(HAS_WEBAPP),) ifneq ($(HAS_WEBAPP),)
cd webapp && npm run lint cd webapp && npm run lint
endif endif
## Runs gofmt against all packages. ## Run golangci-lint on codebase.
.PHONY: gofmt .PHONY: golangci-lint
gofmt: golangci-lint:
ifneq ($(HAS_SERVER),) @if ! [ -x "$$(command -v golangci-lint)" ]; then \
@echo Running gofmt echo "golangci-lint is not installed. Please see https://github.com/golangci/golangci-lint#install for installation instructions."; \
@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; \ exit 1; \
fi; \ fi; \
fi; \
done
@echo Gofmt success
endif
## Runs govet against all packages. @echo Running golangci-lint
.PHONY: govet golangci-lint run ./...
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
## Builds the server, if it exists, including support for multiple architectures. ## Builds the server, if it exists, including support for multiple architectures.
.PHONY: server .PHONY: server
@ -104,6 +75,7 @@ ifneq ($(HAS_WEBAPP),)
endif endif
## Builds the webapp in debug mode, if it exists. ## Builds the webapp in debug mode, if it exists.
.PHONY: webapp-debug
webapp-debug: webapp/.npminstall webapp-debug: webapp/.npminstall
ifneq ($(HAS_WEBAPP),) ifneq ($(HAS_WEBAPP),)
cd webapp && \ cd webapp && \

View file

@ -85,13 +85,13 @@ func uploadPlugin(client *model.Client4, pluginID, bundlePath string) error {
log.Print("Uploading plugin via API.") log.Print("Uploading plugin via API.")
_, resp := client.UploadPluginForced(pluginBundle) _, resp := client.UploadPluginForced(pluginBundle)
if resp.Error != nil { 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.") log.Print("Enabling plugin.")
_, resp = client.EnablePlugin(pluginID) _, resp = client.EnablePlugin(pluginID)
if resp.Error != nil { 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 return nil

View file

@ -19,6 +19,7 @@ func TestServeHTTP(t *testing.T) {
result := w.Result() result := w.Result()
assert.NotNil(result) assert.NotNil(result)
defer result.Body.Close()
bodyBytes, err := ioutil.ReadAll(result.Body) bodyBytes, err := ioutil.ReadAll(result.Body)
assert.Nil(err) assert.Nil(err)
bodyString := string(bodyBytes) bodyString := string(bodyBytes)