Skip to content

Commit

Permalink
fix(generate): clean up go package name
Browse files Browse the repository at this point in the history
This fixes issue where code generation on dbc files with name containing
dashes, underscores, and dots fails due to incorrectly generated package name.
  • Loading branch information
Hashem Hashem authored and hashemmm96 committed Dec 8, 2022
1 parent 83c88b0 commit 555e544
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/generate/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ func Database(d *descriptor.Database) ([]byte, error) {

func Package(f *File, d *descriptor.Database) {
packageName := strings.TrimSuffix(path.Base(d.SourceFile), path.Ext(d.SourceFile)) + "can"
// Remove illegal characters from package name
packageName = strings.ReplaceAll(packageName, ".", "")
packageName = strings.ReplaceAll(packageName, "-", "")
packageName = strings.ReplaceAll(packageName, "_", "")
f.P("// Package ", packageName, " provides primitives for encoding and decoding ", d.Name(), " CAN messages.")
f.P("//")
f.P("// Source: ", d.SourceFile)
Expand Down

0 comments on commit 555e544

Please sign in to comment.