doc,tools: enforce use of node: prefix

PR-URL: https://github.com/nodejs/node/pull/53950
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
This commit is contained in:
Antoine du Hamel 2024-07-21 17:44:27 +02:00 committed by GitHub
parent befbe69a0d
commit bc677d1937
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 23 additions and 9 deletions

View file

@ -704,7 +704,7 @@ import {
executionAsyncId,
executionAsyncResource,
createHook,
} from 'async_hooks';
} from 'node:async_hooks';
const sym = Symbol('state'); // Private symbol to avoid pollution
createHook({

View file

@ -378,7 +378,7 @@ import {
setTimeout,
setImmediate,
setInterval,
} from 'timers/promises';
} from 'node:timers/promises';
```
```cjs
@ -408,7 +408,7 @@ added: v15.0.0
```mjs
import {
setTimeout,
} from 'timers/promises';
} from 'node:timers/promises';
const res = await setTimeout(100, 'result');
@ -442,7 +442,7 @@ added: v15.0.0
```mjs
import {
setImmediate,
} from 'timers/promises';
} from 'node:timers/promises';
const res = await setImmediate('result');
@ -483,7 +483,7 @@ or implicitly to keep the event loop alive.
```mjs
import {
setInterval,
} from 'timers/promises';
} from 'node:timers/promises';
const interval = 100;
for await (const startTime of setInterval(interval, Date.now())) {

View file

@ -17,7 +17,7 @@ operating system via a collection of POSIX-like functions.
```mjs
import { readFile } from 'node:fs/promises';
import { WASI } from 'wasi';
import { WASI } from 'node:wasi';
import { argv, env } from 'node:process';
const wasi = new WASI({
@ -40,7 +40,7 @@ wasi.start(instance);
```cjs
'use strict';
const { readFile } = require('node:fs/promises');
const { WASI } = require('wasi');
const { WASI } = require('node:wasi');
const { argv, env } = require('node:process');
const { join } = require('node:path');

View file

@ -1455,7 +1455,7 @@ Node.js event loop.
import {
Worker,
isMainThread,
} from 'worker_threads';
} from 'node:worker_threads';
if (isMainThread) {
new Worker(new URL(import.meta.url));

View file

@ -1,4 +1,9 @@
import { requireEslintTool } from '../tools/eslint/eslint.config_utils.mjs';
import {
noRestrictedSyntaxCommonAll,
noRestrictedSyntaxCommonLib,
requireEslintTool,
} from '../tools/eslint/eslint.config_utils.mjs';
import { builtinModules as builtin } from 'node:module';
const globals = requireEslintTool('globals');
@ -8,6 +13,15 @@ export default [
rules: {
// Ease some restrictions in doc examples.
'no-restricted-properties': 'off',
'no-restricted-syntax': [
'error',
...noRestrictedSyntaxCommonAll,
...noRestrictedSyntaxCommonLib,
{
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(',')})`,
message: 'Use `node:` prefix.',
},
],
'no-undef': 'off',
'no-unused-expressions': 'off',
'no-unused-vars': 'off',