@interlace/eslint-devkit 1.4.4 → 1.6.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 (43) hide show
  1. package/package.json +22 -12
  2. package/src/aria-definitions.js +0 -14
  3. package/src/ast/ast-utils.js +0 -72
  4. package/src/ast/index.js +0 -6
  5. package/src/ast-node-types.d.ts +29 -0
  6. package/src/ast-node-types.js +174 -0
  7. package/src/index.d.ts +11 -2
  8. package/src/index.js +5 -38
  9. package/src/messaging/config.js +0 -88
  10. package/src/messaging/constants.js +20 -142
  11. package/src/messaging/formatters-ai.js +0 -89
  12. package/src/messaging/formatters-v2.js +0 -151
  13. package/src/messaging/formatters.js +2 -145
  14. package/src/messaging/index.js +0 -6
  15. package/src/messaging/types-v2.js +0 -5
  16. package/src/messaging/types.js +0 -5
  17. package/src/node/fs.js +0 -61
  18. package/src/node/index.js +0 -6
  19. package/src/node/os.js +0 -33
  20. package/src/node/path.js +0 -126
  21. package/src/resolver/dependency-analysis.js +64 -562
  22. package/src/resolver/index.js +0 -6
  23. package/src/resolver/resolver-adapter.js +0 -39
  24. package/src/resolver/resolver-detection.js +0 -48
  25. package/src/resolver/resolver.d.ts +11 -0
  26. package/src/resolver/resolver.js +49 -112
  27. package/src/resolver.js +0 -5
  28. package/src/rule-creation/index.d.ts +1 -0
  29. package/src/rule-creation/index.js +1 -6
  30. package/src/rule-creation/mock-context.d.ts +5 -0
  31. package/src/rule-creation/mock-context.js +1 -9
  32. package/src/rule-creation/rule-creator.d.ts +59 -10
  33. package/src/rule-creation/rule-creator.js +64 -40
  34. package/src/rule-creation/sql-injection-rule.d.ts +68 -0
  35. package/src/rule-creation/sql-injection-rule.js +116 -0
  36. package/src/security/index.js +0 -6
  37. package/src/security/security-utils.js +9 -287
  38. package/src/types/index.js +0 -9
  39. package/src/types/meta-augmentation.js +0 -5
  40. package/src/types/type-utils.d.ts +1 -1
  41. package/src/types/type-utils.js +34 -145
  42. package/AGENTS.md +0 -151
  43. package/CHANGELOG.md +0 -153
@@ -1,9 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.buildASTSelector = buildASTSelector;
9
4
  exports.formatAgentMessage = formatAgentMessage;
@@ -11,25 +6,6 @@ exports.formatMessageNextGen = formatMessageNextGen;
11
6
  exports.formatLLMMessageNextGen = formatLLMMessageNextGen;
12
7
  const constants_1 = require("./constants");
13
8
  const config_1 = require("./config");
14
- /**
15
- * Builds a relative esquery selector from an AST node
16
- * Goes up to the nearest "anchor" (function, class, method) for context
17
- *
18
- * @param node - The AST node that triggered the lint error
19
- * @param maxDepth - Maximum levels to traverse up (default: 3)
20
- * @returns An esquery-compatible selector string
21
- *
22
- * @example
23
- * ```typescript
24
- * // For a node: db.query('SELECT...')
25
- * buildASTSelector(node)
26
- * // Returns: "CallExpression[callee.property.name='query']"
27
- *
28
- * // For a node inside a method:
29
- * buildASTSelector(node)
30
- * // Returns: "MethodDefinition[key.name='getUser'] CallExpression[callee.name='eval']"
31
- * ```
32
- */
33
9
  function buildASTSelector(node, maxDepth = 3) {
34
10
  const parts = [];
35
11
  let current = node;
@@ -39,7 +15,6 @@ function buildASTSelector(node, maxDepth = 3) {
39
15
  if (selector) {
40
16
  parts.unshift(selector);
41
17
  }
42
- // Stop at anchor nodes (stable reference points)
43
18
  if (isAnchorNode(current.type)) {
44
19
  break;
45
20
  }
@@ -48,9 +23,6 @@ function buildASTSelector(node, maxDepth = 3) {
48
23
  }
49
24
  return parts.join(' ');
50
25
  }
51
- /**
52
- * Builds a selector for a single node
53
- */
54
26
  function buildNodeSelector(node) {
55
27
  switch (node.type) {
56
28
  case 'CallExpression':
@@ -92,9 +64,6 @@ function buildNodeSelector(node) {
92
64
  return node.type;
93
65
  }
94
66
  }
95
- /**
96
- * Checks if a node type is an "anchor" (stable reference point)
97
- */
98
67
  function isAnchorNode(type) {
99
68
  return [
100
69
  'FunctionDeclaration',
@@ -106,12 +75,6 @@ function isAnchorNode(type) {
106
75
  'Program',
107
76
  ].includes(type);
108
77
  }
109
- // ============================================================================
110
- // CWE ENRICHMENT
111
- // ============================================================================
112
- /**
113
- * Auto-enriches options with security benchmark data based on CWE
114
- */
115
78
  function enrichFromCWE(options) {
116
79
  if (!options.cwe)
117
80
  return options;
@@ -125,16 +88,8 @@ function enrichFromCWE(options) {
125
88
  compliance: options.compliance ?? constants_1.CWE_COMPLIANCE_MAPPING[options.cwe],
126
89
  };
127
90
  }
128
- // ============================================================================
129
- // FORMATTERS
130
- // ============================================================================
131
- /**
132
- * Formats a message as structured JSON for AI Agents
133
- * Minimizes token usage while retaining strict semantic targeting
134
- */
135
91
  function formatAgentMessage(options, compress = false) {
136
92
  const enriched = enrichFromCWE(options);
137
- // Compressed keys if enabled (Token Economy)
138
93
  if (compress) {
139
94
  return JSON.stringify({
140
95
  id: enriched.cwe ?? enriched.ruleId,
@@ -145,7 +100,6 @@ function formatAgentMessage(options, compress = false) {
145
100
  refs: [enriched.documentationLink],
146
101
  });
147
102
  }
148
- // Verbose structured JSON (Standard Agent Schema)
149
103
  return JSON.stringify({
150
104
  ruleId: enriched.ruleId ?? enriched.cwe,
151
105
  severity: enriched.severity,
@@ -161,16 +115,12 @@ function formatAgentMessage(options, compress = false) {
161
115
  documentation: enriched.documentationLink,
162
116
  });
163
117
  }
164
- /**
165
- * Formats a human-readable message with optional hidden AI hints
166
- */
167
118
  function formatHumanMessage(options, includeHints = false) {
168
119
  const enriched = enrichFromCWE(options);
169
120
  const { icon, cwe, description, severity, fix, documentationLink } = enriched;
170
121
  const owasp = enriched.owasp;
171
122
  const cvss = enriched.cvss;
172
123
  const compliance = enriched.compliance;
173
- // Build standards reference string
174
124
  const standards = [];
175
125
  if (cwe)
176
126
  standards.push(cwe);
@@ -188,7 +138,6 @@ function formatHumanMessage(options, includeHints = false) {
188
138
  : '';
189
139
  const firstLine = `${icon} ${standardsPart}${description} | ${severity}${compliancePart}`;
190
140
  let secondLine = ` Fix: ${fix} | ${documentationLink}`;
191
- // Inject hidden AI hints for Cursor/Copilot (Hybrid Mode)
192
141
  if (includeHints) {
193
142
  const agentOptions = options;
194
143
  if (agentOptions.astSelector || agentOptions.aiHints) {
@@ -203,37 +152,6 @@ function formatHumanMessage(options, includeHints = false) {
203
152
  }
204
153
  return `${firstLine}\n${secondLine}`;
205
154
  }
206
- // ============================================================================
207
- // MAIN ENTRY POINT (Context-Aware)
208
- // ============================================================================
209
- /**
210
- * Context-aware message formatter (Next-Gen)
211
- *
212
- * Automatically routes between output formats based on the resolved AI mode:
213
- * - CLI: Human-readable with emojis and prose
214
- * - CI: Human-readable (no colors)
215
- * - IDE_CURSOR: Human-readable + hidden AI hints
216
- * - AGENT_JSON: Structured JSON for agents
217
- *
218
- * @param options - Message options including optional agent hints
219
- * @param context - ESLint rule context (for accessing settings)
220
- * @returns Formatted message string
221
- *
222
- * @example
223
- * ```typescript
224
- * // In an ESLint rule
225
- * context.report({
226
- * node,
227
- * message: formatMessageNextGen({
228
- * icon: '🔒',
229
- * severity: 'CRITICAL',
230
- * description: 'SQL Injection',
231
- * fix: 'Use parameterized queries',
232
- * astSelector: buildASTSelector(node),
233
- * }, context),
234
- * });
235
- * ```
236
- */
237
155
  function formatMessageNextGen(options, context) {
238
156
  const mode = (0, config_1.resolveAIMode)(context);
239
157
  const compress = (0, config_1.resolveCompression)(context);
@@ -248,13 +166,6 @@ function formatMessageNextGen(options, context) {
248
166
  return formatHumanMessage(options, false);
249
167
  }
250
168
  }
251
- // ============================================================================
252
- // LEGACY API (Backward compatibility)
253
- // ============================================================================
254
- /**
255
- * @deprecated Use formatMessageNextGen(options, context) instead
256
- * Legacy formatter that uses global state instead of context
257
- */
258
169
  function formatLLMMessageNextGen(options) {
259
170
  const mode = (0, config_1.getAIMessagingMode)();
260
171
  const compress = (0, config_1.isTokenCompressionEnabled)();
@@ -1,18 +1,9 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.formatSecurityMessage = formatSecurityMessage;
9
4
  exports.formatCodeQualityMessage = formatCodeQualityMessage;
10
5
  exports.formatPerformanceMessage = formatPerformanceMessage;
11
6
  const constants_1 = require("./constants");
12
- // ============================================================================
13
- // SHARED UTILITIES
14
- // ============================================================================
15
- /** Icons for each category */
16
7
  const CATEGORY_ICONS = {
17
8
  security: '🔒',
18
9
  'circular-dependency': '🔄',
@@ -24,14 +15,6 @@ const CATEGORY_ICONS = {
24
15
  'dead-code': '💀',
25
16
  performance: '⚡',
26
17
  };
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
18
  const SEVERITY_SHORT = {
36
19
  CRITICAL: 'CRIT',
37
20
  HIGH: 'HIGH',
@@ -39,15 +22,9 @@ const SEVERITY_SHORT = {
39
22
  LOW: 'LOW',
40
23
  INFO: 'INFO',
41
24
  };
42
- /**
43
- * Renders the optional `why` line.
44
- */
45
25
  function renderWhy(why) {
46
26
  return why ? `\n Why: ${why}` : '';
47
27
  }
48
- /**
49
- * Renders the optional vulnerable/safe code examples.
50
- */
51
28
  function renderExamples(vulnerable, safe) {
52
29
  const parts = [];
53
30
  if (vulnerable)
@@ -56,9 +33,6 @@ function renderExamples(vulnerable, safe) {
56
33
  parts.push(` ✓ ${safe}`);
57
34
  return parts.length > 0 ? '\n' + parts.join('\n') : '';
58
35
  }
59
- /**
60
- * Renders inline examples for compact mode (same line as fix).
61
- */
62
36
  function renderInlineExamples(vulnerable, safe) {
63
37
  const parts = [];
64
38
  if (vulnerable)
@@ -67,18 +41,9 @@ function renderInlineExamples(vulnerable, safe) {
67
41
  parts.push(`✓ ${safe}`);
68
42
  return parts.length > 0 ? ' | ' + parts.join(' ') : '';
69
43
  }
70
- /**
71
- * Renders the optional docs link suffix.
72
- */
73
44
  function renderDocs(docs) {
74
45
  return docs ? ` | ${docs}` : '';
75
46
  }
76
- // ============================================================================
77
- // SECURITY FORMATTER
78
- // ============================================================================
79
- /**
80
- * Auto-enriches security options with CWE benchmark data.
81
- */
82
47
  function enrichSecurity(options) {
83
48
  if (!options.cwe)
84
49
  return options;
@@ -92,9 +57,6 @@ function enrichSecurity(options) {
92
57
  compliance: options.compliance ?? constants_1.CWE_COMPLIANCE_MAPPING[options.cwe],
93
58
  };
94
59
  }
95
- /**
96
- * Builds the standards reference string (CWE, OWASP, CVSS).
97
- */
98
60
  function buildStandards(cwe, owasp, cvss) {
99
61
  const parts = [];
100
62
  if (cwe)
@@ -109,13 +71,6 @@ function buildStandards(cwe, owasp, cvss) {
109
71
  parts.push(`CVSS:${cvss}`);
110
72
  return parts.length > 0 ? `${parts.join(' ')} | ` : '';
111
73
  }
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
74
  function buildCompactStandards(cwe, cvss) {
120
75
  const parts = [];
121
76
  if (cwe)
@@ -124,46 +79,11 @@ function buildCompactStandards(cwe, cvss) {
124
79
  parts.push(`${cvss}`);
125
80
  return parts.length > 0 ? `${parts.join(' ')} ` : '';
126
81
  }
127
- /**
128
- * Builds the compliance tag string.
129
- */
130
82
  function buildCompliance(compliance) {
131
83
  return compliance && compliance.length > 0
132
84
  ? ` [${compliance.slice(0, 4).join(',')}]`
133
85
  : '';
134
86
  }
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
87
  function formatSecurityMessage(options, mode = 'human') {
168
88
  const enriched = enrichSecurity(options);
169
89
  if (mode === 'agent') {
@@ -174,7 +94,6 @@ function formatSecurityMessage(options, mode = 'human') {
174
94
  }
175
95
  return securityToHuman(enriched);
176
96
  }
177
- /** Human mode: rich, multi-line */
178
97
  function securityToHuman(enriched) {
179
98
  const { cwe, owasp, cvss, compliance, description, severity, fix, docs, why, vulnerable, safe } = enriched;
180
99
  const icon = CATEGORY_ICONS['security'];
@@ -186,11 +105,6 @@ function securityToHuman(enriched) {
186
105
  const examples = renderExamples(vulnerable, safe);
187
106
  return `${line1}${whyLine}${fixLine}${examples}`;
188
107
  }
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
108
  function securityToCompact(enriched) {
195
109
  const { cwe, cvss, description, severity, fix, vulnerable, safe } = enriched;
196
110
  const sev = SEVERITY_SHORT[severity] || severity;
@@ -198,15 +112,6 @@ function securityToCompact(enriched) {
198
112
  const examples = renderInlineExamples(vulnerable, safe);
199
113
  return `${std}${description} | ${sev}\n Fix: ${fix}${examples}`;
200
114
  }
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
115
  function securityToAgentJSON(enriched) {
211
116
  const obj = {
212
117
  id: enriched.cwe,
@@ -220,27 +125,6 @@ function securityToAgentJSON(enriched) {
220
125
  obj['good'] = enriched.safe;
221
126
  return JSON.stringify(obj);
222
127
  }
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
128
  function formatCodeQualityMessage(options, mode = 'human') {
245
129
  if (mode === 'agent') {
246
130
  return codeQualityToAgentJSON(options);
@@ -250,7 +134,6 @@ function formatCodeQualityMessage(options, mode = 'human') {
250
134
  }
251
135
  return codeQualityToHuman(options);
252
136
  }
253
- /** Human mode: rich output with cycle path */
254
137
  function codeQualityToHuman(options) {
255
138
  const { category, description, severity, fix, docs, why, cycle, vulnerable, safe } = options;
256
139
  const icon = CATEGORY_ICONS[category] || '📐';
@@ -263,7 +146,6 @@ function codeQualityToHuman(options) {
263
146
  : '';
264
147
  return `${line1}${whyLine}${fixLine}${examples}${cycleLine}`;
265
148
  }
266
- /** Compact mode: inlined examples, abbreviated severity */
267
149
  function codeQualityToCompact(options) {
268
150
  const { description, severity, fix, vulnerable, safe, cycle } = options;
269
151
  const sev = SEVERITY_SHORT[severity] || severity;
@@ -273,11 +155,6 @@ function codeQualityToCompact(options) {
273
155
  : '';
274
156
  return `${description} | ${sev}\n Fix: ${fix}${examples}${cycleSuffix}`;
275
157
  }
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
158
  function codeQualityToAgentJSON(options) {
282
159
  const obj = {
283
160
  category: options.category,
@@ -292,27 +169,6 @@ function codeQualityToAgentJSON(options) {
292
169
  obj['good'] = options.safe;
293
170
  return JSON.stringify(obj);
294
171
  }
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
172
  function formatPerformanceMessage(options, mode = 'human') {
317
173
  if (mode === 'agent') {
318
174
  return performanceToAgentJSON(options);
@@ -322,7 +178,6 @@ function formatPerformanceMessage(options, mode = 'human') {
322
178
  }
323
179
  return performanceToHuman(options);
324
180
  }
325
- /** Human mode: rich with impact metrics */
326
181
  function performanceToHuman(options) {
327
182
  const { description, severity, fix, docs, why, vulnerable, safe, impact } = options;
328
183
  const icon = CATEGORY_ICONS['performance'];
@@ -335,7 +190,6 @@ function performanceToHuman(options) {
335
190
  const examples = renderExamples(vulnerable, safe);
336
191
  return `${line1}${whyLine}${fixLine}${impactLine}${examples}`;
337
192
  }
338
- /** Compact mode: inline impact and examples */
339
193
  function performanceToCompact(options) {
340
194
  const { description, severity, fix, vulnerable, safe, impact } = options;
341
195
  const sev = SEVERITY_SHORT[severity] || severity;
@@ -343,11 +197,6 @@ function performanceToCompact(options) {
343
197
  const examples = renderInlineExamples(vulnerable, safe);
344
198
  return `${description} | ${sev}${impactSuffix}\n Fix: ${fix}${examples}`;
345
199
  }
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
200
  function performanceToAgentJSON(options) {
352
201
  const obj = {
353
202
  description: options.description,