@alint-js/core 0.0.28 → 0.0.29
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/dist/agent.d.mts +1 -1
- package/dist/extract-CIWssxNK.mjs +358 -0
- package/dist/index.d.mts +3 -5
- package/dist/index.mjs +3 -357
- package/dist/languages-js.d.mts +5 -0
- package/dist/languages-js.mjs +2 -0
- package/dist/structured-output.d.mts +1 -1
- package/dist/{types-BM_nUu_Z.d.mts → types-CMLoj9J9.d.mts} +2 -86
- package/dist/types-DSvXUVZ7.d.mts +86 -0
- package/package.json +5 -1
package/dist/agent.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as AgentTool, D as AgentAdapter, O as AgentRequest, j as AgentUsage, k as AgentResult, v as RuleContext } from "./types-CMLoj9J9.mjs";
|
|
2
2
|
//#region src/agent/retry.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* Declares that the complete adapter invocation can be safely replayed.
|
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { extname } from "node:path";
|
|
3
|
+
import { clamp } from "es-toolkit";
|
|
4
|
+
import { parseSync } from "oxc-parser";
|
|
5
|
+
//#region src/core/source/runtime.ts
|
|
6
|
+
function createSourceFile(path, text) {
|
|
7
|
+
return {
|
|
8
|
+
language: inferLanguage(path),
|
|
9
|
+
lines: text.split(/\r?\n/),
|
|
10
|
+
path,
|
|
11
|
+
text
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function createSourceRuntime() {
|
|
15
|
+
return {
|
|
16
|
+
getText,
|
|
17
|
+
readFile: async (filePath) => createSourceFile(filePath, await readFile(filePath, "utf8")),
|
|
18
|
+
sliceLines,
|
|
19
|
+
sliceRange
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function getText(target) {
|
|
23
|
+
return target.text;
|
|
24
|
+
}
|
|
25
|
+
function sliceLines(file, range) {
|
|
26
|
+
const startLine = clampLine(range.startLine, file.lines.length);
|
|
27
|
+
const endLine = clampLine(range.endLine, file.lines.length);
|
|
28
|
+
const orderedStartLine = Math.min(startLine, endLine);
|
|
29
|
+
const orderedEndLine = Math.max(startLine, endLine);
|
|
30
|
+
const text = file.lines.slice(orderedStartLine - 1, orderedEndLine).join("\n");
|
|
31
|
+
return {
|
|
32
|
+
filePath: file.path,
|
|
33
|
+
loc: {
|
|
34
|
+
end: {
|
|
35
|
+
column: file.lines[orderedEndLine - 1]?.length ?? 0,
|
|
36
|
+
line: orderedEndLine
|
|
37
|
+
},
|
|
38
|
+
start: {
|
|
39
|
+
column: 0,
|
|
40
|
+
line: orderedStartLine
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
text
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function sliceRange(file, range) {
|
|
47
|
+
const start = clampOffset(range.start, file.text.length);
|
|
48
|
+
const end = clampOffset(range.end, file.text.length);
|
|
49
|
+
const orderedStart = Math.min(start, end);
|
|
50
|
+
const orderedEnd = Math.max(start, end);
|
|
51
|
+
return {
|
|
52
|
+
filePath: file.path,
|
|
53
|
+
loc: {
|
|
54
|
+
end: getPosition(file.text, orderedEnd),
|
|
55
|
+
start: getPosition(file.text, orderedStart)
|
|
56
|
+
},
|
|
57
|
+
text: file.text.slice(orderedStart, orderedEnd)
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function clampLine(line, lineCount) {
|
|
61
|
+
if (lineCount === 0) return 1;
|
|
62
|
+
return clamp(Math.trunc(line), 1, lineCount);
|
|
63
|
+
}
|
|
64
|
+
function clampOffset(offset, textLength) {
|
|
65
|
+
return clamp(Math.trunc(offset), 0, textLength);
|
|
66
|
+
}
|
|
67
|
+
function getPosition(text, offset) {
|
|
68
|
+
let line = 1;
|
|
69
|
+
let column = 0;
|
|
70
|
+
let index = 0;
|
|
71
|
+
while (index < offset) {
|
|
72
|
+
const character = text[index];
|
|
73
|
+
if (character === "\r") {
|
|
74
|
+
if (text[index + 1] === "\n" && index + 1 < offset) index += 1;
|
|
75
|
+
line += 1;
|
|
76
|
+
column = 0;
|
|
77
|
+
} else if (character === "\n") {
|
|
78
|
+
line += 1;
|
|
79
|
+
column = 0;
|
|
80
|
+
} else column += 1;
|
|
81
|
+
index += 1;
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
column,
|
|
85
|
+
line
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function inferLanguage(path) {
|
|
89
|
+
switch (extname(path)) {
|
|
90
|
+
case ".cjs":
|
|
91
|
+
case ".js":
|
|
92
|
+
case ".jsx":
|
|
93
|
+
case ".mjs": return "javascript";
|
|
94
|
+
case ".cts":
|
|
95
|
+
case ".mts":
|
|
96
|
+
case ".ts":
|
|
97
|
+
case ".tsx": return "typescript";
|
|
98
|
+
default: return "unknown";
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/core/languages/js/parser.ts
|
|
103
|
+
function parseSync$1(filename, sourceText, options) {
|
|
104
|
+
return parseSync(filename, sourceText, options);
|
|
105
|
+
}
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region src/core/languages/js/extract.ts
|
|
108
|
+
function extractJsSourceTargets(file) {
|
|
109
|
+
const result = parseSync$1(file.path, file.text, { sourceType: "module" });
|
|
110
|
+
const state = {
|
|
111
|
+
bindingNodes: /* @__PURE__ */ new Map(),
|
|
112
|
+
exportedNodes: /* @__PURE__ */ new Set(),
|
|
113
|
+
file,
|
|
114
|
+
inferredNames: /* @__PURE__ */ new Map(),
|
|
115
|
+
seenClasses: /* @__PURE__ */ new Set(),
|
|
116
|
+
seenFunctions: /* @__PURE__ */ new Set(),
|
|
117
|
+
targets: [],
|
|
118
|
+
visited: /* @__PURE__ */ new Set()
|
|
119
|
+
};
|
|
120
|
+
collectModuleBindings(result.program, state);
|
|
121
|
+
collectExportedBindings(result.program, state);
|
|
122
|
+
visit(result.program, state);
|
|
123
|
+
const sortedTargets = [...state.targets].sort((left, right) => (left.range?.start ?? 0) - (right.range?.start ?? 0));
|
|
124
|
+
return [createFileTarget(file), ...withStableIdentities(sortedTargets)];
|
|
125
|
+
}
|
|
126
|
+
function addClassTarget(node, state) {
|
|
127
|
+
if (state.seenClasses.has(node)) return;
|
|
128
|
+
const target = createClassTarget(node, state);
|
|
129
|
+
if (!target) return;
|
|
130
|
+
state.seenClasses.add(node);
|
|
131
|
+
state.targets.push(target);
|
|
132
|
+
}
|
|
133
|
+
function addFunctionTarget(node, state) {
|
|
134
|
+
if (state.seenFunctions.has(node)) return;
|
|
135
|
+
const target = createFunctionTarget(node, state);
|
|
136
|
+
if (!target) return;
|
|
137
|
+
state.seenFunctions.add(node);
|
|
138
|
+
state.targets.push(target);
|
|
139
|
+
}
|
|
140
|
+
function asAstNode(value) {
|
|
141
|
+
return isAstNode(value) ? value : void 0;
|
|
142
|
+
}
|
|
143
|
+
function collectDeclarationBindings(node, state) {
|
|
144
|
+
const name = getNodeName(node);
|
|
145
|
+
if (name && (isClassNode(node) || isFunctionNode(node))) {
|
|
146
|
+
state.bindingNodes.set(name, node);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
if (node.type !== "VariableDeclaration" || !Array.isArray(node.declarations)) return;
|
|
150
|
+
for (const declarator of node.declarations) {
|
|
151
|
+
if (!isAstNode(declarator)) continue;
|
|
152
|
+
const id = asAstNode(declarator.id);
|
|
153
|
+
const initializer = asAstNode(declarator.init);
|
|
154
|
+
if (typeof id?.name === "string" && initializer && (isClassNode(initializer) || isFunctionNode(initializer))) state.bindingNodes.set(id.name, initializer);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function collectExportedBindings(node, state) {
|
|
158
|
+
if (!node) return;
|
|
159
|
+
if (Array.isArray(node)) {
|
|
160
|
+
for (const child of node) collectExportedBindings(child, state);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (node.type === "ExportNamedDeclaration" && !node.source && Array.isArray(node.specifiers)) for (const specifier of node.specifiers) {
|
|
164
|
+
if (!isAstNode(specifier) || specifier.type !== "ExportSpecifier") continue;
|
|
165
|
+
const local = asAstNode(specifier.local);
|
|
166
|
+
if (typeof local?.name === "string") markExportedBinding(local.name, state);
|
|
167
|
+
}
|
|
168
|
+
else if (node.type === "ExportDefaultDeclaration") {
|
|
169
|
+
const declaration = asAstNode(node.declaration);
|
|
170
|
+
if (typeof declaration?.name === "string") markExportedBinding(declaration.name, state);
|
|
171
|
+
}
|
|
172
|
+
for (const value of Object.values(node)) if (Array.isArray(value)) collectExportedBindings(value.filter(isAstNode), state);
|
|
173
|
+
else if (isAstNode(value)) collectExportedBindings(value, state);
|
|
174
|
+
}
|
|
175
|
+
function collectModuleBindings(program, state) {
|
|
176
|
+
if (!Array.isArray(program.body)) return;
|
|
177
|
+
for (const statement of program.body) {
|
|
178
|
+
if (!isAstNode(statement)) continue;
|
|
179
|
+
const declaration = isExportDeclaration(statement) ? asAstNode(statement.declaration) : statement;
|
|
180
|
+
if (declaration) collectDeclarationBindings(declaration, state);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
function createClassTarget(node, state) {
|
|
184
|
+
const range = getRange(node);
|
|
185
|
+
if (!range) return;
|
|
186
|
+
const source = sliceRange(state.file, range);
|
|
187
|
+
const name = getNodeName(node) ?? state.inferredNames.get(node);
|
|
188
|
+
return {
|
|
189
|
+
file: state.file,
|
|
190
|
+
identity: createRangeIdentity("class", name, range),
|
|
191
|
+
kind: "class",
|
|
192
|
+
language: state.file.language,
|
|
193
|
+
loc: source.loc,
|
|
194
|
+
metadata: { exported: isExportedTarget(node, state) },
|
|
195
|
+
name,
|
|
196
|
+
origin: {
|
|
197
|
+
physicalPath: state.file.path,
|
|
198
|
+
range
|
|
199
|
+
},
|
|
200
|
+
range,
|
|
201
|
+
text: source.text
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
function createFileTarget(file) {
|
|
205
|
+
return {
|
|
206
|
+
file,
|
|
207
|
+
identity: "file",
|
|
208
|
+
kind: "file",
|
|
209
|
+
language: file.language,
|
|
210
|
+
origin: { physicalPath: file.path },
|
|
211
|
+
text: file.text
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
function createFunctionTarget(node, state) {
|
|
215
|
+
const range = getRange(node);
|
|
216
|
+
if (!range) return;
|
|
217
|
+
const source = sliceRange(state.file, range);
|
|
218
|
+
const functionNode = node.type === "MethodDefinition" ? asAstNode(node.value) : node;
|
|
219
|
+
const name = getNodeName(node) ?? getNodeName(functionNode) ?? state.inferredNames.get(node);
|
|
220
|
+
return {
|
|
221
|
+
file: state.file,
|
|
222
|
+
identity: createRangeIdentity("function", name, range),
|
|
223
|
+
kind: "function",
|
|
224
|
+
language: state.file.language,
|
|
225
|
+
loc: source.loc,
|
|
226
|
+
metadata: {
|
|
227
|
+
async: functionNode?.async === true,
|
|
228
|
+
exported: isExportedTarget(node, state)
|
|
229
|
+
},
|
|
230
|
+
name,
|
|
231
|
+
origin: {
|
|
232
|
+
physicalPath: state.file.path,
|
|
233
|
+
range
|
|
234
|
+
},
|
|
235
|
+
range,
|
|
236
|
+
text: source.text
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
function createRangeIdentity(kind, name, range) {
|
|
240
|
+
return `${kind}:${name ?? "anonymous"}:${range.start}:${range.end}`;
|
|
241
|
+
}
|
|
242
|
+
function createSemanticIdentity(target) {
|
|
243
|
+
if (target.kind !== "class" && target.kind !== "function" || !target.name) return;
|
|
244
|
+
return `${target.kind}:${target.name}`;
|
|
245
|
+
}
|
|
246
|
+
function getNodeName(node) {
|
|
247
|
+
if (!node) return;
|
|
248
|
+
if (typeof node.name === "string") return node.name;
|
|
249
|
+
const id = asAstNode(node.id);
|
|
250
|
+
if (typeof id?.name === "string") return id.name;
|
|
251
|
+
const key = asAstNode(node.key);
|
|
252
|
+
if (typeof key?.name === "string") return key.name;
|
|
253
|
+
if (typeof key?.value === "string" || typeof key?.value === "number") return String(key.value);
|
|
254
|
+
}
|
|
255
|
+
function getRange(node) {
|
|
256
|
+
if (typeof node.start === "number" && typeof node.end === "number") return {
|
|
257
|
+
end: node.end,
|
|
258
|
+
start: node.start
|
|
259
|
+
};
|
|
260
|
+
if (Array.isArray(node.range) && node.range.length === 2) return {
|
|
261
|
+
end: node.range[1],
|
|
262
|
+
start: node.range[0]
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
function inferChildName(parent, key, child, state) {
|
|
266
|
+
if (state.inferredNames.has(child)) return;
|
|
267
|
+
if (parent.type === "VariableDeclarator" && key === "init") {
|
|
268
|
+
const id = asAstNode(parent.id);
|
|
269
|
+
if (typeof id?.name === "string") state.inferredNames.set(child, id.name);
|
|
270
|
+
}
|
|
271
|
+
if (parent.type === "Property" && key === "value") {
|
|
272
|
+
const name = getNodeName(parent);
|
|
273
|
+
if (name) state.inferredNames.set(child, name);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
function isAstNode(value) {
|
|
277
|
+
return typeof value === "object" && value !== null && typeof value.type === "string";
|
|
278
|
+
}
|
|
279
|
+
function isClassNode(node) {
|
|
280
|
+
return node.type === "ClassDeclaration" || node.type === "ClassExpression";
|
|
281
|
+
}
|
|
282
|
+
function isExportDeclaration(node) {
|
|
283
|
+
return node.type === "ExportDefaultDeclaration" || node.type === "ExportNamedDeclaration";
|
|
284
|
+
}
|
|
285
|
+
function isExportedTarget(node, state) {
|
|
286
|
+
return state.exportedNodes.has(node);
|
|
287
|
+
}
|
|
288
|
+
function isFunctionNode(node) {
|
|
289
|
+
return node.type === "ArrowFunctionExpression" || node.type === "FunctionDeclaration" || node.type === "FunctionExpression";
|
|
290
|
+
}
|
|
291
|
+
function markExportedBinding(name, state) {
|
|
292
|
+
const bindingNode = state.bindingNodes.get(name);
|
|
293
|
+
if (bindingNode) state.exportedNodes.add(bindingNode);
|
|
294
|
+
}
|
|
295
|
+
function markExportedDeclaration(node, state) {
|
|
296
|
+
state.exportedNodes.add(node);
|
|
297
|
+
if (node.type !== "VariableDeclaration" || !Array.isArray(node.declarations)) return;
|
|
298
|
+
for (const declarator of node.declarations) {
|
|
299
|
+
if (!isAstNode(declarator)) continue;
|
|
300
|
+
const initializer = asAstNode(declarator.init);
|
|
301
|
+
if (initializer && (isClassNode(initializer) || isFunctionNode(initializer))) state.exportedNodes.add(initializer);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
function visit(node, state) {
|
|
305
|
+
if (!node) return;
|
|
306
|
+
if (Array.isArray(node)) {
|
|
307
|
+
for (const child of node) visit(child, state);
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
if (state.visited.has(node)) return;
|
|
311
|
+
state.visited.add(node);
|
|
312
|
+
if (node.type === "ExportDefaultDeclaration" || node.type === "ExportNamedDeclaration") {
|
|
313
|
+
if (node.declaration) {
|
|
314
|
+
markExportedDeclaration(node.declaration, state);
|
|
315
|
+
visit(node.declaration, state);
|
|
316
|
+
}
|
|
317
|
+
visitChildren(node, state, /* @__PURE__ */ new Set(["declaration"]));
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
if (isClassNode(node)) addClassTarget(node, state);
|
|
321
|
+
else if (isFunctionNode(node) || node.type === "MethodDefinition") {
|
|
322
|
+
addFunctionTarget(node, state);
|
|
323
|
+
const methodValue = node.type === "MethodDefinition" ? asAstNode(node.value) : void 0;
|
|
324
|
+
if (methodValue) state.seenFunctions.add(methodValue);
|
|
325
|
+
}
|
|
326
|
+
visitChildren(node, state);
|
|
327
|
+
}
|
|
328
|
+
function visitChildren(node, state, skippedKeys = /* @__PURE__ */ new Set()) {
|
|
329
|
+
for (const [key, value] of Object.entries(node)) {
|
|
330
|
+
if (skippedKeys.has(key) || key === "type" || key === "start" || key === "end" || key === "range") continue;
|
|
331
|
+
if (Array.isArray(value)) {
|
|
332
|
+
for (const child of value) if (isAstNode(child)) {
|
|
333
|
+
inferChildName(node, key, child, state);
|
|
334
|
+
visit(child, state);
|
|
335
|
+
}
|
|
336
|
+
} else if (isAstNode(value)) {
|
|
337
|
+
inferChildName(node, key, value, state);
|
|
338
|
+
visit(value, state);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
function withStableIdentities(targets) {
|
|
343
|
+
const semanticIdentityCounts = /* @__PURE__ */ new Map();
|
|
344
|
+
for (const target of targets) {
|
|
345
|
+
const semanticIdentity = createSemanticIdentity(target);
|
|
346
|
+
if (semanticIdentity) semanticIdentityCounts.set(semanticIdentity, (semanticIdentityCounts.get(semanticIdentity) ?? 0) + 1);
|
|
347
|
+
}
|
|
348
|
+
return targets.map((target) => {
|
|
349
|
+
const semanticIdentity = createSemanticIdentity(target);
|
|
350
|
+
if (!semanticIdentity || semanticIdentityCounts.get(semanticIdentity) !== 1) return target;
|
|
351
|
+
return {
|
|
352
|
+
...target,
|
|
353
|
+
identity: semanticIdentity
|
|
354
|
+
};
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
//#endregion
|
|
358
|
+
export { sliceRange as a, sliceLines as i, createSourceFile as n, createSourceRuntime as r, extractJsSourceTargets as t };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { B as RunnerStatsConfig, C as RuleSeverity, E as Target, F as ResolvedProvider, H as SetupModelDefinition, I as ModelSize, L as ProviderDefinition, M as ModelRequirement, N as ResolveModelOptions, P as ResolvedModel, R as ProviderType, S as RuleRegistry, T as RuleWithHandler, V as SetupConfig, _ as RuleConfigEntry, a as AlintLinterOptions, b as RuleHandlers, c as DiagnosticLocation, d as IgnoreConfig, f as LanguageDefinition, g as RuleCacheConfig, h as ProjectTarget, i as AlintConfigItem, l as DirectoryTarget, m as ProcessorDefinition, n as AlintConfigExtends, o as Awaitable, p as PluginDefinition, r as AlintConfigInput, s as DiagnosticDescriptor, t as AlintConfig, u as EnabledRule, v as RuleContext, w as RuleSpecializedHandlers, x as RuleInferenceUsageRecord, y as RuleDefinition, z as RunnerConfig } from "./types-CMLoj9J9.mjs";
|
|
2
|
+
import { _ as SourceTargetOfKind, a as LineRange, c as ProcessorContext, d as SourceLocation, f as SourcePosition, g as SourceTargetKind, h as SourceTarget, i as LanguageContext, l as ProcessorPostprocessContext, m as SourceRuntime, n as FileTarget, o as ProcessedSource, p as SourceRange, r as FunctionTarget, s as ProcessedSourceOrigin, t as ClassTarget, u as SourceFile, v as SourceTargetOrigin, y as SourceText } from "./types-DSvXUVZ7.mjs";
|
|
2
3
|
//#region src/config/config-array.d.ts
|
|
3
4
|
interface EffectiveAlintConfig {
|
|
4
5
|
agent?: AlintConfigItem['agent'];
|
|
@@ -47,9 +48,6 @@ declare function resolveLanguage(file: SourceFile, registry: LanguageRegistry, o
|
|
|
47
48
|
//#region src/core/languages/index.d.ts
|
|
48
49
|
declare function createBuiltInLanguageRegistry(): LanguageRegistry;
|
|
49
50
|
//#endregion
|
|
50
|
-
//#region src/core/languages/js/extract.d.ts
|
|
51
|
-
declare function extractJsSourceTargets(file: SourceFile): SourceTarget[];
|
|
52
|
-
//#endregion
|
|
53
51
|
//#region src/core/types.d.ts
|
|
54
52
|
interface AlintRunFailure {
|
|
55
53
|
filePath?: string;
|
|
@@ -251,4 +249,4 @@ declare function buildRuleRegistry(config: Pick<EffectiveAlintConfig, 'plugins'
|
|
|
251
249
|
//#region src/models/resolve.d.ts
|
|
252
250
|
declare function resolveModel(registry: SetupConfig, options?: ResolveModelOptions): ResolvedModel;
|
|
253
251
|
//#endregion
|
|
254
|
-
export { type AlintConfig, type AlintConfigExtends, type AlintConfigInput, type AlintConfigItem, type AlintLinterOptions, AlintRunError, type AlintRunFailure, type Awaitable, type ClassTarget, type Diagnostic, type DiagnosticDescriptor, type DiagnosticLocation, type DiagnosticProgressPayload, type DirectoryTarget, type EffectiveAlintConfig, type EnabledRule, type FileProgressPayload, type FileTarget, type FunctionTarget, type IgnoreConfig, type InferenceUsageRecord, type LanguageContext, type LanguageDefinition, type LanguageRegistry, type LineRange, type ModelRequirement, type ModelSize, type PluginDefinition, type ProcessedSource, type ProcessedSourceOrigin, type ProcessorContext, type ProcessorDefinition, type ProcessorPostprocessContext, type ProgressFilePath, type ProgressPath, type ProgressReporter, type ProgressTargetKind, type ProjectTarget, type ProviderDefinition, type ProviderType, type ResolveConfigResult, type ResolveLanguageOptions, type ResolveModelOptions, type ResolvedModel, type ResolvedProvider, type RuleCacheConfig, type RuleConfigEntry, type RuleContext, type RuleDefinition, type RuleEndPayload, type RuleHandlers, type RuleInferenceUsageRecord, type RuleRegistry, type RuleSeverity, type RuleSpecializedHandlers, type RuleStartPayload, type RuleWithHandler, type RunEndPayload, type RunExecution, type RunOptions, type RunResult, type RunStartPayload, type RunUsage, type RunUsageTotals, type RunnerConfig, type RunnerStatsConfig, type SetupConfig, type SetupModelDefinition, type SourceFile, type SourceLocation, type SourcePosition, type SourceRange, type SourceRuntime, type SourceTarget, type SourceTargetKind, type SourceTargetOfKind, type SourceTargetOrigin, type SourceText, type Target, type TargetProgressPayload, type UsageProgressPayload, buildRuleRegistry, createBuiltInLanguageRegistry, createSourceFile, createSourceRuntime, defineConfig, definePlugin, defineRule,
|
|
252
|
+
export { type AlintConfig, type AlintConfigExtends, type AlintConfigInput, type AlintConfigItem, type AlintLinterOptions, AlintRunError, type AlintRunFailure, type Awaitable, type ClassTarget, type Diagnostic, type DiagnosticDescriptor, type DiagnosticLocation, type DiagnosticProgressPayload, type DirectoryTarget, type EffectiveAlintConfig, type EnabledRule, type FileProgressPayload, type FileTarget, type FunctionTarget, type IgnoreConfig, type InferenceUsageRecord, type LanguageContext, type LanguageDefinition, type LanguageRegistry, type LineRange, type ModelRequirement, type ModelSize, type PluginDefinition, type ProcessedSource, type ProcessedSourceOrigin, type ProcessorContext, type ProcessorDefinition, type ProcessorPostprocessContext, type ProgressFilePath, type ProgressPath, type ProgressReporter, type ProgressTargetKind, type ProjectTarget, type ProviderDefinition, type ProviderType, type ResolveConfigResult, type ResolveLanguageOptions, type ResolveModelOptions, type ResolvedModel, type ResolvedProvider, type RuleCacheConfig, type RuleConfigEntry, type RuleContext, type RuleDefinition, type RuleEndPayload, type RuleHandlers, type RuleInferenceUsageRecord, type RuleRegistry, type RuleSeverity, type RuleSpecializedHandlers, type RuleStartPayload, type RuleWithHandler, type RunEndPayload, type RunExecution, type RunOptions, type RunResult, type RunStartPayload, type RunUsage, type RunUsageTotals, type RunnerConfig, type RunnerStatsConfig, type SetupConfig, type SetupModelDefinition, type SourceFile, type SourceLocation, type SourcePosition, type SourceRange, type SourceRuntime, type SourceTarget, type SourceTargetKind, type SourceTargetOfKind, type SourceTargetOrigin, type SourceText, type Target, type TargetProgressPayload, type UsageProgressPayload, buildRuleRegistry, createBuiltInLanguageRegistry, createSourceFile, createSourceRuntime, defineConfig, definePlugin, defineRule, hasDiscoveryFilePatterns, matchesDiscoveryFile, normalizeConfig, registerLanguage, resolveConfigForDirectory, resolveConfigForFile, resolveConfigForProject, resolveLanguage, resolveModel, runAlint, sliceLines, sliceRange };
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { r as withAgentRetry } from "./retry-C4sGjSE5.mjs";
|
|
2
|
+
import { a as sliceRange, i as sliceLines, n as createSourceFile, r as createSourceRuntime, t as extractJsSourceTargets } from "./extract-CIWssxNK.mjs";
|
|
2
3
|
import { minimatch } from "minimatch";
|
|
3
4
|
import { isAbsolute, relative, resolve } from "pathe";
|
|
4
5
|
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
5
6
|
import { dirname, extname, isAbsolute as isAbsolute$1, join, relative as relative$1, resolve as resolve$1, sep } from "node:path";
|
|
6
|
-
import { clamp } from "es-toolkit";
|
|
7
|
-
import { parseSync } from "oxc-parser";
|
|
8
7
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
9
8
|
import process, { cwd } from "node:process";
|
|
10
9
|
import { errorCauseFrom, errorMessageFrom } from "@moeru/std/error";
|
|
@@ -233,359 +232,6 @@ function withExpansionMetadata(item, inheritedMatcherScopes, effectiveBasePath)
|
|
|
233
232
|
return item;
|
|
234
233
|
}
|
|
235
234
|
//#endregion
|
|
236
|
-
//#region src/core/source/runtime.ts
|
|
237
|
-
function createSourceFile(path, text) {
|
|
238
|
-
return {
|
|
239
|
-
language: inferLanguage(path),
|
|
240
|
-
lines: text.split(/\r?\n/),
|
|
241
|
-
path,
|
|
242
|
-
text
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
function createSourceRuntime() {
|
|
246
|
-
return {
|
|
247
|
-
getText,
|
|
248
|
-
readFile: async (filePath) => createSourceFile(filePath, await readFile(filePath, "utf8")),
|
|
249
|
-
sliceLines,
|
|
250
|
-
sliceRange
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
function getText(target) {
|
|
254
|
-
return target.text;
|
|
255
|
-
}
|
|
256
|
-
function sliceLines(file, range) {
|
|
257
|
-
const startLine = clampLine(range.startLine, file.lines.length);
|
|
258
|
-
const endLine = clampLine(range.endLine, file.lines.length);
|
|
259
|
-
const orderedStartLine = Math.min(startLine, endLine);
|
|
260
|
-
const orderedEndLine = Math.max(startLine, endLine);
|
|
261
|
-
const text = file.lines.slice(orderedStartLine - 1, orderedEndLine).join("\n");
|
|
262
|
-
return {
|
|
263
|
-
filePath: file.path,
|
|
264
|
-
loc: {
|
|
265
|
-
end: {
|
|
266
|
-
column: file.lines[orderedEndLine - 1]?.length ?? 0,
|
|
267
|
-
line: orderedEndLine
|
|
268
|
-
},
|
|
269
|
-
start: {
|
|
270
|
-
column: 0,
|
|
271
|
-
line: orderedStartLine
|
|
272
|
-
}
|
|
273
|
-
},
|
|
274
|
-
text
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
function sliceRange(file, range) {
|
|
278
|
-
const start = clampOffset(range.start, file.text.length);
|
|
279
|
-
const end = clampOffset(range.end, file.text.length);
|
|
280
|
-
const orderedStart = Math.min(start, end);
|
|
281
|
-
const orderedEnd = Math.max(start, end);
|
|
282
|
-
return {
|
|
283
|
-
filePath: file.path,
|
|
284
|
-
loc: {
|
|
285
|
-
end: getPosition(file.text, orderedEnd),
|
|
286
|
-
start: getPosition(file.text, orderedStart)
|
|
287
|
-
},
|
|
288
|
-
text: file.text.slice(orderedStart, orderedEnd)
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
function clampLine(line, lineCount) {
|
|
292
|
-
if (lineCount === 0) return 1;
|
|
293
|
-
return clamp(Math.trunc(line), 1, lineCount);
|
|
294
|
-
}
|
|
295
|
-
function clampOffset(offset, textLength) {
|
|
296
|
-
return clamp(Math.trunc(offset), 0, textLength);
|
|
297
|
-
}
|
|
298
|
-
function getPosition(text, offset) {
|
|
299
|
-
let line = 1;
|
|
300
|
-
let column = 0;
|
|
301
|
-
let index = 0;
|
|
302
|
-
while (index < offset) {
|
|
303
|
-
const character = text[index];
|
|
304
|
-
if (character === "\r") {
|
|
305
|
-
if (text[index + 1] === "\n" && index + 1 < offset) index += 1;
|
|
306
|
-
line += 1;
|
|
307
|
-
column = 0;
|
|
308
|
-
} else if (character === "\n") {
|
|
309
|
-
line += 1;
|
|
310
|
-
column = 0;
|
|
311
|
-
} else column += 1;
|
|
312
|
-
index += 1;
|
|
313
|
-
}
|
|
314
|
-
return {
|
|
315
|
-
column,
|
|
316
|
-
line
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
function inferLanguage(path) {
|
|
320
|
-
switch (extname(path)) {
|
|
321
|
-
case ".cjs":
|
|
322
|
-
case ".js":
|
|
323
|
-
case ".jsx":
|
|
324
|
-
case ".mjs": return "javascript";
|
|
325
|
-
case ".cts":
|
|
326
|
-
case ".mts":
|
|
327
|
-
case ".ts":
|
|
328
|
-
case ".tsx": return "typescript";
|
|
329
|
-
default: return "unknown";
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
//#endregion
|
|
333
|
-
//#region src/core/languages/js/parser.ts
|
|
334
|
-
function parseSync$1(filename, sourceText, options) {
|
|
335
|
-
return parseSync(filename, sourceText, options);
|
|
336
|
-
}
|
|
337
|
-
//#endregion
|
|
338
|
-
//#region src/core/languages/js/extract.ts
|
|
339
|
-
function extractJsSourceTargets(file) {
|
|
340
|
-
const result = parseSync$1(file.path, file.text, { sourceType: "module" });
|
|
341
|
-
const state = {
|
|
342
|
-
bindingNodes: /* @__PURE__ */ new Map(),
|
|
343
|
-
exportedNodes: /* @__PURE__ */ new Set(),
|
|
344
|
-
file,
|
|
345
|
-
inferredNames: /* @__PURE__ */ new Map(),
|
|
346
|
-
seenClasses: /* @__PURE__ */ new Set(),
|
|
347
|
-
seenFunctions: /* @__PURE__ */ new Set(),
|
|
348
|
-
targets: [],
|
|
349
|
-
visited: /* @__PURE__ */ new Set()
|
|
350
|
-
};
|
|
351
|
-
collectModuleBindings(result.program, state);
|
|
352
|
-
collectExportedBindings(result.program, state);
|
|
353
|
-
visit(result.program, state);
|
|
354
|
-
const sortedTargets = [...state.targets].sort((left, right) => (left.range?.start ?? 0) - (right.range?.start ?? 0));
|
|
355
|
-
return [createFileTarget(file), ...withStableIdentities(sortedTargets)];
|
|
356
|
-
}
|
|
357
|
-
function addClassTarget(node, state) {
|
|
358
|
-
if (state.seenClasses.has(node)) return;
|
|
359
|
-
const target = createClassTarget(node, state);
|
|
360
|
-
if (!target) return;
|
|
361
|
-
state.seenClasses.add(node);
|
|
362
|
-
state.targets.push(target);
|
|
363
|
-
}
|
|
364
|
-
function addFunctionTarget(node, state) {
|
|
365
|
-
if (state.seenFunctions.has(node)) return;
|
|
366
|
-
const target = createFunctionTarget(node, state);
|
|
367
|
-
if (!target) return;
|
|
368
|
-
state.seenFunctions.add(node);
|
|
369
|
-
state.targets.push(target);
|
|
370
|
-
}
|
|
371
|
-
function asAstNode(value) {
|
|
372
|
-
return isAstNode(value) ? value : void 0;
|
|
373
|
-
}
|
|
374
|
-
function collectDeclarationBindings(node, state) {
|
|
375
|
-
const name = getNodeName(node);
|
|
376
|
-
if (name && (isClassNode(node) || isFunctionNode(node))) {
|
|
377
|
-
state.bindingNodes.set(name, node);
|
|
378
|
-
return;
|
|
379
|
-
}
|
|
380
|
-
if (node.type !== "VariableDeclaration" || !Array.isArray(node.declarations)) return;
|
|
381
|
-
for (const declarator of node.declarations) {
|
|
382
|
-
if (!isAstNode(declarator)) continue;
|
|
383
|
-
const id = asAstNode(declarator.id);
|
|
384
|
-
const initializer = asAstNode(declarator.init);
|
|
385
|
-
if (typeof id?.name === "string" && initializer && (isClassNode(initializer) || isFunctionNode(initializer))) state.bindingNodes.set(id.name, initializer);
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
function collectExportedBindings(node, state) {
|
|
389
|
-
if (!node) return;
|
|
390
|
-
if (Array.isArray(node)) {
|
|
391
|
-
for (const child of node) collectExportedBindings(child, state);
|
|
392
|
-
return;
|
|
393
|
-
}
|
|
394
|
-
if (node.type === "ExportNamedDeclaration" && !node.source && Array.isArray(node.specifiers)) for (const specifier of node.specifiers) {
|
|
395
|
-
if (!isAstNode(specifier) || specifier.type !== "ExportSpecifier") continue;
|
|
396
|
-
const local = asAstNode(specifier.local);
|
|
397
|
-
if (typeof local?.name === "string") markExportedBinding(local.name, state);
|
|
398
|
-
}
|
|
399
|
-
else if (node.type === "ExportDefaultDeclaration") {
|
|
400
|
-
const declaration = asAstNode(node.declaration);
|
|
401
|
-
if (typeof declaration?.name === "string") markExportedBinding(declaration.name, state);
|
|
402
|
-
}
|
|
403
|
-
for (const value of Object.values(node)) if (Array.isArray(value)) collectExportedBindings(value.filter(isAstNode), state);
|
|
404
|
-
else if (isAstNode(value)) collectExportedBindings(value, state);
|
|
405
|
-
}
|
|
406
|
-
function collectModuleBindings(program, state) {
|
|
407
|
-
if (!Array.isArray(program.body)) return;
|
|
408
|
-
for (const statement of program.body) {
|
|
409
|
-
if (!isAstNode(statement)) continue;
|
|
410
|
-
const declaration = isExportDeclaration(statement) ? asAstNode(statement.declaration) : statement;
|
|
411
|
-
if (declaration) collectDeclarationBindings(declaration, state);
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
function createClassTarget(node, state) {
|
|
415
|
-
const range = getRange(node);
|
|
416
|
-
if (!range) return;
|
|
417
|
-
const source = sliceRange(state.file, range);
|
|
418
|
-
const name = getNodeName(node) ?? state.inferredNames.get(node);
|
|
419
|
-
return {
|
|
420
|
-
file: state.file,
|
|
421
|
-
identity: createRangeIdentity("class", name, range),
|
|
422
|
-
kind: "class",
|
|
423
|
-
language: state.file.language,
|
|
424
|
-
loc: source.loc,
|
|
425
|
-
metadata: { exported: isExportedTarget(node, state) },
|
|
426
|
-
name,
|
|
427
|
-
origin: {
|
|
428
|
-
physicalPath: state.file.path,
|
|
429
|
-
range
|
|
430
|
-
},
|
|
431
|
-
range,
|
|
432
|
-
text: source.text
|
|
433
|
-
};
|
|
434
|
-
}
|
|
435
|
-
function createFileTarget(file) {
|
|
436
|
-
return {
|
|
437
|
-
file,
|
|
438
|
-
identity: "file",
|
|
439
|
-
kind: "file",
|
|
440
|
-
language: file.language,
|
|
441
|
-
origin: { physicalPath: file.path },
|
|
442
|
-
text: file.text
|
|
443
|
-
};
|
|
444
|
-
}
|
|
445
|
-
function createFunctionTarget(node, state) {
|
|
446
|
-
const range = getRange(node);
|
|
447
|
-
if (!range) return;
|
|
448
|
-
const source = sliceRange(state.file, range);
|
|
449
|
-
const functionNode = node.type === "MethodDefinition" ? asAstNode(node.value) : node;
|
|
450
|
-
const name = getNodeName(node) ?? getNodeName(functionNode) ?? state.inferredNames.get(node);
|
|
451
|
-
return {
|
|
452
|
-
file: state.file,
|
|
453
|
-
identity: createRangeIdentity("function", name, range),
|
|
454
|
-
kind: "function",
|
|
455
|
-
language: state.file.language,
|
|
456
|
-
loc: source.loc,
|
|
457
|
-
metadata: {
|
|
458
|
-
async: functionNode?.async === true,
|
|
459
|
-
exported: isExportedTarget(node, state)
|
|
460
|
-
},
|
|
461
|
-
name,
|
|
462
|
-
origin: {
|
|
463
|
-
physicalPath: state.file.path,
|
|
464
|
-
range
|
|
465
|
-
},
|
|
466
|
-
range,
|
|
467
|
-
text: source.text
|
|
468
|
-
};
|
|
469
|
-
}
|
|
470
|
-
function createRangeIdentity(kind, name, range) {
|
|
471
|
-
return `${kind}:${name ?? "anonymous"}:${range.start}:${range.end}`;
|
|
472
|
-
}
|
|
473
|
-
function createSemanticIdentity(target) {
|
|
474
|
-
if (target.kind !== "class" && target.kind !== "function" || !target.name) return;
|
|
475
|
-
return `${target.kind}:${target.name}`;
|
|
476
|
-
}
|
|
477
|
-
function getNodeName(node) {
|
|
478
|
-
if (!node) return;
|
|
479
|
-
if (typeof node.name === "string") return node.name;
|
|
480
|
-
const id = asAstNode(node.id);
|
|
481
|
-
if (typeof id?.name === "string") return id.name;
|
|
482
|
-
const key = asAstNode(node.key);
|
|
483
|
-
if (typeof key?.name === "string") return key.name;
|
|
484
|
-
if (typeof key?.value === "string" || typeof key?.value === "number") return String(key.value);
|
|
485
|
-
}
|
|
486
|
-
function getRange(node) {
|
|
487
|
-
if (typeof node.start === "number" && typeof node.end === "number") return {
|
|
488
|
-
end: node.end,
|
|
489
|
-
start: node.start
|
|
490
|
-
};
|
|
491
|
-
if (Array.isArray(node.range) && node.range.length === 2) return {
|
|
492
|
-
end: node.range[1],
|
|
493
|
-
start: node.range[0]
|
|
494
|
-
};
|
|
495
|
-
}
|
|
496
|
-
function inferChildName(parent, key, child, state) {
|
|
497
|
-
if (state.inferredNames.has(child)) return;
|
|
498
|
-
if (parent.type === "VariableDeclarator" && key === "init") {
|
|
499
|
-
const id = asAstNode(parent.id);
|
|
500
|
-
if (typeof id?.name === "string") state.inferredNames.set(child, id.name);
|
|
501
|
-
}
|
|
502
|
-
if (parent.type === "Property" && key === "value") {
|
|
503
|
-
const name = getNodeName(parent);
|
|
504
|
-
if (name) state.inferredNames.set(child, name);
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
function isAstNode(value) {
|
|
508
|
-
return typeof value === "object" && value !== null && typeof value.type === "string";
|
|
509
|
-
}
|
|
510
|
-
function isClassNode(node) {
|
|
511
|
-
return node.type === "ClassDeclaration" || node.type === "ClassExpression";
|
|
512
|
-
}
|
|
513
|
-
function isExportDeclaration(node) {
|
|
514
|
-
return node.type === "ExportDefaultDeclaration" || node.type === "ExportNamedDeclaration";
|
|
515
|
-
}
|
|
516
|
-
function isExportedTarget(node, state) {
|
|
517
|
-
return state.exportedNodes.has(node);
|
|
518
|
-
}
|
|
519
|
-
function isFunctionNode(node) {
|
|
520
|
-
return node.type === "ArrowFunctionExpression" || node.type === "FunctionDeclaration" || node.type === "FunctionExpression";
|
|
521
|
-
}
|
|
522
|
-
function markExportedBinding(name, state) {
|
|
523
|
-
const bindingNode = state.bindingNodes.get(name);
|
|
524
|
-
if (bindingNode) state.exportedNodes.add(bindingNode);
|
|
525
|
-
}
|
|
526
|
-
function markExportedDeclaration(node, state) {
|
|
527
|
-
state.exportedNodes.add(node);
|
|
528
|
-
if (node.type !== "VariableDeclaration" || !Array.isArray(node.declarations)) return;
|
|
529
|
-
for (const declarator of node.declarations) {
|
|
530
|
-
if (!isAstNode(declarator)) continue;
|
|
531
|
-
const initializer = asAstNode(declarator.init);
|
|
532
|
-
if (initializer && (isClassNode(initializer) || isFunctionNode(initializer))) state.exportedNodes.add(initializer);
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
function visit(node, state) {
|
|
536
|
-
if (!node) return;
|
|
537
|
-
if (Array.isArray(node)) {
|
|
538
|
-
for (const child of node) visit(child, state);
|
|
539
|
-
return;
|
|
540
|
-
}
|
|
541
|
-
if (state.visited.has(node)) return;
|
|
542
|
-
state.visited.add(node);
|
|
543
|
-
if (node.type === "ExportDefaultDeclaration" || node.type === "ExportNamedDeclaration") {
|
|
544
|
-
if (node.declaration) {
|
|
545
|
-
markExportedDeclaration(node.declaration, state);
|
|
546
|
-
visit(node.declaration, state);
|
|
547
|
-
}
|
|
548
|
-
visitChildren(node, state, /* @__PURE__ */ new Set(["declaration"]));
|
|
549
|
-
return;
|
|
550
|
-
}
|
|
551
|
-
if (isClassNode(node)) addClassTarget(node, state);
|
|
552
|
-
else if (isFunctionNode(node) || node.type === "MethodDefinition") {
|
|
553
|
-
addFunctionTarget(node, state);
|
|
554
|
-
const methodValue = node.type === "MethodDefinition" ? asAstNode(node.value) : void 0;
|
|
555
|
-
if (methodValue) state.seenFunctions.add(methodValue);
|
|
556
|
-
}
|
|
557
|
-
visitChildren(node, state);
|
|
558
|
-
}
|
|
559
|
-
function visitChildren(node, state, skippedKeys = /* @__PURE__ */ new Set()) {
|
|
560
|
-
for (const [key, value] of Object.entries(node)) {
|
|
561
|
-
if (skippedKeys.has(key) || key === "type" || key === "start" || key === "end" || key === "range") continue;
|
|
562
|
-
if (Array.isArray(value)) {
|
|
563
|
-
for (const child of value) if (isAstNode(child)) {
|
|
564
|
-
inferChildName(node, key, child, state);
|
|
565
|
-
visit(child, state);
|
|
566
|
-
}
|
|
567
|
-
} else if (isAstNode(value)) {
|
|
568
|
-
inferChildName(node, key, value, state);
|
|
569
|
-
visit(value, state);
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
function withStableIdentities(targets) {
|
|
574
|
-
const semanticIdentityCounts = /* @__PURE__ */ new Map();
|
|
575
|
-
for (const target of targets) {
|
|
576
|
-
const semanticIdentity = createSemanticIdentity(target);
|
|
577
|
-
if (semanticIdentity) semanticIdentityCounts.set(semanticIdentity, (semanticIdentityCounts.get(semanticIdentity) ?? 0) + 1);
|
|
578
|
-
}
|
|
579
|
-
return targets.map((target) => {
|
|
580
|
-
const semanticIdentity = createSemanticIdentity(target);
|
|
581
|
-
if (!semanticIdentity || semanticIdentityCounts.get(semanticIdentity) !== 1) return target;
|
|
582
|
-
return {
|
|
583
|
-
...target,
|
|
584
|
-
identity: semanticIdentity
|
|
585
|
-
};
|
|
586
|
-
});
|
|
587
|
-
}
|
|
588
|
-
//#endregion
|
|
589
235
|
//#region src/core/languages/js/index.ts
|
|
590
236
|
const javascriptLanguage = {
|
|
591
237
|
extensions: [
|
|
@@ -968,7 +614,7 @@ function createDirectoryExecutionPlans(directories, fileOffset) {
|
|
|
968
614
|
}
|
|
969
615
|
//#endregion
|
|
970
616
|
//#region package.json
|
|
971
|
-
var version = "0.0.
|
|
617
|
+
var version = "0.0.29";
|
|
972
618
|
//#endregion
|
|
973
619
|
//#region src/core/targets/execution.ts
|
|
974
620
|
var AlintRuleExecutionError = class extends Error {
|
|
@@ -1879,4 +1525,4 @@ function defineRule(rule) {
|
|
|
1879
1525
|
return rule;
|
|
1880
1526
|
}
|
|
1881
1527
|
//#endregion
|
|
1882
|
-
export { AlintRunError, buildRuleRegistry, createBuiltInLanguageRegistry, createSourceFile, createSourceRuntime, defineConfig, definePlugin, defineRule,
|
|
1528
|
+
export { AlintRunError, buildRuleRegistry, createBuiltInLanguageRegistry, createSourceFile, createSourceRuntime, defineConfig, definePlugin, defineRule, hasDiscoveryFilePatterns, matchesDiscoveryFile, normalizeConfig, registerLanguage, resolveConfigForDirectory, resolveConfigForFile, resolveConfigForProject, resolveLanguage, resolveModel, runAlint, sliceLines, sliceRange };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { P as ResolvedModel, v as RuleContext } from "./types-CMLoj9J9.mjs";
|
|
2
2
|
import { GenericSchema, InferOutput } from "valibot";
|
|
3
3
|
import { JsonSchema } from "@valibot/to-json-schema";
|
|
4
4
|
import { Message } from "@xsai/shared-chat";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { c as ProcessorContext, h as SourceTarget, i as LanguageContext, l as ProcessorPostprocessContext, m as SourceRuntime, n as FileTarget, o as ProcessedSource, r as FunctionTarget, t as ClassTarget, u as SourceFile } from "./types-DSvXUVZ7.mjs";
|
|
1
2
|
//#region src/config/types.d.ts
|
|
2
3
|
type ModelSize = 'large' | 'medium' | 'small';
|
|
3
4
|
interface ProviderDefinition {
|
|
@@ -96,91 +97,6 @@ interface AgentUsage {
|
|
|
96
97
|
totalTokens?: number;
|
|
97
98
|
}
|
|
98
99
|
//#endregion
|
|
99
|
-
//#region src/core/source/types.d.ts
|
|
100
|
-
type ClassTarget = SourceTargetOfKind<'class'>;
|
|
101
|
-
type FileTarget = SourceTargetOfKind<'file'>;
|
|
102
|
-
type FunctionTarget = SourceTargetOfKind<'function'>;
|
|
103
|
-
interface LanguageContext {
|
|
104
|
-
cwd: string;
|
|
105
|
-
languageOptions: Record<string, unknown>;
|
|
106
|
-
src: SourceRuntime;
|
|
107
|
-
}
|
|
108
|
-
interface LineRange {
|
|
109
|
-
endLine: number;
|
|
110
|
-
startLine: number;
|
|
111
|
-
}
|
|
112
|
-
interface ProcessedSource {
|
|
113
|
-
identity: string;
|
|
114
|
-
language?: string;
|
|
115
|
-
origin?: ProcessedSourceOrigin;
|
|
116
|
-
path: string;
|
|
117
|
-
text: string;
|
|
118
|
-
}
|
|
119
|
-
interface ProcessedSourceOrigin {
|
|
120
|
-
physicalPath: string;
|
|
121
|
-
range?: SourceRange;
|
|
122
|
-
virtualPath?: string;
|
|
123
|
-
}
|
|
124
|
-
interface ProcessorContext {
|
|
125
|
-
cwd: string;
|
|
126
|
-
options: Record<string, unknown>;
|
|
127
|
-
src: SourceRuntime;
|
|
128
|
-
}
|
|
129
|
-
interface ProcessorPostprocessContext extends ProcessorContext {
|
|
130
|
-
file: SourceFile;
|
|
131
|
-
processedSources: ProcessedSource[];
|
|
132
|
-
}
|
|
133
|
-
interface SourceFile {
|
|
134
|
-
language: string;
|
|
135
|
-
lines: string[];
|
|
136
|
-
path: string;
|
|
137
|
-
text: string;
|
|
138
|
-
}
|
|
139
|
-
interface SourceLocation {
|
|
140
|
-
end: SourcePosition;
|
|
141
|
-
start: SourcePosition;
|
|
142
|
-
}
|
|
143
|
-
interface SourcePosition {
|
|
144
|
-
column: number;
|
|
145
|
-
line: number;
|
|
146
|
-
}
|
|
147
|
-
interface SourceRange {
|
|
148
|
-
end: number;
|
|
149
|
-
start: number;
|
|
150
|
-
}
|
|
151
|
-
interface SourceRuntime {
|
|
152
|
-
getText: (target: SourceFile | SourceTarget) => string;
|
|
153
|
-
readFile: (filePath: string) => Promise<SourceFile>;
|
|
154
|
-
sliceLines: (file: SourceFile, range: LineRange) => SourceText;
|
|
155
|
-
sliceRange: (file: SourceFile, range: SourceRange) => SourceText;
|
|
156
|
-
}
|
|
157
|
-
interface SourceTarget {
|
|
158
|
-
file: SourceFile;
|
|
159
|
-
identity: string;
|
|
160
|
-
kind: SourceTargetKind;
|
|
161
|
-
language: string;
|
|
162
|
-
loc?: SourceLocation;
|
|
163
|
-
metadata?: Record<string, unknown>;
|
|
164
|
-
name?: string;
|
|
165
|
-
origin?: SourceTargetOrigin;
|
|
166
|
-
range?: SourceRange;
|
|
167
|
-
text: string;
|
|
168
|
-
}
|
|
169
|
-
type SourceTargetKind = 'class' | 'file' | 'fragment' | 'function' | 'symbol' | (string & {});
|
|
170
|
-
type SourceTargetOfKind<Kind extends SourceTargetKind> = Omit<SourceTarget, 'kind'> & {
|
|
171
|
-
kind: Kind;
|
|
172
|
-
};
|
|
173
|
-
interface SourceTargetOrigin {
|
|
174
|
-
physicalPath: string;
|
|
175
|
-
range?: SourceRange;
|
|
176
|
-
virtualPath?: string;
|
|
177
|
-
}
|
|
178
|
-
interface SourceText {
|
|
179
|
-
filePath: string;
|
|
180
|
-
loc: SourceLocation;
|
|
181
|
-
text: string;
|
|
182
|
-
}
|
|
183
|
-
//#endregion
|
|
184
100
|
//#region src/dsl/types.d.ts
|
|
185
101
|
type AlintConfig = readonly AlintConfigInput[];
|
|
186
102
|
type AlintConfigExtends = AlintConfigInput | string;
|
|
@@ -327,4 +243,4 @@ interface RuleWithHandler {
|
|
|
327
243
|
}
|
|
328
244
|
type Target = DirectoryTarget | ProjectTarget | SourceTarget;
|
|
329
245
|
//#endregion
|
|
330
|
-
export {
|
|
246
|
+
export { AgentTool as A, RunnerStatsConfig as B, RuleSeverity as C, AgentAdapter as D, Target as E, ResolvedProvider as F, SetupModelDefinition as H, ModelSize as I, ProviderDefinition as L, ModelRequirement as M, ResolveModelOptions as N, AgentRequest as O, ResolvedModel as P, ProviderType as R, RuleRegistry as S, RuleWithHandler as T, SetupConfig as V, RuleConfigEntry as _, AlintLinterOptions as a, RuleHandlers as b, DiagnosticLocation as c, IgnoreConfig as d, LanguageDefinition as f, RuleCacheConfig as g, ProjectTarget as h, AlintConfigItem as i, AgentUsage as j, AgentResult as k, DirectoryTarget as l, ProcessorDefinition as m, AlintConfigExtends as n, Awaitable as o, PluginDefinition as p, AlintConfigInput as r, DiagnosticDescriptor as s, AlintConfig as t, EnabledRule as u, RuleContext as v, RuleSpecializedHandlers as w, RuleInferenceUsageRecord as x, RuleDefinition as y, RunnerConfig as z };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
//#region src/core/source/types.d.ts
|
|
2
|
+
type ClassTarget = SourceTargetOfKind<'class'>;
|
|
3
|
+
type FileTarget = SourceTargetOfKind<'file'>;
|
|
4
|
+
type FunctionTarget = SourceTargetOfKind<'function'>;
|
|
5
|
+
interface LanguageContext {
|
|
6
|
+
cwd: string;
|
|
7
|
+
languageOptions: Record<string, unknown>;
|
|
8
|
+
src: SourceRuntime;
|
|
9
|
+
}
|
|
10
|
+
interface LineRange {
|
|
11
|
+
endLine: number;
|
|
12
|
+
startLine: number;
|
|
13
|
+
}
|
|
14
|
+
interface ProcessedSource {
|
|
15
|
+
identity: string;
|
|
16
|
+
language?: string;
|
|
17
|
+
origin?: ProcessedSourceOrigin;
|
|
18
|
+
path: string;
|
|
19
|
+
text: string;
|
|
20
|
+
}
|
|
21
|
+
interface ProcessedSourceOrigin {
|
|
22
|
+
physicalPath: string;
|
|
23
|
+
range?: SourceRange;
|
|
24
|
+
virtualPath?: string;
|
|
25
|
+
}
|
|
26
|
+
interface ProcessorContext {
|
|
27
|
+
cwd: string;
|
|
28
|
+
options: Record<string, unknown>;
|
|
29
|
+
src: SourceRuntime;
|
|
30
|
+
}
|
|
31
|
+
interface ProcessorPostprocessContext extends ProcessorContext {
|
|
32
|
+
file: SourceFile;
|
|
33
|
+
processedSources: ProcessedSource[];
|
|
34
|
+
}
|
|
35
|
+
interface SourceFile {
|
|
36
|
+
language: string;
|
|
37
|
+
lines: string[];
|
|
38
|
+
path: string;
|
|
39
|
+
text: string;
|
|
40
|
+
}
|
|
41
|
+
interface SourceLocation {
|
|
42
|
+
end: SourcePosition;
|
|
43
|
+
start: SourcePosition;
|
|
44
|
+
}
|
|
45
|
+
interface SourcePosition {
|
|
46
|
+
column: number;
|
|
47
|
+
line: number;
|
|
48
|
+
}
|
|
49
|
+
interface SourceRange {
|
|
50
|
+
end: number;
|
|
51
|
+
start: number;
|
|
52
|
+
}
|
|
53
|
+
interface SourceRuntime {
|
|
54
|
+
getText: (target: SourceFile | SourceTarget) => string;
|
|
55
|
+
readFile: (filePath: string) => Promise<SourceFile>;
|
|
56
|
+
sliceLines: (file: SourceFile, range: LineRange) => SourceText;
|
|
57
|
+
sliceRange: (file: SourceFile, range: SourceRange) => SourceText;
|
|
58
|
+
}
|
|
59
|
+
interface SourceTarget {
|
|
60
|
+
file: SourceFile;
|
|
61
|
+
identity: string;
|
|
62
|
+
kind: SourceTargetKind;
|
|
63
|
+
language: string;
|
|
64
|
+
loc?: SourceLocation;
|
|
65
|
+
metadata?: Record<string, unknown>;
|
|
66
|
+
name?: string;
|
|
67
|
+
origin?: SourceTargetOrigin;
|
|
68
|
+
range?: SourceRange;
|
|
69
|
+
text: string;
|
|
70
|
+
}
|
|
71
|
+
type SourceTargetKind = 'class' | 'file' | 'fragment' | 'function' | 'symbol' | (string & {});
|
|
72
|
+
type SourceTargetOfKind<Kind extends SourceTargetKind> = Omit<SourceTarget, 'kind'> & {
|
|
73
|
+
kind: Kind;
|
|
74
|
+
};
|
|
75
|
+
interface SourceTargetOrigin {
|
|
76
|
+
physicalPath: string;
|
|
77
|
+
range?: SourceRange;
|
|
78
|
+
virtualPath?: string;
|
|
79
|
+
}
|
|
80
|
+
interface SourceText {
|
|
81
|
+
filePath: string;
|
|
82
|
+
loc: SourceLocation;
|
|
83
|
+
text: string;
|
|
84
|
+
}
|
|
85
|
+
//#endregion
|
|
86
|
+
export { SourceTargetOfKind as _, LineRange as a, ProcessorContext as c, SourceLocation as d, SourcePosition as f, SourceTargetKind as g, SourceTarget as h, LanguageContext as i, ProcessorPostprocessContext as l, SourceRuntime as m, FileTarget as n, ProcessedSource as o, SourceRange as p, FunctionTarget as r, ProcessedSourceOrigin as s, ClassTarget as t, SourceFile as u, SourceTargetOrigin as v, SourceText as y };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alint-js/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.29",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
7
7
|
"types": "./dist/index.d.mts",
|
|
@@ -15,6 +15,10 @@
|
|
|
15
15
|
"types": "./dist/structured-output.d.mts",
|
|
16
16
|
"default": "./dist/structured-output.mjs"
|
|
17
17
|
},
|
|
18
|
+
"./languages/js": {
|
|
19
|
+
"types": "./dist/languages-js.d.mts",
|
|
20
|
+
"default": "./dist/languages-js.mjs"
|
|
21
|
+
},
|
|
18
22
|
"./package.json": "./package.json"
|
|
19
23
|
},
|
|
20
24
|
"files": [
|