Skip to content

Commit

Permalink
fix: add quotes to identifier with hyphen
Browse files Browse the repository at this point in the history
Signed-off-by: jakezhu9 <[email protected]>
  • Loading branch information
jakezhu9 committed Nov 25, 2023
1 parent 17b297a commit 4f320df
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/tools/gen/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ func formatName(name string) string {
if _, ok := kclKeywords[name]; ok {
return fmt.Sprintf("$%s", name)
}
if strings.Contains(name, "-") {
return fmt.Sprintf(`"%s"`, name)
}
return name
}

Expand Down
10 changes: 10 additions & 0 deletions pkg/tools/gen/testdata/yaml/identifier/expect.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""
This file was generated by the KCL auto-gen tool. DO NOT EDIT.
Editing this file might prove futile when you re-run the KCL auto-gen generate command.
"""

identifier = {
"a-b" = "identifier with hyphen"
a_b = "identifier with underscore"
$if = "identifier with keyword"
}
4 changes: 4 additions & 0 deletions pkg/tools/gen/testdata/yaml/identifier/input.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
identifier:
a-b: "identifier with hyphen"
a_b: "identifier with underscore"
if: "identifier with keyword"

0 comments on commit 4f320df

Please sign in to comment.