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

     1  package noreservedsignals
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/blueinnovationsgroup/can-go/pkg/dbc"
     7  	"github.com/blueinnovationsgroup/can-go/pkg/dbc/analysis"
     8  )
     9  
    10  func Analyzer() *analysis.Analyzer {
    11  	return &analysis.Analyzer{
    12  		Name: "noreservedsignals",
    13  		Doc:  `checks that no signals have the prefix "Reserved"`,
    14  		Run:  run,
    15  	}
    16  }
    17  
    18  func run(pass *analysis.Pass) error {
    19  	for _, d := range pass.File.Defs {
    20  		messageDef, ok := d.(*dbc.MessageDef)
    21  		if !ok {
    22  			continue
    23  		}
    24  		for _, signalDef := range messageDef.Signals {
    25  			if strings.HasPrefix(string(signalDef.Name), "Reserved") {
    26  				pass.Reportf(signalDef.Pos, "remove reserved signals")
    27  			}
    28  		}
    29  	}
    30  	return nil
    31  }