* Mirror of the api-validation annotation reader, for `--` SQL comments: * scans up to three consecutive non-empty preceding lines for the prefix. * `allowed` when a non-empty reason follows; `missingReason` flags a dangling * annotation so it fails rather than silently passing.
( lines: string[], startLine: number )
| 161 | * annotation so it fails rather than silently passing. |
| 162 | */ |
| 163 | function readAnnotation( |
| 164 | lines: string[], |
| 165 | startLine: number |
| 166 | ): { allowed: boolean; missingReason: boolean } { |
| 167 | let inspected = 0 |
| 168 | for (let i = startLine - 2; i >= 0 && inspected < 3; i--) { |
| 169 | const trimmed = lines[i]?.trim() ?? '' |
| 170 | if (trimmed.length === 0) continue |
| 171 | inspected++ |
| 172 | if (!trimmed.startsWith('--')) return { allowed: false, missingReason: false } |
| 173 | const idx = trimmed.indexOf(ANNOTATION_PREFIX) |
| 174 | if (idx === -1) continue |
| 175 | const reason = trimmed.slice(idx + ANNOTATION_PREFIX.length).trim() |
| 176 | if (reason.length === 0) return { allowed: false, missingReason: true } |
| 177 | return { allowed: true, missingReason: false } |
| 178 | } |
| 179 | return { allowed: false, missingReason: false } |
| 180 | } |
| 181 | |
| 182 | interface RawMatch { |
| 183 | kind: 'error' | 'annotate' | 'warn' |