()
| 40 | } |
| 41 | |
| 42 | func 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 | |
| 81 | func getEvent(p *loader.Program) types.Type { |
| 82 | for _, pkg := range p.AllPackages { |
nothing calls this directly
no test coverage detected