github.com/blueinnovationsgroup/can-go@v0.0.0-20230518195432-d0567cda0028/pkg/dbc/analysis/passes/uniquenodenames/analyzer.go (about) 1 package uniquenodenames 2 3 import ( 4 "github.com/blueinnovationsgroup/can-go/pkg/dbc" 5 "github.com/blueinnovationsgroup/can-go/pkg/dbc/analysis" 6 ) 7 8 func Analyzer() *analysis.Analyzer { 9 return &analysis.Analyzer{ 10 Name: "uniquenodenames", 11 Doc: "check that all declared node names are unique", 12 Run: run, 13 } 14 } 15 16 func run(pass *analysis.Pass) error { 17 nodeNames := make(map[dbc.Identifier]struct{}) 18 for _, def := range pass.File.Defs { 19 if def, ok := def.(*dbc.NodesDef); ok { 20 for _, nodeName := range def.NodeNames { 21 if _, ok := nodeNames[nodeName]; ok { 22 pass.Reportf(def.Pos, "non-unique node name") 23 } 24 nodeNames[nodeName] = struct{}{} 25 } 26 } 27 } 28 return nil 29 }