diff --git a/scripts/check-sql-date-binding.ts b/scripts/check-sql-date-binding.ts index abbacb1f9c2..514e8884fd4 100644 --- a/scripts/check-sql-date-binding.ts +++ b/scripts/check-sql-date-binding.ts @@ -544,6 +544,18 @@ function analyzeSource(source: string, file = 'source.ts'): FileAnalysis { return { violations } } +/** + * Skips the parse for files that cannot bind the tag. + * + * `collectSqlBindings` and `isDrizzleImportCall` both match the specifier as a string literal, + * so a source that never names the module yields no bindings and no violations. That is all but + * ~590 of the ~13,900 scanned files, and not parsing them takes the audit from ~4.5s to ~0.8s. + * An escaped specifier (`'drizzle\x2dorm'`) would evade the substring; the repo contains none. + */ +function mayBindDrizzleSql(source: string): boolean { + return source.includes(DRIZZLE_MODULE) +} + function collectSources(dir: string, found: string[] = []): string[] { for (const entry of readdirSync(dir, { withFileTypes: true })) { if (SKIP_DIRS.has(entry.name)) continue @@ -560,7 +572,9 @@ function main(): void { const skipped: { file: string; parseError: string }[] = [] for (const file of files) { - const analysis = analyzeSource(readFileSync(file, 'utf8'), file) + const source = readFileSync(file, 'utf8') + if (!mayBindDrizzleSql(source)) continue + const analysis = analyzeSource(source, file) if (analysis.parseError) skipped.push({ file, parseError: analysis.parseError }) violations.push(...analysis.violations) }