mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-05-12 22:10:25 +00:00
chore: add modernizer linter (#11936)
- Go has a suite of small linters that helps with modernizing Go code by using newer functions and catching small mistakes, https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/modernize. - Enable this linter in golangci-lint. - There's also [`go fix`](https://go.dev/blog/gofix), which is not yet released as a linter in golangci-lint: https://github.com/golangci/golangci-lint/pull/6385 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/11936 Reviewed-by: Mathieu Fenniak <mfenniak@noreply.codeberg.org> Co-authored-by: Gusted <postmaster@gusted.xyz> Co-committed-by: Gusted <postmaster@gusted.xyz>
This commit is contained in:
parent
d728fddec5
commit
77dbc35138
249 changed files with 659 additions and 1010 deletions
|
|
@ -266,17 +266,17 @@ func addEmailBindingRules() {
|
|||
}
|
||||
|
||||
func portOnly(hostport string) string {
|
||||
colon := strings.IndexByte(hostport, ':')
|
||||
if colon == -1 {
|
||||
_, after, ok := strings.Cut(hostport, ":")
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
if i := strings.Index(hostport, "]:"); i != -1 {
|
||||
return hostport[i+len("]:"):]
|
||||
if _, after, ok := strings.Cut(hostport, "]:"); ok {
|
||||
return after
|
||||
}
|
||||
if strings.Contains(hostport, "]") {
|
||||
return ""
|
||||
}
|
||||
return hostport[colon+len(":"):]
|
||||
return after
|
||||
}
|
||||
|
||||
func validPort(p string) bool {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"net"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"forgejo.org/modules/setting"
|
||||
|
|
@ -40,12 +41,7 @@ func IsValidSiteURL(uri string) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
for _, scheme := range setting.Service.ValidSiteURLSchemes {
|
||||
if scheme == u.Scheme {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return slices.Contains(setting.Service.ValidSiteURLSchemes, u.Scheme)
|
||||
}
|
||||
|
||||
// IsAPIURL checks if URL is current Gitea instance API URL
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ package validation
|
|||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"slices"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
|
|
@ -87,10 +88,8 @@ func ValidateMaxLen(value string, maxLen int, name string) []string {
|
|||
}
|
||||
|
||||
func ValidateOneOf(value any, allowed []any, name string) []string {
|
||||
for _, allowedElem := range allowed {
|
||||
if value == allowedElem {
|
||||
return []string{}
|
||||
}
|
||||
if slices.Contains(allowed, value) {
|
||||
return []string{}
|
||||
}
|
||||
return []string{fmt.Sprintf("Field %s contains the value %v, which is not in allowed subset %v", name, value, allowed)}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue