Expanded linting + fix warnings (#1396)

* Expand the linters and types of warnings to improve consistency and safety

* Fail lint workflow if there are errors

* golint has been replaced by revive

* Hand-pick some of the default exclude list

* Ignore error when trying to delete preview gif

* Ignore linter warning opening playlist path

* Rename user field Id -> ID

* A bunch of renames to address linter warnings

* Rename ChatClient -> Client per linter suggestion best practice

* Rename ChatServer -> Server per linter suggestion best practice

* More linter warning fixes

* Add missing comments to all exported functions and properties
This commit is contained in:
Gabe Kangas
2021-09-12 00:18:15 -07:00
committed by GitHub
parent 70e9f4945f
commit c6c6f0233d
57 changed files with 331 additions and 186 deletions

View File

@@ -20,6 +20,7 @@ import (
// EventPayload is a generic key/value map for sending out to chat clients.
type EventPayload map[string]interface{}
// OutboundEvent represents an event that is sent out to all listeners of the chat server.
type OutboundEvent interface {
GetBroadcastPayload() EventPayload
GetMessageType() EventType
@@ -28,10 +29,11 @@ type OutboundEvent interface {
// Event is any kind of event. A type is required to be specified.
type Event struct {
Type EventType `json:"type,omitempty"`
Id string `json:"id"`
ID string `json:"id"`
Timestamp time.Time `json:"timestamp"`
}
// UserEvent is an event with an associated user.
type UserEvent struct {
User *user.User `json:"user"`
HiddenAt *time.Time `json:"hiddenAt,omitempty"`
@@ -44,6 +46,7 @@ type MessageEvent struct {
RawBody string `json:"-"`
}
// SystemActionEvent is an event that represents an action that took place, not a chat message.
type SystemActionEvent struct {
Event
MessageEvent
@@ -51,13 +54,13 @@ type SystemActionEvent struct {
// SetDefaults will set default properties of all inbound events.
func (e *Event) SetDefaults() {
e.Id = shortid.MustGenerate()
e.ID = shortid.MustGenerate()
e.Timestamp = time.Now()
}
// SetDefaults will set default properties of all inbound events.
func (e *UserMessageEvent) SetDefaults() {
e.Id = shortid.MustGenerate()
e.ID = shortid.MustGenerate()
e.Timestamp = time.Now()
e.RenderAndSanitizeMessageBody()
}
@@ -92,6 +95,7 @@ func RenderAndSanitize(raw string) string {
return strings.TrimSpace(safe)
}
// RenderMarkdown will return HTML rendered from the string body of a chat message.
func RenderMarkdown(raw string) string {
markdown := goldmark.New(
goldmark.WithRendererOptions(