Skip to content

Commit 5b81b1c

Browse files
rhodeonkyleconroy
authored andcommitted
Renamed the metadata ParseParamsAndFlags() function to ParseCommentFlags() in order to be more generic as it now returns the rule skip list and could potentially return more data in the future.
1 parent 5c1546d commit 5b81b1c

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

internal/compiler/parse.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (c *Compiler) parseQuery(stmt ast.Node, src string, o opts.Parser) (*Query,
6565
return nil, err
6666
}
6767

68-
md.Params, md.Flags, md.RuleSkiplist, err = metadata.ParseParamsAndFlags(cleanedComments)
68+
md.Params, md.Flags, md.RuleSkiplist, err = metadata.ParseCommentFlags(cleanedComments)
6969
if err != nil {
7070
return nil, err
7171
}

internal/metadata/meta.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ func ParseQueryNameAndType(t string, commentStyle CommentSyntax) (string, string
118118
return "", "", nil
119119
}
120120

121-
func ParseParamsAndFlags(comments []string) (map[string]string, map[string]bool, map[string]struct{}, error) {
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.
123+
func ParseCommentFlags(comments []string) (map[string]string, map[string]bool, map[string]struct{}, error) {
122124
params := make(map[string]string)
123125
flags := make(map[string]bool)
124126
ruleSkiplist := make(map[string]struct{})

internal/metadata/meta_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func TestParseQueryParams(t *testing.T) {
7979
" @param @invalid UUID ",
8080
},
8181
} {
82-
params, _, _, err := ParseParamsAndFlags(comments)
82+
params, _, _, err := ParseCommentFlags(comments)
8383
if err != nil {
8484
t.Errorf("expected comments to parse, got err: %s", err)
8585
}
@@ -125,7 +125,7 @@ func TestParseQueryFlags(t *testing.T) {
125125
" @param @flag-bar UUID",
126126
},
127127
} {
128-
_, flags, _, err := ParseParamsAndFlags(comments)
128+
_, flags, _, err := ParseCommentFlags(comments)
129129
if err != nil {
130130
t.Errorf("expected comments to parse, got err: %s", err)
131131
}
@@ -158,7 +158,7 @@ func TestParseQueryRuleBlocklist(t *testing.T) {
158158
" @sqlc-vet-disable delete-without-where ",
159159
},
160160
} {
161-
_, flags, ruleBlocklist, err := ParseParamsAndFlags(comments)
161+
_, flags, ruleBlocklist, err := ParseCommentFlags(comments)
162162
if err != nil {
163163
t.Errorf("expected comments to parse, got err: %s", err)
164164
}

0 commit comments

Comments
 (0)