github.com/blueinnovationsgroup/can-go@v0.0.0-20230518195432-d0567cda0028/pkg/dbc/analysis/passes/signalnames/analyzer.go (about)

     1  package signalnames
     2  
     3  import (
     4  	"github.com/blueinnovationsgroup/can-go/internal/identifiers"
     5  	"github.com/blueinnovationsgroup/can-go/pkg/dbc"
     6  	"github.com/blueinnovationsgroup/can-go/pkg/dbc/analysis"
     7  )
     8  
     9  func Analyzer() *analysis.Analyzer {
    10  	return &analysis.Analyzer{
    11  		Name: "signalnames",
    12  		Doc:  "check that signal names are valid CamelCase identifiers",
    13  		Run:  run,
    14  	}
    15  }
    16  
    17  func run(pass *analysis.Pass) error {
    18  	for _, d := range pass.File.Defs {
    19  		messageDef, ok := d.(*dbc.MessageDef)
    20  		if !ok {
    21  			continue
    22  		}
    23  		for _, signalDef := range messageDef.Signals {
    24  			if !identifiers.IsCamelCase(string(signalDef.Name)) {
    25  				pass.Reportf(signalDef.Pos, "signal names must be CamelCase")
    26  			}
    27  		}
    28  	}
    29  	return nil
    30  }