source: frontend/node_modules/eslint-plugin-import/docs/rules/enforce-node-protocol-usage.md

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 2.1 KB
Line 
1# import/enforce-node-protocol-usage
2
3🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
4
5<!-- end auto-generated rule header -->
6
7Enforce either using, or omitting, the `node:` protocol when importing Node.js builtin modules.
8
9## Rule Details
10
11This rule enforces that builtins node imports are using, or omitting, the `node:` protocol.
12
13Determining whether a specifier is a core module depends on the node version being used to run `eslint`.
14This version can be specified in the configuration with the [`import/node-version` setting](../../README.md#importnode-version).
15
16Reasons to prefer using the protocol include:
17
18 - the code is more explicitly and clearly referencing a Node.js built-in module
19
20Reasons to prefer omitting the protocol include:
21
22 - some tools don't support the `node:` protocol
23 - the code is more portable, because import maps and automatic polyfilling can be used
24
25## Options
26
27The rule requires a single string option which may be one of:
28
29 - `'always'` - enforces that builtins node imports are using the `node:` protocol.
30 - `'never'` - enforces that builtins node imports are not using the `node:` protocol.
31
32## Examples
33
34### `'always'`
35
36❌ Invalid
37
38```js
39import fs from 'fs';
40export { promises } from 'fs';
41// require
42const fs = require('fs/promises');
43```
44
45✅ Valid
46
47```js
48import fs from 'node:fs';
49export { promises } from 'node:fs';
50import * as test from 'node:test';
51// require
52const fs = require('node:fs/promises');
53```
54
55### `'never'`
56
57❌ Invalid
58
59```js
60import fs from 'node:fs';
61export { promises } from 'node:fs';
62// require
63const fs = require('node:fs/promises');
64```
65
66✅ Valid
67
68```js
69import fs from 'fs';
70export { promises } from 'fs';
71
72// require
73const fs = require('fs/promises');
74
75// This rule will not enforce not using `node:` protocol when the module is only available under the `node:` protocol.
76import * as test from 'node:test';
77```
78
79## When Not To Use It
80
81If you don't want to consistently enforce using, or omitting, the `node:` protocol when importing Node.js builtin modules.
Note: See TracBrowser for help on using the repository browser.