@alint-js/core 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -197,6 +197,7 @@ interface RunOptions {
197
197
  cacheOnly?: boolean;
198
198
  config?: AlintConfig;
199
199
  cwd?: string;
200
+ defaultModel?: string;
200
201
  directories?: string[];
201
202
  files?: string[];
202
203
  modelOverride?: string;
package/dist/index.mjs CHANGED
@@ -602,7 +602,7 @@ function recordMissingLanguages(into, rules, registry, path) {
602
602
  }
603
603
  //#endregion
604
604
  //#region package.json
605
- var version = "0.3.1";
605
+ var version = "0.4.0";
606
606
  //#endregion
607
607
  //#region src/core/cache/types.ts
608
608
  const CACHE_MAGIC = "ALINT_CACHE";
@@ -1381,6 +1381,14 @@ function terminalCount(execution) {
1381
1381
  }
1382
1382
  //#endregion
1383
1383
  //#region src/models/resolve.ts
1384
+ var UnknownModelError = class extends Error {
1385
+ request;
1386
+ constructor(request) {
1387
+ super(`Unknown model "${request}".`);
1388
+ this.name = "UnknownModelError";
1389
+ this.request = request;
1390
+ }
1391
+ };
1384
1392
  function resolveModel(registry, options = {}) {
1385
1393
  const candidates = flattenModels(registry);
1386
1394
  const ruleId = options.ruleId ?? "<unknown>";
@@ -1400,7 +1408,7 @@ function resolveModel(registry, options = {}) {
1400
1408
  }
1401
1409
  const duplicateIdentity = [...matchesByCanonical].find(([, matches]) => matches.length > 1)?.[0];
1402
1410
  if (duplicateIdentity !== void 0) throw duplicateDefinitionError(duplicateIdentity);
1403
- if (matchingCandidates.length === 0) throw new Error(`Unknown model "${request}".`);
1411
+ if (matchingCandidates.length === 0) throw new UnknownModelError(request);
1404
1412
  if (matchingCandidates.length > 1) {
1405
1413
  const choices = [...matchesByCanonical.keys()];
1406
1414
  throw new Error(`Ambiguous model "${request}".\nSpecify a provider-qualified model:\n${choices.map((choice) => ` ${choice}`).join("\n")}`);
@@ -1521,13 +1529,21 @@ function createRuleRuntimes(options) {
1521
1529
  }
1522
1530
  } },
1523
1531
  model: async (selector) => {
1524
- const request = options.runOptions.modelOverride ?? (typeof selector === "string" ? selector : void 0);
1532
+ const explicitRequest = options.runOptions.modelOverride ?? (typeof selector === "string" ? selector : void 0);
1533
+ const fallbackRequest = explicitRequest === void 0 && selector === void 0 && enabledRule.rule.model === void 0 ? options.runOptions.defaultModel : void 0;
1534
+ const request = explicitRequest ?? fallbackRequest;
1525
1535
  const requirement = mergeModelRequirement(enabledRule.rule.model, typeof selector === "string" ? void 0 : selector);
1526
- const resolvedModel = resolveModel(options.setupConfig, {
1527
- request,
1528
- requirement,
1529
- ruleId: enabledRule.id
1530
- });
1536
+ let resolvedModel;
1537
+ try {
1538
+ resolvedModel = resolveModel(options.setupConfig, {
1539
+ request,
1540
+ requirement,
1541
+ ruleId: enabledRule.id
1542
+ });
1543
+ } catch (error) {
1544
+ if (fallbackRequest !== void 0 && error instanceof UnknownModelError) throw new Error(`Default model "${fallbackRequest}" is not configured. Configure a system default model or select a model for this project.`, { cause: error });
1545
+ throw error;
1546
+ }
1531
1547
  const state = executionState.getStore();
1532
1548
  if (state && !state.sealed) state.currentModel = toDiagnosticModel(resolvedModel, request);
1533
1549
  return resolvedModel;
@@ -2429,6 +2445,7 @@ async function runAlint(options = {}) {
2429
2445
  readOnly: options.cacheOnly
2430
2446
  });
2431
2447
  const cacheContext = { modelHash: stableHash({
2448
+ defaultModel: options.modelOverride === void 0 ? options.defaultModel : void 0,
2432
2449
  modelOverride: options.modelOverride,
2433
2450
  outputLanguage: options.outputLanguage,
2434
2451
  setupConfig
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@alint-js/core",
3
3
  "type": "module",
4
- "version": "0.3.1",
4
+ "version": "0.4.0",
5
5
  "exports": {
6
6
  ".": {
7
7
  "types": "./dist/index.d.mts",