Skip to content

Commit 44a08f7

Browse files
aduh95RafaelGSS
authored andcommitted
doc,tools: enforce use of node: prefix
PR-URL: #53950 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
1 parent defdc3c commit 44a08f7

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
lines changed

‎doc/api/async_hooks.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ import{
704704
executionAsyncId,
705705
executionAsyncResource,
706706
createHook,
707-
} from'async_hooks';
707+
} from'node:async_hooks';
708708
constsym=Symbol('state'); // Private symbol to avoid pollution
709709

710710
createHook({

‎doc/api/timers.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ import{
378378
setTimeout,
379379
setImmediate,
380380
setInterval,
381-
} from'timers/promises';
381+
} from'node:timers/promises';
382382
```
383383

384384
```cjs
@@ -408,7 +408,7 @@ added: v15.0.0
408408
```mjs
409409
import{
410410
setTimeout,
411-
} from'timers/promises';
411+
} from'node:timers/promises';
412412

413413
constres=awaitsetTimeout(100, 'result');
414414

@@ -442,7 +442,7 @@ added: v15.0.0
442442
```mjs
443443
import{
444444
setImmediate,
445-
} from'timers/promises';
445+
} from'node:timers/promises';
446446

447447
constres=awaitsetImmediate('result');
448448

@@ -483,7 +483,7 @@ or implicitly to keep the event loop alive.
483483
```mjs
484484
import{
485485
setInterval,
486-
} from'timers/promises';
486+
} from'node:timers/promises';
487487

488488
constinterval=100;
489489
forawait (conststartTimeofsetInterval(interval, Date.now())){

‎doc/api/wasi.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ operating system via a collection of POSIX-like functions.
1717

1818
```mjs
1919
import{readFile } from'node:fs/promises';
20-
import{WASI } from'wasi';
20+
import{WASI } from'node:wasi';
2121
import{argv, env } from'node:process';
2222

2323
constwasi=newWASI({
@@ -40,7 +40,7 @@ wasi.start(instance);
4040
```cjs
4141
'use strict';
4242
const{readFile } =require('node:fs/promises');
43-
const{WASI } =require('wasi');
43+
const{WASI } =require('node:wasi');
4444
const{argv, env } =require('node:process');
4545
const{join } =require('node:path');
4646

‎doc/api/worker_threads.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,7 @@ Node.js event loop.
14551455
import{
14561456
Worker,
14571457
isMainThread,
1458-
} from 'worker_threads';
1458+
} from 'node:worker_threads';
14591459
14601460
if (isMainThread){
14611461
new Worker(new URL(import.meta.url));

‎doc/eslint.config_partial.mjs‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import{requireEslintTool}from'../tools/eslint/eslint.config_utils.mjs';
1+
import{
2+
noRestrictedSyntaxCommonAll,
3+
noRestrictedSyntaxCommonLib,
4+
requireEslintTool,
5+
}from'../tools/eslint/eslint.config_utils.mjs';
6+
import{builtinModulesasbuiltin}from'node:module';
27

38
constglobals=requireEslintTool('globals');
49

@@ -8,6 +13,15 @@ export default [
813
rules: {
914
// Ease some restrictions in doc examples.
1015
'no-restricted-properties': 'off',
16+
'no-restricted-syntax': [
17+
'error',
18+
...noRestrictedSyntaxCommonAll,
19+
...noRestrictedSyntaxCommonLib,
20+
{
21+
selector: `CallExpression[callee.name="require"][arguments.0.type="Literal"]:matches(${builtin.map((name)=>`[arguments.0.value="${name}"]`).join(',')}),ImportDeclaration:matches(${builtin.map((name)=>`[source.value="${name}"]`).join(',')})`,
22+
message: 'Use `node:` prefix.',
23+
},
24+
],
1125
'no-undef': 'off',
1226
'no-unused-expressions': 'off',
1327
'no-unused-vars': 'off',

0 commit comments

Comments
(0)