/
ts-eslint.d.ts
706 lines (625 loc) · 23.8 KB
/
ts-eslint.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
/*
Redefine these types for these reasons:
1) We can better control what properties are option and what are not.
2) We have to replace definitions with our definitions which use our typescript-estree types.
3) We can better document the fields so it's easier for new contributers to understand.
The def is wrapped up in a fake module so that it can be used in eslint-rules.d.ts
*/
declare module 'ts-eslint' {
import { TSESTree } from '@typescript-eslint/typescript-estree';
import { ParserServices } from '@typescript-eslint/parser';
import { AST, Linter, Rule } from 'eslint';
import { JSONSchema4 } from 'json-schema';
//#region SourceCode
namespace SourceCode {
export interface Config {
text: string;
ast: AST.Program;
parserServices?: ParserServices;
scopeManager?: Scope.ScopeManager;
visitorKeys?: VisitorKeys;
}
export interface VisitorKeys {
[nodeType: string]: string[];
}
export type FilterPredicate = (
tokenOrComment: TSESTree.Token | TSESTree.Comment,
) => boolean;
export type CursorWithSkipOptions =
| number
| FilterPredicate
| {
includeComments?: boolean;
filter?: FilterPredicate;
skip?: number;
};
export type CursorWithCountOptions =
| number
| FilterPredicate
| {
includeComments?: boolean;
filter?: FilterPredicate;
count?: number;
};
}
class SourceCode {
text: string;
ast: AST.Program;
lines: string[];
hasBOM: boolean;
parserServices: ParserServices;
scopeManager: Scope.ScopeManager;
visitorKeys: SourceCode.VisitorKeys;
constructor(text: string, ast: AST.Program);
// eslint-disable-next-line no-dupe-class-members
constructor(config: SourceCode.Config);
static splitLines(text: string): string[];
getText(
node?: TSESTree.Node,
beforeCount?: number,
afterCount?: number,
): string;
getLines(): string[];
getAllComments(): TSESTree.Comment[];
getComments(
node: TSESTree.Node,
): { leading: TSESTree.Comment[]; trailing: TSESTree.Comment[] };
getJSDocComment(node: TSESTree.Node): TSESTree.Node | TSESTree.Token | null;
getNodeByRangeIndex(index: number): TSESTree.Node | null;
isSpaceBetweenTokens(
first: TSESTree.Token,
second: TSESTree.Token,
): boolean;
getLocFromIndex(index: number): TSESTree.LineAndColumnData;
getIndexFromLoc(location: TSESTree.LineAndColumnData): number;
// Inherited methods from TokenStore
// ---------------------------------
getTokenByRangeStart(
offset: number,
options?: { includeComments?: boolean },
): TSESTree.Token | null;
getFirstToken(
node: TSESTree.Node,
options?: SourceCode.CursorWithSkipOptions,
): TSESTree.Token | null;
getFirstTokens(
node: TSESTree.Node,
options?: SourceCode.CursorWithCountOptions,
): TSESTree.Token[];
getLastToken(
node: TSESTree.Node,
options?: SourceCode.CursorWithSkipOptions,
): TSESTree.Token | null;
getLastTokens(
node: TSESTree.Node,
options?: SourceCode.CursorWithCountOptions,
): TSESTree.Token[];
getTokenBefore(
node: TSESTree.Node | TSESTree.Token | TSESTree.Comment,
options?: SourceCode.CursorWithSkipOptions,
): TSESTree.Token | null;
getTokensBefore(
node: TSESTree.Node | TSESTree.Token | TSESTree.Comment,
options?: SourceCode.CursorWithCountOptions,
): TSESTree.Token[];
getTokenAfter(
node: TSESTree.Node | TSESTree.Token | TSESTree.Comment,
options?: SourceCode.CursorWithSkipOptions,
): TSESTree.Token | null;
getTokensAfter(
node: TSESTree.Node | TSESTree.Token | TSESTree.Comment,
options?: SourceCode.CursorWithCountOptions,
): TSESTree.Token[];
getFirstTokenBetween(
left: TSESTree.Node | TSESTree.Token | TSESTree.Comment,
right: TSESTree.Node | TSESTree.Token | TSESTree.Comment,
options?: SourceCode.CursorWithSkipOptions,
): TSESTree.Token | null;
getFirstTokensBetween(
left: TSESTree.Node | TSESTree.Token | TSESTree.Comment,
right: TSESTree.Node | TSESTree.Token | TSESTree.Comment,
options?: SourceCode.CursorWithCountOptions,
): TSESTree.Token[];
getLastTokenBetween(
left: TSESTree.Node | TSESTree.Token | TSESTree.Comment,
right: TSESTree.Node | TSESTree.Token | TSESTree.Comment,
options?: SourceCode.CursorWithSkipOptions,
): TSESTree.Token | null;
getLastTokensBetween(
left: TSESTree.Node | TSESTree.Token | TSESTree.Comment,
right: TSESTree.Node | TSESTree.Token | TSESTree.Comment,
options?: SourceCode.CursorWithCountOptions,
): TSESTree.Token[];
getTokensBetween(
left: TSESTree.Node | TSESTree.Token | TSESTree.Comment,
right: TSESTree.Node | TSESTree.Token | TSESTree.Comment,
padding?:
| number
| SourceCode.FilterPredicate
| SourceCode.CursorWithCountOptions,
): TSESTree.Token[];
getTokens(
node: TSESTree.Node,
beforeCount?: number,
afterCount?: number,
): TSESTree.Token[];
// eslint-disable-next-line no-dupe-class-members
getTokens(
node: TSESTree.Node,
options: SourceCode.FilterPredicate | SourceCode.CursorWithCountOptions,
): TSESTree.Token[];
commentsExistBetween(
left: TSESTree.Node | TSESTree.Token,
right: TSESTree.Node | TSESTree.Token,
): boolean;
getCommentsBefore(
nodeOrToken: TSESTree.Node | TSESTree.Token,
): TSESTree.Comment[];
getCommentsAfter(
nodeOrToken: TSESTree.Node | TSESTree.Token,
): TSESTree.Comment[];
getCommentsInside(node: TSESTree.Node): TSESTree.Comment[];
}
//#endregion SourceCode
//#region Rule
interface RuleMetaDataDocs {
/**
* The general category the rule falls within
*/
category:
| 'Best Practices'
| 'Stylistic Issues'
| 'Variables'
| 'Possible Errors';
/**
* Concise description of the rule
*/
description: string;
/**
* Extra information linking the rule to a tslint rule
*/
extraDescription?: string[];
/**
* The recommendation level for the rule.
* Used by the build tools to generate the recommended config.
* Set to false to not include it as a recommendation
*/
recommended: 'error' | 'warn' | false;
/**
* The URL of the rule's docs
*/
url: string;
}
interface RuleMetaData<TMessageIds extends string> {
/**
* True if the rule is deprecated, false otherwise
*/
deprecated?: boolean;
/**
* Documentation for the rule
*/
docs: RuleMetaDataDocs;
/**
* The fixer category. Omit if there is no fixer
*/
fixable?: 'code' | 'whitespace';
/**
* A map of messages which the rule can report.
* The key is the messageId, and the string is the parameterised error string.
* See: https://eslint.org/docs/developer-guide/working-with-rules#messageids
*/
messages: Record<TMessageIds, string>;
/**
* The type of rule.
* - `"problem"` means the rule is identifying code that either will cause an error or may cause a confusing behavior. Developers should consider this a high priority to resolve.
* - `"suggestion"` means the rule is identifying something that could be done in a better way but no errors will occur if the code isn’t changed.
* - `"layout"` means the rule cares primarily about whitespace, semicolons, commas, and parentheses, all the parts of the program that determine how the code looks rather than how it executes. These rules work on parts of the code that aren’t specified in the AST.
*/
type: 'suggestion' | 'problem' | 'layout';
/**
* The name of the rule this rule was replaced by, if it was deprecated.
*/
replacedBy?: string;
/**
* The options schema. Supply an empty array if there are no options.
*/
schema: JSONSchema4 | JSONSchema4[];
}
interface RuleFix {
range: AST.Range;
text: string;
}
interface RuleFixer {
insertTextAfter(
nodeOrToken: TSESTree.Node | TSESTree.Token,
text: string,
): RuleFix;
insertTextAfterRange(range: AST.Range, text: string): RuleFix;
insertTextBefore(
nodeOrToken: TSESTree.Node | TSESTree.Token,
text: string,
): RuleFix;
insertTextBeforeRange(range: AST.Range, text: string): RuleFix;
remove(nodeOrToken: TSESTree.Node | TSESTree.Token): RuleFix;
removeRange(range: AST.Range): RuleFix;
replaceText(
nodeOrToken: TSESTree.Node | TSESTree.Token,
text: string,
): RuleFix;
replaceTextRange(range: AST.Range, text: string): RuleFix;
}
type ReportFixFunction = (
fixer: RuleFixer,
) => null | RuleFix | RuleFix[] | IterableIterator<RuleFix>;
interface ReportDescriptor<TMessageIds extends string> {
/**
* The parameters for the message string associated with `messageId`.
*/
data?: Record<string, any>;
/**
* The fixer function.
*/
fix?: ReportFixFunction | null;
/**
* The messageId which is being reported.
*/
messageId: TMessageIds;
/**
* The Node or AST Token which the report is being attached to
*/
node: TSESTree.Node | TSESTree.Comment | TSESTree.Token;
/**
* An override of the location of the report
*/
loc?: TSESTree.SourceLocation;
}
interface RuleContext<
TMessageIds extends string,
TOptions extends Readonly<any[]>
> {
/**
* The rule ID.
*/
id: string;
/**
* An array of the configured options for this rule.
* This array does not include the rule severity.
*/
options: TOptions;
/**
* The shared settings from configuration.
* We do not have any shared settings in this plugin.
*/
settings: {};
/**
* The name of the parser from configuration.
*/
parserPath: string;
/**
* The parser options configured for this run
*/
parserOptions: Linter.ParserOptions;
/**
* An object containing parser-provided services for rules
*/
parserServices?: ParserServices;
/**
* Returns an array of the ancestors of the currently-traversed node, starting at
* the root of the AST and continuing through the direct parent of the current node.
* This array does not include the currently-traversed node itself.
*/
getAncestors(): TSESTree.Node[];
/**
* Returns a list of variables declared by the given node.
* This information can be used to track references to variables.
*/
getDeclaredVariables(node: TSESTree.Node): Scope.Variable[];
/**
* Returns the filename associated with the source.
*/
getFilename(): string;
/**
* Returns the scope of the currently-traversed node.
* This information can be used track references to variables.
*/
getScope(): Scope.Scope;
/**
* Returns a SourceCode object that you can use to work with the source that
* was passed to ESLint.
*/
getSourceCode(): SourceCode;
/**
* Marks a variable with the given name in the current scope as used.
* This affects the no-unused-vars rule.
*/
markVariableAsUsed(name: string): boolean;
/**
* Reports a problem in the code.
*/
report(descriptor: ReportDescriptor<TMessageIds>): void;
}
// This isn't the correct signature, but it makes it easier to do custom unions within reusable listneers
// never will break someone's code unless they specifically type the function argument
type RuleFunction<T extends TSESTree.BaseNode = never> = (node: T) => void;
interface RuleListener {
[nodeSelector: string]: RuleFunction | undefined;
ArrayExpression?: RuleFunction<TSESTree.ArrayExpression>;
ArrayPattern?: RuleFunction<TSESTree.ArrayPattern>;
ArrowFunctionExpression?: RuleFunction<TSESTree.ArrowFunctionExpression>;
AssignmentPattern?: RuleFunction<TSESTree.AssignmentPattern>;
AwaitExpression?: RuleFunction<TSESTree.AwaitExpression>;
BlockStatement?: RuleFunction<TSESTree.BlockStatement>;
BreakStatement?: RuleFunction<TSESTree.BreakStatement>;
CallExpression?: RuleFunction<TSESTree.CallExpression>;
CatchClause?: RuleFunction<TSESTree.CatchClause>;
ClassBody?: RuleFunction<TSESTree.ClassBody>;
ClassDeclaration?: RuleFunction<TSESTree.ClassDeclaration>;
ClassExpression?: RuleFunction<TSESTree.ClassExpression>;
Comment?: RuleFunction<TSESTree.Comment>;
ConditionalExpression?: RuleFunction<TSESTree.ConditionalExpression>;
ContinueStatement?: RuleFunction<TSESTree.ContinueStatement>;
DebuggerStatement?: RuleFunction<TSESTree.DebuggerStatement>;
Decorator?: RuleFunction<TSESTree.Decorator>;
DoWhileStatement?: RuleFunction<TSESTree.DoWhileStatement>;
EmptyStatement?: RuleFunction<TSESTree.EmptyStatement>;
ExportAllDeclaration?: RuleFunction<TSESTree.ExportAllDeclaration>;
ExportDefaultDeclaration?: RuleFunction<TSESTree.ExportDefaultDeclaration>;
ExportNamedDeclaration?: RuleFunction<TSESTree.ExportNamedDeclaration>;
ExportSpecifier?: RuleFunction<TSESTree.ExportSpecifier>;
ExpressionStatement?: RuleFunction<TSESTree.ExpressionStatement>;
ForInStatement?: RuleFunction<TSESTree.ForInStatement>;
ForOfStatement?: RuleFunction<TSESTree.ForOfStatement>;
ForStatement?: RuleFunction<TSESTree.ForStatement>;
Identifier?: RuleFunction<TSESTree.Identifier>;
IfStatement?: RuleFunction<TSESTree.IfStatement>;
Import?: RuleFunction<TSESTree.Import>;
ImportDeclaration?: RuleFunction<TSESTree.ImportDeclaration>;
ImportDefaultSpecifier?: RuleFunction<TSESTree.ImportDefaultSpecifier>;
ImportNamespaceSpecifier?: RuleFunction<TSESTree.ImportNamespaceSpecifier>;
ImportSpecifier?: RuleFunction<TSESTree.ImportSpecifier>;
JSXAttribute?: RuleFunction<TSESTree.JSXAttribute>;
JSXClosingElement?: RuleFunction<TSESTree.JSXClosingElement>;
JSXClosingFragment?: RuleFunction<TSESTree.JSXClosingFragment>;
JSXElement?: RuleFunction<TSESTree.JSXElement>;
JSXEmptyExpression?: RuleFunction<TSESTree.JSXEmptyExpression>;
JSXExpressionContainer?: RuleFunction<TSESTree.JSXExpressionContainer>;
JSXFragment?: RuleFunction<TSESTree.JSXFragment>;
JSXIdentifier?: RuleFunction<TSESTree.JSXIdentifier>;
JSXMemberExpression?: RuleFunction<TSESTree.JSXMemberExpression>;
JSXOpeningElement?: RuleFunction<TSESTree.JSXOpeningElement>;
JSXOpeningFragment?: RuleFunction<TSESTree.JSXOpeningFragment>;
JSXSpreadAttribute?: RuleFunction<TSESTree.JSXSpreadAttribute>;
JSXSpreadChild?: RuleFunction<TSESTree.JSXSpreadChild>;
JSXText?: RuleFunction<TSESTree.JSXText>;
LabeledStatement?: RuleFunction<TSESTree.LabeledStatement>;
MemberExpression?: RuleFunction<TSESTree.MemberExpression>;
MetaProperty?: RuleFunction<TSESTree.MetaProperty>;
MethodDefinition?: RuleFunction<TSESTree.MethodDefinition>;
NewExpression?: RuleFunction<TSESTree.NewExpression>;
ObjectExpression?: RuleFunction<TSESTree.ObjectExpression>;
ObjectPattern?: RuleFunction<TSESTree.ObjectPattern>;
Program?: RuleFunction<TSESTree.Program>;
Property?: RuleFunction<TSESTree.Property>;
RestElement?: RuleFunction<TSESTree.RestElement>;
ReturnStatement?: RuleFunction<TSESTree.ReturnStatement>;
SequenceExpression?: RuleFunction<TSESTree.SequenceExpression>;
SpreadElement?: RuleFunction<TSESTree.SpreadElement>;
Super?: RuleFunction<TSESTree.Super>;
SwitchCase?: RuleFunction<TSESTree.SwitchCase>;
SwitchStatement?: RuleFunction<TSESTree.SwitchStatement>;
TaggedTemplateExpression?: RuleFunction<TSESTree.TaggedTemplateExpression>;
TemplateElement?: RuleFunction<TSESTree.TemplateElement>;
TemplateLiteral?: RuleFunction<TSESTree.TemplateLiteral>;
ThisExpression?: RuleFunction<TSESTree.ThisExpression>;
ThrowStatement?: RuleFunction<TSESTree.ThrowStatement>;
Token?: RuleFunction<TSESTree.Token>;
TryStatement?: RuleFunction<TSESTree.TryStatement>;
TSAbstractKeyword?: RuleFunction<TSESTree.TSAbstractKeyword>;
TSAbstractMethodDefinition?: RuleFunction<
TSESTree.TSAbstractMethodDefinition
>;
TSAnyKeyword?: RuleFunction<TSESTree.TSAnyKeyword>;
TSArrayType?: RuleFunction<TSESTree.TSArrayType>;
TSAsExpression?: RuleFunction<TSESTree.TSAsExpression>;
TSAsyncKeyword?: RuleFunction<TSESTree.TSAsyncKeyword>;
TSBigIntKeyword?: RuleFunction<TSESTree.TSBigIntKeyword>;
TSBooleanKeyword?: RuleFunction<TSESTree.TSBooleanKeyword>;
TSCallSignatureDeclaration?: RuleFunction<
TSESTree.TSCallSignatureDeclaration
>;
TSConditionalType?: RuleFunction<TSESTree.TSConditionalType>;
TSConstructSignatureDeclaration?: RuleFunction<
TSESTree.TSConstructSignatureDeclaration
>;
TSDeclareKeyword?: RuleFunction<TSESTree.TSDeclareKeyword>;
TSDeclareFunction?: RuleFunction<TSESTree.TSDeclareFunction>;
TSEnumDeclaration?: RuleFunction<TSESTree.TSEnumDeclaration>;
TSEnumMember?: RuleFunction<TSESTree.TSEnumMember>;
TSExportAssignment?: RuleFunction<TSESTree.TSExportAssignment>;
TSExportKeyword?: RuleFunction<TSESTree.TSExportKeyword>;
TSExternalModuleReference?: RuleFunction<
TSESTree.TSExternalModuleReference
>;
TSImportEqualsDeclaration?: RuleFunction<
TSESTree.TSImportEqualsDeclaration
>;
TSImportType?: RuleFunction<TSESTree.TSImportType>;
TSIndexedAccessType?: RuleFunction<TSESTree.TSIndexedAccessType>;
TSIndexSignature?: RuleFunction<TSESTree.TSIndexSignature>;
TSInferType?: RuleFunction<TSESTree.TSInferType>;
TSInterfaceBody?: RuleFunction<TSESTree.TSInterfaceBody>;
TSInterfaceDeclaration?: RuleFunction<TSESTree.TSInterfaceDeclaration>;
TSIntersectionType?: RuleFunction<TSESTree.TSIntersectionType>;
TSLiteralType?: RuleFunction<TSESTree.TSLiteralType>;
TSMappedType?: RuleFunction<TSESTree.TSMappedType>;
TSMethodSignature?: RuleFunction<TSESTree.TSMethodSignature>;
TSModuleBlock?: RuleFunction<TSESTree.TSModuleBlock>;
TSModuleDeclaration?: RuleFunction<TSESTree.TSModuleDeclaration>;
TSNamespaceExportDeclaration?: RuleFunction<
TSESTree.TSNamespaceExportDeclaration
>;
TSNeverKeyword?: RuleFunction<TSESTree.TSNeverKeyword>;
TSNonNullExpression?: RuleFunction<TSESTree.TSNonNullExpression>;
TSNullKeyword?: RuleFunction<TSESTree.TSNullKeyword>;
TSNumberKeyword?: RuleFunction<TSESTree.TSNumberKeyword>;
TSObjectKeyword?: RuleFunction<TSESTree.TSObjectKeyword>;
TSOptionalType?: RuleFunction<TSESTree.TSOptionalType>;
TSParameterProperty?: RuleFunction<TSESTree.TSParameterProperty>;
TSParenthesizedType?: RuleFunction<TSESTree.TSParenthesizedType>;
TSPrivateKeyword?: RuleFunction<TSESTree.TSPrivateKeyword>;
TSPropertySignature?: RuleFunction<TSESTree.TSPropertySignature>;
TSProtectedKeyword?: RuleFunction<TSESTree.TSProtectedKeyword>;
TSPublicKeyword?: RuleFunction<TSESTree.TSPublicKeyword>;
TSQualifiedName?: RuleFunction<TSESTree.TSQualifiedName>;
TSReadonlyKeyword?: RuleFunction<TSESTree.TSReadonlyKeyword>;
TSRestType?: RuleFunction<TSESTree.TSRestType>;
TSStaticKeyword?: RuleFunction<TSESTree.TSStaticKeyword>;
TSStringKeyword?: RuleFunction<TSESTree.TSStringKeyword>;
TSSymbolKeyword?: RuleFunction<TSESTree.TSSymbolKeyword>;
TSThisType?: RuleFunction<TSESTree.TSThisType>;
TSTupleType?: RuleFunction<TSESTree.TSTupleType>;
TSTypeAliasDeclaration?: RuleFunction<TSESTree.TSTypeAliasDeclaration>;
TSTypeAnnotation?: RuleFunction<TSESTree.TSTypeAnnotation>;
TSTypeAssertion?: RuleFunction<TSESTree.TSTypeAssertion>;
TSTypeLiteral?: RuleFunction<TSESTree.TSTypeLiteral>;
TSTypeOperator?: RuleFunction<TSESTree.TSTypeOperator>;
TSTypeParameter?: RuleFunction<TSESTree.TSTypeParameter>;
TSTypeParameterDeclaration?: RuleFunction<
TSESTree.TSTypeParameterDeclaration
>;
TSTypeParameterInstantiation?: RuleFunction<
TSESTree.TSTypeParameterInstantiation
>;
TSTypePredicate?: RuleFunction<TSESTree.TSTypePredicate>;
TSTypeQuery?: RuleFunction<TSESTree.TSTypeQuery>;
TSTypeReference?: RuleFunction<TSESTree.TSTypeReference>;
TSUndefinedKeyword?: RuleFunction<TSESTree.TSUndefinedKeyword>;
TSUnionType?: RuleFunction<TSESTree.TSUnionType>;
TSUnknownKeyword?: RuleFunction<TSESTree.TSUnknownKeyword>;
TSVoidKeyword?: RuleFunction<TSESTree.TSVoidKeyword>;
VariableDeclaration?: RuleFunction<TSESTree.VariableDeclaration>;
VariableDeclarator?: RuleFunction<TSESTree.VariableDeclarator>;
WhileStatement?: RuleFunction<TSESTree.WhileStatement>;
WithStatement?: RuleFunction<TSESTree.WithStatement>;
YieldExpression?: RuleFunction<TSESTree.YieldExpression>;
}
interface RuleModule<
TMessageIds extends string,
TOptions extends Readonly<any[]>,
// for extending base rules
TRuleListener extends RuleListener = RuleListener
> {
/**
* Metadata about the rule
*/
meta: RuleMetaData<TMessageIds>;
/**
* Function which returns an object with methods that ESLint calls to “visit”
* nodes while traversing the abstract syntax tree.
*/
create(context: RuleContext<TMessageIds, TOptions>): TRuleListener;
}
//#endregion Rule
namespace Scope {
interface ScopeManager {
scopes: Scope[];
globalScope: Scope | null;
acquire(node: TSESTree.Node, inner?: boolean): Scope | null;
getDeclaredVariables(node: TSESTree.Node): Variable[];
}
interface Reference {
identifier: TSESTree.Identifier;
from: Scope;
resolved: Variable | null;
writeExpr: TSESTree.Node | null;
init: boolean;
isWrite(): boolean;
isRead(): boolean;
isWriteOnly(): boolean;
isReadOnly(): boolean;
isReadWrite(): boolean;
}
interface Variable {
name: string;
identifiers: TSESTree.Identifier[];
references: Reference[];
defs: Definition[];
scope: Scope;
eslintUsed?: boolean;
}
interface Scope {
type:
| 'block'
| 'catch'
| 'class'
| 'for'
| 'function'
| 'function-expression-name'
| 'global'
| 'module'
| 'switch'
| 'with'
| 'TDZ';
isStrict: boolean;
upper: Scope | null;
childScopes: Scope[];
variableScope: Scope;
block: TSESTree.Node;
variables: Variable[];
set: Map<string, Variable>;
references: Reference[];
through: Reference[];
functionExpressionScope: boolean;
}
type DefinitionType =
| { type: 'CatchClause'; node: TSESTree.CatchClause; parent: null }
| {
type: 'ClassName';
node: TSESTree.ClassDeclaration | TSESTree.ClassExpression;
parent: null;
}
| {
type: 'FunctionName';
node: TSESTree.FunctionDeclaration | TSESTree.FunctionExpression;
parent: null;
}
| { type: 'ImplicitGlobalVariable'; node: TSESTree.Program; parent: null }
| {
type: 'ImportBinding';
node:
| TSESTree.ImportSpecifier
| TSESTree.ImportDefaultSpecifier
| TSESTree.ImportNamespaceSpecifier;
parent: TSESTree.ImportDeclaration;
}
| {
type: 'Parameter';
node:
| TSESTree.FunctionDeclaration
| TSESTree.FunctionExpression
| TSESTree.ArrowFunctionExpression;
parent: null;
}
| { type: 'TDZ'; node: any; parent: null }
| {
type: 'Variable';
node: TSESTree.VariableDeclarator;
parent: TSESTree.VariableDeclaration;
};
type Definition = DefinitionType & { name: TSESTree.Identifier };
}
export {
ReportDescriptor,
ReportFixFunction,
RuleContext,
RuleFix,
RuleFixer,
RuleFunction,
RuleListener,
RuleMetaData,
RuleMetaDataDocs,
Scope,
SourceCode,
};
export default RuleModule;
}