fix linter errors in plugin (#696)

This commit is contained in:
Doug Lauder 2021-07-09 06:59:44 -04:00 committed by GitHub
parent 74cf28fee5
commit 0dec704ddc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 59 additions and 45 deletions

View file

@ -12,33 +12,57 @@ linters-settings:
govet:
check-shadowing: true
enable-all: true
disable:
- fieldalignment
misspell:
locale: US
lll:
line-length: 150
linters:
disable-all: true
enable:
- bodyclose
- deadcode
- errcheck
- gocritic
- gofmt
- goimports
- golint
- gosec
- gosimple
- govet
- deadcode
- ineffassign
- misspell
- nakedret
- staticcheck
- structcheck
- varcheck
- unparam
- errcheck
- govet
- bodyclose
- durationcheck
- errorlint
- exhaustive
- exportloopref
- gosec
- makezero
- staticcheck
- prealloc
- asciicheck
- depguard
- dogsled
- dupl
- goconst
- gocritic
- godot
- goerr113
- goheader
- golint
- nakedret
- gomodguard
- goprintffuncname
- gosimple
- lll
- misspell
- nolintlint
- stylecheck
- typecheck
- unconvert
- unused
- varcheck
- whitespace
- gocyclo
issues:
exclude-rules:

View file

@ -40,12 +40,16 @@ type WSHub struct {
}
func (h *WSHub) SendWSMessage(data []byte) {
h.API.PublishPluginClusterEvent(model.PluginClusterEvent{
err := h.API.PublishPluginClusterEvent(model.PluginClusterEvent{
Id: "websocket_event",
Data: data,
}, model.PluginClusterEventSendOptions{
SendType: model.PluginClusterEventSendTypeReliable,
})
if err != nil {
h.API.LogError("Error sending websocket message", map[string]interface{}{"err": err})
}
}
func (h *WSHub) SetReceiveWSMessage(handler func(data []byte)) {
@ -96,7 +100,7 @@ func (p *Plugin) OnActivate() error {
client := pluginapi.NewClient(p.API, p.Driver)
sqlDB, err := client.Store.GetMasterDB()
if err != nil {
return fmt.Errorf("error initializing the DB: %v", err)
return fmt.Errorf("error initializing the DB: %w", err)
}
baseURL := ""
@ -128,12 +132,12 @@ func (p *Plugin) OnActivate() error {
var db store.Store
db, err = sqlstore.New(cfg.DBType, cfg.DBConfigString, cfg.DBTablePrefix, logger, sqlDB)
if err != nil {
return fmt.Errorf("error initializing the DB: %v", err)
return fmt.Errorf("error initializing the DB: %w", err)
}
if cfg.AuthMode == server.MattermostAuthMod {
layeredStore, err2 := mattermostauthlayer.New(cfg.DBType, sqlDB, db, logger)
if err2 != nil {
return fmt.Errorf("error initializing the DB: %v", err2)
return fmt.Errorf("error initializing the DB: %w", err2)
}
db = layeredStore
}
@ -150,7 +154,7 @@ func (p *Plugin) OnActivate() error {
return server.Start()
}
func (p *Plugin) OnPluginClusterEvent(c *plugin.Context, ev model.PluginClusterEvent) {
func (p *Plugin) OnPluginClusterEvent(_ *plugin.Context, ev model.PluginClusterEvent) {
if ev.Id == "websocket_event" {
p.wsHub.handleWSMessage(ev.Data)
}
@ -161,7 +165,7 @@ func (p *Plugin) OnDeactivate() error {
}
// ServeHTTP demonstrates a plugin that handles HTTP requests by greeting the world.
func (p *Plugin) ServeHTTP(c *plugin.Context, w http.ResponseWriter, r *http.Request) {
func (p *Plugin) ServeHTTP(_ *plugin.Context, w http.ResponseWriter, r *http.Request) {
router := p.server.GetRootRouter()
router.ServeHTTP(w, r)
}

View file

@ -2,7 +2,7 @@ run:
timeout: 5m
modules-download-mode: readonly
skip-dirs:
- services/store/sqlstore/migrations/
- services/store/sqlstore/migrations
linters-settings:
gofmt:
@ -14,9 +14,6 @@ linters-settings:
- fieldalignment
lll:
line-length: 150
gomnd:
ignored-numbers: 10
linters:
disable-all: true
@ -49,7 +46,7 @@ linters:
- goerr113
- goheader
- golint
# - gomnd
- nakedret
- gomodguard
- goprintffuncname
- gosimple
@ -57,6 +54,8 @@ linters:
- misspell
- nolintlint
- stylecheck
- typecheck
- unconvert
- unused
- whitespace
- gocyclo

View file

@ -1,7 +1,6 @@
package client
import (
"bytes"
"encoding/json"
"fmt"
"io"
@ -88,18 +87,10 @@ func (c *Client) DoAPIPost(url, data string) (*http.Response, error) {
return c.DoAPIRequest(http.MethodPost, c.APIURL+url, data, "")
}
func (c *Client) doAPIPostBytes(url string, data []byte) (*http.Response, error) {
return c.doAPIRequestBytes(http.MethodPost, c.APIURL+url, data, "")
}
func (c *Client) DoAPIPut(url, data string) (*http.Response, error) {
return c.DoAPIRequest(http.MethodPut, c.APIURL+url, data, "")
}
func (c *Client) doAPIPutBytes(url string, data []byte) (*http.Response, error) {
return c.doAPIRequestBytes(http.MethodPut, c.APIURL+url, data, "")
}
func (c *Client) DoAPIDelete(url string) (*http.Response, error) {
return c.DoAPIRequest(http.MethodDelete, c.APIURL+url, "", "")
}
@ -108,10 +99,6 @@ func (c *Client) DoAPIRequest(method, url, data, etag string) (*http.Response, e
return c.doAPIRequestReader(method, url, strings.NewReader(data), etag)
}
func (c *Client) doAPIRequestBytes(method, url string, data []byte, etag string) (*http.Response, error) {
return c.doAPIRequestReader(method, url, bytes.NewReader(data), etag)
}
func (c *Client) doAPIRequestReader(method, url string, data io.Reader, _ /* etag */ string) (*http.Response, error) {
rq, err := http.NewRequest(method, url, data)
if err != nil {

View file

@ -403,15 +403,15 @@ func (s *SQLStore) InsertBlock(c store.Container, block *model.Block, userID str
Set("update_at", block.UpdateAt).
Set("delete_at", block.DeleteAt)
q, args, err := query.ToSql()
if err != nil {
s.logger.Error("InsertBlock error converting update query object to SQL", mlog.Err(err))
return err
q, args, err2 := query.ToSql()
if err2 != nil {
s.logger.Error("InsertBlock error converting update query object to SQL", mlog.Err(err2))
return err2
}
if _, err := tx.Exec(q, args...); err != nil {
s.logger.Error(`InsertBlock error occurred while updating existing block`, mlog.String("blockID", block.ID), mlog.Err(err))
return err
if _, err2 := tx.Exec(q, args...); err2 != nil {
s.logger.Error(`InsertBlock error occurred while updating existing block`, mlog.String("blockID", block.ID), mlog.Err(err2))
return err2
}
} else {
block.CreatedBy = userID

View file

@ -60,8 +60,8 @@ func StoreTestBlocksStore(t *testing.T, setup func(t *testing.T) (store.Store, f
func testInsertBlock(t *testing.T, store store.Store, container store.Container) {
userID := testUserID
blocks, err := store.GetAllBlocks(container)
require.NoError(t, err)
blocks, errBlocks := store.GetAllBlocks(container)
require.NoError(t, errBlocks)
initialCount := len(blocks)
t.Run("valid block", func(t *testing.T) {