Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc,tools: enforce use of node: prefix #53950

Merged
merged 1 commit into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading