@interlace/eslint-devkit 1.2.1 → 1.3.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/AGENTS.md +99 -300
- package/README.md +4 -3
- package/package.json +2 -3
- package/src/aria-definitions.d.ts +5 -0
- package/src/aria-definitions.js +7 -3
- package/src/ast/ast-utils.d.ts +5 -0
- package/src/ast/ast-utils.js +5 -1
- package/src/ast/index.d.ts +5 -0
- package/src/ast/index.js +5 -1
- package/src/index.d.ts +7 -2
- package/src/index.js +9 -4
- package/src/messaging/config.d.ts +129 -0
- package/src/messaging/config.js +186 -0
- package/src/messaging/constants.d.ts +16 -2
- package/src/messaging/constants.js +62 -6
- package/src/messaging/formatters-ai.d.ts +94 -0
- package/src/messaging/formatters-ai.js +265 -0
- package/src/messaging/formatters.d.ts +5 -0
- package/src/messaging/formatters.js +3 -4
- package/src/messaging/index.d.ts +7 -0
- package/src/messaging/index.js +7 -1
- package/src/messaging/types.d.ts +39 -1
- package/src/messaging/types.js +3 -4
- package/src/node/fs.d.ts +5 -0
- package/src/node/fs.js +5 -1
- package/src/node/index.d.ts +5 -0
- package/src/node/index.js +5 -1
- package/src/node/os.d.ts +5 -0
- package/src/node/os.js +5 -1
- package/src/node/path.d.ts +5 -0
- package/src/node/path.js +5 -1
- package/src/resolver/dependency-analysis.d.ts +5 -0
- package/src/resolver/dependency-analysis.js +5 -1
- package/src/resolver/index.d.ts +5 -0
- package/src/resolver/index.js +5 -1
- package/src/resolver/resolver-adapter.d.ts +5 -0
- package/src/resolver/resolver-adapter.js +5 -1
- package/src/resolver/resolver-detection.d.ts +5 -0
- package/src/resolver/resolver-detection.js +11 -7
- package/src/resolver/resolver.d.ts +5 -0
- package/src/resolver/resolver.js +5 -1
- package/src/resolver.d.ts +5 -0
- package/src/resolver.js +5 -1
- package/src/rule-creation/index.d.ts +5 -0
- package/src/rule-creation/index.js +5 -1
- package/src/rule-creation/rule-creator.d.ts +5 -0
- package/src/rule-creation/rule-creator.js +6 -2
- package/src/security/index.d.ts +5 -0
- package/src/security/index.js +5 -1
- package/src/security/security-utils.d.ts +5 -0
- package/src/security/security-utils.js +5 -1
- package/src/types/index.d.ts +5 -0
- package/src/types/index.js +5 -1
- package/src/types/type-utils.d.ts +5 -0
- package/src/types/type-utils.js +5 -1
- package/src/aria-definitions.js.map +0 -1
- package/src/ast/ast-utils.js.map +0 -1
- package/src/ast/index.js.map +0 -1
- package/src/index.js.map +0 -1
- package/src/messaging/constants.js.map +0 -1
- package/src/messaging/formatters.js.map +0 -1
- package/src/messaging/index.js.map +0 -1
- package/src/messaging/types.js.map +0 -1
- package/src/node/fs.js.map +0 -1
- package/src/node/index.js.map +0 -1
- package/src/node/os.js.map +0 -1
- package/src/node/path.js.map +0 -1
- package/src/resolver/dependency-analysis.js.map +0 -1
- package/src/resolver/index.js.map +0 -1
- package/src/resolver/resolver-adapter.js.map +0 -1
- package/src/resolver/resolver-detection.js.map +0 -1
- package/src/resolver/resolver.js.map +0 -1
- package/src/resolver.js.map +0 -1
- package/src/rule-creation/index.js.map +0 -1
- package/src/rule-creation/rule-creator.js.map +0 -1
- package/src/security/index.js.map +0 -1
- package/src/security/security-utils.js.map +0 -1
- package/src/types/index.js.map +0 -1
- package/src/types/type-utils.js.map +0 -1
package/AGENTS.md
CHANGED
|
@@ -1,352 +1,151 @@
|
|
|
1
|
-
#
|
|
1
|
+
# AGENTS.md
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> Context for AI coding agents working on @interlace/eslint-devkit
|
|
4
4
|
|
|
5
|
-
|
|
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):**
|
|
5
|
+
## Setup Commands
|
|
26
6
|
|
|
27
7
|
```bash
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
```
|
|
8
|
+
# Install dependencies (from monorepo root)
|
|
9
|
+
pnpm install
|
|
31
10
|
|
|
32
|
-
|
|
11
|
+
# Build this package
|
|
12
|
+
nx build eslint-devkit
|
|
33
13
|
|
|
34
|
-
|
|
14
|
+
# Run tests
|
|
15
|
+
nx test eslint-devkit
|
|
35
16
|
|
|
36
|
-
|
|
37
|
-
|
|
17
|
+
# Run tests with coverage
|
|
18
|
+
nx test eslint-devkit --coverage
|
|
38
19
|
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
});
|
|
20
|
+
# Lint this package
|
|
21
|
+
nx lint eslint-devkit
|
|
71
22
|
```
|
|
72
23
|
|
|
73
|
-
##
|
|
24
|
+
## Code Style
|
|
74
25
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
**Parameters:**
|
|
26
|
+
- TypeScript strict mode
|
|
27
|
+
- Export all public utilities from `src/index.ts`
|
|
28
|
+
- Use TSDoc comments for all public APIs
|
|
29
|
+
- Use `c8 ignore` comments with documented reasons for untestable code
|
|
30
|
+
- Tree-shakeable exports (no side effects)
|
|
82
31
|
|
|
83
|
-
|
|
84
|
-
- `meta` (object): Rule metadata (type, docs, messages, schema)
|
|
85
|
-
- `defaultOptions` (array): Default rule options
|
|
86
|
-
- `create` (function): Rule implementation function
|
|
32
|
+
## Testing Instructions
|
|
87
33
|
|
|
88
|
-
|
|
34
|
+
- Tests use Vitest
|
|
35
|
+
- Test files are in `__tests__/` directories or `*.test.ts` files
|
|
36
|
+
- Coverage target: ≥90% lines, ≥95% functions
|
|
37
|
+
- All tests must pass before committing
|
|
89
38
|
|
|
90
|
-
|
|
39
|
+
## Project Structure
|
|
91
40
|
|
|
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
41
|
```
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
});
|
|
42
|
+
src/
|
|
43
|
+
├── index.ts # Main exports
|
|
44
|
+
├── rule-creator/ # createRule, createRuleCreator
|
|
45
|
+
├── ast-utils/ # AST analysis utilities
|
|
46
|
+
├── type-utils/ # TypeScript type utilities
|
|
47
|
+
├── message-utils/ # formatLLMMessage and icons
|
|
48
|
+
└── types/ # Type definitions
|
|
135
49
|
```
|
|
136
50
|
|
|
137
|
-
|
|
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)` |
|
|
51
|
+
## Package Purpose
|
|
148
52
|
|
|
149
|
-
|
|
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
|
|
53
|
+
Utilities for building **LLM-optimized ESLint rules**. This is the foundation package used by all security plugins in the monorepo. It provides standardized rule creation, AST utilities, type checking helpers, and message formatting.
|
|
172
54
|
|
|
173
|
-
|
|
55
|
+
## Core Exports
|
|
174
56
|
|
|
175
|
-
|
|
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:**
|
|
57
|
+
### Rule Creation
|
|
211
58
|
|
|
212
59
|
```typescript
|
|
213
|
-
import {
|
|
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"
|
|
60
|
+
import { createRule, createRuleCreator } from '@interlace/eslint-devkit';
|
|
220
61
|
```
|
|
221
62
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
### Example 1: Console.log Detection
|
|
63
|
+
### AST Utilities
|
|
225
64
|
|
|
226
65
|
```typescript
|
|
227
66
|
import {
|
|
67
|
+
isNodeOfType,
|
|
68
|
+
isFunctionNode,
|
|
228
69
|
isMemberExpression,
|
|
70
|
+
isCallExpression,
|
|
71
|
+
getIdentifierName,
|
|
72
|
+
getFunctionName,
|
|
73
|
+
getStaticValue,
|
|
229
74
|
isInsideNode,
|
|
230
75
|
getAncestorOfType,
|
|
231
|
-
getIdentifierName,
|
|
232
76
|
} 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
77
|
```
|
|
257
78
|
|
|
258
|
-
###
|
|
79
|
+
### Type Utilities
|
|
259
80
|
|
|
260
81
|
```typescript
|
|
261
82
|
import {
|
|
262
83
|
hasParserServices,
|
|
263
84
|
getParserServices,
|
|
264
85
|
getTypeOfNode,
|
|
86
|
+
isStringType,
|
|
87
|
+
isNumberType,
|
|
265
88
|
isPromiseType,
|
|
89
|
+
isArrayType,
|
|
266
90
|
} 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
91
|
```
|
|
298
92
|
|
|
299
|
-
|
|
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.
|
|
93
|
+
### Message Formatting
|
|
311
94
|
|
|
312
|
-
|
|
313
|
-
|
|
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.
|
|
95
|
+
```typescript
|
|
96
|
+
import { formatLLMMessage, MessageIcons } from '@interlace/eslint-devkit';
|
|
97
|
+
```
|
|
335
98
|
|
|
336
|
-
|
|
337
|
-
A: Use `context.report()` with a `fix` function that returns a fixer operation.
|
|
99
|
+
### Type Re-exports
|
|
338
100
|
|
|
339
|
-
|
|
101
|
+
```typescript
|
|
102
|
+
import { TSESLint, TSESTree, AST_NODE_TYPES } from '@interlace/eslint-devkit';
|
|
103
|
+
```
|
|
340
104
|
|
|
341
|
-
|
|
342
|
-
- **@typescript-eslint/utils:** Official TypeScript ESLint utilities
|
|
105
|
+
## Creating a New Rule
|
|
343
106
|
|
|
344
|
-
|
|
107
|
+
```typescript
|
|
108
|
+
import {
|
|
109
|
+
createRule,
|
|
110
|
+
formatLLMMessage,
|
|
111
|
+
MessageIcons,
|
|
112
|
+
AST_NODE_TYPES,
|
|
113
|
+
} from '@interlace/eslint-devkit';
|
|
345
114
|
|
|
346
|
-
|
|
115
|
+
export const myRule = createRule({
|
|
116
|
+
name: 'my-rule',
|
|
117
|
+
meta: {
|
|
118
|
+
type: 'problem',
|
|
119
|
+
docs: { description: 'My rule description' },
|
|
120
|
+
hasSuggestions: true,
|
|
121
|
+
messages: {
|
|
122
|
+
error: formatLLMMessage({
|
|
123
|
+
icon: MessageIcons.SECURITY,
|
|
124
|
+
issueName: 'Security Issue',
|
|
125
|
+
cwe: 'CWE-XXX',
|
|
126
|
+
description: 'Description of the issue',
|
|
127
|
+
severity: 'HIGH',
|
|
128
|
+
fix: 'How to fix it',
|
|
129
|
+
documentationLink: 'https://...',
|
|
130
|
+
}),
|
|
131
|
+
},
|
|
132
|
+
schema: [],
|
|
133
|
+
},
|
|
134
|
+
defaultOptions: [],
|
|
135
|
+
create(context) {
|
|
136
|
+
return {
|
|
137
|
+
CallExpression(node) {
|
|
138
|
+
// Rule implementation
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
```
|
|
347
144
|
|
|
348
|
-
##
|
|
145
|
+
## Best Practices
|
|
349
146
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
147
|
+
1. **Use AST_NODE_TYPES**: Always use `AST_NODE_TYPES.Identifier` instead of string `'Identifier'`
|
|
148
|
+
2. **Use formatLLMMessage**: All security messages should use the structured format
|
|
149
|
+
3. **Check parser services**: Always check `hasParserServices()` before using type utilities
|
|
150
|
+
4. **Single-pass traversal**: Rules should visit nodes once (O(n) complexity)
|
|
151
|
+
5. **Export rule options types**: Export the Options interface for TypeScript users
|
package/README.md
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@interlace/eslint-devkit)
|
|
6
6
|
[](https://www.npmjs.com/package/@interlace/eslint-devkit)
|
|
7
|
+
[](https://app.codecov.io/gh/ofri-peretz/eslint/components?components%5B0%5D=eslint_devkit)
|
|
7
8
|
|
|
8
9
|
> **Keywords:** ESLint utilities, LLM-optimized, AI assistant, auto-fix, TypeScript ESLint, AST utilities, type checking, rule creation, GitHub Copilot, Cursor AI, Claude AI, structured error messages, deterministic fixes
|
|
9
10
|
|
|
@@ -150,7 +151,7 @@ Rules built with this utility package achieve:
|
|
|
150
151
|
| **OWASP Mapping** | ✅ 2021 + 2025 | Forward-compatible security standards |
|
|
151
152
|
| **Compliance Tags** | ✅ Auto | SOC2, HIPAA, PCI-DSS, GDPR, ISO27001 |
|
|
152
153
|
|
|
153
|
-
> 📊 **[Full Benchmarks →](https://github.com/ofri-peretz/
|
|
154
|
+
> 📊 **[Full Benchmarks →](https://github.com/ofri-peretz/eslint/blob/main/docs/BENCHMARK.md)**
|
|
154
155
|
|
|
155
156
|
---
|
|
156
157
|
|
|
@@ -505,7 +506,7 @@ const rule = createRule<[], 'messageId'>({
|
|
|
505
506
|
|
|
506
507
|
## Related Packages
|
|
507
508
|
|
|
508
|
-
- **[
|
|
509
|
+
- **[eslint-plugin-llm-optimized](https://www.npmjs.com/package/eslint-plugin-llm-optimized)** - Ready-to-use LLM-optimized rules built with this package
|
|
509
510
|
- **[@typescript-eslint/utils](https://www.npmjs.com/package/@typescript-eslint/utils)** - Official TypeScript ESLint utilities
|
|
510
511
|
- **[eslint-plugin-import](https://www.npmjs.com/package/eslint-plugin-import)** - Import/export validation
|
|
511
512
|
|
|
@@ -519,7 +520,7 @@ MIT © [Ofri Peretz](https://github.com/ofri-peretz)
|
|
|
519
520
|
|
|
520
521
|
## Contributing
|
|
521
522
|
|
|
522
|
-
Contributions welcome! See [CONTRIBUTING.md](https://github.com/ofri-peretz/
|
|
523
|
+
Contributions welcome! See [CONTRIBUTING.md](https://github.com/ofri-peretz/eslint/blob/main/CONTRIBUTING.md).
|
|
523
524
|
|
|
524
525
|
---
|
|
525
526
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@interlace/eslint-devkit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "TypeScript utilities for building LLM-optimized ESLint plugins - AST helpers, type utilities, security benchmarks, and SARIF output",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -82,7 +82,6 @@
|
|
|
82
82
|
"tslib": "^2.3.0"
|
|
83
83
|
},
|
|
84
84
|
"devDependencies": {
|
|
85
|
-
"@typescript-eslint/parser": "^8.46.2"
|
|
86
|
-
"vitest": "^4.0.4"
|
|
85
|
+
"@typescript-eslint/parser": "^8.46.2"
|
|
87
86
|
}
|
|
88
87
|
}
|
package/src/aria-definitions.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
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.
|
|
5
6
|
*/
|
|
6
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
8
|
exports.ROLE_SUPPORTED_ARIA_PROPS = exports.ARIA_UNSUPPORTED_ELEMENTS = exports.ARIA_REQUIRED_PROPS = exports.ARIA_ATTRIBUTES = exports.ARIA_ROLES = void 0;
|
|
9
|
+
/**
|
|
10
|
+
* ARIA Definitions
|
|
11
|
+
* Lists of valid ARIA roles and attributes
|
|
12
|
+
*/
|
|
8
13
|
exports.ARIA_ROLES = new Set([
|
|
9
14
|
'alert',
|
|
10
15
|
'alertdialog',
|
|
@@ -970,4 +975,3 @@ exports.ROLE_SUPPORTED_ARIA_PROPS = {
|
|
|
970
975
|
]),
|
|
971
976
|
treeitem: new Set(['aria-expanded', 'aria-level', 'aria-selected']),
|
|
972
977
|
};
|
|
973
|
-
//# sourceMappingURL=aria-definitions.js.map
|
package/src/ast/ast-utils.d.ts
CHANGED
package/src/ast/ast-utils.js
CHANGED
|
@@ -1,4 +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
|
+
*/
|
|
2
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
8
|
exports.isNodeOfType = isNodeOfType;
|
|
4
9
|
exports.isFunctionNode = isFunctionNode;
|
|
@@ -198,4 +203,3 @@ function extractFunctionSignature(node) {
|
|
|
198
203
|
}
|
|
199
204
|
return `(${params}) => {...}`;
|
|
200
205
|
}
|
|
201
|
-
//# sourceMappingURL=ast-utils.js.map
|
package/src/ast/index.d.ts
CHANGED
package/src/ast/index.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
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
|
+
*/
|
|
2
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
8
|
const tslib_1 = require("tslib");
|
|
4
9
|
// AST utilities for ESLint rule development
|
|
5
10
|
tslib_1.__exportStar(require("../ast/ast-utils"), exports);
|
|
6
|
-
//# sourceMappingURL=index.js.map
|
package/src/index.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
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
|
+
*/
|
|
1
6
|
/**
|
|
2
7
|
* @interlace/eslint-devkit
|
|
3
8
|
*
|
|
@@ -21,8 +26,8 @@ export * from './security';
|
|
|
21
26
|
export * from './node';
|
|
22
27
|
export * from './resolver';
|
|
23
28
|
export * from './aria-definitions';
|
|
24
|
-
export type { Severity, OWASPCategory, OWASP2025Category, OWASP2021Category, ComplianceFramework, LLMMessageOptions, EnterpriseMessageOptions, SARIFResult, } from './messaging';
|
|
25
|
-
export { CVSS_RANGES, CWE_MAPPING, CWE_COMPLIANCE_MAPPING, OWASP_DETAILS, OWASP_2025_DETAILS, OWASP_2021_DETAILS, OWASP_2021_TO_2025, MessageIcons, getSecurityBenchmarks, severityToCVSS, toSARIF, } from './messaging';
|
|
29
|
+
export type { Severity, OWASPCategory, OWASP2025Category, OWASP2021Category, OWASPServerlessCategory, ComplianceFramework, LLMMessageOptions, EnterpriseMessageOptions, SARIFResult, } from './messaging';
|
|
30
|
+
export { CVSS_RANGES, CWE_MAPPING, CWE_COMPLIANCE_MAPPING, OWASP_DETAILS, OWASP_2025_DETAILS, OWASP_2021_DETAILS, OWASP_SERVERLESS_DETAILS, OWASP_2021_TO_2025, MessageIcons, getSecurityBenchmarks, severityToCVSS, toSARIF, } from './messaging';
|
|
26
31
|
/**
|
|
27
32
|
* Re-export commonly used types and utilities from @typescript-eslint/utils
|
|
28
33
|
*/
|
package/src/index.js
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.AST_NODE_TYPES = exports.ESLintUtils = exports.toSARIF = exports.severityToCVSS = exports.getSecurityBenchmarks = exports.MessageIcons = exports.OWASP_2021_TO_2025 = exports.OWASP_SERVERLESS_DETAILS = exports.OWASP_2021_DETAILS = exports.OWASP_2025_DETAILS = exports.OWASP_DETAILS = exports.CWE_COMPLIANCE_MAPPING = exports.CWE_MAPPING = exports.CVSS_RANGES = void 0;
|
|
9
|
+
const tslib_1 = require("tslib");
|
|
2
10
|
/**
|
|
3
11
|
* @interlace/eslint-devkit
|
|
4
12
|
*
|
|
@@ -14,9 +22,6 @@
|
|
|
14
22
|
* - SARIF output for security tool integration
|
|
15
23
|
* - Custom message templates for organizations
|
|
16
24
|
*/
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.AST_NODE_TYPES = exports.ESLintUtils = exports.toSARIF = exports.severityToCVSS = exports.getSecurityBenchmarks = exports.MessageIcons = exports.OWASP_2021_TO_2025 = exports.OWASP_2021_DETAILS = exports.OWASP_2025_DETAILS = exports.OWASP_DETAILS = exports.CWE_COMPLIANCE_MAPPING = exports.CWE_MAPPING = exports.CVSS_RANGES = void 0;
|
|
19
|
-
const tslib_1 = require("tslib");
|
|
20
25
|
// Rule creation utilities
|
|
21
26
|
tslib_1.__exportStar(require("./rule-creation"), exports);
|
|
22
27
|
// AST utilities
|
|
@@ -40,6 +45,7 @@ Object.defineProperty(exports, "CWE_COMPLIANCE_MAPPING", { enumerable: true, get
|
|
|
40
45
|
Object.defineProperty(exports, "OWASP_DETAILS", { enumerable: true, get: function () { return messaging_1.OWASP_DETAILS; } });
|
|
41
46
|
Object.defineProperty(exports, "OWASP_2025_DETAILS", { enumerable: true, get: function () { return messaging_1.OWASP_2025_DETAILS; } });
|
|
42
47
|
Object.defineProperty(exports, "OWASP_2021_DETAILS", { enumerable: true, get: function () { return messaging_1.OWASP_2021_DETAILS; } });
|
|
48
|
+
Object.defineProperty(exports, "OWASP_SERVERLESS_DETAILS", { enumerable: true, get: function () { return messaging_1.OWASP_SERVERLESS_DETAILS; } });
|
|
43
49
|
Object.defineProperty(exports, "OWASP_2021_TO_2025", { enumerable: true, get: function () { return messaging_1.OWASP_2021_TO_2025; } });
|
|
44
50
|
Object.defineProperty(exports, "MessageIcons", { enumerable: true, get: function () { return messaging_1.MessageIcons; } });
|
|
45
51
|
Object.defineProperty(exports, "getSecurityBenchmarks", { enumerable: true, get: function () { return messaging_1.getSecurityBenchmarks; } });
|
|
@@ -51,4 +57,3 @@ Object.defineProperty(exports, "toSARIF", { enumerable: true, get: function () {
|
|
|
51
57
|
var utils_1 = require("@typescript-eslint/utils");
|
|
52
58
|
Object.defineProperty(exports, "ESLintUtils", { enumerable: true, get: function () { return utils_1.ESLintUtils; } });
|
|
53
59
|
Object.defineProperty(exports, "AST_NODE_TYPES", { enumerable: true, get: function () { return utils_1.AST_NODE_TYPES; } });
|
|
54
|
-
//# sourceMappingURL=index.js.map
|