forked from mysticatea/eslint-plugin-node
-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy patheslint-compat.js
43 lines (36 loc) · 1.29 KB
/
eslint-compat.js
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
/**
* @fileoverview Utilities for eslint compatibility.
* @see https://eslint.org/docs/latest/use/migrate-to-9.0.0#removed-context-methods
* @author aladdin-add<[email protected]>
*/
"use strict"
/** @import { Rule } from 'eslint' */
/** @typedef {import('estree').Node} Node */
exports.getSourceCode = function (/** @type Rule.RuleContext */ context) {
return context.sourceCode || context.getSourceCode()
}
exports.getScope = function (
/** @type {Rule.RuleContext} */ context,
/** @type {Node} */ node
) {
const sourceCode = exports.getSourceCode(context)
return sourceCode.getScope?.(node || sourceCode.ast) || context.getScope()
}
exports.getAncestors = function (
/** @type {Rule.RuleContext} */ context,
/** @type {Node} */ node
) {
const sourceCode = exports.getSourceCode(context)
return sourceCode.getAncestors?.(node) || context.getAncestors()
}
exports.getCwd = function (/** @type {Rule.RuleContext} */ context) {
return context.cwd || context.getCwd()
}
exports.getPhysicalFilename = function (
/** @type {Rule.RuleContext} */ context
) {
return context.physicalFilename || context.getPhysicalFilename?.()
}
exports.getFilename = function (/** @type {Rule.RuleContext} */ context) {
return context.filename || context.getFilename?.()
}