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

Function GetComments

internal/lint/code/comments.go:100–127  ·  view source on GitHub ↗

GetComments returns all comments in the given source code.

(source []byte, lang *Language)

Source from the content-addressed store, hash-verified

98
99// GetComments returns all comments in the given source code.
100func GetComments(source []byte, lang *Language) ([]Comment, error) {
101 var comments []Comment
102
103 parser := sitter.NewParser()
104 parser.SetLanguage(lang.Parser)
105
106 tree, err := parser.ParseCtx(context.Background(), nil, source)
107 if err != nil {
108 return comments, err
109 }
110 engine := NewQueryEngine(tree, lang)
111
112 for _, query := range lang.Queries {
113 q, qErr := sitter.NewQuery([]byte(query.Expr), lang.Parser)
114 if qErr != nil {
115 return comments, qErr
116 }
117 comments = append(comments, engine.run(query.Name, q, source)...)
118 }
119
120 if len(lang.Queries) > 1 {
121 sort.Slice(comments, func(p, q int) bool {
122 return comments[p].Line < comments[q].Line
123 })
124 }
125
126 return coalesce(comments), nil
127}

Callers 3

lintCodeMethod · 0.92
lintFragmentsMethod · 0.92
TestCommentsFunction · 0.85

Calls 3

runMethod · 0.95
NewQueryEngineFunction · 0.85
coalesceFunction · 0.85

Tested by 1

TestCommentsFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…