mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-04-26 06:04:46 +00:00
feat(build): lint-locale-usage ability to return exit code 4 on missing msgids
This commit is contained in:
parent
1296b7fdc0
commit
c368ff5ae4
2 changed files with 29 additions and 1 deletions
2
Makefile
2
Makefile
|
@ -462,7 +462,7 @@ lint-locale:
|
||||||
|
|
||||||
.PHONY: lint-locale-usage
|
.PHONY: lint-locale-usage
|
||||||
lint-locale-usage:
|
lint-locale-usage:
|
||||||
$(GO) run build/lint-locale-usage.go
|
$(GO) run build/lint-locale-usage.go --allow-missing-msgids
|
||||||
|
|
||||||
.PHONY: lint-md
|
.PHONY: lint-md
|
||||||
lint-md: node_modules
|
lint-md: node_modules
|
||||||
|
|
|
@ -230,12 +230,33 @@ func (omh OnMsgidHandler) HandleTemplateFile(fname string, src any) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// This command assumes that we get started from the project root directory
|
// This command assumes that we get started from the project root directory
|
||||||
|
//
|
||||||
|
// Possible command line flags:
|
||||||
|
//
|
||||||
|
// --allow-missing-msgids don't return an error code if missing message IDs are found
|
||||||
|
//
|
||||||
|
// EXIT CODES:
|
||||||
|
//
|
||||||
|
// 0 success, no issues found
|
||||||
|
// 1 unable to walk directory tree
|
||||||
|
// 2 unable to parse locale ini/json files
|
||||||
|
// 3 unable to parse go or text/template files
|
||||||
|
// 4 found missing message IDs
|
||||||
func main() {
|
func main() {
|
||||||
|
allowMissingMsgids := false
|
||||||
|
for _, arg := range os.Args {
|
||||||
|
switch arg {
|
||||||
|
case "--allow-missing-msgids":
|
||||||
|
allowMissingMsgids = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onError := func(err error) {
|
onError := func(err error) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
|
os.Exit(3)
|
||||||
}
|
}
|
||||||
|
|
||||||
msgids := make(container.Set[string])
|
msgids := make(container.Set[string])
|
||||||
|
@ -268,8 +289,11 @@ func main() {
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gotAnyMsgidError := false
|
||||||
|
|
||||||
omh := OnMsgidHandler(func(fset *token.FileSet, pos token.Pos, msgid string) {
|
omh := OnMsgidHandler(func(fset *token.FileSet, pos token.Pos, msgid string) {
|
||||||
if !msgids.Contains(msgid) {
|
if !msgids.Contains(msgid) {
|
||||||
|
gotAnyMsgidError = true
|
||||||
fmt.Printf("%s:\tmissing msgid: %s\n", fset.Position(pos).String(), msgid)
|
fmt.Printf("%s:\tmissing msgid: %s\n", fset.Position(pos).String(), msgid)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -302,4 +326,8 @@ func main() {
|
||||||
fmt.Printf("walkdir ERROR: %s\n", err.Error())
|
fmt.Printf("walkdir ERROR: %s\n", err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !allowMissingMsgids && gotAnyMsgidError {
|
||||||
|
os.Exit(4)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue