import { resolve } from 'node:path' import { performance } from 'node:perf_hooks' import { analyzeProject } from './analyze.js' import { dedupeDiagnostics, type LintResult } from './diagnostic.js' import { runOxlint } from './oxlint/run.js' import { assertSingleTypeUniverse } from './preflight.js' import { discoverProject } from './project.js' export type LintDomainOptions = { root?: string fix?: boolean preflight?: boolean /** Cancels the external Oxlint process and rejects the lint operation. */ signal?: AbortSignal } export async function lintDomain(options: LintDomainOptions = {}): Promise { const started = performance.now() const root = resolve(options.root ?? process.cwd()) if (options.preflight !== false) await assertSingleTypeUniverse(root) const [project, oxlint] = await Promise.all([ discoverProject(root), runOxlint(root, options.fix ?? false, { signal: options.signal }), ]) const diagnostics = dedupeDiagnostics([...oxlint.diagnostics, ...analyzeProject(project)]) return { root: project.root, diagnostics, files: Math.max(project.files.length, oxlint.files), durationMs: Math.max(0, Math.round(performance.now() - started)), exitCode: diagnostics.some((diagnostic) => diagnostic.severity === 'error') ? 1 : 0, } }