@alint-js/core 0.0.5 → 0.0.7

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
@@ -34,21 +34,38 @@ interface SetupModelDefinition {
34
34
  }
35
35
  //#endregion
36
36
  //#region src/core/source/types.d.ts
37
- interface ClassUnit extends SourceUnit {
38
- exported: boolean;
39
- kind: 'class';
40
- }
41
- interface FunctionUnit extends SourceUnit {
42
- async: boolean;
43
- exported: boolean;
44
- kind: 'function';
37
+ interface LanguageContext {
38
+ cwd: string;
39
+ languageOptions: Record<string, unknown>;
40
+ src: SourceRuntime;
45
41
  }
46
42
  interface LineRange {
47
43
  endLine: number;
48
44
  startLine: number;
49
45
  }
46
+ interface ProcessedSource {
47
+ identity: string;
48
+ language?: string;
49
+ origin?: ProcessedSourceOrigin;
50
+ path: string;
51
+ text: string;
52
+ }
53
+ interface ProcessedSourceOrigin {
54
+ physicalPath: string;
55
+ range?: SourceRange;
56
+ virtualPath?: string;
57
+ }
58
+ interface ProcessorContext {
59
+ cwd: string;
60
+ options: Record<string, unknown>;
61
+ src: SourceRuntime;
62
+ }
63
+ interface ProcessorPostprocessContext extends ProcessorContext {
64
+ file: SourceFile;
65
+ processedSources: ProcessedSource[];
66
+ }
50
67
  interface SourceFile {
51
- language: 'javascript' | 'typescript' | 'unknown';
68
+ language: string;
52
69
  lines: string[];
53
70
  path: string;
54
71
  text: string;
@@ -66,22 +83,32 @@ interface SourceRange {
66
83
  start: number;
67
84
  }
68
85
  interface SourceRuntime {
69
- getText: (target: SourceFile | SourceUnit) => string;
86
+ getText: (target: SourceFile | SourceTarget) => string;
70
87
  readFile: (filePath: string) => Promise<SourceFile>;
71
88
  sliceLines: (file: SourceFile, range: LineRange) => SourceText;
72
89
  sliceRange: (file: SourceFile, range: SourceRange) => SourceText;
73
90
  }
74
- interface SourceText {
75
- filePath: string;
76
- loc: SourceLocation;
91
+ interface SourceTarget {
92
+ file: SourceFile;
93
+ identity: string;
94
+ kind: SourceTargetKind;
95
+ language: string;
96
+ loc?: SourceLocation;
97
+ metadata?: Record<string, unknown>;
98
+ name?: string;
99
+ origin?: SourceTargetOrigin;
100
+ range?: SourceRange;
77
101
  text: string;
78
102
  }
79
- interface SourceUnit {
80
- file: SourceFile;
81
- kind: 'class' | 'function';
103
+ type SourceTargetKind = 'class' | 'file' | 'fragment' | 'function' | 'symbol' | (string & {});
104
+ interface SourceTargetOrigin {
105
+ physicalPath: string;
106
+ range?: SourceRange;
107
+ virtualPath?: string;
108
+ }
109
+ interface SourceText {
110
+ filePath: string;
82
111
  loc: SourceLocation;
83
- name?: string;
84
- range: SourceRange;
85
112
  text: string;
86
113
  }
87
114
  //#endregion
@@ -115,11 +142,28 @@ interface ResolveModelOptions {
115
142
  }
116
143
  //#endregion
117
144
  //#region src/dsl/types.d.ts
118
- interface AlintConfig {
145
+ type AlintConfig = readonly AlintConfigInput[];
146
+ type AlintConfigExtends = AlintConfigInput | string;
147
+ type AlintConfigInput = AlintConfigItem | readonly AlintConfigInput[];
148
+ interface AlintConfigItem {
149
+ basePath?: string;
150
+ extends?: readonly AlintConfigExtends[];
151
+ files?: readonly (readonly string[] | string)[];
119
152
  ignore?: IgnoreConfig;
120
- plugins?: PluginDefinition[];
153
+ ignores?: readonly string[];
154
+ language?: string;
155
+ languageOptions?: Record<string, unknown>;
156
+ linterOptions?: AlintLinterOptions;
157
+ name?: string;
158
+ plugins?: Record<string, PluginDefinition>;
159
+ processor?: ProcessorDefinition | string;
121
160
  rules?: Record<string, RuleConfigEntry>;
122
161
  runner?: RunnerConfig;
162
+ settings?: Record<string, unknown>;
163
+ }
164
+ interface AlintLinterOptions {
165
+ noInlineConfig?: boolean;
166
+ reportUnusedDisableDirectives?: RuleSeverity;
123
167
  }
124
168
  type Awaitable<T> = Promise<T> | T;
125
169
  interface DiagnosticDescriptor {
@@ -142,15 +186,25 @@ interface EnabledRule {
142
186
  id: string;
143
187
  localId: string;
144
188
  rule: RuleDefinition;
145
- scope: string;
146
189
  severity: Exclude<RuleSeverity, 'off'>;
147
190
  }
148
191
  interface IgnoreConfig {
149
192
  gitignore?: boolean;
150
193
  }
194
+ interface LanguageDefinition {
195
+ extensions?: readonly string[];
196
+ extract: (file: SourceFile, context: LanguageContext) => Awaitable<SourceTarget[]>;
197
+ name: string;
198
+ }
151
199
  interface PluginDefinition {
152
- rules: Record<string, RuleDefinition>;
153
- scope: string;
200
+ configs?: Record<string, AlintConfigInput>;
201
+ languages?: Record<string, LanguageDefinition>;
202
+ processors?: Record<string, ProcessorDefinition>;
203
+ rules?: Record<string, RuleDefinition>;
204
+ }
205
+ interface ProcessorDefinition {
206
+ postprocess?: (diagnostics: DiagnosticDescriptor[], context: ProcessorPostprocessContext) => Awaitable<DiagnosticDescriptor[]>;
207
+ preprocess: (file: SourceFile, context: ProcessorContext) => Awaitable<ProcessedSource[]>;
154
208
  }
155
209
  type RuleCacheConfig = boolean | {
156
210
  level?: 'target';
@@ -167,8 +221,9 @@ interface RuleContext {
167
221
  recordUsage: (usage: RuleInferenceUsageRecord) => void;
168
222
  };
169
223
  model: (selector?: ModelRequirement | string) => Promise<ResolvedModel>;
224
+ outputLanguage?: string;
170
225
  report: (diagnostic: DiagnosticDescriptor) => void;
171
- scope: string;
226
+ settings: Record<string, unknown>;
172
227
  src: SourceRuntime;
173
228
  }
174
229
  interface RuleDefinition {
@@ -177,9 +232,7 @@ interface RuleDefinition {
177
232
  model?: ModelRequirement;
178
233
  }
179
234
  interface RuleHandlers {
180
- onClass?: (classNode: ClassUnit) => Awaitable<void>;
181
- onFile?: (file: SourceFile) => Awaitable<void>;
182
- onFunction?: (functionNode: FunctionUnit) => Awaitable<void>;
235
+ onTarget?: (target: SourceTarget) => Awaitable<void>;
183
236
  }
184
237
  interface RuleInferenceUsageRecord {
185
238
  filePath?: string;
@@ -197,6 +250,54 @@ interface RuleRegistry {
197
250
  }
198
251
  type RuleSeverity = 'error' | 'off' | 'warn';
199
252
  //#endregion
253
+ //#region src/config/config-array.d.ts
254
+ interface EffectiveAlintConfig {
255
+ language?: string;
256
+ languageOptions: Record<string, unknown>;
257
+ linterOptions: Record<string, unknown>;
258
+ plugins: Record<string, PluginDefinition>;
259
+ processor?: AlintConfigItem['processor'];
260
+ rules: Record<string, RuleConfigEntry>;
261
+ runner?: AlintConfigItem['runner'];
262
+ settings: Record<string, unknown>;
263
+ }
264
+ interface ResolveConfigOptions {
265
+ cwd: string;
266
+ }
267
+ interface ResolveConfigResult {
268
+ config: EffectiveAlintConfig;
269
+ ignored: boolean;
270
+ matched: AlintConfigItem[];
271
+ skipped: Array<{
272
+ item: AlintConfigItem;
273
+ reason: string;
274
+ }>;
275
+ }
276
+ declare function hasDiscoveryFilePatterns(input: AlintConfig): boolean;
277
+ declare function matchesDiscoveryFile(filePath: string, input: AlintConfig, options: ResolveConfigOptions): boolean;
278
+ declare function normalizeConfig(input: readonly AlintConfigInput[]): AlintConfigItem[];
279
+ declare function resolveConfigForFile(filePath: string, input: AlintConfig, options: ResolveConfigOptions): ResolveConfigResult;
280
+ //#endregion
281
+ //#region src/core/languages/registry.d.ts
282
+ interface LanguageRegistry {
283
+ byExtension: Map<string, string>;
284
+ languages: Map<string, LanguageDefinition>;
285
+ }
286
+ declare function registerLanguage(registry: LanguageRegistry, language: LanguageDefinition): void;
287
+ //#endregion
288
+ //#region src/core/languages/resolve.d.ts
289
+ interface ResolveLanguageOptions {
290
+ language?: string;
291
+ processedLanguage?: string;
292
+ }
293
+ declare function resolveLanguage(file: SourceFile, registry: LanguageRegistry, options: ResolveLanguageOptions): LanguageDefinition;
294
+ //#endregion
295
+ //#region src/core/languages/index.d.ts
296
+ declare function createBuiltInLanguageRegistry(): LanguageRegistry;
297
+ //#endregion
298
+ //#region src/core/languages/js/extract.d.ts
299
+ declare function extractJsSourceTargets(file: SourceFile): SourceTarget[];
300
+ //#endregion
200
301
  //#region src/core/types.d.ts
201
302
  interface Diagnostic {
202
303
  evidence?: unknown;
@@ -256,7 +357,7 @@ interface ProgressReporter {
256
357
  onTargetStart?: (payload: TargetProgressPayload) => void;
257
358
  onUsage?: (payload: UsageProgressPayload) => void;
258
359
  }
259
- type ProgressTargetKind = 'class' | 'file' | 'function';
360
+ type ProgressTargetKind = SourceTargetKind;
260
361
  interface RuleEndPayload {
261
362
  cache: 'hit' | 'miss';
262
363
  endedAt?: number;
@@ -286,6 +387,7 @@ interface RunOptions {
286
387
  cwd?: string;
287
388
  files?: string[];
288
389
  modelOverride?: string;
390
+ outputLanguage?: string;
289
391
  progress?: ProgressReporter;
290
392
  runner?: RunnerOptions;
291
393
  setupConfig?: SetupConfig;
@@ -338,13 +440,6 @@ declare class AlintRunError extends Error {
338
440
  }
339
441
  declare function runAlint(options?: RunOptions): Promise<RunResult>;
340
442
  //#endregion
341
- //#region src/core/source/js.d.ts
342
- interface JsSourceUnits {
343
- classes: ClassUnit[];
344
- functions: FunctionUnit[];
345
- }
346
- declare function extractJsSourceUnits(file: SourceFile): JsSourceUnits;
347
- //#endregion
348
443
  //#region src/core/source/runtime.d.ts
349
444
  declare function createSourceFile(path: string, text: string): SourceFile;
350
445
  declare function createSourceRuntime(): SourceRuntime;
@@ -352,14 +447,14 @@ declare function sliceLines(file: SourceFile, range: LineRange): SourceText;
352
447
  declare function sliceRange(file: SourceFile, range: SourceRange): SourceText;
353
448
  //#endregion
354
449
  //#region src/dsl/define.d.ts
355
- declare function defineConfig(config: AlintConfig): AlintConfig;
450
+ declare function defineConfig(config: readonly AlintConfigInput[]): AlintConfig;
356
451
  declare function definePlugin(plugin: PluginDefinition): PluginDefinition;
357
452
  declare function defineRule(rule: RuleDefinition): RuleDefinition;
358
453
  //#endregion
359
454
  //#region src/dsl/registry.d.ts
360
- declare function buildRuleRegistry(config: AlintConfig): RuleRegistry;
455
+ declare function buildRuleRegistry(config: Pick<EffectiveAlintConfig, 'plugins' | 'rules'>): RuleRegistry;
361
456
  //#endregion
362
457
  //#region src/models/resolve.d.ts
363
458
  declare function resolveModel(registry: SetupConfig, options?: ResolveModelOptions): ResolvedModel;
364
459
  //#endregion
365
- export { type AlintConfig, AlintRunError, type Awaitable, type ClassUnit, type Diagnostic, type DiagnosticDescriptor, type DiagnosticLocation, type DiagnosticProgressPayload, type EnabledRule, type FileProgressPayload, type FunctionUnit, type IgnoreConfig, type InferenceUsageRecord, type LineRange, type ModelRequirement, type ModelSize, type PluginDefinition, type ProgressFilePath, type ProgressPath, type ProgressReporter, type ProgressTargetKind, type ProviderDefinition, type ProviderType, type ResolveModelOptions, type ResolvedModel, type ResolvedProvider, type RuleConfigEntry, type RuleContext, type RuleDefinition, type RuleEndPayload, type RuleHandlers, type RuleInferenceUsageRecord, type RuleRegistry, type RuleSeverity, type RuleStartPayload, type RunEndPayload, type RunOptions, type RunResult, type RunStartPayload, type RunUsage, type RunnerConfig, type SetupConfig, type SetupModelDefinition, type SourceFile, type SourceLocation, type SourcePosition, type SourceRange, type SourceRuntime, type SourceText, type SourceUnit, type TargetProgressPayload, type UsageProgressPayload, buildRuleRegistry, createSourceFile, createSourceRuntime, defineConfig, definePlugin, defineRule, extractJsSourceUnits, resolveModel, runAlint, sliceLines, sliceRange };
460
+ export { type AlintConfig, type AlintConfigExtends, type AlintConfigInput, type AlintConfigItem, type AlintLinterOptions, AlintRunError, type Awaitable, type Diagnostic, type DiagnosticDescriptor, type DiagnosticLocation, type DiagnosticProgressPayload, type EffectiveAlintConfig, type EnabledRule, type FileProgressPayload, 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 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 RuleStartPayload, type RunEndPayload, type RunOptions, type RunResult, type RunStartPayload, type RunUsage, type RunnerConfig, type SetupConfig, type SetupModelDefinition, type SourceFile, type SourceLocation, type SourcePosition, type SourceRange, type SourceRuntime, type SourceTarget, type SourceTargetKind, type SourceTargetOrigin, type SourceText, type TargetProgressPayload, type UsageProgressPayload, buildRuleRegistry, createBuiltInLanguageRegistry, createSourceFile, createSourceRuntime, defineConfig, definePlugin, defineRule, extractJsSourceTargets, hasDiscoveryFilePatterns, matchesDiscoveryFile, normalizeConfig, registerLanguage, resolveConfigForFile, resolveLanguage, resolveModel, runAlint, sliceLines, sliceRange };