mirror of
https://github.com/go-gitea/gitea
synced 2025-07-23 18:58:38 +00:00
Enable addtional linters (#34085)
enable mirror, usestdlibbars and perfsprint part of: https://github.com/go-gitea/gitea/issues/34083 --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"html"
|
||||
"html/template"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -73,7 +74,7 @@ func NewFuncMap() template.FuncMap {
|
||||
"TimeEstimateString": timeEstimateString,
|
||||
|
||||
"LoadTimes": func(startTime time.Time) string {
|
||||
return fmt.Sprint(time.Since(startTime).Nanoseconds()/1e6) + "ms"
|
||||
return strconv.FormatInt(time.Since(startTime).Nanoseconds()/1e6, 10) + "ms"
|
||||
},
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
|
@@ -15,7 +15,7 @@ import (
|
||||
|
||||
func TestSubjectBodySeparator(t *testing.T) {
|
||||
test := func(input, subject, body string) {
|
||||
loc := mailSubjectSplit.FindIndex([]byte(input))
|
||||
loc := mailSubjectSplit.FindStringIndex(input)
|
||||
if loc == nil {
|
||||
assert.Empty(t, subject, "no subject found, but one expected")
|
||||
assert.Equal(t, body, input)
|
||||
|
@@ -5,9 +5,9 @@ package templates
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"html"
|
||||
"html/template"
|
||||
"strconv"
|
||||
|
||||
activities_model "code.gitea.io/gitea/models/activities"
|
||||
"code.gitea.io/gitea/models/avatars"
|
||||
@@ -28,7 +28,7 @@ func NewAvatarUtils(ctx context.Context) *AvatarUtils {
|
||||
|
||||
// AvatarHTML creates the HTML for an avatar
|
||||
func AvatarHTML(src string, size int, class, name string) template.HTML {
|
||||
sizeStr := fmt.Sprintf(`%d`, size)
|
||||
sizeStr := strconv.Itoa(size)
|
||||
|
||||
if name == "" {
|
||||
name = "avatar"
|
||||
|
@@ -99,7 +99,7 @@ func dateTimeFormat(format string, datetime any) template.HTML {
|
||||
attrs = append(attrs, `format="datetime"`, `month="short"`, `day="numeric"`, `hour="numeric"`, `minute="numeric"`, `second="numeric"`, `data-tooltip-content`, `data-tooltip-interactive="true"`)
|
||||
return template.HTML(fmt.Sprintf(`<relative-time %s datetime="%s">%s</relative-time>`, strings.Join(attrs, " "), datetimeEscaped, textEscaped))
|
||||
default:
|
||||
panic(fmt.Sprintf("Unsupported format %s", format))
|
||||
panic("Unsupported format " + format)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -4,6 +4,7 @@
|
||||
package templates
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"html"
|
||||
"html/template"
|
||||
@@ -33,7 +34,7 @@ func dictMerge(base map[string]any, arg any) bool {
|
||||
// The dot syntax is highly discouraged because it might cause unclear key conflicts. It's always good to use explicit keys.
|
||||
func dict(args ...any) (map[string]any, error) {
|
||||
if len(args)%2 != 0 {
|
||||
return nil, fmt.Errorf("invalid dict constructor syntax: must have key-value pairs")
|
||||
return nil, errors.New("invalid dict constructor syntax: must have key-value pairs")
|
||||
}
|
||||
m := make(map[string]any, len(args)/2)
|
||||
for i := 0; i < len(args); i += 2 {
|
||||
|
@@ -5,6 +5,7 @@ package templates
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
)
|
||||
@@ -24,7 +25,7 @@ func countFmt(data any) string {
|
||||
return ""
|
||||
}
|
||||
if num < 1000 {
|
||||
return fmt.Sprintf("%d", num)
|
||||
return strconv.FormatInt(num, 10)
|
||||
} else if num < 1_000_000 {
|
||||
num2 := float32(num) / 1000.0
|
||||
return fmt.Sprintf("%.1fk", num2)
|
||||
|
@@ -16,7 +16,7 @@ type ErrWrongSyntax struct {
|
||||
}
|
||||
|
||||
func (err ErrWrongSyntax) Error() string {
|
||||
return fmt.Sprintf("wrong syntax found in %s", err.Template)
|
||||
return "wrong syntax found in " + err.Template
|
||||
}
|
||||
|
||||
// ErrVarMissing represents an error that no matched variable
|
||||
|
Reference in New Issue
Block a user