MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / hasGeneratedHeader

Function hasGeneratedHeader

src/extraction/generated-detection.ts:207–245  ·  view source on GitHub ↗
(content: string)

Source from the content-addressed store, hash-verified

205 * per query: the verdict is persisted on the file record.
206 */
207export function hasGeneratedHeader(content: string): boolean {
208 if (!content) return false;
209
210 const head = content.length > HEADER_SCAN_CHARS ? content.slice(0, HEADER_SCAN_CHARS) : content;
211 // Fast reject for ~every hand-written file: no line splitting, no allocation
212 // (V8 keeps `head` as a sliced view of `content`).
213 if (!GENERATED_STEM.test(head)) return false;
214
215 const lines = head.split('\n');
216 const limit = Math.min(lines.length, HEADER_SCAN_LINES);
217 let openBlock: (typeof BLOCK_DELIMS)[number] | null = null;
218
219 for (let i = 0; i < limit; i++) {
220 const line = lines[i]!;
221 const inBlock = openBlock !== null;
222
223 if (inBlock || COMMENT_LEADER.test(line)) {
224 for (const pattern of GENERATED_CONTENT_PATTERNS) {
225 if (pattern.test(line)) return true;
226 }
227 }
228
229 // Advance the block-comment state AFTER testing, so the opening line of a
230 // `/* Code generated … */` block is itself matched by the leader rule.
231 if (openBlock) {
232 if (line.includes(openBlock.close)) openBlock = null;
233 continue;
234 }
235 for (const delim of BLOCK_DELIMS) {
236 const at = line.indexOf(delim.open);
237 if (at < 0) continue;
238 // Same-line close (`/* … */`, a one-line docstring) leaves no open block.
239 if (line.indexOf(delim.close, at + delim.open.length) < 0) openBlock = delim;
240 break;
241 }
242 }
243
244 return false;
245}
246
247/**
248 * The union signal: path convention OR content banner. This is what the

Calls

no outgoing calls

Tested by

no test coverage detected