MCPcopy
hub / github.com/rs/zerolog / main

Function main

cmd/lint/lint.go:42–79  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

40}
41
42func main() {
43 // load the package and all its dependencies
44 conf := loader.Config{}
45 conf.Import(rootPkg)
46 p, err := conf.Load()
47 if err != nil {
48 fmt.Fprintf(os.Stderr, "Error: unable to load the root package. %s\n", err.Error())
49 os.Exit(1)
50 }
51
52 // get the github.com/rs/zerolog.Event type
53 event := getEvent(p)
54 if event == nil {
55 fmt.Fprintln(os.Stderr, "Error: github.com/rs/zerolog.Event declaration not found, maybe zerolog is not imported in the scanned package?")
56 os.Exit(1)
57 }
58
59 // get all selections (function calls) with the github.com/rs/zerolog.Event (or pointer) receiver
60 selections := getSelectionsWithReceiverType(p, event)
61
62 // print the violations (if any)
63 hasViolations := false
64 for _, s := range selections {
65 if hasBadFinisher(p, s) {
66 hasViolations = true
67 fmt.Printf("Error: missing or bad finisher for log chain, last call: %q at: %s:%v\n", s.fn.Name(), p.Fset.File(s.Pos()).Name(), p.Fset.Position(s.Pos()).Line)
68 }
69 }
70
71 // if no violations detected, return normally
72 if !hasViolations {
73 fmt.Println("No violations found")
74 return
75 }
76
77 // if violations were detected, return error code
78 os.Exit(1)
79}
80
81func getEvent(p *loader.Program) types.Type {
82 for _, pkg := range p.AllPackages {

Callers

nothing calls this directly

Calls 6

getEventFunction · 0.85
hasBadFinisherFunction · 0.85
PrintfMethod · 0.80
PrintlnMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected