prunelle 0.1.1 → 0.5.2

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 (105) hide show
  1. package/llms.txt +23 -19
  2. package/package.json +8 -2
  3. package/src/a11y/declaration.ts +335 -0
  4. package/src/a11y/index.ts +446 -0
  5. package/src/a11y/rgaa-map.ts +184 -0
  6. package/src/attrs.ts +11 -3
  7. package/src/build/bundle.ts +80 -36
  8. package/src/build/client-entries.ts +3 -2
  9. package/src/build/client-plugin.ts +8 -4
  10. package/src/build/client-prune.ts +56 -6
  11. package/src/build/compile.ts +11 -9
  12. package/src/build/ecoindex.ts +229 -0
  13. package/src/build/index.ts +174 -108
  14. package/src/build/islands.ts +2 -2
  15. package/src/build/manifest.ts +66 -5
  16. package/src/build/output.ts +2 -2
  17. package/src/build/plugin-host.ts +91 -33
  18. package/src/build/precompress.ts +15 -2
  19. package/src/build/prerender.ts +128 -46
  20. package/src/build/report.ts +23 -2
  21. package/src/build/resolve.ts +8 -6
  22. package/src/build/routes.ts +175 -10
  23. package/src/build/static.ts +137 -39
  24. package/src/build/status-pages.ts +127 -0
  25. package/src/build/style-bundles.ts +526 -0
  26. package/src/cli/check-forms.ts +654 -0
  27. package/src/cli/check-links.ts +619 -0
  28. package/src/cli/check.ts +52 -5
  29. package/src/cli/commands.ts +86 -4
  30. package/src/cli/docs.ts +402 -0
  31. package/src/cli/inspect.ts +31 -2
  32. package/src/cli/mcp-tools.ts +480 -0
  33. package/src/cli/mcp.ts +205 -0
  34. package/src/cli/new.ts +2 -2
  35. package/src/cli/render.ts +261 -0
  36. package/src/cli/upgrade-names.ts +73 -13
  37. package/src/cli/upgrade.ts +137 -16
  38. package/src/compiler/analyze.ts +20 -6
  39. package/src/compiler/cacheability.ts +592 -0
  40. package/src/compiler/compliance-rgaa.ts +502 -0
  41. package/src/compiler/compliance.ts +120 -221
  42. package/src/compiler/dev-source.ts +87 -0
  43. package/src/compiler/dom-attrs.ts +138 -65
  44. package/src/compiler/dom.ts +12 -11
  45. package/src/compiler/expr-context.ts +167 -57
  46. package/src/compiler/props.ts +87 -36
  47. package/src/compiler/scope.ts +56 -17
  48. package/src/compiler/ssr-prunelle-tags.ts +27 -14
  49. package/src/compiler/ssr.ts +216 -84
  50. package/src/dev/error-log.ts +151 -0
  51. package/src/dev/index.ts +84 -34
  52. package/src/dev/open-editor.ts +204 -0
  53. package/src/dev/protocol.ts +1 -0
  54. package/src/dev/reload.ts +5 -3
  55. package/src/dev/supervisor.ts +42 -25
  56. package/src/dev/watchers.ts +47 -11
  57. package/src/dom/action.ts +4 -1
  58. package/src/dom/attrs.ts +15 -3
  59. package/src/dom/extras.ts +2 -2
  60. package/src/dom/island.ts +11 -10
  61. package/src/plugins/config.ts +4 -4
  62. package/src/plugins/index.ts +2 -2
  63. package/src/plugins/public.ts +5 -2
  64. package/src/plugins/services.ts +62 -0
  65. package/src/plugins/types.ts +32 -0
  66. package/src/server/action-protect.ts +198 -0
  67. package/src/server/action-registry.ts +1 -1
  68. package/src/server/action.ts +82 -27
  69. package/src/server/assets.ts +34 -2
  70. package/src/server/compress.ts +91 -9
  71. package/src/server/errors.ts +303 -65
  72. package/src/server/form-schema.ts +343 -0
  73. package/src/server/health.ts +244 -0
  74. package/src/server/http.ts +128 -31
  75. package/src/server/index.ts +230 -260
  76. package/src/server/loader.ts +5 -0
  77. package/src/server/param-matchers.ts +112 -0
  78. package/src/server/plugin-host.ts +123 -88
  79. package/src/server/public.ts +3 -3
  80. package/src/server/rate-limit.ts +58 -35
  81. package/src/server/request-body.ts +1 -1
  82. package/src/server/route-cache.ts +423 -0
  83. package/src/server/route-table.ts +339 -8
  84. package/src/server/router.ts +125 -40
  85. package/src/server/routing.ts +196 -63
  86. package/src/server/security.ts +208 -32
  87. package/src/server/serve-handlers.ts +21 -7
  88. package/src/server/start.ts +60 -16
  89. package/src/server/static-dir.ts +61 -8
  90. package/src/server/stream.ts +41 -22
  91. package/src/ssr/context.ts +85 -3
  92. package/src/ssr/index.ts +120 -1
  93. package/src/ssr/region.ts +31 -19
  94. package/src/test/browser.ts +6 -0
  95. package/src/test/index.ts +17 -3
  96. package/src/ts-plugin/diagnostics.ts +378 -0
  97. package/src/ts-plugin/fixes.ts +364 -0
  98. package/src/ts-plugin/index.ts +194 -0
  99. package/templates/_shared/AGENTS.md +2 -2
  100. package/templates/_shared/mcp.json +11 -0
  101. package/templates/_shared/src/routes/legal.tsx +5 -0
  102. package/templates/_shared/tsconfig.json +5 -0
  103. package/templates/blog/prunelle.config.ts +1 -1
  104. package/templates/blog/src/routes/index.tsx +4 -0
  105. package/ts-plugin.cjs +4277 -0
package/src/test/index.ts CHANGED
@@ -2,12 +2,14 @@
2
2
 
3
3
  import type { BuildManifest, BuildOptions } from '../build/index'
4
4
  import type { PrunelleApp, ServerAction, ServerRuntimeConfig } from '../server/index'
5
- import { readdirSync, rmSync } from 'node:fs'
5
+ import { existsSync, readdirSync, rmSync } from 'node:fs'
6
6
  import { dirname, join, resolve } from 'node:path'
7
7
  import { build } from '../build/index'
8
8
  import { relPosix } from '../build/files'
9
9
  import { processSuffix, removeDeadProcessDirs } from '../build/output'
10
+ import { ensureCacheGitignore } from '../build/precompress'
10
11
  import { resolveServerConfig } from '../server/index'
12
+ import { FORM_TIMESTAMP_FIELD, honeypotFieldName, signFormTimestamp } from '../server/action-protect'
11
13
  import { startBuiltApp } from '../server/loader'
12
14
 
13
15
  const TEST_DIR_PREFIX = 'test-'
@@ -41,12 +43,17 @@ const ownOutDirs: string[] = []
41
43
  function ownOutDir(root: string): string {
42
44
  const cacheDir = join(root, '.prunelle-cache')
43
45
  removeDeadProcessDirs(cacheDir, TEST_DIR_PREFIX)
46
+ ensureCacheGitignore(cacheDir)
44
47
  if (ownOutDirs.length === 0) {
45
48
  process.once('exit', () => {
46
49
  for (const dir of ownOutDirs) {
47
50
  rmSync(dir, { recursive: true, force: true })
48
- if (readdirSync(dirname(dir)).length === 0)
49
- rmSync(dirname(dir), { recursive: true, force: true })
51
+ const parent = dirname(dir)
52
+ if (!existsSync(parent))
53
+ continue
54
+ const remaining = readdirSync(parent)
55
+ if (remaining.length === 0 || (remaining.length === 1 && remaining[0] === '.gitignore'))
56
+ rmSync(parent, { recursive: true, force: true })
50
57
  }
51
58
  })
52
59
  }
@@ -162,6 +169,13 @@ export async function testApp(options: TestAppOptions): Promise<TestApp> {
162
169
  const fd = new FormData()
163
170
  for (const [k, v] of Object.entries(fields))
164
171
  fd.append(k, v)
172
+ if (typeof action !== 'string' && action.protect !== undefined) {
173
+ const hp = honeypotFieldName(action.protect)
174
+ if (hp !== undefined && !Object.hasOwn(fields, hp))
175
+ fd.append(hp, '')
176
+ if (action.protect.minTime !== undefined && !Object.hasOwn(fields, FORM_TIMESTAMP_FIELD))
177
+ fd.append(FORM_TIMESTAMP_FIELD, signFormTimestamp(Date.now() - Math.max(0, action.protect.minTime) - 1000, actionUrl))
178
+ }
165
179
  const h = new Headers(headers)
166
180
  if (!h.has('origin'))
167
181
  h.set('origin', 'http://localhost')
@@ -0,0 +1,378 @@
1
+ // Runs Prunelle's single-file compiler & compliance checks and maps them to TypeScript diagnostics.
2
+
3
+ import type { Node, Program } from 'oxc-parser'
4
+ import type ts from 'typescript'
5
+ import type { ComplianceConfig, ComplianceRule } from '../compiler/compliance'
6
+ import type { PrunelleFixDescriptor } from './fixes'
7
+ import { existsSync, readFileSync, statSync } from 'node:fs'
8
+ import { dirname, join, resolve } from 'node:path'
9
+ import { parseSync } from 'oxc-parser'
10
+ import { isInNodeModules, relPosix } from '../build/files'
11
+ import { analyzeModule, parseTsx } from '../compiler/analyze'
12
+ import { walk } from '../compiler/ast'
13
+ import { shouldEmitWarning } from '../compiler/compliance'
14
+ import { collectMistakes, PrunelleMistake } from '../compiler/mistakes'
15
+ import { unwrapTsExpr } from '../compiler/shared'
16
+ import { checkBareSignals } from '../compiler/signal-reads'
17
+ import { classifyMistakeFix, classifyWarningFix, PRUNELLE_CODE } from './fixes'
18
+
19
+ export const PRUNELLE_DIAG_SOURCE = 'prunelle'
20
+
21
+ const TS_EXT_RE = /\.[cm]?tsx?$/i
22
+ const DTS_EXT_RE = /\.d\.[cm]?ts$/i
23
+ const SIGNAL_HINT_RE = /\b(?:signal|computed)\b/
24
+ const EMPTY_SET: ReadonlySet<string> = new Set()
25
+ const REL_EXTS = ['', '.ts', '.tsx', '/index.ts', '/index.tsx']
26
+ const TOKEN_RE = /^[A-Za-z_$][\w$-]*(?::[A-Za-z_$][\w$-]*)?|^'[^'\r\n]*'|^"[^"\r\n]*"|^<[A-Za-z_$][\w$.-]*/
27
+
28
+ export interface PrunellePluginOptions {
29
+ projectRoot?: string | undefined
30
+ compliance?: ComplianceConfig | undefined
31
+ site?: string | undefined
32
+ /** Optional file reader (e.g. from ts.LanguageServiceHost) used to resolve imported signal exports. */
33
+ readFile?: ((path: string) => string | undefined) | undefined
34
+ }
35
+
36
+ export interface PrunelleDiagnosticItem {
37
+ code: number
38
+ category: 'error' | 'warning'
39
+ start: number
40
+ length: number
41
+ message: string
42
+ fix?: PrunelleFixDescriptor | undefined
43
+ }
44
+
45
+ interface StaticConfigCache {
46
+ mtimeMs: number
47
+ site?: string | undefined
48
+ compliance?: ComplianceConfig | undefined
49
+ }
50
+
51
+ const configCache = new Map<string, StaticConfigCache>()
52
+
53
+ /** True when `fileName` is a project `.ts`/`.tsx` source file eligible for Prunelle analysis. */
54
+ export function isCheckableFile(fileName: string): boolean {
55
+ return TS_EXT_RE.test(fileName) && !DTS_EXT_RE.test(fileName) && !isInNodeModules(fileName)
56
+ }
57
+
58
+ function propKeyName(node: Node): string | undefined {
59
+ if (node.type === 'Identifier')
60
+ return node.name
61
+ if (node.type === 'Literal' && typeof node.value === 'string')
62
+ return node.value
63
+ return undefined
64
+ }
65
+
66
+ function staticString(node: Node): string | undefined {
67
+ const inner = unwrapTsExpr(node)
68
+ if (inner.type === 'Literal' && typeof inner.value === 'string')
69
+ return inner.value
70
+ return undefined
71
+ }
72
+
73
+ function extractConfigObject(program: Program): Extract<Node, { type: 'ObjectExpression' }> | undefined {
74
+ for (const stmt of program.body) {
75
+ if (stmt.type !== 'ExportDefaultDeclaration')
76
+ continue
77
+ const decl = unwrapTsExpr(stmt.declaration)
78
+ if (decl.type === 'ObjectExpression')
79
+ return decl
80
+ if (decl.type === 'CallExpression' && decl.arguments[0] !== undefined) {
81
+ const arg = unwrapTsExpr(decl.arguments[0])
82
+ if (arg.type === 'ObjectExpression')
83
+ return arg
84
+ }
85
+ }
86
+ return undefined
87
+ }
88
+
89
+ function parseStaticCompliance(node: Node): ComplianceConfig | undefined {
90
+ const obj = unwrapTsExpr(node)
91
+ if (obj.type !== 'ObjectExpression')
92
+ return undefined
93
+ const out: ComplianceConfig = {}
94
+ for (const prop of obj.properties) {
95
+ if (prop.type !== 'Property')
96
+ continue
97
+ const key = propKeyName(prop.key)
98
+ const val = unwrapTsExpr(prop.value)
99
+ if (key === 'publicBody' && val.type === 'Literal' && typeof val.value === 'boolean') {
100
+ out.publicBody = val.value
101
+ }
102
+ else if (key === 'legalNotice' && val.type === 'Literal' && (val.value === false || typeof val.value === 'string')) {
103
+ out.legalNotice = val.value
104
+ }
105
+ else if (key === 'ignore' && val.type === 'ArrayExpression') {
106
+ const rules: ComplianceRule[] = []
107
+ for (const el of val.elements) {
108
+ if (el !== null && el.type !== 'SpreadElement') {
109
+ const s = staticString(el)
110
+ if (s !== undefined)
111
+ rules.push(s as ComplianceRule)
112
+ }
113
+ }
114
+ out.ignore = rules
115
+ }
116
+ }
117
+ return out
118
+ }
119
+
120
+ /** Statically parses `site` and `compliance` literals from `prunelle.config.ts` without executing user code. */
121
+ export function readStaticProjectConfig(projectRoot: string | undefined): { site?: string | undefined, compliance?: ComplianceConfig | undefined } {
122
+ if (projectRoot === undefined || projectRoot === '')
123
+ return {}
124
+ const cfgPath = join(projectRoot, 'prunelle.config.ts')
125
+ if (!existsSync(cfgPath))
126
+ return {}
127
+ let mtimeMs: number
128
+ try {
129
+ mtimeMs = statSync(cfgPath).mtimeMs
130
+ }
131
+ catch {
132
+ return {}
133
+ }
134
+ const cached = configCache.get(cfgPath)
135
+ if (cached !== undefined && cached.mtimeMs === mtimeMs)
136
+ return { site: cached.site, compliance: cached.compliance }
137
+
138
+ let site: string | undefined
139
+ let compliance: ComplianceConfig | undefined
140
+ try {
141
+ const code = readFileSync(cfgPath, 'utf8')
142
+ const parsed = parseSync(cfgPath, code, { lang: 'ts', sourceType: 'module' })
143
+ const obj = parsed.errors.length === 0 ? extractConfigObject(parsed.program) : undefined
144
+ if (obj !== undefined) {
145
+ for (const prop of obj.properties) {
146
+ if (prop.type !== 'Property')
147
+ continue
148
+ const key = propKeyName(prop.key)
149
+ if (key === 'site')
150
+ site = staticString(prop.value)
151
+ else if (key === 'compliance')
152
+ compliance = parseStaticCompliance(prop.value)
153
+ }
154
+ }
155
+ }
156
+ catch {
157
+ return {}
158
+ }
159
+ configCache.set(cfgPath, { mtimeMs, site, compliance })
160
+ return { site, compliance }
161
+ }
162
+
163
+ function indexNodesAtOffsets(program: Program, offsets: ReadonlySet<number>): Map<number, Node[]> {
164
+ const byOffset = new Map<number, Node[]>()
165
+ if (offsets.size === 0)
166
+ return byOffset
167
+ walk(program, (node) => {
168
+ if (!offsets.has(node.start))
169
+ return
170
+ let list = byOffset.get(node.start)
171
+ if (list === undefined) {
172
+ list = []
173
+ byOffset.set(node.start, list)
174
+ }
175
+ list.push(node)
176
+ })
177
+ return byOffset
178
+ }
179
+
180
+ function clampSingleLine(code: string, start: number, end: number): { start: number, length: number } {
181
+ const safeStart = Math.max(0, Math.min(start, code.length))
182
+ const safeEnd = Math.max(safeStart, Math.min(end, code.length))
183
+ const nl = code.indexOf('\n', safeStart)
184
+ const effectiveEnd = nl !== -1 && nl < safeEnd ? nl : safeEnd
185
+ return { start: safeStart, length: Math.max(1, effectiveEnd - safeStart) }
186
+ }
187
+
188
+ function spanFromNodes(nodes: readonly Node[], code: string, start: number): { start: number, length: number } {
189
+ for (const node of nodes) {
190
+ if (node.type === 'JSXAttribute')
191
+ return clampSingleLine(code, node.start, node.end)
192
+ if (node.type === 'JSXElement') {
193
+ const opening = node.openingElement
194
+ const hasNewline = code.slice(opening.start, opening.end).includes('\n')
195
+ return clampSingleLine(code, opening.start, hasNewline ? opening.name.end : opening.end)
196
+ }
197
+ if (node.type === 'JSXOpeningElement') {
198
+ const hasNewline = code.slice(node.start, node.end).includes('\n')
199
+ return clampSingleLine(code, node.start, hasNewline ? node.name.end : node.end)
200
+ }
201
+ if (node.type === 'ImportSpecifier' || node.type === 'ExpressionStatement' || node.type === 'Literal' || node.type === 'MemberExpression' || node.type === 'Identifier' || node.type === 'CallExpression' || node.type === 'VariableDeclarator')
202
+ return clampSingleLine(code, node.start, node.end)
203
+ if (node.type === 'ArrowFunctionExpression' || node.type === 'FunctionExpression')
204
+ return clampSingleLine(code, node.start, node.end)
205
+ }
206
+ const safeStart = Math.max(0, Math.min(start, Math.max(0, code.length - 1)))
207
+ const match = TOKEN_RE.exec(code.slice(safeStart))
208
+ const length = match !== null ? match[0].length : Math.min(1, Math.max(0, code.length - safeStart))
209
+ return { start: safeStart, length: Math.max(1, length) }
210
+ }
211
+
212
+ function normalizeDisplayPath(fileName: string, projectRoot: string | undefined): string {
213
+ if (projectRoot === undefined || projectRoot === '')
214
+ return fileName
215
+ const rel = relPosix(projectRoot, fileName)
216
+ return rel !== '' ? rel : fileName
217
+ }
218
+
219
+ function mergeCompliance(base: ComplianceConfig | undefined, override: ComplianceConfig | undefined): ComplianceConfig | undefined {
220
+ if (base === undefined)
221
+ return override
222
+ if (override === undefined)
223
+ return base
224
+ return {
225
+ ignore: override.ignore ?? base.ignore,
226
+ publicBody: override.publicBody ?? base.publicBody,
227
+ legalNotice: override.legalNotice ?? base.legalNotice,
228
+ }
229
+ }
230
+
231
+ function resolveRelativeSource(fromFile: string, specifier: string, readFile: (path: string) => string | undefined): { path: string, code: string } | undefined {
232
+ const base = resolve(dirname(fromFile), specifier)
233
+ const stripped = base.replace(/\.[cm]?js$/i, '')
234
+ for (const ext of REL_EXTS) {
235
+ const candidate = `${stripped}${ext}`
236
+ if (!TS_EXT_RE.test(candidate))
237
+ continue
238
+ const code = readFile(candidate)
239
+ if (code !== undefined)
240
+ return { path: candidate, code }
241
+ }
242
+ return undefined
243
+ }
244
+
245
+ function collectImportedSignalMistakes(
246
+ fileName: string,
247
+ program: Program,
248
+ imports: readonly { source: string, specifiers: readonly { local: string, imported: string }[] }[],
249
+ readFile: ((path: string) => string | undefined) | undefined,
250
+ ): PrunelleMistake[] {
251
+ if (readFile === undefined)
252
+ return []
253
+ const importedSignals = new Set<string>()
254
+ const importedSignalMembers = new Map<string, Set<string>>()
255
+ for (const imp of imports) {
256
+ if (!imp.source.startsWith('./') && !imp.source.startsWith('../'))
257
+ continue
258
+ const resolved = resolveRelativeSource(fileName, imp.source, readFile)
259
+ if (resolved === undefined || !SIGNAL_HINT_RE.test(resolved.code))
260
+ continue
261
+ let depProgram: Program
262
+ try {
263
+ depProgram = parseTsx(resolved.path, resolved.code)
264
+ }
265
+ catch {
266
+ continue
267
+ }
268
+ const { value: dep } = collectMistakes(() => analyzeModule(resolved.path, resolved.code, depProgram))
269
+ if (dep === undefined || dep.signalExports.length === 0)
270
+ continue
271
+ const exported = new Set(dep.signalExports)
272
+ for (const spec of imp.specifiers) {
273
+ if (spec.imported === '*') {
274
+ importedSignalMembers.set(spec.local, exported)
275
+ }
276
+ else if (exported.has(spec.imported)) {
277
+ importedSignals.add(spec.local)
278
+ }
279
+ }
280
+ }
281
+ if (importedSignals.size === 0 && importedSignalMembers.size === 0)
282
+ return []
283
+ return collectMistakes(() => checkBareSignals(program, EMPTY_SET, fileName, importedSignals, importedSignalMembers)).mistakes
284
+ }
285
+
286
+ /** Runs Prunelle compiler & compliance checks on one TS/TSX file and returns positioned diagnostics + mechanical fixes. */
287
+ export function collectPrunelleDiagnostics(
288
+ fileName: string,
289
+ code: string,
290
+ options: PrunellePluginOptions = {},
291
+ ): PrunelleDiagnosticItem[] {
292
+ if (!isCheckableFile(fileName))
293
+ return []
294
+
295
+ let program: Program
296
+ try {
297
+ program = parseTsx(fileName, code)
298
+ }
299
+ catch {
300
+ // While the user is typing incomplete syntax, TypeScript's syntactic diagnostics report it already.
301
+ return []
302
+ }
303
+
304
+ const { value, mistakes, error } = collectMistakes(() => analyzeModule(fileName, code, program))
305
+ const allMistakes = [...mistakes]
306
+ if (error instanceof PrunelleMistake)
307
+ allMistakes.push(error)
308
+ if (value !== undefined)
309
+ allMistakes.push(...collectImportedSignalMistakes(fileName, program, value.imports, options.readFile))
310
+
311
+ const staticCfg = options.compliance !== undefined && options.site !== undefined
312
+ ? {}
313
+ : readStaticProjectConfig(options.projectRoot)
314
+ const compliance = mergeCompliance(staticCfg.compliance, options.compliance)
315
+ const site = options.site ?? staticCfg.site
316
+
317
+ const activeWarnings = (value?.warnings ?? []).filter(w => shouldEmitWarning(w, compliance, site))
318
+ if (allMistakes.length === 0 && activeWarnings.length === 0)
319
+ return []
320
+
321
+ const offsets = new Set<number>()
322
+ for (const m of allMistakes)
323
+ offsets.add(m.start ?? 0)
324
+ for (const w of activeWarnings)
325
+ offsets.add(w.start)
326
+ const nodesByOffset = indexNodesAtOffsets(program, offsets)
327
+
328
+ const displayFile = normalizeDisplayPath(fileName, options.projectRoot)
329
+ const items: PrunelleDiagnosticItem[] = []
330
+
331
+ for (const m of allMistakes) {
332
+ const start = m.start ?? 0
333
+ const nodes = nodesByOffset.get(start) ?? []
334
+ const classified = classifyMistakeFix(m.message, fileName, nodes, code)
335
+ const span = classified?.diagSpan ?? spanFromNodes(nodes, code, start)
336
+ items.push({
337
+ code: classified?.code ?? PRUNELLE_CODE.ERROR,
338
+ category: 'error',
339
+ start: span.start,
340
+ length: span.length,
341
+ message: m.message.replaceAll(fileName, displayFile),
342
+ ...(classified !== undefined ? { fix: classified.fix } : {}),
343
+ })
344
+ }
345
+
346
+ for (const w of activeWarnings) {
347
+ const nodes = nodesByOffset.get(w.start) ?? []
348
+ const classified = classifyWarningFix(w.message, nodes)
349
+ const span = classified?.diagSpan ?? spanFromNodes(nodes, code, w.start)
350
+ items.push({
351
+ code: classified?.code ?? PRUNELLE_CODE.WARNING,
352
+ category: 'warning',
353
+ start: span.start,
354
+ length: span.length,
355
+ message: w.message.replaceAll(fileName, displayFile),
356
+ ...(classified !== undefined ? { fix: classified.fix } : {}),
357
+ })
358
+ }
359
+
360
+ return items
361
+ }
362
+
363
+ /** Converts a `PrunelleDiagnosticItem` into a TypeScript `ts.Diagnostic`. */
364
+ export function toTsDiagnostic(
365
+ tsLib: typeof ts,
366
+ item: PrunelleDiagnosticItem,
367
+ sourceFile: ts.SourceFile | undefined,
368
+ ): ts.Diagnostic {
369
+ return {
370
+ file: sourceFile,
371
+ start: item.start,
372
+ length: item.length,
373
+ messageText: item.message,
374
+ category: item.category === 'warning' ? tsLib.DiagnosticCategory.Warning : tsLib.DiagnosticCategory.Error,
375
+ code: item.code,
376
+ source: PRUNELLE_DIAG_SOURCE,
377
+ }
378
+ }