|
1 | 1 | import { type TSESLint, type TSESTree } from '@typescript-eslint/utils';
|
2 | 2 |
|
3 | 3 | declare module '@typescript-eslint/utils/dist/ts-eslint/Rule' {
|
4 |
| - // eslint-disable-next-line @typescript-eslint/no-unused-vars |
5 |
| - export interface RuleContext<TMessageIds extends string, TOptions extends readonly unknown[]> { |
6 |
| - /** |
7 |
| - * The filename associated with the source. |
8 |
| - */ |
9 |
| - filename: string; |
| 4 | + // eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 5 | + export interface RuleContext< |
| 6 | + TMessageIds extends string, |
| 7 | + TOptions extends readonly unknown[] |
| 8 | + > { |
| 9 | + /** |
| 10 | + * The filename associated with the source. |
| 11 | + */ |
| 12 | + filename: string; |
10 | 13 |
|
11 |
| - /** |
12 |
| - * A SourceCode object that you can use to work with the source that |
13 |
| - * was passed to ESLint. |
14 |
| - */ |
15 |
| - sourceCode: Readonly<TSESLint.SourceCode>; |
16 |
| - } |
| 14 | + /** |
| 15 | + * A SourceCode object that you can use to work with the source that |
| 16 | + * was passed to ESLint. |
| 17 | + */ |
| 18 | + sourceCode: Readonly<TSESLint.SourceCode>; |
| 19 | + } |
17 | 20 | }
|
18 | 21 |
|
19 | 22 | declare module '@typescript-eslint/utils/dist/ts-eslint/SourceCode' {
|
20 |
| - export interface SourceCode { |
21 |
| - /** |
22 |
| - * Returns the scope of the given node. |
23 |
| - * This information can be used track references to variables. |
24 |
| - * @since 8.37.0 |
25 |
| - */ |
26 |
| - getScope(node: TSESTree.Node): TSESLint.Scope.Scope; |
27 |
| - /** |
28 |
| - * Returns an array of the ancestors of the given node, starting at |
29 |
| - * the root of the AST and continuing through the direct parent of the current node. |
30 |
| - * This array does not include the currently-traversed node itself. |
31 |
| - * @since 8.38.0 |
32 |
| - */ |
33 |
| - getAncestors(node: TSESTree.Node): TSESTree.Node[]; |
34 |
| - /** |
35 |
| - * Returns a list of variables declared by the given node. |
36 |
| - * This information can be used to track references to variables. |
37 |
| - * @since 8.38.0 |
38 |
| - */ |
39 |
| - getDeclaredVariables( |
40 |
| - node: TSESTree.Node, |
41 |
| - ): readonly TSESLint.Scope.Variable[]; |
42 |
| - } |
| 23 | + export interface SourceCode { |
| 24 | + /** |
| 25 | + * Returns the scope of the given node. |
| 26 | + * This information can be used track references to variables. |
| 27 | + * @since 8.37.0 |
| 28 | + */ |
| 29 | + getScope(node: TSESTree.Node): TSESLint.Scope.Scope; |
| 30 | + /** |
| 31 | + * Returns an array of the ancestors of the given node, starting at |
| 32 | + * the root of the AST and continuing through the direct parent of the current node. |
| 33 | + * This array does not include the currently-traversed node itself. |
| 34 | + * @since 8.38.0 |
| 35 | + */ |
| 36 | + getAncestors(node: TSESTree.Node): TSESTree.Node[]; |
| 37 | + /** |
| 38 | + * Returns a list of variables declared by the given node. |
| 39 | + * This information can be used to track references to variables. |
| 40 | + * @since 8.38.0 |
| 41 | + */ |
| 42 | + getDeclaredVariables( |
| 43 | + node: TSESTree.Node |
| 44 | + ): readonly TSESLint.Scope.Variable[]; |
| 45 | + } |
43 | 46 | }
|
44 | 47 |
|
45 | 48 | /* istanbul ignore next */
|
46 | 49 | export const getFilename = (
|
47 |
| - context: TSESLint.RuleContext<string, unknown[]>, |
| 50 | + context: TSESLint.RuleContext<string, unknown[]> |
48 | 51 | ) => {
|
49 |
| - return context.filename ?? context.getFilename(); |
| 52 | + return context.filename ?? context.getFilename(); |
50 | 53 | };
|
51 | 54 |
|
52 | 55 | /* istanbul ignore next */
|
53 | 56 | export const getSourceCode = (
|
54 |
| - context: TSESLint.RuleContext<string, unknown[]>, |
| 57 | + context: TSESLint.RuleContext<string, unknown[]> |
55 | 58 | ) => {
|
56 |
| - return context.sourceCode ?? context.getSourceCode(); |
| 59 | + return context.sourceCode ?? context.getSourceCode(); |
57 | 60 | };
|
58 | 61 |
|
59 | 62 | /* istanbul ignore next */
|
60 | 63 | export const getScope = (
|
61 |
| - context: TSESLint.RuleContext<string, unknown[]>, |
62 |
| - node: TSESTree.Node, |
| 64 | + context: TSESLint.RuleContext<string, unknown[]>, |
| 65 | + node: TSESTree.Node |
63 | 66 | ) => {
|
64 |
| - return getSourceCode(context).getScope?.(node) ?? context.getScope(); |
| 67 | + return getSourceCode(context).getScope?.(node) ?? context.getScope(); |
65 | 68 | };
|
66 | 69 |
|
67 | 70 | /* istanbul ignore next */
|
68 | 71 | export const getDeclaredVariables = (
|
69 |
| - context: TSESLint.RuleContext<string, unknown[]>, |
70 |
| - node: TSESTree.Node, |
| 72 | + context: TSESLint.RuleContext<string, unknown[]>, |
| 73 | + node: TSESTree.Node |
71 | 74 | ) => {
|
72 |
| - return ( |
73 |
| - getSourceCode(context).getDeclaredVariables?.(node) ?? |
74 |
| - context.getDeclaredVariables(node) |
75 |
| - ); |
| 75 | + return ( |
| 76 | + getSourceCode(context).getDeclaredVariables?.(node) ?? |
| 77 | + context.getDeclaredVariables(node) |
| 78 | + ); |
76 | 79 | };
|
0 commit comments