@rslint/core 0.6.3 → 0.6.5

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.ts CHANGED
@@ -1,32 +1,10 @@
1
- export declare function applyFixes(options: ApplyFixesRequest): Promise<ApplyFixesResponse>;
2
-
3
- export declare interface ApplyFixesRequest {
4
- fileContent: string;
5
- diagnostics: Diagnostic[];
6
- }
7
-
8
- export declare interface ApplyFixesResponse {
9
- fixedContent: string[];
10
- wasFixed: boolean;
11
- appliedCount: number;
12
- unappliedCount: number;
13
- }
1
+ /// <reference lib="esnext.disposable" />
14
2
 
15
3
  /**
16
4
  * Type-safe config helper. Returns the config array as-is (identity function).
17
5
  */
18
6
  export declare function defineConfig(config: RslintConfig): RslintConfig;
19
7
 
20
- export declare interface Diagnostic {
21
- ruleName: string;
22
- message: string;
23
- messageId: string;
24
- filePath: string;
25
- range: Range;
26
- severity?: string;
27
- suggestions: any[];
28
- }
29
-
30
8
  /**
31
9
  * A real ESLint plugin object, as exported by community packages
32
10
  * (`eslint-plugin-unicorn`, etc.). Only the fields rslint consumes are
@@ -43,75 +21,6 @@ export declare interface ESLintPlugin {
43
21
  [key: string]: unknown;
44
22
  }
45
23
 
46
- /**
47
- * Edge in the flow graph (from antecedent to current)
48
- */
49
- declare interface FlowEdge {
50
- from: number;
51
- to: number;
52
- }
53
-
54
- /**
55
- * Flow graph for visualization
56
- */
57
- declare interface FlowGraph {
58
- nodes: FlowGraphNode[];
59
- edges: FlowEdge[];
60
- }
61
-
62
- /**
63
- * Node in the flow graph
64
- */
65
- declare interface FlowGraphNode {
66
- id: number;
67
- flags: number;
68
- flagNames?: string[];
69
- nodePos?: number;
70
- nodeEnd?: number;
71
- nodeKindName?: string;
72
- }
73
-
74
- /**
75
- * Control flow analysis information
76
- */
77
- export declare interface FlowInfo {
78
- flags: number;
79
- flagNames?: string[];
80
- nodeKind?: number;
81
- nodeKindName?: string;
82
- nodePos?: number;
83
- nodeEnd?: number;
84
- antecedent?: FlowInfo;
85
- antecedents?: FlowInfo[];
86
- graph?: FlowGraph;
87
- }
88
-
89
- export declare function getAstInfo(options: GetAstInfoRequest): Promise<GetAstInfoResponse>;
90
-
91
- /**
92
- * Request for AST info at a specific position
93
- */
94
- export declare interface GetAstInfoRequest {
95
- fileContent: string;
96
- position: number;
97
- end?: number;
98
- kind?: number;
99
- depth?: number;
100
- fileName?: string;
101
- compilerOptions?: Record<string, unknown>;
102
- }
103
-
104
- /**
105
- * Response containing detailed AST information
106
- */
107
- export declare interface GetAstInfoResponse {
108
- node?: NodeInfo;
109
- type?: TypeInfo;
110
- symbol?: SymbolInfo;
111
- signature?: SignatureInfo;
112
- flow?: FlowInfo;
113
- }
114
-
115
24
  /**
116
25
  * Define a global-ignores config entry.
117
26
  *
@@ -134,15 +43,6 @@ export declare const importPlugin: {
134
43
  };
135
44
  };
136
45
 
137
- /**
138
- * Index signature information
139
- */
140
- export declare interface IndexInfo {
141
- keyType: TypeInfo;
142
- valueType: TypeInfo;
143
- isReadonly: boolean;
144
- }
145
-
146
46
  export declare const jestPlugin: {
147
47
  configs: {
148
48
  recommended: RslintConfigEntry;
@@ -167,36 +67,47 @@ export declare const jsxA11yPlugin: {
167
67
  */
168
68
  declare type KnownPlugin = (typeof NATIVE_PLUGINS)[number];
169
69
 
170
- export declare interface LanguageOptions {
171
- parserOptions?: ParserOptions;
172
- }
173
-
174
70
  /**
175
71
  * Language-specific configuration.
176
72
  */
177
- declare interface LanguageOptions_2 {
178
- parserOptions?: ParserOptions_2;
73
+ declare interface LanguageOptions {
74
+ parserOptions?: ParserOptions;
179
75
  }
180
76
 
181
- export declare function lint(options: LintOptions): Promise<LintResponse>;
77
+ export declare interface LintMessage {
78
+ ruleId: string | null;
79
+ severity: 1 | 2;
80
+ message: string;
81
+ messageId?: string;
82
+ line: number;
83
+ column: number;
84
+ endLine?: number;
85
+ endColumn?: number;
86
+ fix?: LintMessageFix;
87
+ suggestions?: LintSuggestion[];
88
+ }
182
89
 
183
- export declare interface LintOptions {
184
- files?: string[];
185
- config?: string;
186
- workingDirectory?: string;
187
- ruleOptions?: Record<string, string>;
188
- fileContents?: Record<string, string>;
189
- languageOptions?: LanguageOptions;
190
- includeEncodedSourceFiles?: boolean;
90
+ /** A single fix edit as a flat UTF-16 offset range + replacement text (ESLint shape). */
91
+ export declare interface LintMessageFix {
92
+ range: [number, number];
93
+ text: string;
191
94
  }
192
95
 
193
- export declare interface LintResponse {
194
- diagnostics: Diagnostic[];
96
+ export declare interface LintResult {
97
+ filePath: string;
98
+ messages: LintMessage[];
195
99
  errorCount: number;
196
- fileCount: number;
197
- ruleCount: number;
198
- duration: string;
199
- encodedSourceFiles?: Record<string, string>;
100
+ warningCount: number;
101
+ fixableErrorCount: number;
102
+ fixableWarningCount: number;
103
+ output?: string;
104
+ }
105
+
106
+ export declare interface LintSuggestion {
107
+ messageId?: string;
108
+ data?: Record<string, string>;
109
+ desc: string;
110
+ fix: LintMessageFix;
200
111
  }
201
112
 
202
113
  /**
@@ -209,144 +120,10 @@ export declare interface LintResponse {
209
120
  */
210
121
  declare const NATIVE_PLUGINS: readonly ["@typescript-eslint", "import", "jest", "jsx-a11y", "promise", "react", "react-hooks", "unicorn"];
211
122
 
212
- /**
213
- * Detailed information about an AST node
214
- */
215
- export declare interface NodeInfo {
216
- id?: number;
217
- kind: number;
218
- kindName: string;
219
- pos: number;
220
- end: number;
221
- flags: number;
222
- flagNames?: string[];
223
- text?: string;
224
- fileName?: string;
225
- parent?: NodeInfo;
226
- name?: NodeInfo;
227
- expression?: NodeInfo;
228
- left?: NodeInfo;
229
- right?: NodeInfo;
230
- operatorToken?: NodeInfo;
231
- operand?: NodeInfo;
232
- condition?: NodeInfo;
233
- whenTrue?: NodeInfo;
234
- whenFalse?: NodeInfo;
235
- thenStatement?: NodeInfo;
236
- elseStatement?: NodeInfo;
237
- body?: NodeInfo;
238
- initializer?: NodeInfo;
239
- type?: NodeInfo;
240
- members?: NodeInfo[];
241
- heritageClauses?: NodeInfo[];
242
- typeParameters?: NodeInfo[];
243
- parameters?: NodeInfo[];
244
- modifiers?: NodeInfo[];
245
- arguments?: NodeInfo[];
246
- statements?: NodeInfo[];
247
- properties?: NodeInfo[];
248
- elements?: NodeInfo[];
249
- declarationList?: NodeInfo;
250
- declarations?: NodeInfo[];
251
- importClause?: NodeInfo;
252
- moduleSpecifier?: NodeInfo;
253
- namedBindings?: NodeInfo;
254
- exportClause?: NodeInfo;
255
- incrementor?: NodeInfo;
256
- statement?: NodeInfo;
257
- caseBlock?: NodeInfo;
258
- clauses?: NodeInfo[];
259
- tryBlock?: NodeInfo;
260
- catchClause?: NodeInfo;
261
- finallyBlock?: NodeInfo;
262
- variableDeclaration?: NodeInfo;
263
- block?: NodeInfo;
264
- argumentExpression?: NodeInfo;
265
- equalsToken?: NodeInfo;
266
- objectAssignmentInitializer?: NodeInfo;
267
- head?: NodeInfo;
268
- templateSpans?: NodeInfo[];
269
- literal?: NodeInfo;
270
- tag?: NodeInfo;
271
- template?: NodeInfo;
272
- questionToken?: NodeInfo;
273
- dotDotDotToken?: NodeInfo;
274
- exclamationToken?: NodeInfo;
275
- asteriskToken?: NodeInfo;
276
- equalsGreaterThanToken?: NodeInfo;
277
- questionDotToken?: NodeInfo;
278
- typeArguments?: NodeInfo[];
279
- constraint?: NodeInfo;
280
- defaultType?: NodeInfo;
281
- locals?: SymbolInfo[];
282
- endOfFileToken?: NodeInfo;
283
- imports?: NodeInfo[];
284
- isDeclarationFile?: boolean;
285
- scriptKind?: number;
286
- identifierCount?: number;
287
- symbolCount?: number;
288
- nodeCount?: number;
289
- listMetas?: Record<string, NodeListMeta>;
290
- }
291
-
292
- /**
293
- * NodeList metadata (Pos, End, HasTrailingComma)
294
- */
295
- declare interface NodeListMeta {
296
- pos: number;
297
- end: number;
298
- hasTrailingComma: boolean;
299
- }
300
-
301
- /**
302
- * Node.js implementation of RslintService using child processes
303
- */
304
- export declare class NodeRslintService implements RslintServiceInterface {
305
- private nextMessageId;
306
- private readonly pendingMessages;
307
- private readonly rslintPath;
308
- private readonly process;
309
- private chunks;
310
- private chunkSize;
311
- private expectedSize;
312
- constructor(options?: RSlintOptions);
313
- /**
314
- * Send a message to the rslint process
315
- */
316
- sendMessage(kind: string, data: any): Promise<any>;
317
- /**
318
- * Handle incoming binary data chunks
319
- */
320
- private handleChunk;
321
- /**
322
- * Handle a complete message from rslint
323
- */
324
- private handleMessage;
325
- /**
326
- * Terminate the rslint process
327
- */
328
- terminate(): void;
329
- }
330
-
331
- /**
332
- * Function parameter information (deprecated - use SymbolInfo instead)
333
- */
334
- export declare interface ParameterInfo {
335
- name: string;
336
- type?: TypeInfo;
337
- optional: boolean;
338
- rest: boolean;
339
- }
340
-
341
- export declare interface ParserOptions {
342
- projectService?: boolean;
343
- project?: string[] | string;
344
- }
345
-
346
123
  /**
347
124
  * TypeScript parser options. `project` may be a single tsconfig path or a list.
348
125
  */
349
- declare interface ParserOptions_2 {
126
+ declare interface ParserOptions {
350
127
  /**
351
128
  * Enable project service for typed linting (runs the TypeScript language
352
129
  * service behind the scenes).
@@ -365,25 +142,12 @@ declare interface ParserOptions_2 {
365
142
  project?: string | string[];
366
143
  }
367
144
 
368
- /**
369
- * Shared types for rslint IPC protocol across all environments
370
- */
371
- declare interface Position {
372
- line: number;
373
- column: number;
374
- }
375
-
376
145
  export declare const promisePlugin: {
377
146
  configs: {
378
147
  recommended: RslintConfigEntry;
379
148
  };
380
149
  };
381
150
 
382
- declare interface Range {
383
- start: Position;
384
- end: Position;
385
- }
386
-
387
151
  export declare const reactHooksPlugin: {
388
152
  configs: {
389
153
  recommended: RslintConfigEntry;
@@ -396,8 +160,43 @@ export declare const reactPlugin: {
396
160
  };
397
161
  };
398
162
 
163
+ export declare class Rslint {
164
+ #private;
165
+ constructor(options?: RslintOptions);
166
+ /**
167
+ * Lint a string of code as if it lived at `filePath` (default a synthetic
168
+ * `.ts` path).
169
+ *
170
+ * ESLint-alignment note: if `code` begins with a UTF-8 BOM, the reported
171
+ * offsets (`fix.range`, `column`) are relative to the BOM-included input you
172
+ * passed — self-consistent within that input (result `output`, line/column,
173
+ * and re-applying `fix` all line up), but one unit ahead of ESLint v10, which
174
+ * strips a leading BOM from its in-memory source. (The overlay keeps the BOM
175
+ * and Go's offsets include it; lintFiles is unaffected because Go reads disk
176
+ * files BOM-stripped.) Strip a leading `U+FEFF` first for ESLint-identical
177
+ * offsets.
178
+ */
179
+ lintText(code: string, options?: {
180
+ filePath?: string;
181
+ }): Promise<LintResult[]>;
182
+ /**
183
+ * Lint files matched by glob pattern(s), resolved against `cwd`. Results are
184
+ * ordered by the linted file's path (deterministic), not by glob-walk order.
185
+ */
186
+ lintFiles(patterns: string | string[]): Promise<LintResult[]>;
187
+ /**
188
+ * Write the `output` of each result back to its file. Mirrors ESLint's
189
+ * guards: only when `output` is a string and `filePath` is absolute (so a
190
+ * lintText `<text>` result is skipped automatically).
191
+ */
192
+ static outputFixes(results: LintResult[]): Promise<void>;
193
+ /** Tear down the long-lived Go `--api` process. */
194
+ close(): Promise<void>;
195
+ [Symbol.asyncDispose](): Promise<void>;
196
+ }
197
+
399
198
  /** Top-level rslint config: an array of entries. */
400
- declare type RslintConfig = RslintConfigEntry[];
199
+ export declare type RslintConfig = RslintConfigEntry[];
401
200
 
402
201
  /**
403
202
  * A single entry in an rslint config array. Multiple entries may target
@@ -419,7 +218,7 @@ export declare interface RslintConfigEntry {
419
218
  */
420
219
  ignores?: string[];
421
220
  /** Language-level configuration (parser, etc.). */
422
- languageOptions?: LanguageOptions_2;
221
+ languageOptions?: LanguageOptions;
423
222
  /**
424
223
  * Plugins enabled for this entry. Two forms:
425
224
  *
@@ -457,39 +256,34 @@ export declare interface RslintConfigEntry {
457
256
  rules?: RulesRecord;
458
257
  }
459
258
 
460
- export declare interface RSlintOptions {
461
- rslintPath?: string;
462
- workingDirectory?: string;
463
- }
464
-
465
- /**
466
- * Main RslintService class that automatically uses the appropriate implementation
467
- */
468
- export declare class RSLintService {
469
- private readonly service;
470
- constructor(service: RslintServiceInterface);
471
- /**
472
- * Run the linter on specified files
473
- */
474
- lint(options?: LintOptions): Promise<LintResponse>;
475
- /**
476
- * Apply fixes to a file based on diagnostics
477
- */
478
- applyFixes(options: ApplyFixesRequest): Promise<ApplyFixesResponse>;
259
+ export declare interface RslintOptions {
260
+ /** Base directory for config discovery and relative path resolution. */
261
+ cwd?: string;
262
+ /** Extra config appended after the resolved/discovered config (ESLint's overrideConfig). */
263
+ overrideConfig?: RslintConfigEntry | RslintConfigEntry[] | null;
479
264
  /**
480
- * Get detailed AST information at a specific position
481
- * Returns Node, Type, Symbol, Signature, and Flow information
265
+ * `string` use this config file (no discovery).
266
+ * `true` — use only `overrideConfig` (no file, no discovery).
267
+ * `null`/absent — auto-discover the nearest config (ESLint v10 semantics; no `false`).
482
268
  */
483
- getAstInfo(options: GetAstInfoRequest): Promise<GetAstInfoResponse>;
269
+ overrideConfigFile?: string | true | null;
270
+ /** Apply rule auto-fixes; results carry `output` (the JS side persists via outputFixes). */
271
+ fix?: boolean;
484
272
  /**
485
- * Close the service
273
+ * In-memory file overlay (path → content) for fully in-memory linting (issue
274
+ * #1106): put the `tsconfig.json` that `parserOptions.project` names plus any
275
+ * dependency files here, then lint a buffer with `lintText`. Keys resolve
276
+ * against `cwd` like a linted path (relative or absolute both work); a
277
+ * same-path `lintText` code entry wins. Inside the tsconfig (`files`) and
278
+ * `parserOptions.project`, use relative paths — the TS compiler resolves
279
+ * those, and a bare POSIX-absolute path there has no drive letter on Windows,
280
+ * so it won't match the overlay. rslint-only — ESLint has no in-memory file
281
+ * map.
282
+ *
283
+ * Give the tsconfig explicit `files`, not a broad `include` glob: a glob is
284
+ * expanded against the real filesystem and would scan `cwd` on disk.
486
285
  */
487
- close(): Promise<void>;
488
- }
489
-
490
- export declare interface RslintServiceInterface {
491
- sendMessage(kind: string, data: any): Promise<any>;
492
- terminate(): void;
286
+ virtualFiles?: Record<string, string>;
493
287
  }
494
288
 
495
289
  /**
@@ -524,41 +318,15 @@ declare type RuleSeverity = 'off' | 'warn' | 'error';
524
318
  */
525
319
  declare type RulesRecord = Record<string, RuleEntry>;
526
320
 
527
- /**
528
- * Detailed information about a function/method signature
529
- */
530
- export declare interface SignatureInfo {
531
- flags: number;
532
- flagNames?: string[];
533
- minArgumentCount: number;
534
- pos?: number;
535
- fileName?: string;
536
- parameters?: SymbolInfo[];
537
- thisParameter?: SymbolInfo;
538
- typeParameters?: TypeInfo[];
539
- returnType?: TypeInfo;
540
- typePredicate?: TypePredicateInfo;
541
- declaration?: NodeInfo;
542
- }
321
+ export declare function runCLI({ argv, }?: RunCLIOptions): Promise<void>;
543
322
 
544
- /**
545
- * Detailed information about a TypeScript symbol
546
- */
547
- export declare interface SymbolInfo {
548
- id?: number;
549
- name: string;
550
- escapedName?: string;
551
- flags: number;
552
- flagNames?: string[];
553
- checkFlags?: number;
554
- checkFlagNames?: string[];
555
- pos?: number;
556
- fileName?: string;
557
- declarations?: NodeInfo[];
558
- valueDeclaration?: NodeInfo;
559
- members?: SymbolInfo[];
560
- exports?: SymbolInfo[];
561
- }
323
+ export declare type RunCLIOptions = {
324
+ /**
325
+ * The command-line arguments to parse, matching the shape of Node.js `process.argv`
326
+ * @default process.argv
327
+ */
328
+ argv?: string[];
329
+ };
562
330
 
563
331
  export declare const ts: {
564
332
  configs: {
@@ -567,56 +335,6 @@ export declare const ts: {
567
335
  };
568
336
  };
569
337
 
570
- /**
571
- * Detailed information about a TypeScript type
572
- */
573
- export declare interface TypeInfo {
574
- id?: number;
575
- flags: number;
576
- flagNames?: string[];
577
- objectFlags?: number;
578
- objectFlagNames?: string[];
579
- intrinsicName?: string;
580
- typeString: string;
581
- pos?: number;
582
- fileName?: string;
583
- value?: unknown;
584
- freshType?: TypeInfo;
585
- regularType?: TypeInfo;
586
- symbol?: SymbolInfo;
587
- aliasSymbol?: SymbolInfo;
588
- typeArguments?: TypeInfo[];
589
- baseTypes?: TypeInfo[];
590
- properties?: SymbolInfo[];
591
- callSignatures?: SignatureInfo[];
592
- constructSignatures?: SignatureInfo[];
593
- indexInfos?: IndexInfo[];
594
- types?: TypeInfo[];
595
- constraint?: TypeInfo;
596
- default?: TypeInfo;
597
- target?: TypeInfo;
598
- }
599
-
600
- /**
601
- * Generic type parameter information
602
- */
603
- export declare interface TypeParamInfo {
604
- name: string;
605
- constraint?: TypeInfo;
606
- default?: TypeInfo;
607
- }
608
-
609
- /**
610
- * Type predicate information for type guards
611
- */
612
- export declare interface TypePredicateInfo {
613
- kind: number;
614
- kindName: string;
615
- parameterName?: string;
616
- parameterIndex?: number;
617
- type?: TypeInfo;
618
- }
619
-
620
338
  export declare const unicornPlugin: {
621
339
  configs: {
622
340
  recommended: RslintConfigEntry;