forgejo/models/asymkey/lint-locale-usage/llu.go
Έλλεν Εμίλια Άννα Zscheile 4fd275116d feat: teach lint-locale-usage about ObjectVerification.Reason (#10755)
Add special parsing to handle the keys found in the `Reason` field of `ObjectVerification` structs.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10755
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: Έλλεν Εμίλια Άννα Zscheile <fogti+devel@ytrizja.de>
Co-committed-by: Έλλεν Εμίλια Άννα Zscheile <fogti+devel@ytrizja.de>
2026-01-11 09:40:49 +01:00

33 lines
807 B
Go

// 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
for _, i := range n.Elts {
if kve, ok := i.(*ast.KeyValueExpr); ok {
ident, ok = kve.Key.(*ast.Ident)
if ok && ident.Name == "Reason" {
handler.HandleGoTrArgument(fset, kve.Value, "")
}
} else {
handler.OnWarning(fset, i.Pos(), "unable to parse ObjectVerification field assignment")
}
}
}