Debian Codegraph @

website/cmd/generate_config/generate_config.go

raw
1 package main
2
3 import (
4 "bytes"
5 "fmt"
6 "regexp"
7 "sort"
8
9 "github.com/BurntSushi/toml"
10 "honnef.co/go/tools/analysis/lint"
11 "honnef.co/go/tools/config"
12 "honnef.co/go/tools/quickfix"
13 "honnef.co/go/tools/simple"
14 "honnef.co/go/tools/staticcheck"
15 "honnef.co/go/tools/stylecheck"
16 "honnef.co/go/tools/unused"
17 )
18
19 func main() {
20 cfg := config.DefaultConfig
21
22 checks := []string{"all"}
23 do := func(analyzers ...*lint.Analyzer) {
24 for _, a := range analyzers {
25 if a.Doc.NonDefault {
26 // Use backticks to quote the check name so TOML doesn't escape them
27 checks = append(checks, fmt.Sprintf("-{{< check `%s` >}}", a.Analyzer.Name))
28 }
29 }
30 }
31 do(simple.Analyzers...)
32 do(staticcheck.Analyzers...)
33 do(stylecheck.Analyzers...)
34 do(unused.Analyzer)
35 do(quickfix.Analyzers...)
36
37 sort.Slice(checks[1:], func(i, j int) bool {
38 return checks[i+1] < checks[j+1]
39 })
40
41 cfg.Checks = checks
42
43 buf := bytes.Buffer{}
44 toml.NewEncoder(&buf).Encode(cfg)
45
46 r := regexp.MustCompile(`(?m)^[a-z_]+`)
47 out := r.ReplaceAllString(buf.String(), "{{< option `$0` >}}")
48
49 fmt.Println("---")
50 fmt.Println("headless: true")
51 fmt.Println("---")
52 fmt.Println("```toml")
53 fmt.Print(out)
54 fmt.Println("```")
55 }