prysm-pulse/tools/nogo_config/main.go
Preston Van Loon f537a98fcd
Add staticchecks to bazel builds (#13298)
* Update staticcheck to latest

* Add static checks while ignoring for third party / external stuff

* Added a hack to keep go mod happy.

* disable SA2002

* Pin go mod tidy checker image to golang:1.20-alpine
2023-12-08 05:42:55 +00:00

95 lines
1.8 KiB
Go

package main
import (
"encoding/json"
"flag"
"fmt"
"io"
"os"
"strings"
)
const exclusionMessage = "Excluded by @prysm//tools/nogo_config tool"
var (
defaultExclusions = []string{
"external/.*",
}
)
var (
input = flag.String("input", "", "(required) input file")
output = flag.String("output", "", "(required) output file")
checks = flag.String("checks", "", "(required) comma separated list of checks to exclude")
exclusions = flag.String("exclude_files", strings.Join(defaultExclusions, ","), "exclusions file")
silent = flag.Bool("silent", false, "disable logging")
)
func main() {
flag.Parse()
if *input == "" || *output == "" {
fmt.Println("Error: input and output must be specified. Review the help text.")
flag.Usage()
return
}
if *checks == "" {
fmt.Println("Error: checks must be specified. Review the help text.")
flag.Usage()
return
}
e := defaultExclusions
if *exclusions != "" {
e = strings.Split(*exclusions, ",")
}
f, err := os.Open(*input)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
defer func() {
err := f.Close()
if err != nil {
panic(err)
}
}()
data, err := io.ReadAll(f)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
var c Configs
if err := json.Unmarshal(data, &c); err != nil {
fmt.Printf("Error: %v\n", err)
return
}
for _, check := range strings.Split(*checks, ",") {
c.AddExclusion(strings.TrimSpace(check), e)
}
out, err := os.Create(*output)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
defer func() {
err := out.Close()
if err != nil {
panic(err)
}
}()
if err := json.NewEncoder(out).Encode(c); err != nil {
fmt.Printf("Error: %v\n", err)
return
}
if !*silent {
fmt.Printf("Wrote %v\n", *output)
}
}