Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion scripts/check-sql-date-binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand Down
Loading