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: govet:
check-shadowing: true check-shadowing: true
enable-all: true enable-all: true
disable:
- fieldalignment
misspell: misspell:
locale: US locale: US
lll:
line-length: 150
linters: linters:
disable-all: true disable-all: true
enable: enable:
- bodyclose
- deadcode
- errcheck
- gocritic
- gofmt - gofmt
- goimports - goimports
- golint - deadcode
- gosec
- gosimple
- govet
- ineffassign - ineffassign
- misspell
- nakedret
- staticcheck
- structcheck - 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 - stylecheck
- typecheck - typecheck
- unconvert - unconvert
- unused - unused
- varcheck
- whitespace - whitespace
- gocyclo
issues: issues:
exclude-rules: exclude-rules:

View file

@ -40,12 +40,16 @@ type WSHub struct {
} }
func (h *WSHub) SendWSMessage(data []byte) { func (h *WSHub) SendWSMessage(data []byte) {
h.API.PublishPluginClusterEvent(model.PluginClusterEvent{ err := h.API.PublishPluginClusterEvent(model.PluginClusterEvent{
Id: "websocket_event", Id: "websocket_event",
Data: data, Data: data,
}, model.PluginClusterEventSendOptions{ }, model.PluginClusterEventSendOptions{
SendType: model.PluginClusterEventSendTypeReliable, 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)) { func (h *WSHub) SetReceiveWSMessage(handler func(data []byte)) {
@ -96,7 +100,7 @@ func (p *Plugin) OnActivate() error {
client := pluginapi.NewClient(p.API, p.Driver) client := pluginapi.NewClient(p.API, p.Driver)
sqlDB, err := client.Store.GetMasterDB() sqlDB, err := client.Store.GetMasterDB()
if err != nil { if err != nil {
return fmt.Errorf("error initializing the DB: %v", err) return fmt.Errorf("error initializing the DB: %w", err)
} }
baseURL := "" baseURL := ""
@ -128,12 +132,12 @@ func (p *Plugin) OnActivate() error {
var db store.Store var db store.Store
db, err = sqlstore.New(cfg.DBType, cfg.DBConfigString, cfg.DBTablePrefix, logger, sqlDB) db, err = sqlstore.New(cfg.DBType, cfg.DBConfigString, cfg.DBTablePrefix, logger, sqlDB)
if err != nil { 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 { if cfg.AuthMode == server.MattermostAuthMod {
layeredStore, err2 := mattermostauthlayer.New(cfg.DBType, sqlDB, db, logger) layeredStore, err2 := mattermostauthlayer.New(cfg.DBType, sqlDB, db, logger)
if err2 != nil { if err2 != nil {
return fmt.Errorf("error initializing the DB: %v", err2) return fmt.Errorf("error initializing the DB: %w", err2)
} }
db = layeredStore db = layeredStore
} }
@ -150,7 +154,7 @@ func (p *Plugin) OnActivate() error {
return server.Start() 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" { if ev.Id == "websocket_event" {
p.wsHub.handleWSMessage(ev.Data) 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. // 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 := p.server.GetRootRouter()
router.ServeHTTP(w, r) router.ServeHTTP(w, r)
} }

View file

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

View file

@ -1,7 +1,6 @@
package client package client
import ( import (
"bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
@ -88,18 +87,10 @@ func (c *Client) DoAPIPost(url, data string) (*http.Response, error) {
return c.DoAPIRequest(http.MethodPost, c.APIURL+url, data, "") 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) { func (c *Client) DoAPIPut(url, data string) (*http.Response, error) {
return c.DoAPIRequest(http.MethodPut, c.APIURL+url, data, "") 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) { func (c *Client) DoAPIDelete(url string) (*http.Response, error) {
return c.DoAPIRequest(http.MethodDelete, c.APIURL+url, "", "") 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) 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) { func (c *Client) doAPIRequestReader(method, url string, data io.Reader, _ /* etag */ string) (*http.Response, error) {
rq, err := http.NewRequest(method, url, data) rq, err := http.NewRequest(method, url, data)
if err != nil { 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("update_at", block.UpdateAt).
Set("delete_at", block.DeleteAt) Set("delete_at", block.DeleteAt)
q, args, err := query.ToSql() q, args, err2 := query.ToSql()
if err != nil { if err2 != nil {
s.logger.Error("InsertBlock error converting update query object to SQL", mlog.Err(err)) s.logger.Error("InsertBlock error converting update query object to SQL", mlog.Err(err2))
return err return err2
} }
if _, err := tx.Exec(q, args...); err != nil { 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(err)) s.logger.Error(`InsertBlock error occurred while updating existing block`, mlog.String("blockID", block.ID), mlog.Err(err2))
return err return err2
} }
} else { } else {
block.CreatedBy = userID 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) { func testInsertBlock(t *testing.T, store store.Store, container store.Container) {
userID := testUserID userID := testUserID
blocks, err := store.GetAllBlocks(container) blocks, errBlocks := store.GetAllBlocks(container)
require.NoError(t, err) require.NoError(t, errBlocks)
initialCount := len(blocks) initialCount := len(blocks)
t.Run("valid block", func(t *testing.T) { t.Run("valid block", func(t *testing.T) {