1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-08-13 23:46:23 -07:00

Fix anti-patterns pointed out by DeepSource

But not the switch fallthroughs/expression lists, there's no benefit
This commit is contained in:
Eggbertx 2020-07-09 15:54:31 -07:00
parent 497a3925e0
commit 55317504a1
17 changed files with 53 additions and 67 deletions

View file

@ -60,10 +60,8 @@ var funcMap = template.FuncMap{
// String functions
// "arrToString": arrToString,
"intToString": strconv.Itoa,
"escapeString": func(a string) string {
return html.EscapeString(a)
},
"intToString": strconv.Itoa,
"escapeString": html.EscapeString,
"formatFilesize": func(sizeInt int) string {
size := float32(sizeInt)
if size < 1000 {
@ -87,7 +85,7 @@ var funcMap = template.FuncMap{
},
"truncateMessage": func(msg string, limit int, maxLines int) string {
var truncated bool
split := strings.SplitN(msg, "<br />", -1)
split := strings.Split(msg, "<br />")
if len(split) > maxLines {
split = split[:maxLines]

View file

@ -10,7 +10,7 @@ import (
)
//TruncateHTML truncates a template.HTML string to a certain visible character limit and line limit
func truncateHTML(htmlText template.HTML, characterLimit int, maxLines int) template.HTML {
func truncateHTML(htmlText template.HTML, characterLimit, maxLines int) template.HTML {
dom, err := x_html.Parse(strings.NewReader(string(htmlText)))
if err != nil {
gclog.Println(gclog.LErrorLog, err.Error())
@ -30,9 +30,8 @@ func removeNextSiblings(node *x_html.Node) {
node.Parent.RemoveChild(node)
}
func truncateHTMLNodes(node *x_html.Node, charactersLeft int, linesLeft int) (charsLeft int, lineLeft int) {
func truncateHTMLNodes(node *x_html.Node, charactersLeft, linesLeft int) (charsLeft, lineLeft int) {
//Uses a depth first search to map nodes and remove the rest.
if node == nil {
return charactersLeft, linesLeft
}