@interlace/eslint-devkit 1.3.3 โ 1.4.1
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.
- package/CHANGELOG.md +113 -0
- package/README.md +20 -9
- package/package.json +13 -11
- package/src/aria-definitions.d.ts +5 -0
- package/src/aria-definitions.js +28 -1
- package/src/index.d.ts +1 -0
- package/src/index.js +4 -0
- package/src/messaging/formatters-ai.d.ts +22 -3
- package/src/messaging/formatters-v2.d.ts +84 -0
- package/src/messaging/formatters-v2.js +363 -0
- package/src/messaging/types-v2.d.ts +112 -0
- package/src/messaging/types-v2.js +7 -0
- package/src/node/path.js +29 -5
- package/src/resolver/dependency-analysis.d.ts +73 -11
- package/src/resolver/dependency-analysis.js +375 -84
- package/src/resolver/resolver-adapter.js +1 -0
- package/src/resolver/resolver-detection.js +16 -11
- package/src/resolver/resolver.d.ts +6 -26
- package/src/resolver/resolver.js +162 -185
- package/src/security/security-utils.js +3 -3
- package/src/types/index.d.ts +1 -0
- package/src/types/index.js +4 -0
- package/src/types/meta-augmentation.d.ts +44 -0
- package/src/types/meta-augmentation.js +7 -0
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.formatSecurityMessage = formatSecurityMessage;
|
|
9
|
+
exports.formatCodeQualityMessage = formatCodeQualityMessage;
|
|
10
|
+
exports.formatPerformanceMessage = formatPerformanceMessage;
|
|
11
|
+
const constants_1 = require("./constants");
|
|
12
|
+
// ============================================================================
|
|
13
|
+
// SHARED UTILITIES
|
|
14
|
+
// ============================================================================
|
|
15
|
+
/** Icons for each category */
|
|
16
|
+
const CATEGORY_ICONS = {
|
|
17
|
+
security: '๐',
|
|
18
|
+
'circular-dependency': '๐',
|
|
19
|
+
'unused-import': '๐งน',
|
|
20
|
+
'barrel-file': '๐ฆ',
|
|
21
|
+
'dependency-boundary': '๐ง',
|
|
22
|
+
'import-order': '๐',
|
|
23
|
+
'naming-convention': 'โ๏ธ',
|
|
24
|
+
'dead-code': '๐',
|
|
25
|
+
performance: 'โก',
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Compact-mode severity strings. Measured against `tiktoken` o200k_base:
|
|
29
|
+
* CRITICAL โ CRIT saves 0 tokens (both 2)
|
|
30
|
+
* MEDIUM โ MED saves 1 token (2 โ 1)
|
|
31
|
+
* HIGH/LOW/INFO already 1 token
|
|
32
|
+
* The abbreviations are kept primarily for visual width consistency in
|
|
33
|
+
* compact mode, not for measurable token savings.
|
|
34
|
+
*/
|
|
35
|
+
const SEVERITY_SHORT = {
|
|
36
|
+
CRITICAL: 'CRIT',
|
|
37
|
+
HIGH: 'HIGH',
|
|
38
|
+
MEDIUM: 'MED',
|
|
39
|
+
LOW: 'LOW',
|
|
40
|
+
INFO: 'INFO',
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Renders the optional `why` line.
|
|
44
|
+
*/
|
|
45
|
+
function renderWhy(why) {
|
|
46
|
+
return why ? `\n Why: ${why}` : '';
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Renders the optional vulnerable/safe code examples.
|
|
50
|
+
*/
|
|
51
|
+
function renderExamples(vulnerable, safe) {
|
|
52
|
+
const parts = [];
|
|
53
|
+
if (vulnerable)
|
|
54
|
+
parts.push(` โ ${vulnerable}`);
|
|
55
|
+
if (safe)
|
|
56
|
+
parts.push(` โ ${safe}`);
|
|
57
|
+
return parts.length > 0 ? '\n' + parts.join('\n') : '';
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Renders inline examples for compact mode (same line as fix).
|
|
61
|
+
*/
|
|
62
|
+
function renderInlineExamples(vulnerable, safe) {
|
|
63
|
+
const parts = [];
|
|
64
|
+
if (vulnerable)
|
|
65
|
+
parts.push(`โ ${vulnerable}`);
|
|
66
|
+
if (safe)
|
|
67
|
+
parts.push(`โ ${safe}`);
|
|
68
|
+
return parts.length > 0 ? ' | ' + parts.join(' ') : '';
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Renders the optional docs link suffix.
|
|
72
|
+
*/
|
|
73
|
+
function renderDocs(docs) {
|
|
74
|
+
return docs ? ` | ${docs}` : '';
|
|
75
|
+
}
|
|
76
|
+
// ============================================================================
|
|
77
|
+
// SECURITY FORMATTER
|
|
78
|
+
// ============================================================================
|
|
79
|
+
/**
|
|
80
|
+
* Auto-enriches security options with CWE benchmark data.
|
|
81
|
+
*/
|
|
82
|
+
function enrichSecurity(options) {
|
|
83
|
+
if (!options.cwe)
|
|
84
|
+
return options;
|
|
85
|
+
const cweData = constants_1.CWE_MAPPING[options.cwe];
|
|
86
|
+
if (!cweData)
|
|
87
|
+
return options;
|
|
88
|
+
return {
|
|
89
|
+
...options,
|
|
90
|
+
owasp: options.owasp ?? cweData.owasp,
|
|
91
|
+
cvss: options.cvss ?? cweData.cvss,
|
|
92
|
+
compliance: options.compliance ?? constants_1.CWE_COMPLIANCE_MAPPING[options.cwe],
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Builds the standards reference string (CWE, OWASP, CVSS).
|
|
97
|
+
*/
|
|
98
|
+
function buildStandards(cwe, owasp, cvss) {
|
|
99
|
+
const parts = [];
|
|
100
|
+
if (cwe)
|
|
101
|
+
parts.push(cwe);
|
|
102
|
+
if (owasp) {
|
|
103
|
+
const owaspCode = owasp.split(':')[0];
|
|
104
|
+
const owaspDetails = constants_1.OWASP_DETAILS[owasp];
|
|
105
|
+
const owaspName = owaspDetails?.name?.split(' ')[0] || '';
|
|
106
|
+
parts.push(`OWASP:${owaspCode}-${owaspName}`);
|
|
107
|
+
}
|
|
108
|
+
if (cvss !== undefined)
|
|
109
|
+
parts.push(`CVSS:${cvss}`);
|
|
110
|
+
return parts.length > 0 ? `${parts.join(' ')} | ` : '';
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Builds compact standards (CWE + CVSS only). Drops OWASP and compliance,
|
|
114
|
+
* which together cost ~27 tokens in a typical SQLi rule (measured with
|
|
115
|
+
* `tiktoken` o200k_base). LLMs already know what `CWE-89` means; the
|
|
116
|
+
* spelled-out `OWASP:A05-Injection [SOC2,PCI-DSS,HIPAA,ISO27001]` block
|
|
117
|
+
* is GRC-dashboard ergonomics, not agent fuel.
|
|
118
|
+
*/
|
|
119
|
+
function buildCompactStandards(cwe, cvss) {
|
|
120
|
+
const parts = [];
|
|
121
|
+
if (cwe)
|
|
122
|
+
parts.push(cwe);
|
|
123
|
+
if (cvss !== undefined)
|
|
124
|
+
parts.push(`${cvss}`);
|
|
125
|
+
return parts.length > 0 ? `${parts.join(' ')} ` : '';
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Builds the compliance tag string.
|
|
129
|
+
*/
|
|
130
|
+
function buildCompliance(compliance) {
|
|
131
|
+
return compliance && compliance.length > 0
|
|
132
|
+
? ` [${compliance.slice(0, 4).join(',')}]`
|
|
133
|
+
: '';
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Formats a security-focused rule message.
|
|
137
|
+
*
|
|
138
|
+
* Supports three output modes:
|
|
139
|
+
* - `'human'` (default): Rich multi-line with OWASP, compliance, examples
|
|
140
|
+
* - `'compact'`: Token-optimized two-line (CWE+CVSS, inline examples)
|
|
141
|
+
* - `'agent'`: Minified JSON with self-describing keys
|
|
142
|
+
*
|
|
143
|
+
* Tokens measured with `tiktoken` o200k_base on the example below:
|
|
144
|
+
* human=120, compact=65, agent=72. (V1 baseline for the same content
|
|
145
|
+
* minus `why`/`vulnerable`/`safe`: 69 tokens.)
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* // Human mode (~120 tokens)
|
|
150
|
+
* formatSecurityMessage({
|
|
151
|
+
* cwe: 'CWE-89', severity: 'CRITICAL',
|
|
152
|
+
* description: 'SQL injection via string concatenation',
|
|
153
|
+
* why: 'Attackers can modify the query structure',
|
|
154
|
+
* vulnerable: "db.query('SELECT...' + userId)",
|
|
155
|
+
* safe: "db.query('SELECT...$1', [userId])",
|
|
156
|
+
* fix: 'Use parameterized queries ($1, $2)',
|
|
157
|
+
* docs: 'https://node-postgres.com/...',
|
|
158
|
+
* });
|
|
159
|
+
*
|
|
160
|
+
* // Compact mode (~65 tokens โ actually cheaper than V1)
|
|
161
|
+
* formatSecurityMessage({ ...same... }, 'compact');
|
|
162
|
+
*
|
|
163
|
+
* // Agent mode (~72 tokens)
|
|
164
|
+
* formatSecurityMessage({ ...same... }, 'agent');
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
function formatSecurityMessage(options, mode = 'human') {
|
|
168
|
+
const enriched = enrichSecurity(options);
|
|
169
|
+
if (mode === 'agent') {
|
|
170
|
+
return securityToAgentJSON(enriched);
|
|
171
|
+
}
|
|
172
|
+
if (mode === 'compact') {
|
|
173
|
+
return securityToCompact(enriched);
|
|
174
|
+
}
|
|
175
|
+
return securityToHuman(enriched);
|
|
176
|
+
}
|
|
177
|
+
/** Human mode: rich, multi-line */
|
|
178
|
+
function securityToHuman(enriched) {
|
|
179
|
+
const { cwe, owasp, cvss, compliance, description, severity, fix, docs, why, vulnerable, safe } = enriched;
|
|
180
|
+
const icon = CATEGORY_ICONS['security'];
|
|
181
|
+
const standardsPart = buildStandards(cwe, owasp, cvss);
|
|
182
|
+
const compliancePart = buildCompliance(compliance);
|
|
183
|
+
const line1 = `${icon} ${standardsPart}${description} | ${severity}${compliancePart}`;
|
|
184
|
+
const whyLine = renderWhy(why);
|
|
185
|
+
const fixLine = `\n Fix: ${fix}${renderDocs(docs)}`;
|
|
186
|
+
const examples = renderExamples(vulnerable, safe);
|
|
187
|
+
return `${line1}${whyLine}${fixLine}${examples}`;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Compact mode: token-optimized two-line.
|
|
191
|
+
* Drops OWASP display, drops compliance tags, inlines examples.
|
|
192
|
+
* Target: ~45 tokens (vs 72 for v1, 124 for full v2).
|
|
193
|
+
*/
|
|
194
|
+
function securityToCompact(enriched) {
|
|
195
|
+
const { cwe, cvss, description, severity, fix, vulnerable, safe } = enriched;
|
|
196
|
+
const sev = SEVERITY_SHORT[severity] || severity;
|
|
197
|
+
const std = buildCompactStandards(cwe, cvss);
|
|
198
|
+
const examples = renderInlineExamples(vulnerable, safe);
|
|
199
|
+
return `${std}${description} | ${sev}\n Fix: ${fix}${examples}`;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Agent mode: minified JSON with self-describing keys.
|
|
203
|
+
* Schema: { id, cvss, description, fix, bad?, good? }
|
|
204
|
+
*
|
|
205
|
+
* Measured with `tiktoken` o200k_base on a realistic SQLi payload, full
|
|
206
|
+
* keys cost only +1 token vs single-letter abbreviations (72 โ 73). The
|
|
207
|
+
* interpretability win for cold-start agents (no system-prompt key
|
|
208
|
+
* dictionary) is worth that token.
|
|
209
|
+
*/
|
|
210
|
+
function securityToAgentJSON(enriched) {
|
|
211
|
+
const obj = {
|
|
212
|
+
id: enriched.cwe,
|
|
213
|
+
cvss: enriched.cvss ?? (0, constants_1.severityToCVSS)(enriched.severity),
|
|
214
|
+
description: enriched.description,
|
|
215
|
+
fix: enriched.fix,
|
|
216
|
+
};
|
|
217
|
+
if (enriched.vulnerable)
|
|
218
|
+
obj['bad'] = enriched.vulnerable;
|
|
219
|
+
if (enriched.safe)
|
|
220
|
+
obj['good'] = enriched.safe;
|
|
221
|
+
return JSON.stringify(obj);
|
|
222
|
+
}
|
|
223
|
+
// ============================================================================
|
|
224
|
+
// CODE QUALITY FORMATTER
|
|
225
|
+
// ============================================================================
|
|
226
|
+
/**
|
|
227
|
+
* Formats a code quality / structural rule message.
|
|
228
|
+
*
|
|
229
|
+
* No CWE/OWASP/CVSS โ these are architecture concerns, not vulnerabilities.
|
|
230
|
+
* Supports cycle path rendering for circular dependency rules.
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```typescript
|
|
234
|
+
* formatCodeQualityMessage({
|
|
235
|
+
* category: 'circular-dependency',
|
|
236
|
+
* severity: 'WARNING',
|
|
237
|
+
* description: 'Circular import detected: A โ B โ C โ A',
|
|
238
|
+
* why: 'Circular imports cause undefined values at import time',
|
|
239
|
+
* cycle: ['src/A.ts', 'src/B.ts', 'src/C.ts', 'src/A.ts'],
|
|
240
|
+
* fix: 'Extract shared types to a separate module',
|
|
241
|
+
* });
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
function formatCodeQualityMessage(options, mode = 'human') {
|
|
245
|
+
if (mode === 'agent') {
|
|
246
|
+
return codeQualityToAgentJSON(options);
|
|
247
|
+
}
|
|
248
|
+
if (mode === 'compact') {
|
|
249
|
+
return codeQualityToCompact(options);
|
|
250
|
+
}
|
|
251
|
+
return codeQualityToHuman(options);
|
|
252
|
+
}
|
|
253
|
+
/** Human mode: rich output with cycle path */
|
|
254
|
+
function codeQualityToHuman(options) {
|
|
255
|
+
const { category, description, severity, fix, docs, why, cycle, vulnerable, safe } = options;
|
|
256
|
+
const icon = CATEGORY_ICONS[category] || '๐';
|
|
257
|
+
const line1 = `${icon} ${description} | ${severity}`;
|
|
258
|
+
const whyLine = renderWhy(why);
|
|
259
|
+
const fixLine = `\n Fix: ${fix}${renderDocs(docs)}`;
|
|
260
|
+
const examples = renderExamples(vulnerable, safe);
|
|
261
|
+
const cycleLine = cycle && cycle.length > 0
|
|
262
|
+
? `\n Cycle: ${cycle.join(' โ ')}`
|
|
263
|
+
: '';
|
|
264
|
+
return `${line1}${whyLine}${fixLine}${examples}${cycleLine}`;
|
|
265
|
+
}
|
|
266
|
+
/** Compact mode: inlined examples, abbreviated severity */
|
|
267
|
+
function codeQualityToCompact(options) {
|
|
268
|
+
const { description, severity, fix, vulnerable, safe, cycle } = options;
|
|
269
|
+
const sev = SEVERITY_SHORT[severity] || severity;
|
|
270
|
+
const examples = renderInlineExamples(vulnerable, safe);
|
|
271
|
+
const cycleSuffix = cycle && cycle.length > 0
|
|
272
|
+
? ` [${cycle.map(f => f.split('/').pop()).join('โ')}]`
|
|
273
|
+
: '';
|
|
274
|
+
return `${description} | ${sev}\n Fix: ${fix}${examples}${cycleSuffix}`;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Agent mode: compact JSON with self-describing keys.
|
|
278
|
+
* Schema: { category, description, fix, cycle?, bad?, good? }
|
|
279
|
+
* Measured: full keys cost 0 extra tokens vs `cat/d/f/cy/b/g` (both 70).
|
|
280
|
+
*/
|
|
281
|
+
function codeQualityToAgentJSON(options) {
|
|
282
|
+
const obj = {
|
|
283
|
+
category: options.category,
|
|
284
|
+
description: options.description,
|
|
285
|
+
fix: options.fix,
|
|
286
|
+
};
|
|
287
|
+
if (options.cycle)
|
|
288
|
+
obj['cycle'] = options.cycle;
|
|
289
|
+
if (options.vulnerable)
|
|
290
|
+
obj['bad'] = options.vulnerable;
|
|
291
|
+
if (options.safe)
|
|
292
|
+
obj['good'] = options.safe;
|
|
293
|
+
return JSON.stringify(obj);
|
|
294
|
+
}
|
|
295
|
+
// ============================================================================
|
|
296
|
+
// PERFORMANCE FORMATTER
|
|
297
|
+
// ============================================================================
|
|
298
|
+
/**
|
|
299
|
+
* Formats a performance-focused rule message.
|
|
300
|
+
*
|
|
301
|
+
* Uses complexity metrics instead of security metadata.
|
|
302
|
+
*
|
|
303
|
+
* @example
|
|
304
|
+
* ```typescript
|
|
305
|
+
* formatPerformanceMessage({
|
|
306
|
+
* severity: 'MEDIUM',
|
|
307
|
+
* description: 'Loop-based INSERT detected โ O(n) database calls',
|
|
308
|
+
* why: 'Each iteration opens a new round-trip, causing Nรlatency',
|
|
309
|
+
* vulnerable: 'for (const row of rows) { await db.query("INSERT...", row); }',
|
|
310
|
+
* safe: 'await db.query("INSERT INTO t VALUES " + values.join(","), flat)',
|
|
311
|
+
* impact: { current: 'O(n) queries', optimized: 'O(1) query' },
|
|
312
|
+
* fix: 'Use bulk INSERT with a single VALUES clause',
|
|
313
|
+
* });
|
|
314
|
+
* ```
|
|
315
|
+
*/
|
|
316
|
+
function formatPerformanceMessage(options, mode = 'human') {
|
|
317
|
+
if (mode === 'agent') {
|
|
318
|
+
return performanceToAgentJSON(options);
|
|
319
|
+
}
|
|
320
|
+
if (mode === 'compact') {
|
|
321
|
+
return performanceToCompact(options);
|
|
322
|
+
}
|
|
323
|
+
return performanceToHuman(options);
|
|
324
|
+
}
|
|
325
|
+
/** Human mode: rich with impact metrics */
|
|
326
|
+
function performanceToHuman(options) {
|
|
327
|
+
const { description, severity, fix, docs, why, vulnerable, safe, impact } = options;
|
|
328
|
+
const icon = CATEGORY_ICONS['performance'];
|
|
329
|
+
const line1 = `${icon} ${description} | ${severity}`;
|
|
330
|
+
const whyLine = renderWhy(why);
|
|
331
|
+
const fixLine = `\n Fix: ${fix}${renderDocs(docs)}`;
|
|
332
|
+
const impactLine = impact
|
|
333
|
+
? `\n Impact: ${impact.current} โ ${impact.optimized}`
|
|
334
|
+
: '';
|
|
335
|
+
const examples = renderExamples(vulnerable, safe);
|
|
336
|
+
return `${line1}${whyLine}${fixLine}${impactLine}${examples}`;
|
|
337
|
+
}
|
|
338
|
+
/** Compact mode: inline impact and examples */
|
|
339
|
+
function performanceToCompact(options) {
|
|
340
|
+
const { description, severity, fix, vulnerable, safe, impact } = options;
|
|
341
|
+
const sev = SEVERITY_SHORT[severity] || severity;
|
|
342
|
+
const impactSuffix = impact ? ` (${impact.current}โ${impact.optimized})` : '';
|
|
343
|
+
const examples = renderInlineExamples(vulnerable, safe);
|
|
344
|
+
return `${description} | ${sev}${impactSuffix}\n Fix: ${fix}${examples}`;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Agent mode: compact JSON with self-describing keys.
|
|
348
|
+
* Schema: { description, fix, impact?: { current, optimized }, bad?, good? }
|
|
349
|
+
* Measured: full keys cost 0 extra tokens vs `d/f/imp{c,o}/b/g` (both 75).
|
|
350
|
+
*/
|
|
351
|
+
function performanceToAgentJSON(options) {
|
|
352
|
+
const obj = {
|
|
353
|
+
description: options.description,
|
|
354
|
+
fix: options.fix,
|
|
355
|
+
};
|
|
356
|
+
if (options.impact)
|
|
357
|
+
obj['impact'] = { current: options.impact.current, optimized: options.impact.optimized };
|
|
358
|
+
if (options.vulnerable)
|
|
359
|
+
obj['bad'] = options.vulnerable;
|
|
360
|
+
if (options.safe)
|
|
361
|
+
obj['good'] = options.safe;
|
|
362
|
+
return JSON.stringify(obj);
|
|
363
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* V2 Message Formatter Types
|
|
8
|
+
*
|
|
9
|
+
* Category-specific message option interfaces for security, code quality,
|
|
10
|
+
* and performance rules. Each type exposes purpose-specific fields
|
|
11
|
+
* (e.g., `vulnerable`/`safe` for security, `cycle` for code quality).
|
|
12
|
+
*/
|
|
13
|
+
import type { Severity, OWASPCategory, ComplianceFramework } from './types';
|
|
14
|
+
/**
|
|
15
|
+
* Base fields shared by all v2 message categories.
|
|
16
|
+
*
|
|
17
|
+
* Key additions over v1 `LLMMessageOptions`:
|
|
18
|
+
* - `why` โ architectural rationale (industry best practice for LLM teaching)
|
|
19
|
+
* - `vulnerable` / `safe` โ before/after code examples for reliable auto-fix
|
|
20
|
+
*/
|
|
21
|
+
export interface BaseMessageOptionsV2 {
|
|
22
|
+
/** Severity level */
|
|
23
|
+
severity: Severity;
|
|
24
|
+
/** Concise description of the issue */
|
|
25
|
+
description: string;
|
|
26
|
+
/**
|
|
27
|
+
* Architectural rationale explaining *why* this pattern is dangerous.
|
|
28
|
+
* Transforms the message from "detection" into a "teaching prompt".
|
|
29
|
+
*/
|
|
30
|
+
why?: string;
|
|
31
|
+
/** Specific, actionable fix instruction */
|
|
32
|
+
fix: string;
|
|
33
|
+
/** Documentation link */
|
|
34
|
+
docs?: string;
|
|
35
|
+
/** Estimated remediation effort */
|
|
36
|
+
effort?: 'trivial' | 'low' | 'medium' | 'high';
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Options for security-focused rules (CWE-mapped).
|
|
40
|
+
*
|
|
41
|
+
* Evolution of v1 `LLMMessageOptions` with:
|
|
42
|
+
* - `vulnerable` / `safe` code examples for before/after comparison
|
|
43
|
+
* - `why` rationale for LLM teaching
|
|
44
|
+
* - Auto-enrichment from CWE (OWASP, CVSS, compliance)
|
|
45
|
+
*/
|
|
46
|
+
export interface SecurityMessageOptions extends BaseMessageOptionsV2 {
|
|
47
|
+
/** CWE reference (e.g., 'CWE-89') โ triggers auto-enrichment */
|
|
48
|
+
cwe?: string;
|
|
49
|
+
/** OWASP Top 10 category (auto-detected from CWE if omitted) */
|
|
50
|
+
owasp?: OWASPCategory;
|
|
51
|
+
/** CVSS 3.1 score 0.0โ10.0 (auto-calculated from severity if omitted) */
|
|
52
|
+
cvss?: number;
|
|
53
|
+
/** Affected compliance frameworks (auto-detected from CWE if omitted) */
|
|
54
|
+
compliance?: ComplianceFramework[];
|
|
55
|
+
/**
|
|
56
|
+
* Vulnerable code example (the "before").
|
|
57
|
+
* Shown as `โ` in human mode, `bad` in agent JSON.
|
|
58
|
+
*/
|
|
59
|
+
vulnerable?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Safe code example (the "after").
|
|
62
|
+
* Shown as `โ` in human mode, `good` in agent JSON.
|
|
63
|
+
*/
|
|
64
|
+
safe?: string;
|
|
65
|
+
}
|
|
66
|
+
/** Well-known code quality categories */
|
|
67
|
+
export type CodeQualityCategory = 'circular-dependency' | 'unused-import' | 'barrel-file' | 'dependency-boundary' | 'import-order' | 'naming-convention' | 'dead-code';
|
|
68
|
+
/**
|
|
69
|
+
* Options for code quality / structural rules.
|
|
70
|
+
* No CWE/OWASP/CVSS โ these are architecture concerns, not vulnerabilities.
|
|
71
|
+
*/
|
|
72
|
+
export interface CodeQualityMessageOptions extends BaseMessageOptionsV2 {
|
|
73
|
+
/** Well-known category for grouping and routing */
|
|
74
|
+
category: CodeQualityCategory | string;
|
|
75
|
+
/**
|
|
76
|
+
* Import cycle path (for circular dependency rules).
|
|
77
|
+
* Rendered as `A โ B โ C โ A` in human mode.
|
|
78
|
+
*/
|
|
79
|
+
cycle?: string[];
|
|
80
|
+
/**
|
|
81
|
+
* Vulnerable code example (the "before").
|
|
82
|
+
*/
|
|
83
|
+
vulnerable?: string;
|
|
84
|
+
/**
|
|
85
|
+
* Safe code example (the "after").
|
|
86
|
+
*/
|
|
87
|
+
safe?: string;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Options for performance-focused rules.
|
|
91
|
+
* Uses complexity metrics instead of security metadata.
|
|
92
|
+
*/
|
|
93
|
+
export interface PerformanceMessageOptions extends BaseMessageOptionsV2 {
|
|
94
|
+
/**
|
|
95
|
+
* Vulnerable code example (the "before").
|
|
96
|
+
*/
|
|
97
|
+
vulnerable?: string;
|
|
98
|
+
/**
|
|
99
|
+
* Safe code example (the "after").
|
|
100
|
+
*/
|
|
101
|
+
safe?: string;
|
|
102
|
+
/**
|
|
103
|
+
* Performance impact metrics.
|
|
104
|
+
* Displayed as "Impact: O(n) queries โ O(1) query" in human mode.
|
|
105
|
+
*/
|
|
106
|
+
impact?: {
|
|
107
|
+
/** Current (bad) complexity or behavior */
|
|
108
|
+
current: string;
|
|
109
|
+
/** Optimized (good) complexity or behavior */
|
|
110
|
+
optimized: string;
|
|
111
|
+
};
|
|
112
|
+
}
|
package/src/node/path.js
CHANGED
|
@@ -47,11 +47,35 @@ function patternToRegex(pattern, cache) {
|
|
|
47
47
|
if (cached) {
|
|
48
48
|
return cached;
|
|
49
49
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
// Translate the glob in a single left-to-right pass: escape every regex
|
|
51
|
+
// metacharacter, then map the glob wildcards (**, *, ?) to their regex
|
|
52
|
+
// equivalents. Doing it in one pass means an escaped metacharacter can never
|
|
53
|
+
// be re-interpreted as a wildcard. The previous chained-replace only handled
|
|
54
|
+
// `. * ?`, leaving `\ + ( ) [ ] { } ^ $ |` to leak through as regex syntax
|
|
55
|
+
// (CWE-116, incomplete sanitization) โ e.g. the glob `a+b` compiled to the
|
|
56
|
+
// quantifier `a+b` instead of matching the literal `a+b`.
|
|
57
|
+
let escaped = '';
|
|
58
|
+
for (let i = 0; i < pattern.length; i++) {
|
|
59
|
+
const ch = pattern[i];
|
|
60
|
+
if (ch === '*') {
|
|
61
|
+
if (pattern[i + 1] === '*') {
|
|
62
|
+
escaped += '.*';
|
|
63
|
+
i++;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
escaped += '[^/]*';
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else if (ch === '?') {
|
|
70
|
+
escaped += '.';
|
|
71
|
+
}
|
|
72
|
+
else if (/[.+^${}()|[\]\\]/.test(ch)) {
|
|
73
|
+
escaped += '\\' + ch;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
escaped += ch;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
55
79
|
const regex = new RegExp(escaped);
|
|
56
80
|
cache.set(pattern, regex);
|
|
57
81
|
return regex;
|
|
@@ -40,6 +40,8 @@ export interface ImportInfo {
|
|
|
40
40
|
source: string;
|
|
41
41
|
/** Whether this is a dynamic import (import()) */
|
|
42
42
|
dynamic?: boolean;
|
|
43
|
+
/** Whether this is a type-only import (import type {...}) โ erased at compile time */
|
|
44
|
+
typeOnly?: boolean;
|
|
43
45
|
}
|
|
44
46
|
/**
|
|
45
47
|
* Strongly Connected Component result
|
|
@@ -90,13 +92,31 @@ export interface FileSystemCache {
|
|
|
90
92
|
* Resolved import paths cache (LRU)
|
|
91
93
|
* Key: `${fromFile}::${importPath}`, Value: resolved path or null
|
|
92
94
|
* This avoids re-resolving the same import from the same file
|
|
95
|
+
*
|
|
96
|
+
* PERFORMANCE: Uses plain Map instead of LRU cache. The LRU's
|
|
97
|
+
* delete+re-insert on every get() was 3x overhead at 40K+ calls.
|
|
98
|
+
* Within a lint run, memory is bounded by codebase size (~50K entries โ 2MB).
|
|
93
99
|
*/
|
|
94
|
-
resolvedPaths:
|
|
100
|
+
resolvedPaths: Map<string, string | null>;
|
|
95
101
|
/**
|
|
96
102
|
* Files known to not be in any cycle (optimization)
|
|
97
103
|
* Once a file is confirmed to not be in a cycle, we can skip SCC check for it
|
|
98
104
|
*/
|
|
99
105
|
nonCyclicFiles: Set<string>;
|
|
106
|
+
/**
|
|
107
|
+
* Pending cycle reports keyed by *member* file path. Populated when ANY
|
|
108
|
+
* file's DFS discovers a cycle: every member of the discovered cycle gets
|
|
109
|
+
* a pending entry. When ESLint later lints that member, the rule flushes
|
|
110
|
+
* the entry as a diagnostic at `Program:exit`.
|
|
111
|
+
*
|
|
112
|
+
* This is what closes the with-router.tsx gap โ without it, only the file
|
|
113
|
+
* whose DFS discovered the cycle gets the diagnostic, and ordering
|
|
114
|
+
* sometimes leaves other members silent.
|
|
115
|
+
*/
|
|
116
|
+
pendingCycleReports: Map<string, Array<{
|
|
117
|
+
minimalCycle: string[];
|
|
118
|
+
cycleHash: string;
|
|
119
|
+
}>>;
|
|
100
120
|
}
|
|
101
121
|
/**
|
|
102
122
|
* Create a new empty cache
|
|
@@ -240,6 +260,24 @@ export declare function computeSCCsFromFile(startFile: string, options: Omit<Cyc
|
|
|
240
260
|
* @returns true if file is part of a cycle
|
|
241
261
|
*/
|
|
242
262
|
export declare function isFileInCycle(file: string, cache: FileSystemCache): boolean;
|
|
263
|
+
/**
|
|
264
|
+
* Find the shortest cycle path from targetFile back to sourceFile via BFS.
|
|
265
|
+
*
|
|
266
|
+
* This is the path-finding phase โ called ONLY after the SCC pre-check
|
|
267
|
+
* confirms that sourceFile and targetFile are in the same SCC (meaning a
|
|
268
|
+
* cycle MUST exist). BFS guarantees the shortest cycle path is returned.
|
|
269
|
+
*
|
|
270
|
+
* Only traverses files within the same SCC (O(1) lookup per hop), so the
|
|
271
|
+
* worst-case work is proportional to the SCC size, not the entire graph.
|
|
272
|
+
*
|
|
273
|
+
* @param sourceFile - The file that contains the import (cycle closes here)
|
|
274
|
+
* @param targetFile - The file being imported (BFS starts here)
|
|
275
|
+
* @param options - Traversal options (workspaceRoot, barrelExports, cache, resolverSettings)
|
|
276
|
+
* @returns The cycle path [targetFile, ..., sourceFile], or null if not found
|
|
277
|
+
*/
|
|
278
|
+
export declare function findShortestCyclePath(sourceFile: string, targetFile: string, options: Omit<CycleDetectionOptions, 'reportAllCycles' | 'maxDepth'> & {
|
|
279
|
+
maxDepth?: number;
|
|
280
|
+
}): string[] | null;
|
|
243
281
|
/**
|
|
244
282
|
* Get the cycle containing a specific file
|
|
245
283
|
*
|
|
@@ -268,23 +306,47 @@ export interface CycleDetectionOptions {
|
|
|
268
306
|
resolverSettings?: ResolverSetting;
|
|
269
307
|
}
|
|
270
308
|
/**
|
|
271
|
-
*
|
|
309
|
+
* Lightweight per-import cycle detector (Phase 3 optimization)
|
|
310
|
+
*
|
|
311
|
+
* Instead of building the full graph upfront via BFS + Tarjan SCC,
|
|
312
|
+
* this function does a simple bounded DFS from a target file, looking
|
|
313
|
+
* for any path back to the source file. This is architecturally similar
|
|
314
|
+
* to eslint-plugin-import's no-cycle approach and is dramatically faster
|
|
315
|
+
* because it only reads files along the actual traversal path.
|
|
316
|
+
*
|
|
317
|
+
* Performance characteristics:
|
|
318
|
+
* - O(depth) file reads per call (not O(|V|) like BFS)
|
|
319
|
+
* - nonCyclicFiles cache provides O(1) rejection across the lint run
|
|
320
|
+
* - getFileImports cache reuses parsed results across files
|
|
321
|
+
* - Bounded by maxDepth to prevent runaway traversal
|
|
322
|
+
*
|
|
323
|
+
* @param sourceFile - The file containing the import (looking for path back to here)
|
|
324
|
+
* @param targetFile - The file being imported (starting point for DFS)
|
|
325
|
+
* @param options - Detection options
|
|
326
|
+
* @returns Array of cycle paths found (each is an array of file paths ending at sourceFile)
|
|
327
|
+
*/
|
|
328
|
+
export declare function detectCycleFromImport(sourceFile: string, targetFile: string, options: CycleDetectionOptions): string[][];
|
|
329
|
+
/**
|
|
330
|
+
* Find all circular dependencies using SCC + DFS hybrid approach
|
|
272
331
|
*
|
|
273
|
-
* Performance Strategy:
|
|
274
|
-
* 1.
|
|
275
|
-
*
|
|
276
|
-
*
|
|
332
|
+
* Performance Strategy (v2 โ optimized based on benchmark data):
|
|
333
|
+
* 1. Compute SCCs via Tarjan's algorithm on first call (cached for lint run)
|
|
334
|
+
* โ now significantly faster thanks to resolver fast path + getTsconfig cache
|
|
335
|
+
* 2. Use O(1) SCC membership for instant non-cyclic file rejection
|
|
336
|
+
* 3. Only run DFS for files known to be in a cycle (to extract paths)
|
|
337
|
+
* 4. Build graph lazily via getFileImports() with caching
|
|
277
338
|
*
|
|
278
|
-
*
|
|
279
|
-
* -
|
|
280
|
-
* -
|
|
281
|
-
* -
|
|
339
|
+
* Key optimizations vs v1:
|
|
340
|
+
* - Resolver fast path: existsSync for relative imports (10-50x per call)
|
|
341
|
+
* - Global getTsconfig cache: eliminates per-file directory traversal
|
|
342
|
+
* - visited Set: prevents DFS re-traversal of explored subtrees
|
|
343
|
+
* - nonCyclicFiles cache: O(1) rejection across entire lint run
|
|
282
344
|
*
|
|
283
345
|
* @param file - Starting file for cycle detection
|
|
284
346
|
* @param options - Detection options
|
|
285
347
|
* @param currentPath - Current path in DFS (internal use)
|
|
286
348
|
* @param depth - Current depth (internal use)
|
|
287
|
-
* @param visited - Set of
|
|
349
|
+
* @param visited - Set of fully explored files (internal use, persistent)
|
|
288
350
|
* @returns Array of cycles found (each cycle is an array of file paths)
|
|
289
351
|
*/
|
|
290
352
|
export declare function findAllCircularDependencies(file: string, options: CycleDetectionOptions, currentPath?: string[], depth?: number, visited?: Set<string>): string[][];
|