@@ -5,29 +5,44 @@ import (
55 "strings"
66)
77
8- // Remove all lines after a rollback comment.
8+ // Remove all lines that should be ignored by sqlc, such as rollback
9+ // comments or explicit "sqlc:ignore" lines.
910//
1011// goose: -- +goose Down
1112// sql-migrate: -- +migrate Down
1213// tern: ---- create above / drop below ----
1314// dbmate: -- migrate:down
14- func RemoveRollbackStatements (contents string ) string {
15+ // generic: `-- sqlc:ignore` until `-- sqlc:ignore end`
16+ func RemoveIgnoredStatements (contents string ) string {
1517 s := bufio .NewScanner (strings .NewReader (contents ))
1618 var lines []string
19+ var ignoring bool
1720 for s .Scan () {
18- if strings .HasPrefix (s .Text (), "-- +goose Down" ) {
21+ line := s .Text ()
22+
23+ if strings .HasPrefix (line , "-- +goose Down" ) {
1924 break
2025 }
21- if strings .HasPrefix (s . Text () , "-- +migrate Down" ) {
26+ if strings .HasPrefix (line , "-- +migrate Down" ) {
2227 break
2328 }
24- if strings .HasPrefix (s . Text () , "---- create above / drop below ----" ) {
29+ if strings .HasPrefix (line , "---- create above / drop below ----" ) {
2530 break
2631 }
27- if strings .HasPrefix (s . Text () , "-- migrate:down" ) {
32+ if strings .HasPrefix (line , "-- migrate:down" ) {
2833 break
2934 }
30- lines = append (lines , s .Text ())
35+
36+ if strings .HasPrefix (line , "-- sqlc:ignore end" ) {
37+ ignoring = false
38+ } else if strings .HasPrefix (line , "-- sqlc:ignore" ) {
39+ ignoring = true
40+ } else if ignoring {
41+ // make this line empty, so that errors are still reported on the
42+ // correct line
43+ line = ""
44+ }
45+ lines = append (lines , line )
3146 }
3247 return strings .Join (lines , "\n " )
3348}
0 commit comments