Skip to content

Commit

Permalink
doc,tools: enforce use of node: prefix
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
aduh95 authored Jul 21, 2024
1 parent befbe69 commit bc677d1
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion doc/api/async_hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
8 changes: 4 additions & 4 deletions doc/api/timers.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ import {
setTimeout,
setImmediate,
setInterval,
} from 'timers/promises';
} from 'node:timers/promises';
```

```cjs
Expand Down Expand Up @@ -408,7 +408,7 @@ added: v15.0.0
```mjs
import {
setTimeout,
} from 'timers/promises';
} from 'node:timers/promises';

const res = await setTimeout(100, 'result');

Expand Down Expand Up @@ -442,7 +442,7 @@ added: v15.0.0
```mjs
import {
setImmediate,
} from 'timers/promises';
} from 'node:timers/promises';

const res = await setImmediate('result');

Expand Down Expand Up @@ -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())) {
Expand Down
4 changes: 2 additions & 2 deletions doc/api/wasi.md
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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');

Expand Down
2 changes: 1 addition & 1 deletion doc/api/worker_threads.md
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
16 changes: 15 additions & 1 deletion doc/eslint.config_partial.mjs
Original file line number Diff line number Diff line change
@@ -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');

Expand All @@ -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',
Expand Down

0 comments on commit bc677d1

Please sign in to comment.