Skip to content

Commit e8b786c

Browse files
authored
fix: normalize comment text for synthetic comments to ensure cross-platform compatibility (#79)
1 parent 12d0e34 commit e8b786c

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

comments.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,11 @@ func syntheticComments(leading bool, grp *ast.CommentGroup) []bindings.Synthetic
154154
return cmts
155155
}
156156
for _, c := range grp.List {
157+
normalizedText := normalizeCommentText(c.Text)
157158
cmts = append(cmts, bindings.SyntheticComment{
158159
Leading: leading,
159-
SingleLine: !strings.Contains(c.Text, "\n"),
160-
Text: normalizeCommentText(c.Text),
160+
SingleLine: !strings.Contains(normalizedText, "\n"),
161+
Text: normalizedText,
161162
TrailingNewLine: true,
162163
})
163164
}
@@ -169,5 +170,10 @@ func normalizeCommentText(text string) string {
169170
text = strings.TrimPrefix(text, "//")
170171
text = strings.TrimPrefix(text, "/*")
171172
text = strings.TrimSuffix(text, "*/")
173+
174+
// Normalize CRLF to LF for cross-platform compatibility
175+
text = strings.ReplaceAll(text, "\r\n", "\n")
176+
text = strings.ReplaceAll(text, "\r", "\n")
177+
172178
return text
173179
}

0 commit comments

Comments
 (0)