MCPcopy Create free account
hub / github.com/vale-cli/vale / coalesce

Function coalesce

internal/lint/code/comments.go:51–97  ·  view source on GitHub ↗
(comments []Comment)

Source from the content-addressed store, hash-verified

49}
50
51func coalesce(comments []Comment) []Comment {
52 var joined []Comment
53
54 tBuf := bytes.Buffer{}
55 sBuf := bytes.Buffer{}
56
57 for i, comment := range comments {
58 if comment.Scope == "text.comment.block" { //nolint:gocritic
59 joined = append(joined, comment)
60 } else if i == 0 || doneMerging(comment, comments[i-1]) {
61 if tBuf.Len() > 0 {
62 // We have comments to merge ...
63 last := joined[len(joined)-1]
64
65 last.Text += addSourceLine(tBuf.String(), false)
66 last.Source += addSourceLine(sBuf.String(), false)
67
68 joined[len(joined)-1] = last
69
70 tBuf.Reset()
71 sBuf.Reset()
72 }
73 joined = append(joined, comment)
74 } else {
75 tBuf.WriteString(addSourceLine(comment.Text, true))
76 sBuf.WriteString(addSourceLine(comment.Source, true))
77 }
78 }
79
80 if tBuf.Len() > 0 {
81 last := joined[len(joined)-1]
82
83 last.Text += addSourceLine(tBuf.String(), false)
84 last.Source += addSourceLine(sBuf.String(), false)
85
86 joined[len(joined)-1] = last
87
88 tBuf.Reset()
89 sBuf.Reset()
90 }
91
92 for i, comment := range joined {
93 joined[i].Text = strings.TrimLeft(comment.Text, " ")
94 }
95
96 return joined
97}
98
99// GetComments returns all comments in the given source code.
100func GetComments(source []byte, lang *Language) ([]Comment, error) {

Callers 1

GetCommentsFunction · 0.85

Calls 4

doneMergingFunction · 0.85
addSourceLineFunction · 0.85
StringMethod · 0.80
LenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…