@interlace/eslint-devkit 1.0.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 (77) hide show
  1. package/AGENTS.md +352 -0
  2. package/CHANGELOG.md +88 -0
  3. package/LICENSE +22 -0
  4. package/README.md +528 -0
  5. package/package.json +88 -0
  6. package/src/aria-definitions.d.ts +9 -0
  7. package/src/aria-definitions.js +973 -0
  8. package/src/aria-definitions.js.map +1 -0
  9. package/src/ast/ast-utils.d.ts +81 -0
  10. package/src/ast/ast-utils.js +201 -0
  11. package/src/ast/ast-utils.js.map +1 -0
  12. package/src/ast/index.d.ts +1 -0
  13. package/src/ast/index.js +6 -0
  14. package/src/ast/index.js.map +1 -0
  15. package/src/index.d.ts +30 -0
  16. package/src/index.js +54 -0
  17. package/src/index.js.map +1 -0
  18. package/src/messaging/constants.d.ts +120 -0
  19. package/src/messaging/constants.js +744 -0
  20. package/src/messaging/constants.js.map +1 -0
  21. package/src/messaging/formatters.d.ts +124 -0
  22. package/src/messaging/formatters.js +330 -0
  23. package/src/messaging/formatters.js.map +1 -0
  24. package/src/messaging/index.d.ts +3 -0
  25. package/src/messaging/index.js +8 -0
  26. package/src/messaging/index.js.map +1 -0
  27. package/src/messaging/types.d.ts +122 -0
  28. package/src/messaging/types.js +8 -0
  29. package/src/messaging/types.js.map +1 -0
  30. package/src/node/fs.d.ts +65 -0
  31. package/src/node/fs.js +129 -0
  32. package/src/node/fs.js.map +1 -0
  33. package/src/node/index.d.ts +3 -0
  34. package/src/node/index.js +8 -0
  35. package/src/node/index.js.map +1 -0
  36. package/src/node/os.d.ts +24 -0
  37. package/src/node/os.js +49 -0
  38. package/src/node/os.js.map +1 -0
  39. package/src/node/path.d.ts +121 -0
  40. package/src/node/path.js +209 -0
  41. package/src/node/path.js.map +1 -0
  42. package/src/resolver/dependency-analysis.d.ts +421 -0
  43. package/src/resolver/dependency-analysis.js +934 -0
  44. package/src/resolver/dependency-analysis.js.map +1 -0
  45. package/src/resolver/index.d.ts +4 -0
  46. package/src/resolver/index.js +9 -0
  47. package/src/resolver/index.js.map +1 -0
  48. package/src/resolver/resolver-adapter.d.ts +53 -0
  49. package/src/resolver/resolver-adapter.js +126 -0
  50. package/src/resolver/resolver-adapter.js.map +1 -0
  51. package/src/resolver/resolver-detection.d.ts +36 -0
  52. package/src/resolver/resolver-detection.js +219 -0
  53. package/src/resolver/resolver-detection.js.map +1 -0
  54. package/src/resolver/resolver.d.ts +52 -0
  55. package/src/resolver/resolver.js +294 -0
  56. package/src/resolver/resolver.js.map +1 -0
  57. package/src/resolver.d.ts +1 -0
  58. package/src/resolver.js +5 -0
  59. package/src/resolver.js.map +1 -0
  60. package/src/rule-creation/index.d.ts +1 -0
  61. package/src/rule-creation/index.js +6 -0
  62. package/src/rule-creation/index.js.map +1 -0
  63. package/src/rule-creation/rule-creator.d.ts +42 -0
  64. package/src/rule-creation/rule-creator.js +42 -0
  65. package/src/rule-creation/rule-creator.js.map +1 -0
  66. package/src/security/index.d.ts +1 -0
  67. package/src/security/index.js +6 -0
  68. package/src/security/index.js.map +1 -0
  69. package/src/security/security-utils.d.ts +303 -0
  70. package/src/security/security-utils.js +607 -0
  71. package/src/security/security-utils.js.map +1 -0
  72. package/src/types/index.d.ts +1 -0
  73. package/src/types/index.js +6 -0
  74. package/src/types/index.js.map +1 -0
  75. package/src/types/type-utils.d.ts +146 -0
  76. package/src/types/type-utils.js +329 -0
  77. package/src/types/type-utils.js.map +1 -0
package/AGENTS.md ADDED
@@ -0,0 +1,352 @@
1
+ # @interlace/eslint-devkit - AI Agent Guide
2
+
3
+ ## Package Overview
4
+
5
+ **Name:** @interlace/eslint-devkit
6
+ **Version:** 1.4.0
7
+ **Description:** Utilities for building LLM-optimized ESLint rules. TypeScript utilities for creating rules that AI assistants can understand and auto-fix. Most ESLint utilities help you write rules. This package helps you write rules that LLMs can fix automatically.
8
+
9
+ **Keywords:** eslint, eslint-plugin, typescript, utilities, ast, type-checking, plugin-development, llm-optimized, ai-assistant, auto-fix, github-copilot, cursor-ai, claude-ai, structured-error-messages, deterministic-fixes
10
+
11
+ **Homepage:** https://github.com/ofri-peretz/forge-js#readme
12
+ **Repository:** https://github.com/ofri-peretz/forge-js.git
13
+ **Directory:** packages/eslint-devkit
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install --save-dev @interlace/eslint-devkit
19
+ # or
20
+ pnpm add -D @interlace/eslint-devkit
21
+ # or
22
+ yarn add -D @interlace/eslint-devkit
23
+ ```
24
+
25
+ **Peer Dependencies (required):**
26
+
27
+ ```bash
28
+ npm install --save-dev @typescript-eslint/parser typescript
29
+ npm install --save-dev @typescript-eslint/utils
30
+ ```
31
+
32
+ ## Quick Start
33
+
34
+ ### Create Your First Rule
35
+
36
+ ```typescript
37
+ import { createRule, isMemberExpression } from '@interlace/eslint-devkit';
38
+
39
+ export default createRule({
40
+ name: 'no-console-log',
41
+ meta: {
42
+ type: 'problem',
43
+ docs: {
44
+ description: 'Disallow console.log - use logger.debug() instead',
45
+ recommended: 'warn',
46
+ },
47
+ fixable: 'code',
48
+ messages: {
49
+ useLogger: 'Replace console.log with logger.debug() on line {{line}}',
50
+ },
51
+ schema: [],
52
+ },
53
+ defaultOptions: [],
54
+ create(context) {
55
+ return {
56
+ CallExpression(node) {
57
+ if (isMemberExpression(node.callee, 'console', 'log')) {
58
+ context.report({
59
+ node,
60
+ messageId: 'useLogger',
61
+ data: { line: node.loc.start.line },
62
+ fix(fixer) {
63
+ return fixer.replaceText(node.callee, 'logger.debug');
64
+ },
65
+ });
66
+ }
67
+ },
68
+ };
69
+ },
70
+ });
71
+ ```
72
+
73
+ ## API Reference
74
+
75
+ ### Rule Creation
76
+
77
+ #### `createRule(options)`
78
+
79
+ Creates a well-typed ESLint rule with automatic documentation links.
80
+
81
+ **Parameters:**
82
+
83
+ - `name` (string): Rule name (e.g., 'no-console-log')
84
+ - `meta` (object): Rule metadata (type, docs, messages, schema)
85
+ - `defaultOptions` (array): Default rule options
86
+ - `create` (function): Rule implementation function
87
+
88
+ **Returns:** ESLint rule object
89
+
90
+ **Example:**
91
+
92
+ ```typescript
93
+ import { createRule } from '@interlace/eslint-devkit';
94
+
95
+ const rule = createRule({
96
+ name: 'my-rule',
97
+ meta: {
98
+ type: 'problem',
99
+ docs: { description: 'My custom rule' },
100
+ messages: { error: 'Error message' },
101
+ schema: [],
102
+ },
103
+ defaultOptions: [],
104
+ create(context) {
105
+ return {
106
+ // Your rule implementation
107
+ };
108
+ },
109
+ });
110
+ ```
111
+
112
+ #### `createRuleCreator(urlCreator)`
113
+
114
+ Creates a custom rule factory with your documentation URL pattern.
115
+
116
+ **Parameters:**
117
+
118
+ - `urlCreator` (function): Function that takes rule name and returns documentation URL
119
+
120
+ **Returns:** Rule creation function
121
+
122
+ **Example:**
123
+
124
+ ```typescript
125
+ import { createRuleCreator } from '@interlace/eslint-devkit';
126
+
127
+ const createRule = createRuleCreator(
128
+ (ruleName) => `https://your-plugin.dev/rules/${ruleName}`,
129
+ );
130
+
131
+ export default createRule({
132
+ name: 'my-rule',
133
+ // ...
134
+ });
135
+ ```
136
+
137
+ ### AST Utilities
138
+
139
+ #### Node Type Checks
140
+
141
+ | Function | Description | Example |
142
+ | -------------------------- | ---------------------------------- | ---------------------------------- |
143
+ | `isNodeOfType(node, type)` | Type guard for AST nodes | `isNodeOfType(node, 'Identifier')` |
144
+ | `isFunctionNode(node)` | Check if node is any function type | `isFunctionNode(node)` |
145
+ | `isClassNode(node)` | Check if node is a class | `isClassNode(node)` |
146
+ | `isLiteral(node)` | Check if literal value | `isLiteral(node)` |
147
+ | `isTemplateLiteral(node)` | Check if template literal | `isTemplateLiteral(node)` |
148
+
149
+ #### Pattern Matching
150
+
151
+ | Function | Description | Example |
152
+ | -------------------------------------------- | --------------------------------- | -------------------------------------------- |
153
+ | `isMemberExpression(node, object, property)` | Match patterns like `console.log` | `isMemberExpression(node, 'console', 'log')` |
154
+ | `isCallExpression(node, name)` | Check function call by name | `isCallExpression(node, 'fetch')` |
155
+
156
+ #### Value Extraction
157
+
158
+ | Function | Description | Example |
159
+ | ------------------------- | ----------------------- | ------------------------------------ |
160
+ | `getIdentifierName(node)` | Extract identifier name | `getIdentifierName(node) // 'myVar'` |
161
+ | `getFunctionName(node)` | Get function name | `getFunctionName(node) // 'myFunc'` |
162
+ | `getStaticValue(node)` | Extract static value | `getStaticValue(node) // 'hello'` |
163
+
164
+ #### Ancestor Navigation
165
+
166
+ | Function | Description | Example |
167
+ | ------------------------------------------- | ------------------------------- | ----------------------------------------------------- |
168
+ | `isInsideNode(node, parentType, ancestors)` | Check if inside specific parent | `isInsideNode(node, 'TryStatement', ancestors)` |
169
+ | `getAncestorOfType(type, ancestors)` | Find first ancestor of type | `getAncestorOfType('FunctionDeclaration', ancestors)` |
170
+
171
+ ### Type Utilities
172
+
173
+ Type-aware analysis using TypeScript compiler API. These utilities require TypeScript parser services.
174
+
175
+ #### Service Access
176
+
177
+ | Function | Description | Example |
178
+ | ------------------------------- | ------------------------------------------- | --------------------------------------------- |
179
+ | `hasParserServices(context)` | Check if type info available | `if (hasParserServices(context))` |
180
+ | `getParserServices(context)` | Get parser services (throws if unavailable) | `const services = getParserServices(context)` |
181
+ | `getTypeOfNode(node, services)` | Get TypeScript type of node | `const type = getTypeOfNode(node, services)` |
182
+
183
+ #### Type Checks
184
+
185
+ | Function | Description | Example |
186
+ | --------------------------------- | -------------------------- | --------------------------------- |
187
+ | `isStringType(type)` | Check if type is string | `isStringType(type)` |
188
+ | `isNumberType(type)` | Check if type is number | `isNumberType(type)` |
189
+ | `isBooleanType(type)` | Check if type is boolean | `isBooleanType(type)` |
190
+ | `isArrayType(type, checker)` | Check if type is array | `isArrayType(type, checker)` |
191
+ | `isPromiseType(type, checker)` | Check if type is Promise | `isPromiseType(type, checker)` |
192
+ | `isAnyType(type)` | Check if type is any | `isAnyType(type)` |
193
+ | `isUnknownType(type)` | Check if type is unknown | `isUnknownType(type)` |
194
+ | `isNullableType(type)` | Check if type is nullable | `isNullableType(type)` |
195
+ | `getTypeArguments(type, checker)` | Get generic type arguments | `getTypeArguments(type, checker)` |
196
+
197
+ ### LLM Message Format
198
+
199
+ #### `formatLLMMessage(message, data)`
200
+
201
+ Formats error messages for optimal LLM consumption.
202
+
203
+ **Parameters:**
204
+
205
+ - `message` (string): Message template with placeholders
206
+ - `data` (object): Data to fill placeholders
207
+
208
+ **Returns:** Formatted message string
209
+
210
+ **Example:**
211
+
212
+ ```typescript
213
+ import { formatLLMMessage } from '@interlace/eslint-devkit';
214
+
215
+ const message = formatLLMMessage(
216
+ 'Replace {{old}} with {{new}} on line {{line}}',
217
+ { old: 'console.log', new: 'logger.debug', line: 42 },
218
+ );
219
+ // Returns: "Replace console.log with logger.debug on line 42"
220
+ ```
221
+
222
+ ## Complete Examples
223
+
224
+ ### Example 1: Console.log Detection
225
+
226
+ ```typescript
227
+ import {
228
+ isMemberExpression,
229
+ isInsideNode,
230
+ getAncestorOfType,
231
+ getIdentifierName,
232
+ } from '@interlace/eslint-devkit';
233
+
234
+ create(context) {
235
+ return {
236
+ CallExpression(node) {
237
+ if (isMemberExpression(node.callee, 'console', 'log')) {
238
+ const ancestors = context.getAncestors();
239
+ const insideTry = isInsideNode(node, 'TryStatement', ancestors);
240
+
241
+ if (!insideTry) {
242
+ const functionAncestor = getAncestorOfType('FunctionDeclaration', ancestors);
243
+ const functionName = functionAncestor
244
+ ? getIdentifierName(functionAncestor.id)
245
+ : 'anonymous';
246
+
247
+ context.report({
248
+ node,
249
+ message: `Avoid console.log outside error handlers in ${functionName}`,
250
+ });
251
+ }
252
+ }
253
+ },
254
+ };
255
+ }
256
+ ```
257
+
258
+ ### Example 2: Type-Aware Promise Detection
259
+
260
+ ```typescript
261
+ import {
262
+ hasParserServices,
263
+ getParserServices,
264
+ getTypeOfNode,
265
+ isPromiseType,
266
+ } from '@interlace/eslint-devkit';
267
+
268
+ create(context) {
269
+ if (!hasParserServices(context)) {
270
+ return {};
271
+ }
272
+
273
+ const services = getParserServices(context);
274
+ const checker = services.program.getTypeChecker();
275
+
276
+ return {
277
+ CallExpression(node) {
278
+ const type = getTypeOfNode(node, services);
279
+
280
+ if (isPromiseType(type, checker)) {
281
+ const parent = node.parent;
282
+ const isAwaited = parent?.type === 'AwaitExpression';
283
+
284
+ if (!isAwaited) {
285
+ context.report({
286
+ node,
287
+ message: 'Promise is not awaited - add "await" or handle with .then()',
288
+ fix(fixer) {
289
+ return fixer.insertTextBefore(node, 'await ');
290
+ },
291
+ });
292
+ }
293
+ }
294
+ },
295
+ };
296
+ }
297
+ ```
298
+
299
+ ## Best Practices
300
+
301
+ 1. **Provide Specific Error Messages:** Include exact fix instructions
302
+ 2. **Include Auto-Fixes When Possible:** Use fixer API for automatic corrections
303
+ 3. **Structure Error Data for AI:** Use structured data objects with clear fields
304
+ 4. **Use Type Information When Available:** Check for parser services before using type utilities
305
+ 5. **Provide Context in Messages:** Include function names, line numbers, and suggestions
306
+
307
+ ## FAQ
308
+
309
+ **Q: How do I create a new ESLint rule?**
310
+ A: Use `createRule()` with name, meta, defaultOptions, and create function.
311
+
312
+ **Q: How do I check if a node is a specific type?**
313
+ A: Use `isNodeOfType(node, 'TypeName')` or specific helpers like `isFunctionNode(node)`.
314
+
315
+ **Q: How do I match patterns like `console.log`?**
316
+ A: Use `isMemberExpression(node, 'console', 'log')` to match member expressions.
317
+
318
+ **Q: How do I get TypeScript type information?**
319
+ A: Check `hasParserServices(context)`, then use `getParserServices(context)` and `getTypeOfNode(node, services)`.
320
+
321
+ **Q: How do I navigate the AST tree?**
322
+ A: Use `context.getAncestors()` and helper functions like `getAncestorOfType()` or `isInsideNode()`.
323
+
324
+ **Q: How do I extract values from nodes?**
325
+ A: Use `getIdentifierName(node)`, `getFunctionName(node)`, or `getStaticValue(node)`.
326
+
327
+ **Q: How do I format messages for LLMs?**
328
+ A: Use `formatLLMMessage()` with placeholders and data objects.
329
+
330
+ **Q: What's the difference between AST and type utilities?**
331
+ A: AST utilities work on syntax, type utilities require TypeScript parser services and work on semantics.
332
+
333
+ **Q: How do I handle projects without TypeScript?**
334
+ A: Always check `hasParserServices(context)` before using type utilities, return empty object if unavailable.
335
+
336
+ **Q: How do I report an error with auto-fix?**
337
+ A: Use `context.report()` with a `fix` function that returns a fixer operation.
338
+
339
+ ## Related Packages
340
+
341
+ - **@forge-js/eslint-plugin-llm-optimized:** Ready-to-use LLM-optimized rules built with this package
342
+ - **@typescript-eslint/utils:** Official TypeScript ESLint utilities
343
+
344
+ ## License
345
+
346
+ MIT © Ofri Peretz
347
+
348
+ ## Support
349
+
350
+ - **Documentation:** https://github.com/ofri-peretz/forge-js/blob/main/packages/eslint-devkit/README.md
351
+ - **Issues:** https://github.com/ofri-peretz/forge-js/issues
352
+ - **Discussions:** https://github.com/ofri-peretz/forge-js/discussions
package/CHANGELOG.md ADDED
@@ -0,0 +1,88 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@interlace/eslint-devkit` are documented here.
4
+
5
+ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and [SemVer](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [1.0.0] - 2025-11-30
8
+
9
+ ### 🚀 Features
10
+
11
+ - Enhanced LLM message formatting utilities.
12
+ - Improved TypeScript typings for IDE support.
13
+
14
+ ### 🩹 Fixes
15
+
16
+ - Compatibility fixes for TS strict mode.
17
+ - More accurate type guards for AST checking.
18
+
19
+ ### 📌 Notes
20
+
21
+ - Package name aligned to `@interlace/eslint-devkit` (formerly eslint-plugin-utils).
22
+
23
+ ### ❤️ Thank You
24
+
25
+ - Ofri Peretz
26
+
27
+ ---
28
+
29
+ ## [0.3.0] - 2025-11-15
30
+
31
+ ### 🚀 Features
32
+
33
+ - Enhanced type utilities.
34
+ - Improved AST helpers.
35
+ - Better LLM-oriented error messaging.
36
+
37
+ ### 🩹 Fixes
38
+
39
+ - Type checking edge cases.
40
+ - Documentation improvements.
41
+
42
+ ### ❤️ Thank You
43
+
44
+ - Ofri Peretz
45
+
46
+ ---
47
+
48
+ ## [0.2.2] - 2025-11-07
49
+
50
+ ### 🩹 Fixes
51
+
52
+ - Config fixes; removed codecov vite plugin.
53
+ - Adjusted ignore patterns in dependency checks.
54
+ - Added vitest to peerDependencies.
55
+
56
+ ### ❤️ Thank You
57
+
58
+ - Ofri Peretz
59
+
60
+ ---
61
+
62
+ ## [0.2.1] - 2025-11-07
63
+
64
+ ### 🩹 Fixes
65
+
66
+ - Config and dependency-check adjustments.
67
+
68
+ ### ❤️ Thank You
69
+
70
+ - Ofri Peretz
71
+
72
+ ---
73
+
74
+ ## [0.2.0] - 2025-11-02
75
+
76
+ Version bump to align packages; no code changes.
77
+
78
+ ---
79
+
80
+ ## [0.1.1] - 2025-11-02
81
+
82
+ Version bump to align packages; no code changes.
83
+
84
+ ---
85
+
86
+ ## [0.1.0] - 2025-11-02
87
+
88
+ Initial prerelease for the devkit utilities.
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Ofri Peretz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+