import type { LintDiagnostic } from '../diagnostic.js' import type { DomainProject } from '../project.js' import type { SourceFile, SourceToken } from '../source.js' import { isSuppressed } from '../suppression.js' import { ruleCatalog, ruleId, type ImplementedRuleSlug } from './catalog.js' export type AnalyzerRule = { slug: ImplementedRuleSlug analyze(project: DomainProject): readonly LintDiagnostic[] } export function analyzerDiagnostic( slug: ImplementedRuleSlug, file: SourceFile, token: SourceToken, detail?: string, ): LintDiagnostic | undefined { const info = ruleCatalog[slug] const id = ruleId(slug) if (isSuppressed(file, token.line, id)) return undefined return { id, severity: 'error', message: detail ? `${info.message} ${detail}` : info.message, help: info.help, url: info.url, owner: info.owner, location: { path: file.relativePath, line: token.line, column: token.column, offset: token.offset, length: token.length, }, } }