@alint-js/core 0.0.33 → 0.0.35

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.
@@ -13,35 +13,41 @@ var RetryableAgentError = class extends Error {
13
13
  function isRetryableAgentError(error) {
14
14
  return error instanceof RetryableAgentError;
15
15
  }
16
- function withAgentRetry(adapter, retries = 2) {
17
- const invoke = withRetry(async (request) => {
18
- try {
19
- request.signal?.throwIfAborted();
20
- const result = await adapter(request);
21
- request.signal?.throwIfAborted();
22
- return {
23
- ok: true,
24
- result
25
- };
26
- } catch (error) {
27
- if (request.signal?.aborted) return {
28
- error: request.signal.reason,
29
- ok: false
30
- };
31
- if (isRetryableAgentError(error)) throw error;
32
- return {
33
- error,
34
- ok: false
35
- };
36
- }
37
- }, {
38
- retry: retries,
39
- retryDelay: 500,
40
- retryDelayFactor: 2,
41
- retryDelayMax: 3e4
42
- });
16
+ function withAgentRetry(adapter, retries = 2, options = {}) {
43
17
  return async (request) => {
44
- const attempt = await invoke(request);
18
+ let invocation = 0;
19
+ const attempt = await withRetry(async (request) => {
20
+ const attempt = invocation;
21
+ invocation += 1;
22
+ try {
23
+ request.signal?.throwIfAborted();
24
+ if (attempt > 0) options.onRetry?.({
25
+ attempt,
26
+ maxAttempts: retries + 1
27
+ });
28
+ const result = await adapter(request);
29
+ request.signal?.throwIfAborted();
30
+ return {
31
+ ok: true,
32
+ result
33
+ };
34
+ } catch (error) {
35
+ if (request.signal?.aborted) return {
36
+ error: request.signal.reason,
37
+ ok: false
38
+ };
39
+ if (isRetryableAgentError(error)) throw error;
40
+ return {
41
+ error,
42
+ ok: false
43
+ };
44
+ }
45
+ }, {
46
+ retry: retries,
47
+ retryDelay: 500,
48
+ retryDelayFactor: 2,
49
+ retryDelayMax: 3e4
50
+ })(request);
45
51
  if (!attempt.ok) throw attempt.error;
46
52
  return attempt.result;
47
53
  };
package/dist/agent.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { A as AgentTool, D as AgentAdapter, O as AgentRequest, j as AgentUsage, k as AgentResult, v as RuleContext } from "./types-CR_Grd6q.mjs";
1
+ import { A as AgentAdapter, M as AgentResult, N as AgentTool, P as AgentUsage, j as AgentRequest, v as RuleContext } from "./types-m5T_UL76.mjs";
2
2
  //#region src/agent/retry.d.ts
3
3
  /**
4
4
  * Declares that the complete adapter invocation can be safely replayed.
package/dist/agent.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { a as isRetryableAgentError, i as RetryableAgentError, n as defineTool, r as requireAgent, t as combineAbortSignals } from "./agent-weXkvGkc.mjs";
1
+ import { a as isRetryableAgentError, i as RetryableAgentError, n as defineTool, r as requireAgent, t as combineAbortSignals } from "./agent-B6GG68NX.mjs";
2
2
  export { RetryableAgentError, combineAbortSignals, defineTool, isRetryableAgentError, requireAgent };
@@ -0,0 +1,33 @@
1
+ import { S as RuleOptionsInput, _ as RuleConfigEntry, i as AlintConfigItem, p as PluginDefinition, t as AlintConfig, w as RuleOptionsSchema, y as RuleDefinition } from "./types-m5T_UL76.mjs";
2
+ //#region src/dsl/define.d.ts
3
+ type AnyRuleDefinition = RuleDefinition<any>;
4
+ type ConfigItemWithPluginRules<Plugins, Rules> = Omit<AlintConfigItem, 'plugins' | 'rules'> & {
5
+ plugins?: Plugins;
6
+ rules?: RulesForPlugins<NonNullable<Plugins>, Rules>;
7
+ };
8
+ type ConfigItemWithPlugins<Plugins> = Omit<AlintConfigItem, 'plugins' | 'rules'> & {
9
+ plugins?: Plugins;
10
+ rules?: Record<string, RuleConfigEntry<readonly unknown[]> | undefined>;
11
+ };
12
+ type RuleEntryForPlugins<Plugins, Key extends string> = Key extends `${infer Alias}/${infer RuleName}` ? Alias extends keyof Plugins & string ? Plugins[Alias] extends PluginDefinition<infer Rules> ? RuleName extends keyof Rules & string ? Rules[RuleName] extends RuleDefinition<infer OptionsSchema> ? RuleConfigEntry<RuleOptionsInput<OptionsSchema>> : RuleConfigEntry<readonly unknown[]> : RuleConfigEntry<readonly unknown[]> : RuleConfigEntry<readonly unknown[]> : RuleConfigEntry<readonly unknown[]> : RuleConfigEntry<readonly unknown[]>;
13
+ type RulesForPlugins<Plugins, Rules> = { readonly [Key in keyof Rules]: Key extends string ? RuleEntryForPlugins<Plugins, Key> : never; };
14
+ type TypedConfigInput<Item> = Item extends readonly [] ? readonly [] : Item extends readonly [unknown, ...unknown[]] ? { readonly [Index in keyof Item]: TypedConfigInput<Item[Index]>; } : Item extends readonly (infer Element)[] ? readonly TypedConfigInput<Element>[] : TypedConfigItem<Item>;
15
+ type TypedConfigItem<Item> = Item extends {
16
+ plugins?: infer Plugins;
17
+ rules?: infer Rules;
18
+ } ? ConfigItemWithPluginRules<Plugins, Rules> : TypedConfigItemWithoutRuleConfig<Item>;
19
+ type TypedConfigItemWithoutRuleConfig<Item> = Item extends {
20
+ plugins?: infer Plugins;
21
+ } ? ConfigItemWithPlugins<Plugins> : AlintConfigItem;
22
+ declare function defineConfig<const Config extends readonly unknown[]>(config: Config & TypedConfigInput<Config>): AlintConfig;
23
+ declare function definePlugin<const Rules extends Record<string, AnyRuleDefinition> = Record<string, AnyRuleDefinition>>(plugin: Omit<PluginDefinition<Rules>, 'rules'> & {
24
+ rules?: Rules;
25
+ }): PluginDefinition<Rules>;
26
+ declare function defineRule(rule: Omit<RuleDefinition<[]>, 'options'> & {
27
+ options?: undefined;
28
+ }): RuleDefinition<[]>;
29
+ declare function defineRule<const OptionsSchema extends RuleOptionsSchema>(rule: RuleDefinition<OptionsSchema> & {
30
+ options: OptionsSchema;
31
+ }): RuleDefinition<OptionsSchema>;
32
+ //#endregion
33
+ export { definePlugin as n, defineRule as r, defineConfig as t };
@@ -0,0 +1,12 @@
1
+ //#region src/dsl/define.ts
2
+ function defineConfig(config) {
3
+ return config;
4
+ }
5
+ function definePlugin(plugin) {
6
+ return plugin;
7
+ }
8
+ function defineRule(rule) {
9
+ return rule;
10
+ }
11
+ //#endregion
12
+ export { definePlugin as n, defineRule as r, defineConfig as t };
package/dist/dsl.d.mts ADDED
@@ -0,0 +1,3 @@
1
+ import { C as RuleOptionsOutput, D as RuleSpecializedHandlers, E as RuleSeverity, O as RuleWithHandler, S as RuleOptionsInput, T as RuleRegistry, _ 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, k as Target, 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 RuleOptionsSchema, x as RuleInferenceUsageRecord, y as RuleDefinition } from "./types-m5T_UL76.mjs";
2
+ import { n as definePlugin, r as defineRule, t as defineConfig } from "./define-CnBawoAI.mjs";
3
+ export { type AlintConfig, type AlintConfigExtends, type AlintConfigInput, type AlintConfigItem, type AlintLinterOptions, type Awaitable, type DiagnosticDescriptor, type DiagnosticLocation, type DirectoryTarget, type EnabledRule, type IgnoreConfig, type LanguageDefinition, type PluginDefinition, type ProcessorDefinition, type ProjectTarget, type RuleCacheConfig, type RuleConfigEntry, type RuleContext, type RuleDefinition, type RuleHandlers, type RuleInferenceUsageRecord, type RuleOptionsInput, type RuleOptionsOutput, type RuleOptionsSchema, type RuleRegistry, type RuleSeverity, type RuleSpecializedHandlers, type RuleWithHandler, type Target, defineConfig, definePlugin, defineRule };
package/dist/dsl.mjs ADDED
@@ -0,0 +1,2 @@
1
+ import { n as definePlugin, r as defineRule, t as defineConfig } from "./define-Da342Fcx.mjs";
2
+ export { defineConfig, definePlugin, defineRule };
package/dist/index.d.mts CHANGED
@@ -1,5 +1,6 @@
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-CR_Grd6q.mjs";
1
+ import { B as ProviderDefinition, D as RuleSpecializedHandlers, E as RuleSeverity, F as ModelRequirement, G as SetupModelDefinition, H as RunnerConfig, I as ResolveModelOptions, L as ResolvedModel, O as RuleWithHandler, R as ResolvedProvider, T as RuleRegistry, U as RunnerStatsConfig, V as ProviderType, W 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, k as Target, 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, x as RuleInferenceUsageRecord, y as RuleDefinition, z as ModelSize } from "./types-m5T_UL76.mjs";
2
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";
3
+ import { n as definePlugin, r as defineRule, t as defineConfig } from "./define-CnBawoAI.mjs";
3
4
  //#region src/config/config-array.d.ts
4
5
  interface EffectiveAlintConfig {
5
6
  agent?: AlintConfigItem['agent'];
@@ -95,6 +96,12 @@ interface JobEndPayload extends JobStartPayload {
95
96
  interface JobQueuedPayload {
96
97
  job: ProgressJob;
97
98
  }
99
+ interface JobRetryPayload {
100
+ attempt: number;
101
+ job: ProgressJob;
102
+ maxAttempts: number;
103
+ startedAt?: number;
104
+ }
98
105
  interface JobStartPayload {
99
106
  job: ProgressJob;
100
107
  startedAt?: number;
@@ -104,6 +111,8 @@ interface ProgressJob {
104
111
  index: number;
105
112
  inputPath: string;
106
113
  ruleId: string;
114
+ ruleIndex: number;
115
+ ruleTotal: number;
107
116
  target: {
108
117
  identity: string;
109
118
  kind: ProgressTargetKind;
@@ -115,6 +124,7 @@ interface ProgressReporter {
115
124
  onDiagnostic?: (payload: DiagnosticProgressPayload) => void;
116
125
  onJobEnd?: (payload: JobEndPayload) => void;
117
126
  onJobQueued?: (payload: JobQueuedPayload) => void;
127
+ onJobRetry?: (payload: JobRetryPayload) => void;
118
128
  onJobStart?: (payload: JobStartPayload) => void;
119
129
  onRunEnd?: (payload: RunEndPayload) => void;
120
130
  onRunStart?: (payload: RunStartPayload) => void;
@@ -143,6 +153,11 @@ interface RunOptions {
143
153
  modelOverride?: string;
144
154
  outputLanguage?: string;
145
155
  progress?: ProgressReporter;
156
+ /**
157
+ * Run project-scoped rules (`onTargetProject` and the project pass of `onTargetWith`).
158
+ * Defaults to `true`. Pass `false` for runs that target partial subsets of a project.
159
+ */
160
+ projectTargets?: boolean;
146
161
  runner?: RunnerOptions;
147
162
  setupConfig?: SetupConfig;
148
163
  /**
@@ -209,13 +224,11 @@ declare function createSourceRuntime(): SourceRuntime;
209
224
  declare function sliceLines(file: SourceFile, range: LineRange): SourceText;
210
225
  declare function sliceRange(file: SourceFile, range: SourceRange): SourceText;
211
226
  //#endregion
212
- //#region src/dsl/define.d.ts
213
- declare function defineConfig(config: readonly AlintConfigInput[]): AlintConfig;
214
- declare function definePlugin(plugin: PluginDefinition): PluginDefinition;
215
- declare function defineRule(rule: RuleDefinition): RuleDefinition;
216
- //#endregion
217
227
  //#region src/dsl/registry.d.ts
218
- declare function buildRuleRegistry(config: Pick<EffectiveAlintConfig, 'plugins' | 'rules'>): RuleRegistry;
228
+ type RuleRegistryConfig = Pick<EffectiveAlintConfig, 'plugins'> & {
229
+ rules: Record<string, RuleConfigEntry<readonly unknown[]>>;
230
+ };
231
+ declare function buildRuleRegistry(config: RuleRegistryConfig): RuleRegistry;
219
232
  //#endregion
220
233
  //#region src/models/resolve.d.ts
221
234
  declare function resolveModel(registry: SetupConfig, options?: ResolveModelOptions): ResolvedModel;
package/dist/index.mjs CHANGED
@@ -1,4 +1,5 @@
1
- import { o as withAgentRetry, t as combineAbortSignals } from "./agent-weXkvGkc.mjs";
1
+ import { o as withAgentRetry, t as combineAbortSignals } from "./agent-B6GG68NX.mjs";
2
+ import { n as definePlugin, r as defineRule, t as defineConfig } from "./define-Da342Fcx.mjs";
2
3
  import { a as sliceRange, i as sliceLines, n as createSourceFile, r as createSourceRuntime, t as extractJsSourceTargets } from "./extract-CIWssxNK.mjs";
3
4
  import { minimatch } from "minimatch";
4
5
  import { isAbsolute, relative, resolve } from "pathe";
@@ -6,9 +7,9 @@ import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
6
7
  import { dirname, extname, isAbsolute as isAbsolute$1, join, relative as relative$1, resolve as resolve$1, sep } from "node:path";
7
8
  import { AsyncLocalStorage } from "node:async_hooks";
8
9
  import process, { cwd } from "node:process";
10
+ import { array, check, description, getDotPath, is, literal, number, object, optional, pipe, record, safeParse, string, union, unknown } from "valibot";
9
11
  import { createHash, randomUUID } from "node:crypto";
10
12
  import { statSync } from "node:fs";
11
- import { array, check, description, is, literal, number, object, optional, pipe, record, string, union, unknown } from "valibot";
12
13
  import { errorMessageFrom } from "@moeru/std/error";
13
14
  //#region src/config/config-array.ts
14
15
  const effectiveBasePathSymbol = Symbol("effectiveBasePath");
@@ -333,11 +334,13 @@ function buildRuleRegistry(config) {
333
334
  for (const [id, entry] of Object.entries(config.rules)) {
334
335
  const rule = rules.get(id);
335
336
  if (!rule) throw new Error(`Unknown rule "${id}".`);
336
- const severity = normalizeSeverity(entry);
337
+ const normalizedEntry = normalizeRuleConfigEntry(entry);
338
+ const severity = normalizedEntry.severity;
337
339
  if (severity === "off") continue;
338
340
  enabledRules.push({
339
341
  id,
340
342
  localId: localIds.get(id) ?? id,
343
+ options: parseRuleOptions(id, rule.options, normalizedEntry.options),
341
344
  rule,
342
345
  severity
343
346
  });
@@ -347,9 +350,44 @@ function buildRuleRegistry(config) {
347
350
  rules
348
351
  };
349
352
  }
350
- function normalizeSeverity(entry) {
351
- if (Array.isArray(entry)) return entry[0] ?? "warn";
352
- return entry ?? "warn";
353
+ function formatRuleOptionIssues(index, issues) {
354
+ return issues.map((issue) => {
355
+ const path = getDotPath(issue);
356
+ return path === null ? `"${index}": ${issue.message}` : `"${index}.${path}": ${issue.message}`;
357
+ }).join("; ");
358
+ }
359
+ function isRuleConfigTuple(entry) {
360
+ return Array.isArray(entry);
361
+ }
362
+ function normalizeRuleConfigEntry(entry) {
363
+ if (isRuleConfigTuple(entry)) {
364
+ const [severity = "warn", ...options] = entry;
365
+ return {
366
+ options,
367
+ severity
368
+ };
369
+ }
370
+ return {
371
+ options: [],
372
+ severity: entry ?? "warn"
373
+ };
374
+ }
375
+ function parseRuleOption(id, index, schema, value) {
376
+ const result = safeParse(schema, value);
377
+ if (result.success) return result.output;
378
+ if (value === void 0) {
379
+ const emptyObjectResult = safeParse(schema, {});
380
+ if (emptyObjectResult.success) return emptyObjectResult.output;
381
+ }
382
+ throw new TypeError(`Invalid options for rule "${id}": ${formatRuleOptionIssues(index, result.issues)}`);
383
+ }
384
+ function parseRuleOptions(id, schema, options) {
385
+ if (!schema) {
386
+ if (options.length > 0) throw new TypeError(`Rule "${id}" does not accept options.`);
387
+ return [];
388
+ }
389
+ if (options.length > schema.length) throw new TypeError(`Invalid options for rule "${id}": Unexpected option at index ${schema.length}.`);
390
+ return schema.map((optionSchema, index) => parseRuleOption(id, index, optionSchema, options[index]));
353
391
  }
354
392
  //#endregion
355
393
  //#region src/models/resolve.ts
@@ -581,7 +619,7 @@ function statSyncIsDirectory(path) {
581
619
  }
582
620
  //#endregion
583
621
  //#region package.json
584
- var version = "0.0.33";
622
+ var version = "0.0.35";
585
623
  //#endregion
586
624
  //#region src/core/execution/job.ts
587
625
  var CacheReplayProcessingError = class {
@@ -593,9 +631,17 @@ var CacheReplayProcessingError = class {
593
631
  function createRuleJobs(plans) {
594
632
  const jobs = [];
595
633
  const total = plans.reduce((sum, plan) => sum + plan.planned, 0);
634
+ const ruleTotals = /* @__PURE__ */ new Map();
635
+ const ruleIndexes = /* @__PURE__ */ new Map();
636
+ for (const plan of plans) for (const target of plan.targets) for (const execution of target.executions) {
637
+ const ruleId = execution.runtime.enabledRule.id;
638
+ ruleTotals.set(ruleId, (ruleTotals.get(ruleId) ?? 0) + 1);
639
+ }
596
640
  for (const plan of plans) for (const target of plan.targets) for (const execution of target.executions) {
597
641
  const ruleId = execution.runtime.enabledRule.id;
598
642
  const index = jobs.length + 1;
643
+ const ruleIndex = (ruleIndexes.get(ruleId) ?? 0) + 1;
644
+ ruleIndexes.set(ruleId, ruleIndex);
599
645
  jobs.push({
600
646
  execution,
601
647
  job: {
@@ -608,6 +654,8 @@ function createRuleJobs(plans) {
608
654
  index,
609
655
  inputPath: plan.path,
610
656
  ruleId,
657
+ ruleIndex,
658
+ ruleTotal: ruleTotals.get(ruleId) ?? 0,
611
659
  target: {
612
660
  identity: target.identity,
613
661
  kind: target.kind,
@@ -1134,7 +1182,7 @@ async function runAlint(options = {}) {
1134
1182
  });
1135
1183
  const filePlans = createSourceExecutionPlans(files, cwd$1);
1136
1184
  const directoryPlans = createDirectoryExecutionPlans(directories, filePlans.length);
1137
- const projectPlan = resolvedProjectConfig.ignored ? void 0 : createProjectExecutionPlan({
1185
+ const projectPlan = resolvedProjectConfig.ignored || options.projectTargets === false ? void 0 : createProjectExecutionPlan({
1138
1186
  configHash: stableHash({ settings: projectConfig.settings }),
1139
1187
  files,
1140
1188
  index: filePlans.length + directoryPlans.length + 1,
@@ -1239,7 +1287,25 @@ function createRuleRuntimes(options) {
1239
1287
  agent: options.effectiveAgent ? withAgentRetry((request) => options.effectiveAgent({
1240
1288
  ...request,
1241
1289
  signal: combineAbortSignals(executionState.getStore()?.signal, request.signal)
1242
- }), options.options.runner?.agentRetries) : void 0,
1290
+ }), options.options.runner?.agentRetries, { onRetry: ({ attempt, maxAttempts }) => {
1291
+ const state = executionState.getStore();
1292
+ if (!state) return;
1293
+ const startedAt = Date.now();
1294
+ try {
1295
+ options.progress?.onJobRetry?.({
1296
+ attempt,
1297
+ job: state.job,
1298
+ maxAttempts,
1299
+ startedAt
1300
+ });
1301
+ } catch (cause) {
1302
+ if (!state.reporterFailed) {
1303
+ state.reporterCause = cause;
1304
+ state.reporterFailed = true;
1305
+ }
1306
+ throw cause;
1307
+ }
1308
+ } }) : void 0,
1243
1309
  cwd: options.cwd,
1244
1310
  id: enabledRule.id,
1245
1311
  localId: enabledRule.localId,
@@ -1277,6 +1343,7 @@ function createRuleRuntimes(options) {
1277
1343
  if (state) state.currentModel = toDiagnosticModel(resolvedModel, request);
1278
1344
  return resolvedModel;
1279
1345
  },
1346
+ options: enabledRule.options,
1280
1347
  outputLanguage: options.options.outputLanguage,
1281
1348
  report: (descriptor) => {
1282
1349
  const state = executionState.getStore();
@@ -1326,6 +1393,7 @@ function createRuleRuntimes(options) {
1326
1393
  id: enabledRule.id,
1327
1394
  localId: enabledRule.localId,
1328
1395
  model: enabledRule.rule.model,
1396
+ options: enabledRule.options,
1329
1397
  severity: enabledRule.severity
1330
1398
  })
1331
1399
  };
@@ -1417,15 +1485,4 @@ function usageTotals(records) {
1417
1485
  };
1418
1486
  }
1419
1487
  //#endregion
1420
- //#region src/dsl/define.ts
1421
- function defineConfig(config) {
1422
- return config;
1423
- }
1424
- function definePlugin(plugin) {
1425
- return plugin;
1426
- }
1427
- function defineRule(rule) {
1428
- return rule;
1429
- }
1430
- //#endregion
1431
1488
  export { AlintAbortError, AlintRunCancelledError, 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 { P as ResolvedModel, v as RuleContext } from "./types-CR_Grd6q.mjs";
1
+ import { L as ResolvedModel, v as RuleContext } from "./types-m5T_UL76.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,4 +1,5 @@
1
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";
2
+ import { GenericSchema, InferInput, InferOutput } from "valibot";
2
3
  //#region src/config/types.d.ts
3
4
  type ModelSize = 'large' | 'medium' | 'small';
4
5
  interface ProviderDefinition {
@@ -146,7 +147,8 @@ interface DirectoryTarget {
146
147
  interface EnabledRule {
147
148
  id: string;
148
149
  localId: string;
149
- rule: RuleDefinition;
150
+ options: readonly unknown[];
151
+ rule: RuleDefinition<any>;
150
152
  severity: Exclude<RuleSeverity, 'off'>;
151
153
  }
152
154
  interface IgnoreConfig {
@@ -157,11 +159,11 @@ interface LanguageDefinition {
157
159
  extract: (file: SourceFile, context: LanguageContext) => Awaitable<SourceTarget[]>;
158
160
  name: string;
159
161
  }
160
- interface PluginDefinition {
162
+ interface PluginDefinition<Rules extends Record<string, RuleDefinition<any>> = Record<string, RuleDefinition<any>>> {
161
163
  configs?: Record<string, AlintConfigInput>;
162
164
  languages?: Record<string, LanguageDefinition>;
163
165
  processors?: Record<string, ProcessorDefinition>;
164
- rules?: Record<string, RuleDefinition>;
166
+ rules?: Rules;
165
167
  }
166
168
  interface ProcessorDefinition {
167
169
  postprocess?: (diagnostics: DiagnosticDescriptor[], context: ProcessorPostprocessContext) => Awaitable<DiagnosticDescriptor[]>;
@@ -176,8 +178,8 @@ interface ProjectTarget {
176
178
  type RuleCacheConfig = boolean | {
177
179
  level?: 'target';
178
180
  };
179
- type RuleConfigEntry = [RuleSeverity] | RuleSeverity;
180
- interface RuleContext {
181
+ type RuleConfigEntry<Options extends readonly unknown[] = readonly []> = readonly [RuleSeverity, ...Partial<Options>] | RuleSeverity;
182
+ interface RuleContext<Options extends readonly unknown[] = readonly []> {
181
183
  agent?: AgentAdapter;
182
184
  cwd: string;
183
185
  id: string;
@@ -189,6 +191,7 @@ interface RuleContext {
189
191
  recordUsage: (usage: RuleInferenceUsageRecord) => void;
190
192
  };
191
193
  model: (selector?: ModelRequirement | string) => Promise<ResolvedModel>;
194
+ options: Options;
192
195
  outputLanguage?: string;
193
196
  report: (diagnostic: DiagnosticDescriptor) => void;
194
197
  settings: Record<string, unknown>;
@@ -201,12 +204,13 @@ interface RuleContext {
201
204
  signal?: AbortSignal;
202
205
  src: SourceRuntime;
203
206
  }
204
- interface RuleDefinition {
207
+ interface RuleDefinition<OptionsSchema extends RuleOptionsSchema = []> {
205
208
  cache?: RuleCacheConfig;
206
209
  /** Additional stable rule inputs, such as imported prompts, that invalidate cached results when changed. */
207
210
  cacheKey?: unknown;
208
- create: (context: RuleContext) => RuleHandlers;
211
+ create: (context: RuleContext<RuleOptionsOutput<OptionsSchema>>) => RuleHandlers;
209
212
  model?: ModelRequirement;
213
+ options?: OptionsSchema;
210
214
  }
211
215
  type RuleHandlers = RuleSpecializedHandlers | RuleWithHandler;
212
216
  interface RuleInferenceUsageRecord {
@@ -219,9 +223,12 @@ interface RuleInferenceUsageRecord {
219
223
  ruleId?: string;
220
224
  totalTokens?: number;
221
225
  }
226
+ type RuleOptionsInput<OptionsSchema extends RuleOptionsSchema> = { readonly [Index in keyof OptionsSchema]: InferInput<OptionsSchema[Index]>; };
227
+ type RuleOptionsOutput<OptionsSchema extends RuleOptionsSchema> = { readonly [Index in keyof OptionsSchema]: InferOutput<OptionsSchema[Index]>; };
228
+ type RuleOptionsSchema = readonly GenericSchema[];
222
229
  interface RuleRegistry {
223
230
  enabledRules: EnabledRule[];
224
- rules: Map<string, RuleDefinition>;
231
+ rules: Map<string, RuleDefinition<any>>;
225
232
  }
226
233
  type RuleSeverity = 'error' | 'off' | 'warn';
227
234
  interface RuleSpecializedHandlers {
@@ -242,4 +249,4 @@ interface RuleWithHandler {
242
249
  }
243
250
  type Target = DirectoryTarget | ProjectTarget | SourceTarget;
244
251
  //#endregion
245
- 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 };
252
+ export { AgentAdapter as A, ProviderDefinition as B, RuleOptionsOutput as C, RuleSpecializedHandlers as D, RuleSeverity as E, ModelRequirement as F, SetupModelDefinition as G, RunnerConfig as H, ResolveModelOptions as I, ResolvedModel as L, AgentResult as M, AgentTool as N, RuleWithHandler as O, AgentUsage as P, ResolvedProvider as R, RuleOptionsInput as S, RuleRegistry as T, RunnerStatsConfig as U, ProviderType as V, SetupConfig as W, 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, AgentRequest as j, Target 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, RuleOptionsSchema as w, RuleInferenceUsageRecord as x, RuleDefinition as y, ModelSize as z };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@alint-js/core",
3
3
  "type": "module",
4
- "version": "0.0.33",
4
+ "version": "0.0.35",
5
5
  "exports": {
6
6
  ".": {
7
7
  "types": "./dist/index.d.mts",
@@ -11,6 +11,10 @@
11
11
  "types": "./dist/agent.d.mts",
12
12
  "default": "./dist/agent.mjs"
13
13
  },
14
+ "./dsl": {
15
+ "types": "./dist/dsl.d.mts",
16
+ "default": "./dist/dsl.mjs"
17
+ },
14
18
  "./structured-output": {
15
19
  "types": "./dist/structured-output.d.mts",
16
20
  "default": "./dist/structured-output.mjs"