Skip to content

Latest commit

 

History

History
65 lines (44 loc) · 1.23 KB

prefer-node-protocol.md

File metadata and controls

65 lines (44 loc) · 1.23 KB

Prefer using the node: protocol when importing Node.js builtin modules

When importing builtin modules, it's better to use the node: protocol as it makes it perfectly clear that the package is a Node.js builtin module.

And don't forget to upvote this issue if you agree.

This rule is fixable.

Fail

import dgram from 'dgram';
export {strict as default} from 'assert';
import fs from 'fs/promises';

Pass

import dgram from 'node:dgram';
export {strict as default} from 'node:assert';
import fs from 'node:fs/promises';
const fs = require('fs');
import _ from 'lodash';
import fs from './fs.js';

Options

Type: object

checkRequire

Type: boolean
Default: false

Currently, require(…) with the node: protocol is only available on Node.js 16. If you don't care about old versions, you can set this to true.

We'll remove this option and check require(…) by default once this feature get backported to v12.

// eslint unicorn/prefer-node-protocol: ["error", {"checkRequire": true}]
const fs = require('fs'); // Fails