@alint-js/core 0.0.5 → 0.0.6
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 +131 -38
- package/dist/index.mjs +767 -407
- package/package.json +2 -1
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
|
|
38
|
-
|
|
39
|
-
|
|
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:
|
|
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 |
|
|
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
|
|
75
|
-
|
|
76
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
153
|
-
|
|
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';
|
|
@@ -168,7 +222,7 @@ interface RuleContext {
|
|
|
168
222
|
};
|
|
169
223
|
model: (selector?: ModelRequirement | string) => Promise<ResolvedModel>;
|
|
170
224
|
report: (diagnostic: DiagnosticDescriptor) => void;
|
|
171
|
-
|
|
225
|
+
settings: Record<string, unknown>;
|
|
172
226
|
src: SourceRuntime;
|
|
173
227
|
}
|
|
174
228
|
interface RuleDefinition {
|
|
@@ -177,9 +231,7 @@ interface RuleDefinition {
|
|
|
177
231
|
model?: ModelRequirement;
|
|
178
232
|
}
|
|
179
233
|
interface RuleHandlers {
|
|
180
|
-
|
|
181
|
-
onFile?: (file: SourceFile) => Awaitable<void>;
|
|
182
|
-
onFunction?: (functionNode: FunctionUnit) => Awaitable<void>;
|
|
234
|
+
onTarget?: (target: SourceTarget) => Awaitable<void>;
|
|
183
235
|
}
|
|
184
236
|
interface RuleInferenceUsageRecord {
|
|
185
237
|
filePath?: string;
|
|
@@ -197,6 +249,54 @@ interface RuleRegistry {
|
|
|
197
249
|
}
|
|
198
250
|
type RuleSeverity = 'error' | 'off' | 'warn';
|
|
199
251
|
//#endregion
|
|
252
|
+
//#region src/config/config-array.d.ts
|
|
253
|
+
interface EffectiveAlintConfig {
|
|
254
|
+
language?: string;
|
|
255
|
+
languageOptions: Record<string, unknown>;
|
|
256
|
+
linterOptions: Record<string, unknown>;
|
|
257
|
+
plugins: Record<string, PluginDefinition>;
|
|
258
|
+
processor?: AlintConfigItem['processor'];
|
|
259
|
+
rules: Record<string, RuleConfigEntry>;
|
|
260
|
+
runner?: AlintConfigItem['runner'];
|
|
261
|
+
settings: Record<string, unknown>;
|
|
262
|
+
}
|
|
263
|
+
interface ResolveConfigOptions {
|
|
264
|
+
cwd: string;
|
|
265
|
+
}
|
|
266
|
+
interface ResolveConfigResult {
|
|
267
|
+
config: EffectiveAlintConfig;
|
|
268
|
+
ignored: boolean;
|
|
269
|
+
matched: AlintConfigItem[];
|
|
270
|
+
skipped: Array<{
|
|
271
|
+
item: AlintConfigItem;
|
|
272
|
+
reason: string;
|
|
273
|
+
}>;
|
|
274
|
+
}
|
|
275
|
+
declare function hasDiscoveryFilePatterns(input: AlintConfig): boolean;
|
|
276
|
+
declare function matchesDiscoveryFile(filePath: string, input: AlintConfig, options: ResolveConfigOptions): boolean;
|
|
277
|
+
declare function normalizeConfig(input: readonly AlintConfigInput[]): AlintConfigItem[];
|
|
278
|
+
declare function resolveConfigForFile(filePath: string, input: AlintConfig, options: ResolveConfigOptions): ResolveConfigResult;
|
|
279
|
+
//#endregion
|
|
280
|
+
//#region src/core/languages/registry.d.ts
|
|
281
|
+
interface LanguageRegistry {
|
|
282
|
+
byExtension: Map<string, string>;
|
|
283
|
+
languages: Map<string, LanguageDefinition>;
|
|
284
|
+
}
|
|
285
|
+
declare function registerLanguage(registry: LanguageRegistry, language: LanguageDefinition): void;
|
|
286
|
+
//#endregion
|
|
287
|
+
//#region src/core/languages/resolve.d.ts
|
|
288
|
+
interface ResolveLanguageOptions {
|
|
289
|
+
language?: string;
|
|
290
|
+
processedLanguage?: string;
|
|
291
|
+
}
|
|
292
|
+
declare function resolveLanguage(file: SourceFile, registry: LanguageRegistry, options: ResolveLanguageOptions): LanguageDefinition;
|
|
293
|
+
//#endregion
|
|
294
|
+
//#region src/core/languages/index.d.ts
|
|
295
|
+
declare function createBuiltInLanguageRegistry(): LanguageRegistry;
|
|
296
|
+
//#endregion
|
|
297
|
+
//#region src/core/languages/js/extract.d.ts
|
|
298
|
+
declare function extractJsSourceTargets(file: SourceFile): SourceTarget[];
|
|
299
|
+
//#endregion
|
|
200
300
|
//#region src/core/types.d.ts
|
|
201
301
|
interface Diagnostic {
|
|
202
302
|
evidence?: unknown;
|
|
@@ -256,7 +356,7 @@ interface ProgressReporter {
|
|
|
256
356
|
onTargetStart?: (payload: TargetProgressPayload) => void;
|
|
257
357
|
onUsage?: (payload: UsageProgressPayload) => void;
|
|
258
358
|
}
|
|
259
|
-
type ProgressTargetKind =
|
|
359
|
+
type ProgressTargetKind = SourceTargetKind;
|
|
260
360
|
interface RuleEndPayload {
|
|
261
361
|
cache: 'hit' | 'miss';
|
|
262
362
|
endedAt?: number;
|
|
@@ -338,13 +438,6 @@ declare class AlintRunError extends Error {
|
|
|
338
438
|
}
|
|
339
439
|
declare function runAlint(options?: RunOptions): Promise<RunResult>;
|
|
340
440
|
//#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
441
|
//#region src/core/source/runtime.d.ts
|
|
349
442
|
declare function createSourceFile(path: string, text: string): SourceFile;
|
|
350
443
|
declare function createSourceRuntime(): SourceRuntime;
|
|
@@ -352,14 +445,14 @@ declare function sliceLines(file: SourceFile, range: LineRange): SourceText;
|
|
|
352
445
|
declare function sliceRange(file: SourceFile, range: SourceRange): SourceText;
|
|
353
446
|
//#endregion
|
|
354
447
|
//#region src/dsl/define.d.ts
|
|
355
|
-
declare function defineConfig(config:
|
|
448
|
+
declare function defineConfig(config: readonly AlintConfigInput[]): AlintConfig;
|
|
356
449
|
declare function definePlugin(plugin: PluginDefinition): PluginDefinition;
|
|
357
450
|
declare function defineRule(rule: RuleDefinition): RuleDefinition;
|
|
358
451
|
//#endregion
|
|
359
452
|
//#region src/dsl/registry.d.ts
|
|
360
|
-
declare function buildRuleRegistry(config:
|
|
453
|
+
declare function buildRuleRegistry(config: Pick<EffectiveAlintConfig, 'plugins' | 'rules'>): RuleRegistry;
|
|
361
454
|
//#endregion
|
|
362
455
|
//#region src/models/resolve.d.ts
|
|
363
456
|
declare function resolveModel(registry: SetupConfig, options?: ResolveModelOptions): ResolvedModel;
|
|
364
457
|
//#endregion
|
|
365
|
-
export { type AlintConfig,
|
|
458
|
+
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 };
|