Skip to content

Commit

Permalink
CamelCase value descriptor lint error marker the description
Browse files Browse the repository at this point in the history
It was pointing to the value instead
  • Loading branch information
alethenorio committed Jul 10, 2020
1 parent d5c93bd commit 7c556f4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
9 changes: 8 additions & 1 deletion pkg/dbc/analysis/passes/valuedescriptions/analyzer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package valuedescriptions

import (
"fmt"

"go.einride.tech/can/internal/identifiers"
"go.einride.tech/can/pkg/dbc"
"go.einride.tech/can/pkg/dbc/analysis"
Expand Down Expand Up @@ -28,7 +30,12 @@ func run(pass *analysis.Pass) error {
for _, vd := range valueDescriptions {
vd := vd
if !identifiers.IsCamelCase(vd.Description) {
pass.Reportf(vd.Pos, "value description must be CamelCase")
// Descriptor has format "<value> <quote><description>"
//
// So we increase the column position by the size of value + 2 (space and quotes) so the lint
// error marker is on the description and not on the value
vd.Pos.Column += len(fmt.Sprintf("%d", int64(vd.Value))) + 2
pass.Reportf(vd.Pos, "value description must be CamelCase (numbers ignored)")
}
}
}
Expand Down
19 changes: 16 additions & 3 deletions pkg/dbc/analysis/passes/valuedescriptions/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,27 @@ func TestAnalyzer(t *testing.T) {
Name: "ok",
Data: `VAL_ 100 Command 2 "Reboot" 1 "Sync" 0 "Noop";`,
},

{
Name: "ok",
Data: `VAL_ 100 Command 2 "11Reboot" 1 "123" 0 "Noop";`,
},
{
Name: "underscore",
Data: `VAL_ 100 Command 2 "Reboot_Command" 1 "Sync" 0 "Noop";`,
Diagnostics: []*analysis.Diagnostic{
{
Pos: scanner.Position{Line: 1, Column: 18},
Message: "value description must be CamelCase",
Pos: scanner.Position{Line: 1, Column: 21},
Message: "value description must be CamelCase (numbers ignored)",
},
},
},
{
Name: "several digits value",
Data: `VAL_ 100 Command 234 "Reboot_Command" 1 "Sync" 0 "Noop";`,
Diagnostics: []*analysis.Diagnostic{
{
Pos: scanner.Position{Line: 1, Column: 23},
Message: "value description must be CamelCase (numbers ignored)",
},
},
},
Expand Down

0 comments on commit 7c556f4

Please sign in to comment.