1 | import { JSONSchema4 } from '../json-schema';
|
2 | import { ParserServices, TSESTree } from '../ts-estree';
|
3 | import { AST } from './AST';
|
4 | import { Linter } from './Linter';
|
5 | import { Scope } from './Scope';
|
6 | import { SourceCode } from './SourceCode';
|
7 | interface RuleMetaDataDocs {
|
8 | |
9 |
|
10 |
|
11 | category: 'Best Practices' | 'Stylistic Issues' | 'Variables' | 'Possible Errors';
|
12 | |
13 |
|
14 |
|
15 | description: string;
|
16 | |
17 |
|
18 |
|
19 |
|
20 |
|
21 | recommended: 'error' | 'warn' | false;
|
22 | |
23 |
|
24 |
|
25 | url: string;
|
26 | |
27 |
|
28 |
|
29 | suggestion?: boolean;
|
30 | |
31 |
|
32 |
|
33 |
|
34 | requiresTypeChecking?: boolean;
|
35 | |
36 |
|
37 |
|
38 |
|
39 |
|
40 | extendsBaseRule?: boolean | string;
|
41 | }
|
42 | interface RuleMetaData<TMessageIds extends string> {
|
43 | |
44 |
|
45 |
|
46 | deprecated?: boolean;
|
47 | |
48 |
|
49 |
|
50 | docs?: RuleMetaDataDocs;
|
51 | |
52 |
|
53 |
|
54 | fixable?: 'code' | 'whitespace';
|
55 | |
56 |
|
57 |
|
58 |
|
59 |
|
60 | messages: Record<TMessageIds, string>;
|
61 | |
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 | type: 'suggestion' | 'problem' | 'layout';
|
68 | |
69 |
|
70 |
|
71 | replacedBy?: string[];
|
72 | |
73 |
|
74 |
|
75 | schema: JSONSchema4 | JSONSchema4[];
|
76 | }
|
77 | interface RuleFix {
|
78 | range: AST.Range;
|
79 | text: string;
|
80 | }
|
81 | interface RuleFixer {
|
82 | insertTextAfter(nodeOrToken: TSESTree.Node | TSESTree.Token, text: string): RuleFix;
|
83 | insertTextAfterRange(range: AST.Range, text: string): RuleFix;
|
84 | insertTextBefore(nodeOrToken: TSESTree.Node | TSESTree.Token, text: string): RuleFix;
|
85 | insertTextBeforeRange(range: AST.Range, text: string): RuleFix;
|
86 | remove(nodeOrToken: TSESTree.Node | TSESTree.Token): RuleFix;
|
87 | removeRange(range: AST.Range): RuleFix;
|
88 | replaceText(nodeOrToken: TSESTree.Node | TSESTree.Token, text: string): RuleFix;
|
89 | replaceTextRange(range: AST.Range, text: string): RuleFix;
|
90 | }
|
91 | declare type ReportFixFunction = (fixer: RuleFixer) => null | RuleFix | RuleFix[] | IterableIterator<RuleFix>;
|
92 | declare type ReportSuggestionArray<TMessageIds extends string> = ReportDescriptorBase<TMessageIds>[];
|
93 | interface ReportDescriptorBase<TMessageIds extends string> {
|
94 | |
95 |
|
96 |
|
97 | readonly data?: Readonly<Record<string, unknown>>;
|
98 | |
99 |
|
100 |
|
101 | readonly fix?: ReportFixFunction | null;
|
102 | |
103 |
|
104 |
|
105 | readonly messageId: TMessageIds;
|
106 | }
|
107 | interface ReportDescriptorWithSuggestion<TMessageIds extends string> extends ReportDescriptorBase<TMessageIds> {
|
108 | |
109 |
|
110 |
|
111 | readonly suggest?: Readonly<ReportSuggestionArray<TMessageIds>> | null;
|
112 | }
|
113 | interface ReportDescriptorNodeOptionalLoc {
|
114 | |
115 |
|
116 |
|
117 | readonly node: TSESTree.Node | TSESTree.Token;
|
118 | |
119 |
|
120 |
|
121 | readonly loc?: Readonly<TSESTree.SourceLocation> | Readonly<TSESTree.LineAndColumnData>;
|
122 | }
|
123 | interface ReportDescriptorLocOnly {
|
124 | |
125 |
|
126 |
|
127 | loc: Readonly<TSESTree.SourceLocation> | Readonly<TSESTree.LineAndColumnData>;
|
128 | }
|
129 | declare type ReportDescriptor<TMessageIds extends string> = ReportDescriptorWithSuggestion<TMessageIds> & (ReportDescriptorNodeOptionalLoc | ReportDescriptorLocOnly);
|
130 |
|
131 |
|
132 |
|
133 |
|
134 | interface SharedConfigurationSettings {
|
135 | [name: string]: unknown;
|
136 | }
|
137 | interface RuleContext<TMessageIds extends string, TOptions extends readonly unknown[]> {
|
138 | |
139 |
|
140 |
|
141 | id: string;
|
142 | |
143 |
|
144 |
|
145 |
|
146 | options: TOptions;
|
147 | |
148 |
|
149 |
|
150 | parserPath: string;
|
151 | |
152 |
|
153 |
|
154 | parserOptions: Linter.ParserOptions;
|
155 | |
156 |
|
157 |
|
158 | parserServices?: ParserServices;
|
159 | |
160 |
|
161 |
|
162 |
|
163 | settings: SharedConfigurationSettings;
|
164 | |
165 |
|
166 |
|
167 |
|
168 |
|
169 | getAncestors(): TSESTree.Node[];
|
170 | |
171 |
|
172 |
|
173 |
|
174 | getDeclaredVariables(node: TSESTree.Node): Scope.Variable[];
|
175 | |
176 |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 | getCwd?(): string;
|
182 | |
183 |
|
184 |
|
185 | getFilename(): string;
|
186 | |
187 |
|
188 |
|
189 |
|
190 | getScope(): Scope.Scope;
|
191 | |
192 |
|
193 |
|
194 |
|
195 | getSourceCode(): Readonly<SourceCode>;
|
196 | |
197 |
|
198 |
|
199 |
|
200 | markVariableAsUsed(name: string): boolean;
|
201 | |
202 |
|
203 |
|
204 | report(descriptor: ReportDescriptor<TMessageIds>): void;
|
205 | }
|
206 | declare type RuleFunction<T extends TSESTree.BaseNode = never> = (node: T) => void;
|
207 | interface RuleListener {
|
208 | [nodeSelector: string]: RuleFunction | undefined;
|
209 | ArrayExpression?: RuleFunction<TSESTree.ArrayExpression>;
|
210 | ArrayPattern?: RuleFunction<TSESTree.ArrayPattern>;
|
211 | ArrowFunctionExpression?: RuleFunction<TSESTree.ArrowFunctionExpression>;
|
212 | AssignmentPattern?: RuleFunction<TSESTree.AssignmentPattern>;
|
213 | AssignmentExpression?: RuleFunction<TSESTree.AssignmentExpression>;
|
214 | AwaitExpression?: RuleFunction<TSESTree.AwaitExpression>;
|
215 | BigIntLiteral?: RuleFunction<TSESTree.BigIntLiteral>;
|
216 | BinaryExpression?: RuleFunction<TSESTree.BinaryExpression>;
|
217 | BlockStatement?: RuleFunction<TSESTree.BlockStatement>;
|
218 | BreakStatement?: RuleFunction<TSESTree.BreakStatement>;
|
219 | CallExpression?: RuleFunction<TSESTree.CallExpression>;
|
220 | CatchClause?: RuleFunction<TSESTree.CatchClause>;
|
221 | ChainExpression?: RuleFunction<TSESTree.ChainExpression>;
|
222 | ClassBody?: RuleFunction<TSESTree.ClassBody>;
|
223 | ClassDeclaration?: RuleFunction<TSESTree.ClassDeclaration>;
|
224 | ClassExpression?: RuleFunction<TSESTree.ClassExpression>;
|
225 | ClassProperty?: RuleFunction<TSESTree.ClassProperty>;
|
226 | ConditionalExpression?: RuleFunction<TSESTree.ConditionalExpression>;
|
227 | ContinueStatement?: RuleFunction<TSESTree.ContinueStatement>;
|
228 | DebuggerStatement?: RuleFunction<TSESTree.DebuggerStatement>;
|
229 | Decorator?: RuleFunction<TSESTree.Decorator>;
|
230 | DoWhileStatement?: RuleFunction<TSESTree.DoWhileStatement>;
|
231 | EmptyStatement?: RuleFunction<TSESTree.EmptyStatement>;
|
232 | ExportAllDeclaration?: RuleFunction<TSESTree.ExportAllDeclaration>;
|
233 | ExportDefaultDeclaration?: RuleFunction<TSESTree.ExportDefaultDeclaration>;
|
234 | ExportNamedDeclaration?: RuleFunction<TSESTree.ExportNamedDeclaration>;
|
235 | ExportSpecifier?: RuleFunction<TSESTree.ExportSpecifier>;
|
236 | ExpressionStatement?: RuleFunction<TSESTree.ExpressionStatement>;
|
237 | ForInStatement?: RuleFunction<TSESTree.ForInStatement>;
|
238 | ForOfStatement?: RuleFunction<TSESTree.ForOfStatement>;
|
239 | ForStatement?: RuleFunction<TSESTree.ForStatement>;
|
240 | FunctionDeclaration?: RuleFunction<TSESTree.FunctionDeclaration>;
|
241 | FunctionExpression?: RuleFunction<TSESTree.FunctionExpression>;
|
242 | Identifier?: RuleFunction<TSESTree.Identifier>;
|
243 | IfStatement?: RuleFunction<TSESTree.IfStatement>;
|
244 | ImportDeclaration?: RuleFunction<TSESTree.ImportDeclaration>;
|
245 | ImportDefaultSpecifier?: RuleFunction<TSESTree.ImportDefaultSpecifier>;
|
246 | ImportExpression?: RuleFunction<TSESTree.ImportExpression>;
|
247 | ImportNamespaceSpecifier?: RuleFunction<TSESTree.ImportNamespaceSpecifier>;
|
248 | ImportSpecifier?: RuleFunction<TSESTree.ImportSpecifier>;
|
249 | JSXAttribute?: RuleFunction<TSESTree.JSXAttribute>;
|
250 | JSXClosingElement?: RuleFunction<TSESTree.JSXClosingElement>;
|
251 | JSXClosingFragment?: RuleFunction<TSESTree.JSXClosingFragment>;
|
252 | JSXElement?: RuleFunction<TSESTree.JSXElement>;
|
253 | JSXEmptyExpression?: RuleFunction<TSESTree.JSXEmptyExpression>;
|
254 | JSXExpressionContainer?: RuleFunction<TSESTree.JSXExpressionContainer>;
|
255 | JSXFragment?: RuleFunction<TSESTree.JSXFragment>;
|
256 | JSXIdentifier?: RuleFunction<TSESTree.JSXIdentifier>;
|
257 | JSXMemberExpression?: RuleFunction<TSESTree.JSXMemberExpression>;
|
258 | JSXOpeningElement?: RuleFunction<TSESTree.JSXOpeningElement>;
|
259 | JSXOpeningFragment?: RuleFunction<TSESTree.JSXOpeningFragment>;
|
260 | JSXSpreadAttribute?: RuleFunction<TSESTree.JSXSpreadAttribute>;
|
261 | JSXSpreadChild?: RuleFunction<TSESTree.JSXSpreadChild>;
|
262 | JSXText?: RuleFunction<TSESTree.JSXText>;
|
263 | LabeledStatement?: RuleFunction<TSESTree.LabeledStatement>;
|
264 | Literal?: RuleFunction<TSESTree.Literal>;
|
265 | LogicalExpression?: RuleFunction<TSESTree.LogicalExpression>;
|
266 | MemberExpression?: RuleFunction<TSESTree.MemberExpression>;
|
267 | MetaProperty?: RuleFunction<TSESTree.MetaProperty>;
|
268 | MethodDefinition?: RuleFunction<TSESTree.MethodDefinition>;
|
269 | NewExpression?: RuleFunction<TSESTree.NewExpression>;
|
270 | ObjectExpression?: RuleFunction<TSESTree.ObjectExpression>;
|
271 | ObjectPattern?: RuleFunction<TSESTree.ObjectPattern>;
|
272 | Program?: RuleFunction<TSESTree.Program>;
|
273 | Property?: RuleFunction<TSESTree.Property>;
|
274 | RestElement?: RuleFunction<TSESTree.RestElement>;
|
275 | ReturnStatement?: RuleFunction<TSESTree.ReturnStatement>;
|
276 | SequenceExpression?: RuleFunction<TSESTree.SequenceExpression>;
|
277 | SpreadElement?: RuleFunction<TSESTree.SpreadElement>;
|
278 | Super?: RuleFunction<TSESTree.Super>;
|
279 | SwitchCase?: RuleFunction<TSESTree.SwitchCase>;
|
280 | SwitchStatement?: RuleFunction<TSESTree.SwitchStatement>;
|
281 | TaggedTemplateExpression?: RuleFunction<TSESTree.TaggedTemplateExpression>;
|
282 | TemplateElement?: RuleFunction<TSESTree.TemplateElement>;
|
283 | TemplateLiteral?: RuleFunction<TSESTree.TemplateLiteral>;
|
284 | ThisExpression?: RuleFunction<TSESTree.ThisExpression>;
|
285 | ThrowStatement?: RuleFunction<TSESTree.ThrowStatement>;
|
286 | TryStatement?: RuleFunction<TSESTree.TryStatement>;
|
287 | TSAbstractClassProperty?: RuleFunction<TSESTree.TSAbstractClassProperty>;
|
288 | TSAbstractKeyword?: RuleFunction<TSESTree.TSAbstractKeyword>;
|
289 | TSAbstractMethodDefinition?: RuleFunction<TSESTree.TSAbstractMethodDefinition>;
|
290 | TSAnyKeyword?: RuleFunction<TSESTree.TSAnyKeyword>;
|
291 | TSArrayType?: RuleFunction<TSESTree.TSArrayType>;
|
292 | TSAsExpression?: RuleFunction<TSESTree.TSAsExpression>;
|
293 | TSAsyncKeyword?: RuleFunction<TSESTree.TSAsyncKeyword>;
|
294 | TSBigIntKeyword?: RuleFunction<TSESTree.TSBigIntKeyword>;
|
295 | TSBooleanKeyword?: RuleFunction<TSESTree.TSBooleanKeyword>;
|
296 | TSCallSignatureDeclaration?: RuleFunction<TSESTree.TSCallSignatureDeclaration>;
|
297 | TSClassImplements?: RuleFunction<TSESTree.TSClassImplements>;
|
298 | TSConditionalType?: RuleFunction<TSESTree.TSConditionalType>;
|
299 | TSConstructorType?: RuleFunction<TSESTree.TSConstructorType>;
|
300 | TSConstructSignatureDeclaration?: RuleFunction<TSESTree.TSConstructSignatureDeclaration>;
|
301 | TSDeclareKeyword?: RuleFunction<TSESTree.TSDeclareKeyword>;
|
302 | TSDeclareFunction?: RuleFunction<TSESTree.TSDeclareFunction>;
|
303 | TSEmptyBodyFunctionExpression?: RuleFunction<TSESTree.TSEmptyBodyFunctionExpression>;
|
304 | TSEnumDeclaration?: RuleFunction<TSESTree.TSEnumDeclaration>;
|
305 | TSEnumMember?: RuleFunction<TSESTree.TSEnumMember>;
|
306 | TSExportAssignment?: RuleFunction<TSESTree.TSExportAssignment>;
|
307 | TSExportKeyword?: RuleFunction<TSESTree.TSExportKeyword>;
|
308 | TSExternalModuleReference?: RuleFunction<TSESTree.TSExternalModuleReference>;
|
309 | TSFunctionType?: RuleFunction<TSESTree.TSFunctionType>;
|
310 | TSImportEqualsDeclaration?: RuleFunction<TSESTree.TSImportEqualsDeclaration>;
|
311 | TSImportType?: RuleFunction<TSESTree.TSImportType>;
|
312 | TSIndexedAccessType?: RuleFunction<TSESTree.TSIndexedAccessType>;
|
313 | TSIndexSignature?: RuleFunction<TSESTree.TSIndexSignature>;
|
314 | TSInferType?: RuleFunction<TSESTree.TSInferType>;
|
315 | TSInterfaceBody?: RuleFunction<TSESTree.TSInterfaceBody>;
|
316 | TSInterfaceDeclaration?: RuleFunction<TSESTree.TSInterfaceDeclaration>;
|
317 | TSInterfaceHeritage?: RuleFunction<TSESTree.TSInterfaceHeritage>;
|
318 | TSIntersectionType?: RuleFunction<TSESTree.TSIntersectionType>;
|
319 | TSLiteralType?: RuleFunction<TSESTree.TSLiteralType>;
|
320 | TSMappedType?: RuleFunction<TSESTree.TSMappedType>;
|
321 | TSMethodSignature?: RuleFunction<TSESTree.TSMethodSignature>;
|
322 | TSModuleBlock?: RuleFunction<TSESTree.TSModuleBlock>;
|
323 | TSModuleDeclaration?: RuleFunction<TSESTree.TSModuleDeclaration>;
|
324 | TSNamespaceExportDeclaration?: RuleFunction<TSESTree.TSNamespaceExportDeclaration>;
|
325 | TSNeverKeyword?: RuleFunction<TSESTree.TSNeverKeyword>;
|
326 | TSNonNullExpression?: RuleFunction<TSESTree.TSNonNullExpression>;
|
327 | TSNullKeyword?: RuleFunction<TSESTree.TSNullKeyword>;
|
328 | TSNumberKeyword?: RuleFunction<TSESTree.TSNumberKeyword>;
|
329 | TSObjectKeyword?: RuleFunction<TSESTree.TSObjectKeyword>;
|
330 | TSOptionalType?: RuleFunction<TSESTree.TSOptionalType>;
|
331 | TSParameterProperty?: RuleFunction<TSESTree.TSParameterProperty>;
|
332 | TSParenthesizedType?: RuleFunction<TSESTree.TSParenthesizedType>;
|
333 | TSPrivateKeyword?: RuleFunction<TSESTree.TSPrivateKeyword>;
|
334 | TSPropertySignature?: RuleFunction<TSESTree.TSPropertySignature>;
|
335 | TSProtectedKeyword?: RuleFunction<TSESTree.TSProtectedKeyword>;
|
336 | TSPublicKeyword?: RuleFunction<TSESTree.TSPublicKeyword>;
|
337 | TSQualifiedName?: RuleFunction<TSESTree.TSQualifiedName>;
|
338 | TSReadonlyKeyword?: RuleFunction<TSESTree.TSReadonlyKeyword>;
|
339 | TSRestType?: RuleFunction<TSESTree.TSRestType>;
|
340 | TSStaticKeyword?: RuleFunction<TSESTree.TSStaticKeyword>;
|
341 | TSStringKeyword?: RuleFunction<TSESTree.TSStringKeyword>;
|
342 | TSSymbolKeyword?: RuleFunction<TSESTree.TSSymbolKeyword>;
|
343 | TSThisType?: RuleFunction<TSESTree.TSThisType>;
|
344 | TSTupleType?: RuleFunction<TSESTree.TSTupleType>;
|
345 | TSTypeAliasDeclaration?: RuleFunction<TSESTree.TSTypeAliasDeclaration>;
|
346 | TSTypeAnnotation?: RuleFunction<TSESTree.TSTypeAnnotation>;
|
347 | TSTypeAssertion?: RuleFunction<TSESTree.TSTypeAssertion>;
|
348 | TSTypeLiteral?: RuleFunction<TSESTree.TSTypeLiteral>;
|
349 | TSTypeOperator?: RuleFunction<TSESTree.TSTypeOperator>;
|
350 | TSTypeParameter?: RuleFunction<TSESTree.TSTypeParameter>;
|
351 | TSTypeParameterDeclaration?: RuleFunction<TSESTree.TSTypeParameterDeclaration>;
|
352 | TSTypeParameterInstantiation?: RuleFunction<TSESTree.TSTypeParameterInstantiation>;
|
353 | TSTypePredicate?: RuleFunction<TSESTree.TSTypePredicate>;
|
354 | TSTypeQuery?: RuleFunction<TSESTree.TSTypeQuery>;
|
355 | TSTypeReference?: RuleFunction<TSESTree.TSTypeReference>;
|
356 | TSUndefinedKeyword?: RuleFunction<TSESTree.TSUndefinedKeyword>;
|
357 | TSUnionType?: RuleFunction<TSESTree.TSUnionType>;
|
358 | TSUnknownKeyword?: RuleFunction<TSESTree.TSUnknownKeyword>;
|
359 | TSVoidKeyword?: RuleFunction<TSESTree.TSVoidKeyword>;
|
360 | UnaryExpression?: RuleFunction<TSESTree.UnaryExpression>;
|
361 | UpdateExpression?: RuleFunction<TSESTree.UpdateExpression>;
|
362 | VariableDeclaration?: RuleFunction<TSESTree.VariableDeclaration>;
|
363 | VariableDeclarator?: RuleFunction<TSESTree.VariableDeclarator>;
|
364 | WhileStatement?: RuleFunction<TSESTree.WhileStatement>;
|
365 | WithStatement?: RuleFunction<TSESTree.WithStatement>;
|
366 | YieldExpression?: RuleFunction<TSESTree.YieldExpression>;
|
367 | }
|
368 | interface RuleModule<TMessageIds extends string, TOptions extends readonly unknown[], TRuleListener extends RuleListener = RuleListener> {
|
369 | |
370 |
|
371 |
|
372 | meta: RuleMetaData<TMessageIds>;
|
373 | |
374 |
|
375 |
|
376 |
|
377 | create(context: Readonly<RuleContext<TMessageIds, TOptions>>): TRuleListener;
|
378 | }
|
379 | declare type RuleCreateFunction<TMessageIds extends string = never, TOptions extends readonly unknown[] = unknown[], TRuleListener extends RuleListener = RuleListener> = (context: Readonly<RuleContext<TMessageIds, TOptions>>) => TRuleListener;
|
380 | export { ReportDescriptor, ReportFixFunction, ReportSuggestionArray, RuleContext, RuleCreateFunction, RuleFix, RuleFixer, RuleFunction, RuleListener, RuleMetaData, RuleMetaDataDocs, RuleModule, SharedConfigurationSettings, };
|
381 |
|
\ | No newline at end of file |