Files
NapCatQQ/.pnpm-store/v3/files/d3/b2e2c78e5d8818d2cf6efb3dbd2629a87fab6360cc53f12a8000a2c6bfb1acad0968346c6fe3db7f45a8e5601c9c06b7e36b19fcdc95280f0ea2873b21e853
TanTan e311ca3275
Build NapCat Artifacts / Type Check & Test (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

82 lines
2.1 KiB
Plaintext

# import/enforce-node-protocol-usage
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
<!-- end auto-generated rule header -->
Enforce either using, or omitting, the `node:` protocol when importing Node.js builtin modules.
## Rule Details
This rule enforces that builtins node imports are using, or omitting, the `node:` protocol.
Determining whether a specifier is a core module depends on the node version being used to run `eslint`.
This version can be specified in the configuration with the [`import/node-version` setting](../../README.md#importnode-version).
Reasons to prefer using the protocol include:
- the code is more explicitly and clearly referencing a Node.js built-in module
Reasons to prefer omitting the protocol include:
- some tools don't support the `node:` protocol
- the code is more portable, because import maps and automatic polyfilling can be used
## Options
The rule requires a single string option which may be one of:
- `'always'` - enforces that builtins node imports are using the `node:` protocol.
- `'never'` - enforces that builtins node imports are not using the `node:` protocol.
## Examples
### `'always'`
❌ Invalid
```js
import fs from 'fs';
export { promises } from 'fs';
// require
const fs = require('fs/promises');
```
✅ Valid
```js
import fs from 'node:fs';
export { promises } from 'node:fs';
import * as test from 'node:test';
// require
const fs = require('node:fs/promises');
```
### `'never'`
❌ Invalid
```js
import fs from 'node:fs';
export { promises } from 'node:fs';
// require
const fs = require('node:fs/promises');
```
✅ Valid
```js
import fs from 'fs';
export { promises } from 'fs';
// require
const fs = require('fs/promises');
// This rule will not enforce not using `node:` protocol when the module is only available under the `node:` protocol.
import * as test from 'node:test';
```
## When Not To Use It
If you don't want to consistently enforce using, or omitting, the `node:` protocol when importing Node.js builtin modules.