Files
NapCatQQ/.pnpm-store/v3/files/28/4151a4d0c46358eafc1cf96d8fc6e4f126549c1791f76f3d4815d3d63435b4386abdc51eb6e0c0359cb140ddca775de185ca41b5f156bf43ba3383e29c059a
TanTan e311ca3275
Build NapCat Artifacts / Windows Loader Test (push) Canceled after 0s
Build NapCat Artifacts / Type Check & Test (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Framework (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Shell (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

49 lines
1.4 KiB
Plaintext

# eslint-compat-utils
***This package is still in the experimental stage.***
Provides an API for ESLint custom rules that is compatible with the latest ESLint even when using older ESLint.
## Installation
```bash
npm install eslint-compat-utils
```
## Usage
```js
const { getSourceCode } = require("eslint-compat-utils");
module.exports = {
meta: { /* ... */ },
create(context) {
const sourceCode = getSourceCode(context)
return {
"Program"(node) {
const scope = sourceCode.getScope(node);
},
};
},
}
```
### API
#### `getSourceCode(context)`
Returns an extended instance of `context.sourceCode` or the result of `context.getSourceCode()`. Extended instances can use new APIs such as `getScope(node)` even with old ESLint.
#### `getCwd(context)`
Gets the value of `context.cwd`, but for older ESLint it returns the result of `context.getCwd()`.
Versions older than v6.6.0 return a value from the result of `process.cwd()`.
#### `getFilename(context)`
Gets the value of `context.filename`, but for older ESLint it returns the result of `context.getFilename()`.
#### `getPhysicalFilename(context)`
Gets the value of `context.physicalFilename`, but for older ESLint it returns the result of `context.getPhysicalFilename()`.
Versions older than v7.28.0 return a value guessed from the result of `context.getFilename()`, but it may be incorrect.