MCPcopy
hub / github.com/sqlc-dev/sqlc / ParseCommentFlags

Function ParseCommentFlags

internal/metadata/meta.go:123–172  ·  view source on GitHub ↗

ParseCommentFlags processes the comments provided with queries to determine the metadata params, flags and rules to skip. All flags in query comments are prefixed with `@`, e.g. @param, @@sqlc-vet-disable.

(comments []string)

Source from the content-addressed store, hash-verified

121// ParseCommentFlags processes the comments provided with queries to determine the metadata params, flags and rules to skip.
122// All flags in query comments are prefixed with `@`, e.g. @param, @@sqlc-vet-disable.
123func ParseCommentFlags(comments []string) (map[string]string, map[string]bool, map[string]struct{}, error) {
124 params := make(map[string]string)
125 flags := make(map[string]bool)
126 ruleSkiplist := make(map[string]struct{})
127
128 for _, line := range comments {
129 s := bufio.NewScanner(strings.NewReader(line))
130 s.Split(bufio.ScanWords)
131
132 s.Scan()
133 token := s.Text()
134
135 if !strings.HasPrefix(token, "@") {
136 continue
137 }
138
139 switch token {
140 case constants.QueryFlagParam:
141 s.Scan()
142 name := s.Text()
143 var rest []string
144 for s.Scan() {
145 paramToken := s.Text()
146 rest = append(rest, paramToken)
147 }
148 params[name] = strings.Join(rest, " ")
149
150 case constants.QueryFlagSqlcVetDisable:
151 flags[token] = true
152
153 // Vet rules can all be disabled in the same line or split across lines .i.e.
154 // /* @sqlc-vet-disable sqlc/db-prepare delete-without-where */
155 // is equivalent to:
156 // /* @sqlc-vet-disable sqlc/db-prepare */
157 // /* @sqlc-vet-disable delete-without-where */
158 for s.Scan() {
159 ruleSkiplist[s.Text()] = struct{}{}
160 }
161
162 default:
163 flags[token] = true
164 }
165
166 if s.Err() != nil {
167 return params, flags, ruleSkiplist, s.Err()
168 }
169 }
170
171 return params, flags, ruleSkiplist, nil
172}

Callers 4

parseQueryMethod · 0.92
TestParseQueryParamsFunction · 0.85
TestParseQueryFlagsFunction · 0.85

Calls 3

ScanMethod · 0.45
JoinMethod · 0.45
ErrMethod · 0.45

Tested by 3

TestParseQueryParamsFunction · 0.68
TestParseQueryFlagsFunction · 0.68