2026-01-11 09:40:49 +01:00
|
|
|
// Copyright 2026 The Forgejo Authors. All rights reserved.
|
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
|
|
package lintLocaleUsage
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"go/ast"
|
|
|
|
|
"go/token"
|
|
|
|
|
|
|
|
|
|
llu "forgejo.org/build/lint-locale-usage"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// special case: models/asymkey/*.go,
|
|
|
|
|
//
|
|
|
|
|
// handle &ObjectVerification{...}
|
|
|
|
|
func HandleCompositeErrorReason(handler llu.Handler, fset *token.FileSet, n *ast.CompositeLit) {
|
|
|
|
|
ident, ok := n.Type.(*ast.Ident)
|
|
|
|
|
if !ok || ident.Name != "ObjectVerification" {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// fields are normally named
|
2026-04-14 06:27:39 +02:00
|
|
|
var reason ast.Expr
|
|
|
|
|
verified := false
|
2026-01-11 09:40:49 +01:00
|
|
|
for _, i := range n.Elts {
|
|
|
|
|
if kve, ok := i.(*ast.KeyValueExpr); ok {
|
|
|
|
|
ident, ok = kve.Key.(*ast.Ident)
|
2026-04-14 06:27:39 +02:00
|
|
|
if !ok {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
switch ident.Name {
|
|
|
|
|
case "Reason":
|
|
|
|
|
reason = kve.Value
|
|
|
|
|
case "Verified":
|
|
|
|
|
if valueIdent, ok := kve.Value.(*ast.Ident); ok {
|
|
|
|
|
switch valueIdent.Name {
|
|
|
|
|
case "true":
|
|
|
|
|
verified = true
|
|
|
|
|
case "false":
|
|
|
|
|
verified = false
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-01-11 09:40:49 +01:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
handler.OnWarning(fset, i.Pos(), "unable to parse ObjectVerification field assignment")
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-04-14 06:27:39 +02:00
|
|
|
if !verified && reason != nil {
|
|
|
|
|
handler.HandleGoTrArgument(fset, reason, "")
|
|
|
|
|
}
|
2026-01-11 09:40:49 +01:00
|
|
|
}
|