@eduardbar/drift 0.9.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/.github/actions/drift-scan/README.md +61 -0
  2. package/.github/actions/drift-scan/action.yml +65 -0
  3. package/.github/workflows/publish-vscode.yml +78 -0
  4. package/AGENTS.md +83 -23
  5. package/README.md +69 -2
  6. package/ROADMAP.md +130 -98
  7. package/dist/analyzer.d.ts +8 -38
  8. package/dist/analyzer.js +181 -1526
  9. package/dist/badge.js +40 -22
  10. package/dist/ci.js +32 -18
  11. package/dist/cli.js +125 -4
  12. package/dist/config.js +1 -1
  13. package/dist/diff.d.ts +0 -7
  14. package/dist/diff.js +26 -25
  15. package/dist/fix.d.ts +17 -0
  16. package/dist/fix.js +132 -0
  17. package/dist/git/blame.d.ts +22 -0
  18. package/dist/git/blame.js +227 -0
  19. package/dist/git/helpers.d.ts +36 -0
  20. package/dist/git/helpers.js +152 -0
  21. package/dist/git/trend.d.ts +21 -0
  22. package/dist/git/trend.js +81 -0
  23. package/dist/git.d.ts +0 -13
  24. package/dist/git.js +27 -21
  25. package/dist/index.d.ts +5 -1
  26. package/dist/index.js +3 -0
  27. package/dist/map.d.ts +3 -0
  28. package/dist/map.js +103 -0
  29. package/dist/metrics.d.ts +4 -0
  30. package/dist/metrics.js +176 -0
  31. package/dist/plugins.d.ts +6 -0
  32. package/dist/plugins.js +74 -0
  33. package/dist/printer.js +20 -0
  34. package/dist/report.js +654 -293
  35. package/dist/reporter.js +85 -2
  36. package/dist/review.d.ts +15 -0
  37. package/dist/review.js +80 -0
  38. package/dist/rules/comments.d.ts +4 -0
  39. package/dist/rules/comments.js +45 -0
  40. package/dist/rules/complexity.d.ts +4 -0
  41. package/dist/rules/complexity.js +51 -0
  42. package/dist/rules/coupling.d.ts +4 -0
  43. package/dist/rules/coupling.js +19 -0
  44. package/dist/rules/magic.d.ts +4 -0
  45. package/dist/rules/magic.js +33 -0
  46. package/dist/rules/nesting.d.ts +5 -0
  47. package/dist/rules/nesting.js +82 -0
  48. package/dist/rules/phase0-basic.d.ts +11 -0
  49. package/dist/rules/phase0-basic.js +183 -0
  50. package/dist/rules/phase1-complexity.d.ts +7 -0
  51. package/dist/rules/phase1-complexity.js +8 -0
  52. package/dist/rules/phase2-crossfile.d.ts +23 -0
  53. package/dist/rules/phase2-crossfile.js +135 -0
  54. package/dist/rules/phase3-arch.d.ts +23 -0
  55. package/dist/rules/phase3-arch.js +151 -0
  56. package/dist/rules/phase3-configurable.d.ts +6 -0
  57. package/dist/rules/phase3-configurable.js +97 -0
  58. package/dist/rules/phase5-ai.d.ts +8 -0
  59. package/dist/rules/phase5-ai.js +262 -0
  60. package/dist/rules/phase8-semantic.d.ts +17 -0
  61. package/dist/rules/phase8-semantic.js +110 -0
  62. package/dist/rules/promise.d.ts +4 -0
  63. package/dist/rules/promise.js +24 -0
  64. package/dist/rules/shared.d.ts +7 -0
  65. package/dist/rules/shared.js +27 -0
  66. package/dist/snapshot.d.ts +19 -0
  67. package/dist/snapshot.js +119 -0
  68. package/dist/types.d.ts +69 -0
  69. package/dist/utils.d.ts +2 -1
  70. package/dist/utils.js +1 -0
  71. package/docs/AGENTS.md +146 -0
  72. package/docs/PRD.md +208 -0
  73. package/package.json +8 -3
  74. package/packages/eslint-plugin-drift/src/index.ts +1 -1
  75. package/packages/vscode-drift/.vscodeignore +9 -0
  76. package/packages/vscode-drift/LICENSE +21 -0
  77. package/packages/vscode-drift/README.md +64 -0
  78. package/packages/vscode-drift/images/icon.png +0 -0
  79. package/packages/vscode-drift/images/icon.svg +30 -0
  80. package/packages/vscode-drift/package-lock.json +485 -0
  81. package/packages/vscode-drift/package.json +119 -0
  82. package/packages/vscode-drift/src/analyzer.ts +40 -0
  83. package/packages/vscode-drift/src/diagnostics.ts +55 -0
  84. package/packages/vscode-drift/src/extension.ts +135 -0
  85. package/packages/vscode-drift/src/statusbar.ts +55 -0
  86. package/packages/vscode-drift/src/treeview.ts +110 -0
  87. package/packages/vscode-drift/tsconfig.json +18 -0
  88. package/packages/vscode-drift/vscode-drift-0.1.0.vsix +0 -0
  89. package/packages/vscode-drift/vscode-drift-0.1.1.vsix +0 -0
  90. package/src/analyzer.ts +248 -1765
  91. package/src/badge.ts +38 -16
  92. package/src/ci.ts +38 -17
  93. package/src/cli.ts +143 -4
  94. package/src/config.ts +1 -1
  95. package/src/diff.ts +36 -30
  96. package/src/fix.ts +178 -0
  97. package/src/git/blame.ts +279 -0
  98. package/src/git/helpers.ts +198 -0
  99. package/src/git/trend.ts +117 -0
  100. package/src/git.ts +33 -24
  101. package/src/index.ts +16 -1
  102. package/src/map.ts +117 -0
  103. package/src/metrics.ts +200 -0
  104. package/src/plugins.ts +76 -0
  105. package/src/printer.ts +20 -0
  106. package/src/report.ts +666 -296
  107. package/src/reporter.ts +95 -2
  108. package/src/review.ts +98 -0
  109. package/src/rules/comments.ts +56 -0
  110. package/src/rules/complexity.ts +57 -0
  111. package/src/rules/coupling.ts +23 -0
  112. package/src/rules/magic.ts +38 -0
  113. package/src/rules/nesting.ts +88 -0
  114. package/src/rules/phase0-basic.ts +194 -0
  115. package/src/rules/phase1-complexity.ts +8 -0
  116. package/src/rules/phase2-crossfile.ts +177 -0
  117. package/src/rules/phase3-arch.ts +183 -0
  118. package/src/rules/phase3-configurable.ts +132 -0
  119. package/src/rules/phase5-ai.ts +292 -0
  120. package/src/rules/phase8-semantic.ts +136 -0
  121. package/src/rules/promise.ts +29 -0
  122. package/src/rules/shared.ts +39 -0
  123. package/src/snapshot.ts +175 -0
  124. package/src/types.ts +75 -1
  125. package/src/utils.ts +3 -1
  126. package/tests/helpers.ts +45 -0
  127. package/tests/new-features.test.ts +153 -0
  128. package/tests/rules.test.ts +1269 -0
  129. package/vitest.config.ts +15 -0
package/src/index.ts CHANGED
@@ -1,4 +1,19 @@
1
1
  export { analyzeProject, analyzeFile, RULE_WEIGHTS } from './analyzer.js'
2
2
  export { buildReport, formatMarkdown } from './reporter.js'
3
3
  export { computeDiff } from './diff.js'
4
- export type { DriftReport, FileReport, DriftIssue, DriftDiff, FileDiff, DriftConfig } from './types.js'
4
+ export { generateReview, formatReviewMarkdown } from './review.js'
5
+ export { generateArchitectureMap, generateArchitectureSvg } from './map.js'
6
+ export type {
7
+ DriftReport,
8
+ FileReport,
9
+ DriftIssue,
10
+ DriftDiff,
11
+ FileDiff,
12
+ DriftConfig,
13
+ RepoQualityScore,
14
+ MaintenanceRiskMetrics,
15
+ DriftPlugin,
16
+ DriftPluginRule,
17
+ } from './types.js'
18
+ export { loadHistory, saveSnapshot } from './snapshot.js'
19
+ export type { SnapshotEntry, SnapshotHistory } from './snapshot.js'
package/src/map.ts ADDED
@@ -0,0 +1,117 @@
1
+ import { writeFileSync } from 'node:fs'
2
+ import { resolve, relative } from 'node:path'
3
+ import { Project } from 'ts-morph'
4
+
5
+ interface LayerNode {
6
+ name: string
7
+ files: Set<string>
8
+ }
9
+
10
+ function detectLayer(relPath: string): string {
11
+ const normalized = relPath.replace(/\\/g, '/').replace(/^\.\//, '')
12
+ const first = normalized.split('/')[0] || 'root'
13
+ return first
14
+ }
15
+
16
+ function esc(value: string): string {
17
+ return value.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')
18
+ }
19
+
20
+ export function generateArchitectureSvg(targetPath: string): string {
21
+ const project = new Project({
22
+ skipAddingFilesFromTsConfig: true,
23
+ compilerOptions: { allowJs: true, jsx: 1 },
24
+ })
25
+
26
+ project.addSourceFilesAtPaths([
27
+ `${targetPath}/**/*.ts`,
28
+ `${targetPath}/**/*.tsx`,
29
+ `${targetPath}/**/*.js`,
30
+ `${targetPath}/**/*.jsx`,
31
+ `!${targetPath}/**/node_modules/**`,
32
+ `!${targetPath}/**/dist/**`,
33
+ `!${targetPath}/**/.next/**`,
34
+ `!${targetPath}/**/*.d.ts`,
35
+ ])
36
+
37
+ const layers = new Map<string, LayerNode>()
38
+ const edges = new Map<string, number>()
39
+
40
+ for (const file of project.getSourceFiles()) {
41
+ const rel = relative(targetPath, file.getFilePath()).replace(/\\/g, '/')
42
+ const layerName = detectLayer(rel)
43
+ if (!layers.has(layerName)) layers.set(layerName, { name: layerName, files: new Set() })
44
+ layers.get(layerName)!.files.add(rel)
45
+
46
+ for (const decl of file.getImportDeclarations()) {
47
+ const imported = decl.getModuleSpecifierSourceFile()
48
+ if (!imported) continue
49
+ const importedRel = relative(targetPath, imported.getFilePath()).replace(/\\/g, '/')
50
+ const importedLayer = detectLayer(importedRel)
51
+ if (importedLayer === layerName) continue
52
+ const key = `${layerName}->${importedLayer}`
53
+ edges.set(key, (edges.get(key) ?? 0) + 1)
54
+ }
55
+ }
56
+
57
+ const layerList = [...layers.values()].sort((a, b) => a.name.localeCompare(b.name))
58
+ const width = 960
59
+ const rowHeight = 90
60
+ const height = Math.max(180, layerList.length * rowHeight + 120)
61
+ const boxWidth = 240
62
+ const boxHeight = 50
63
+ const left = 100
64
+
65
+ const boxes = layerList.map((layer, index) => {
66
+ const y = 60 + index * rowHeight
67
+ return {
68
+ ...layer,
69
+ x: left,
70
+ y,
71
+ }
72
+ })
73
+
74
+ const boxByName = new Map(boxes.map((box) => [box.name, box]))
75
+
76
+ const lines = [...edges.entries()].map(([key, count]) => {
77
+ const [from, to] = key.split('->')
78
+ const a = boxByName.get(from)
79
+ const b = boxByName.get(to)
80
+ if (!a || !b) return ''
81
+ const startX = a.x + boxWidth
82
+ const startY = a.y + boxHeight / 2
83
+ const endX = b.x
84
+ const endY = b.y + boxHeight / 2
85
+ return `
86
+ <line x1="${startX}" y1="${startY}" x2="${endX}" y2="${endY}" stroke="#64748b" stroke-width="2" marker-end="url(#arrow)" />
87
+ <text x="${(startX + endX) / 2}" y="${(startY + endY) / 2 - 4}" fill="#94a3b8" font-size="11" text-anchor="middle">${count}</text>`
88
+ }).join('')
89
+
90
+ const nodes = boxes.map((box) => `
91
+ <g>
92
+ <rect x="${box.x}" y="${box.y}" width="${boxWidth}" height="${boxHeight}" rx="8" fill="#0f172a" stroke="#334155" />
93
+ <text x="${box.x + 12}" y="${box.y + 22}" fill="#e2e8f0" font-size="13" font-family="monospace">${esc(box.name)}</text>
94
+ <text x="${box.x + 12}" y="${box.y + 38}" fill="#94a3b8" font-size="11" font-family="monospace">${box.files.size} file(s)</text>
95
+ </g>`).join('')
96
+
97
+ return `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">
98
+ <defs>
99
+ <marker id="arrow" markerWidth="10" markerHeight="10" refX="6" refY="3" orient="auto">
100
+ <path d="M0,0 L0,6 L7,3 z" fill="#64748b"/>
101
+ </marker>
102
+ </defs>
103
+ <rect x="0" y="0" width="${width}" height="${height}" fill="#020617" />
104
+ <text x="28" y="34" fill="#f8fafc" font-size="16" font-family="monospace">drift architecture map</text>
105
+ <text x="28" y="54" fill="#94a3b8" font-size="11" font-family="monospace">Layers inferred from top-level directories</text>
106
+ ${lines}
107
+ ${nodes}
108
+ </svg>`
109
+ }
110
+
111
+ export function generateArchitectureMap(targetPath: string, outputFile = 'architecture.svg'): string {
112
+ const resolvedTarget = resolve(targetPath)
113
+ const svg = generateArchitectureSvg(resolvedTarget)
114
+ const outPath = resolve(outputFile)
115
+ writeFileSync(outPath, svg, 'utf8')
116
+ return outPath
117
+ }
package/src/metrics.ts ADDED
@@ -0,0 +1,200 @@
1
+ import { existsSync, readdirSync, statSync } from 'node:fs'
2
+ import { execSync } from 'node:child_process'
3
+ import { join, relative } from 'node:path'
4
+ import type { DriftIssue, DriftReport, FileReport, MaintenanceRiskMetrics, RepoQualityScore, RiskHotspot } from './types.js'
5
+
6
+ const ARCH_RULES = new Set([
7
+ 'circular-dependency',
8
+ 'layer-violation',
9
+ 'cross-boundary-import',
10
+ 'controller-no-db',
11
+ 'service-no-http',
12
+ ])
13
+
14
+ const COMPLEXITY_RULES = new Set([
15
+ 'large-file',
16
+ 'large-function',
17
+ 'high-complexity',
18
+ 'deep-nesting',
19
+ 'too-many-params',
20
+ 'max-function-lines',
21
+ ])
22
+
23
+ const AI_RULES = new Set([
24
+ 'over-commented',
25
+ 'hardcoded-config',
26
+ 'inconsistent-error-handling',
27
+ 'unnecessary-abstraction',
28
+ 'naming-inconsistency',
29
+ 'comment-contradiction',
30
+ 'ai-code-smell',
31
+ ])
32
+
33
+ function clamp(value: number, min: number, max: number): number {
34
+ return Math.max(min, Math.min(max, value))
35
+ }
36
+
37
+ function listFilesRecursively(root: string): string[] {
38
+ if (!existsSync(root)) return []
39
+ const out: string[] = []
40
+ const stack = [root]
41
+ while (stack.length > 0) {
42
+ const current = stack.pop()!
43
+ const entries = readdirSync(current)
44
+ for (const entry of entries) {
45
+ const full = join(current, entry)
46
+ const stat = statSync(full)
47
+ if (stat.isDirectory()) {
48
+ if (entry === 'node_modules' || entry === 'dist' || entry === '.git' || entry === '.next' || entry === 'build') {
49
+ continue
50
+ }
51
+ stack.push(full)
52
+ } else {
53
+ out.push(full)
54
+ }
55
+ }
56
+ }
57
+ return out
58
+ }
59
+
60
+ function hasNearbyTest(targetPath: string, filePath: string): boolean {
61
+ const rel = relative(targetPath, filePath).replace(/\\/g, '/')
62
+ const noExt = rel.replace(/\.[^.]+$/, '')
63
+ const candidates = [
64
+ `${noExt}.test.ts`,
65
+ `${noExt}.test.tsx`,
66
+ `${noExt}.spec.ts`,
67
+ `${noExt}.spec.tsx`,
68
+ `${noExt}.test.js`,
69
+ `${noExt}.spec.js`,
70
+ ]
71
+ return candidates.some((candidate) => existsSync(join(targetPath, candidate)))
72
+ }
73
+
74
+ function getCommitTouchCount(targetPath: string, filePath: string): number {
75
+ try {
76
+ const rel = relative(targetPath, filePath).replace(/\\/g, '/')
77
+ const output = execSync(`git rev-list --count HEAD -- "${rel}"`, {
78
+ cwd: targetPath,
79
+ encoding: 'utf8',
80
+ stdio: ['pipe', 'pipe', 'pipe'],
81
+ }).trim()
82
+ return Number(output) || 0
83
+ } catch {
84
+ return 0
85
+ }
86
+ }
87
+
88
+ function qualityFromIssues(totalFiles: number, issues: DriftIssue[], rules: Set<string>): number {
89
+ const count = issues.filter((issue) => rules.has(issue.rule)).length
90
+ if (totalFiles === 0) return 100
91
+ return clamp(100 - Math.round((count / totalFiles) * 20), 0, 100)
92
+ }
93
+
94
+ export function computeRepoQuality(targetPath: string, files: FileReport[]): RepoQualityScore {
95
+ const allIssues = files.flatMap((file) => file.issues)
96
+ const sourceFiles = files.filter((file) => !file.path.endsWith('package.json'))
97
+ const totalFiles = Math.max(sourceFiles.length, 1)
98
+
99
+ const testingCandidates = listFilesRecursively(targetPath).filter((filePath) =>
100
+ /\.(ts|tsx|js|jsx)$/.test(filePath) &&
101
+ !/\.test\.|\.spec\./.test(filePath) &&
102
+ !filePath.includes('node_modules')
103
+ )
104
+
105
+ const withoutTests = testingCandidates.filter((filePath) => !hasNearbyTest(targetPath, filePath)).length
106
+ const testing = testingCandidates.length === 0
107
+ ? 100
108
+ : clamp(100 - Math.round((withoutTests / testingCandidates.length) * 100), 0, 100)
109
+
110
+ const dimensions = {
111
+ architecture: qualityFromIssues(totalFiles, allIssues, ARCH_RULES),
112
+ complexity: qualityFromIssues(totalFiles, allIssues, COMPLEXITY_RULES),
113
+ 'ai-patterns': qualityFromIssues(totalFiles, allIssues, AI_RULES),
114
+ testing,
115
+ }
116
+
117
+ const overall = Math.round((
118
+ dimensions.architecture +
119
+ dimensions.complexity +
120
+ dimensions['ai-patterns'] +
121
+ dimensions.testing
122
+ ) / 4)
123
+
124
+ return { overall, dimensions }
125
+ }
126
+
127
+ export function computeMaintenanceRisk(report: DriftReport): MaintenanceRiskMetrics {
128
+ const allFiles = report.files
129
+ const hotspots: RiskHotspot[] = allFiles
130
+ .map((file) => {
131
+ const complexityIssues = file.issues.filter((issue) =>
132
+ issue.rule === 'high-complexity' ||
133
+ issue.rule === 'deep-nesting' ||
134
+ issue.rule === 'large-function' ||
135
+ issue.rule === 'max-function-lines'
136
+ ).length
137
+
138
+ const changeFrequency = getCommitTouchCount(report.targetPath, file.path)
139
+ const hasTests = hasNearbyTest(report.targetPath, file.path)
140
+ const reasons: string[] = []
141
+ let risk = 0
142
+
143
+ if (complexityIssues > 0) {
144
+ risk += Math.min(40, complexityIssues * 10)
145
+ reasons.push('high complexity signals')
146
+ }
147
+ if (!hasTests) {
148
+ risk += 25
149
+ reasons.push('no nearby tests')
150
+ }
151
+ if (changeFrequency >= 8) {
152
+ risk += 20
153
+ reasons.push('frequently changed file')
154
+ }
155
+ if (file.score >= 50) {
156
+ risk += 15
157
+ reasons.push('high drift score')
158
+ }
159
+
160
+ return {
161
+ file: file.path,
162
+ driftScore: file.score,
163
+ complexityIssues,
164
+ hasNearbyTests: hasTests,
165
+ changeFrequency,
166
+ risk: clamp(risk, 0, 100),
167
+ reasons,
168
+ }
169
+ })
170
+ .filter((hotspot) => hotspot.risk > 0)
171
+ .sort((a, b) => b.risk - a.risk)
172
+ .slice(0, 10)
173
+
174
+ const highComplexityFiles = hotspots.filter((hotspot) => hotspot.complexityIssues > 0).length
175
+ const filesWithoutNearbyTests = hotspots.filter((hotspot) => !hotspot.hasNearbyTests).length
176
+ const frequentChangeFiles = hotspots.filter((hotspot) => hotspot.changeFrequency >= 8).length
177
+
178
+ const score = hotspots.length === 0
179
+ ? 0
180
+ : Math.round(hotspots.reduce((sum, hotspot) => sum + hotspot.risk, 0) / hotspots.length)
181
+
182
+ const level = score >= 75
183
+ ? 'critical'
184
+ : score >= 55
185
+ ? 'high'
186
+ : score >= 30
187
+ ? 'medium'
188
+ : 'low'
189
+
190
+ return {
191
+ score,
192
+ level,
193
+ hotspots,
194
+ signals: {
195
+ highComplexityFiles,
196
+ filesWithoutNearbyTests,
197
+ frequentChangeFiles,
198
+ },
199
+ }
200
+ }
package/src/plugins.ts ADDED
@@ -0,0 +1,76 @@
1
+ import { existsSync } from 'node:fs'
2
+ import { isAbsolute, resolve } from 'node:path'
3
+ import { createRequire } from 'node:module'
4
+ import type { DriftPlugin, PluginLoadError, LoadedPlugin } from './types.js'
5
+
6
+ const require = createRequire(import.meta.url)
7
+
8
+ function isPluginShape(value: unknown): value is DriftPlugin {
9
+ if (!value || typeof value !== 'object') return false
10
+ const candidate = value as Partial<DriftPlugin>
11
+ if (typeof candidate.name !== 'string') return false
12
+ if (!Array.isArray(candidate.rules)) return false
13
+ return candidate.rules.every((rule) =>
14
+ rule &&
15
+ typeof rule === 'object' &&
16
+ typeof rule.name === 'string' &&
17
+ typeof rule.detect === 'function'
18
+ )
19
+ }
20
+
21
+ function normalizePluginExport(mod: unknown): DriftPlugin | undefined {
22
+ if (isPluginShape(mod)) return mod
23
+ if (mod && typeof mod === 'object' && 'default' in mod) {
24
+ const maybeDefault = (mod as { default?: unknown }).default
25
+ if (isPluginShape(maybeDefault)) return maybeDefault
26
+ }
27
+ return undefined
28
+ }
29
+
30
+ function resolvePluginSpecifier(projectRoot: string, pluginId: string): string {
31
+ if (pluginId.startsWith('.') || pluginId.startsWith('/')) {
32
+ const abs = isAbsolute(pluginId) ? pluginId : resolve(projectRoot, pluginId)
33
+ if (existsSync(abs)) return abs
34
+ if (existsSync(`${abs}.js`)) return `${abs}.js`
35
+ if (existsSync(`${abs}.cjs`)) return `${abs}.cjs`
36
+ if (existsSync(`${abs}.mjs`)) return `${abs}.mjs`
37
+ if (existsSync(`${abs}.ts`)) return `${abs}.ts`
38
+ return abs
39
+ }
40
+ return pluginId
41
+ }
42
+
43
+ export function loadPlugins(projectRoot: string, pluginIds: string[] | undefined): {
44
+ plugins: LoadedPlugin[]
45
+ errors: PluginLoadError[]
46
+ } {
47
+ if (!pluginIds || pluginIds.length === 0) {
48
+ return { plugins: [], errors: [] }
49
+ }
50
+
51
+ const loaded: LoadedPlugin[] = []
52
+ const errors: PluginLoadError[] = []
53
+
54
+ for (const pluginId of pluginIds) {
55
+ const resolved = resolvePluginSpecifier(projectRoot, pluginId)
56
+ try {
57
+ const mod = require(resolved)
58
+ const plugin = normalizePluginExport(mod)
59
+ if (!plugin) {
60
+ errors.push({
61
+ pluginId,
62
+ message: `Invalid plugin contract in '${pluginId}'. Expected: { name, rules[] }`,
63
+ })
64
+ continue
65
+ }
66
+ loaded.push({ id: pluginId, plugin })
67
+ } catch (error) {
68
+ errors.push({
69
+ pluginId,
70
+ message: error instanceof Error ? error.message : String(error),
71
+ })
72
+ }
73
+ }
74
+
75
+ return { plugins: loaded, errors }
76
+ }
package/src/printer.ts CHANGED
@@ -113,6 +113,26 @@ function formatFixSuggestion(issue: DriftIssue): string[] {
113
113
  'Pick one naming convention (camelCase for variables/functions, PascalCase for types)',
114
114
  'Rename snake_case identifiers to camelCase to match TypeScript conventions',
115
115
  ],
116
+ 'controller-no-db': [
117
+ 'Move DB access to a service/repository and inject it into the controller',
118
+ 'Keep controllers focused on transport and orchestration only',
119
+ ],
120
+ 'service-no-http': [
121
+ 'Move HTTP concerns to adapters/clients and keep services framework-agnostic',
122
+ 'Inject interfaces for outbound calls instead of calling fetch/express directly',
123
+ ],
124
+ 'max-function-lines': [
125
+ 'Split the function into smaller units with clear responsibilities',
126
+ 'Extract branch-heavy chunks into dedicated helpers',
127
+ ],
128
+ 'ai-code-smell': [
129
+ 'Address the listed AI-smell signals in this file before adding more code',
130
+ 'Prioritize consistency: naming, error handling, and abstraction level',
131
+ ],
132
+ 'plugin-error': [
133
+ 'Fix or remove the failing plugin in drift.config.*',
134
+ 'Validate plugin contract: export { name, rules[] } and detector functions',
135
+ ],
116
136
  }
117
137
  return suggestions[issue.rule] ?? ['Review and fix manually']
118
138
  }