Skip to content

Commit

Permalink
parser: further trim extra spaces and quotes for alias
Browse files Browse the repository at this point in the history
  • Loading branch information
wineguo authored and WineChord committed Jan 15, 2024
1 parent 962306a commit 9873342
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions parser/fill.go
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ func isCommentDiff(leadingComment string, leadingErr error, trailingComment stri
return (leadingErr == nil && trailingErr == nil) && (leadingComment != trailingComment)
}

func parseAlias(comment string) (string, error) {
func parseAlias(comment string) (alias string, err error) {
const marker = "@alias="
if !strings.Contains(comment, marker) {
return "", fmt.Errorf("annotation alias %s not found in raw comment %s", marker, comment)
Expand All @@ -784,7 +784,10 @@ func parseAlias(comment string) (string, error) {
return "", fmt.Errorf("candidate alias %s is double commented", s[0])
}

alias := strings.TrimSpace(s[1])
defer func() {
alias = strings.Trim(alias, " \"'")
}()
alias = strings.TrimSpace(s[1])
if len(alias) == 0 {
return "", fmt.Errorf("invalid alias after trim space: %s", comment)
}
Expand Down

0 comments on commit 9873342

Please sign in to comment.