improvement(audits): skip the sql-date-binding parse for files without drizzle-orm (#6554)

check:sql-date-binding Babel-parsed all 13,941 source files in apps, packages,
and scripts. A violation can only come from an `sql` tag resolved through a
`drizzle-orm` import, and both the static and dynamic resolvers match the
specifier as a string literal, so a file that never names the module cannot
produce one. Only ~590 files do.

Skipping the parse for the other 92% of bytes takes the audit from ~4.5s to
~0.8s and drops it out of the four slowest audits, taking check:audits from
6.0s to 5.3s wall and 38.0s to 32.9s serial. Output is unchanged.
This commit is contained in:
Waleed
2026-08-11 12:11:13 -07:00
committed by GitHub
parent df052ac75c
commit 440a68bff9
+15 -1
View File
@@ -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)
}