From 4fd275116dbe300e492a65e710ee1e16d85b4ffe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=88=CE=BB=CE=BB=CE=B5=CE=BD=20=CE=95=CE=BC=CE=AF=CE=BB?= =?UTF-8?q?=CE=B9=CE=B1=20=CE=86=CE=BD=CE=BD=CE=B1=20Zscheile?= Date: Sun, 11 Jan 2026 09:40:49 +0100 Subject: [PATCH] feat: teach lint-locale-usage about ObjectVerification.Reason (#10755) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Co-authored-by: Έλλεν Εμίλια Άννα Zscheile Co-committed-by: Έλλεν Εμίλια Άννα Zscheile --- .../allowed-masked-usage.txt | 7 ---- build/lint-locale-usage/bin/handle-go.go | 3 ++ models/asymkey/lint-locale-usage/llu.go | 33 +++++++++++++++++++ 3 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 models/asymkey/lint-locale-usage/llu.go diff --git a/build/lint-locale-usage/allowed-masked-usage.txt b/build/lint-locale-usage/allowed-masked-usage.txt index cfab25a5fd..ca899c7d38 100644 --- a/build/lint-locale-usage/allowed-masked-usage.txt +++ b/build/lint-locale-usage/allowed-masked-usage.txt @@ -6,13 +6,6 @@ translation_meta.test # this also gets instantiated as a Messenger once repo.migrate.migrating_failed.error -# models/asymkey/gpg_key_object_verification.go: $ObjectVerification.Reason -# unfortunately, it is non-trivial to parse all the occurences -gpg.error.extract_sign -gpg.error.failed_retrieval_gpg_keys -gpg.error.generate_hash -gpg.error.no_committer_account - # models/system/notice.go: func (n *Notice) TrStr() string admin.notices.type_1 admin.notices.type_2 diff --git a/build/lint-locale-usage/bin/handle-go.go b/build/lint-locale-usage/bin/handle-go.go index b1757fa0fc..ffa6b13165 100644 --- a/build/lint-locale-usage/bin/handle-go.go +++ b/build/lint-locale-usage/bin/handle-go.go @@ -15,6 +15,7 @@ import ( "strings" llu "forgejo.org/build/lint-locale-usage" + lluAsymKey "forgejo.org/models/asymkey/lint-locale-usage" lluUnit "forgejo.org/models/unit/lint-locale-usage" lluMigrate "forgejo.org/services/migrations/lint-locale-usage" ) @@ -71,6 +72,8 @@ func HandleGoFile(handler llu.Handler, fname string, src any) error { case *ast.CompositeLit: if strings.HasSuffix(fname, "models/unit/unit.go") { lluUnit.HandleCompositeUnit(handler, fset, n2) + } else if strings.Contains(fname, "models/asymkey/") { + lluAsymKey.HandleCompositeErrorReason(handler, fset, n2) } case *ast.FuncDecl: diff --git a/models/asymkey/lint-locale-usage/llu.go b/models/asymkey/lint-locale-usage/llu.go new file mode 100644 index 0000000000..256b5ca12b --- /dev/null +++ b/models/asymkey/lint-locale-usage/llu.go @@ -0,0 +1,33 @@ +// 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") + } + } +}