-
Notifications
You must be signed in to change notification settings - Fork 148
/
Copy pathcompat.ts
34 lines (30 loc) · 873 Bytes
/
compat.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
import type { TSESLint, TSESTree } from '@typescript-eslint/utils';
/* istanbul ignore next */
export const getFilename = (
context: TSESLint.RuleContext<string, unknown[]>
) => {
return context.filename ?? context.getFilename();
};
/* istanbul ignore next */
export const getSourceCode = (
context: TSESLint.RuleContext<string, unknown[]>
) => {
return context.sourceCode ?? context.getSourceCode();
};
/* istanbul ignore next */
export const getScope = (
context: TSESLint.RuleContext<string, unknown[]>,
node: TSESTree.Node
) => {
return getSourceCode(context).getScope?.(node) ?? context.getScope();
};
/* istanbul ignore next */
export const getDeclaredVariables = (
context: TSESLint.RuleContext<string, unknown[]>,
node: TSESTree.Node
) => {
return (
getSourceCode(context).getDeclaredVariables?.(node) ??
context.getDeclaredVariables(node)
);
};