tools: lint js in `doc/**/*.md`

PR-URL: https://github.com/nodejs/node/pull/55904
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
Livia Medeiros 2024-11-20 19:10:38 +09:00 committed by Antoine du Hamel
parent f711a48e15
commit d093820f64
No known key found for this signature in database
GPG Key ID: 21D900FFDB233756
19 changed files with 31 additions and 34 deletions

View File

@ -61,7 +61,7 @@ Errors that occur within _Asynchronous APIs_ may be reported in multiple ways:
<!-- eslint-disable no-useless-return -->
```js
const fs = require('fs/promises');
const fs = require('node:fs/promises');
(async () => {
let data;

View File

@ -509,7 +509,7 @@ module default import or its corresponding sugar syntax:
```js
import { default as cjs } from 'cjs';
// identical to the above
// Identical to the above
import cjsSugar from 'cjs';
console.log(cjs);

View File

@ -505,7 +505,7 @@ inspector.Network.requestWillBeSent({
request: {
url: 'https://nodejs.org/en',
method: 'GET',
}
},
});
```

View File

@ -890,7 +890,7 @@ built-in modules and if a name matching a built-in module is added to the cache,
only `node:`-prefixed require calls are going to receive the built-in module.
Use with care!
<!-- eslint-disable node-core/no-duplicate-requires -->
<!-- eslint-disable node-core/no-duplicate-requires, no-restricted-syntax -->
```js
const assert = require('node:assert');

View File

@ -28,7 +28,7 @@ performance.measure('Start to Now');
performance.mark('A');
(async function doSomeLongRunningProcess() {
await new Promise(r => setTimeout(r, 5000));
await new Promise((r) => setTimeout(r, 5000));
performance.measure('A to Now', 'A');
performance.mark('B');

View File

@ -2107,10 +2107,10 @@ class Test {
constructor() {
finalization.register(this, (ref) => ref.dispose());
// even something like this is highly discouraged
// Even something like this is highly discouraged
// finalization.register(this, () => this.dispose());
}
dispose() {}
}
dispose() {}
}
```

View File

@ -21,7 +21,7 @@ The `punycode` module is a bundled version of the [Punycode.js][] module. It
can be accessed using:
```js
const punycode = require('punycode');
const punycode = require('node:punycode');
```
[Punycode][] is a character encoding scheme defined by RFC 3492 that is

View File

@ -315,7 +315,7 @@ events (due to incorrect stream implementations) do not cause unexpected
crashes. If this is unwanted behavior then `options.cleanup` should be set to
`true`:
```js
```mjs
await finished(rs, { cleanup: true });
```
@ -3926,7 +3926,7 @@ const { StringDecoder } = require('node:string_decoder');
class StringWritable extends Writable {
constructor(options) {
super(options);
this._decoder = new StringDecoder(options && options.defaultEncoding);
this._decoder = new StringDecoder(options?.defaultEncoding);
this.data = '';
}
_write(chunk, encoding, callback) {

View File

@ -3281,7 +3281,7 @@ test('snapshot test with default serialization', (t) => {
test('snapshot test with custom serialization', (t) => {
t.assert.snapshot({ value3: 3, value4: 4 }, {
serializers: [(value) => JSON.stringify(value)]
serializers: [(value) => JSON.stringify(value)],
});
});
```

View File

@ -465,13 +465,13 @@ to set the security level to 0 while using the default OpenSSL cipher list, you
const tls = require('node:tls');
const port = 443;
tls.createServer({ciphers: 'DEFAULT@SECLEVEL=0', minVersion: 'TLSv1'}, function (socket) {
tls.createServer({ ciphers: 'DEFAULT@SECLEVEL=0', minVersion: 'TLSv1' }, function(socket) {
console.log('Client connected with protocol:', socket.getProtocol());
socket.end();
this.close();
}).
listen(port, () => {
tls.connect(port, {ciphers: 'DEFAULT@SECLEVEL=0', maxVersion: 'TLSv1'});
})
.listen(port, () => {
tls.connect(port, { ciphers: 'DEFAULT@SECLEVEL=0', maxVersion: 'TLSv1' });
});
```

View File

@ -245,7 +245,7 @@ console.log(trace_events.getEnabledCategories());
```js
'use strict';
const { Session } = require('inspector');
const { Session } = require('node:inspector');
const session = new Session();
session.connect();

View File

@ -513,7 +513,7 @@ The mapping between error codes and string messages is platform-dependent.
```js
fs.access('file/that/does/not/exist', (err) => {
const name = util.getSystemErrorMessage(err.errno);
console.error(name); // no such file or directory
console.error(name); // No such file or directory
});
```

View File

@ -1296,7 +1296,7 @@ is as follows.
Here's an example.
```js
const { GCProfiler } = require('v8');
const { GCProfiler } = require('node:v8');
const profiler = new GCProfiler();
profiler.start();
setTimeout(() => {

View File

@ -1622,12 +1622,12 @@ in the outer context.
const vm = require('node:vm');
// An undefined `contextObject` option makes the global object contextified.
let context = vm.createContext();
const context = vm.createContext();
console.log(vm.runInContext('globalThis', context) === context); // false
// A contextified global object cannot be frozen.
try {
vm.runInContext('Object.freeze(globalThis);', context);
} catch(e) {
} catch (e) {
console.log(e); // TypeError: Cannot freeze
}
console.log(vm.runInContext('globalThis.foo = 1; foo;', context)); // 1
@ -1652,7 +1652,7 @@ const context = vm.createContext(vm.constants.DONT_CONTEXTIFY);
vm.runInContext('Object.freeze(globalThis);', context);
try {
vm.runInContext('bar = 1; bar;', context);
} catch(e) {
} catch (e) {
console.log(e); // Uncaught ReferenceError: bar is not defined
}
```
@ -1681,7 +1681,7 @@ console.log(vm.runInContext('bar;', context)); // 1
Object.freeze(context);
try {
vm.runInContext('baz = 1; baz;', context);
} catch(e) {
} catch (e) {
console.log(e); // Uncaught ReferenceError: baz is not defined
}
```

View File

@ -218,7 +218,7 @@ markAsUncloneable(anyObject);
const { port1 } = new MessageChannel();
try {
// This will throw an error, because anyObject is not cloneable.
port1.postMessage(anyObject)
port1.postMessage(anyObject);
} catch (error) {
// error.name === 'DataCloneError'
}
@ -908,6 +908,8 @@ not preserved. In particular, [`Buffer`][] objects will be read as
plain [`Uint8Array`][]s on the receiving side, and instances of JavaScript
classes will be cloned as plain JavaScript objects.
<!-- eslint-disable no-unused-private-class-members -->
```js
const b = Symbol('b');

View File

@ -190,10 +190,7 @@ http.createServer((request, response) => {
const raw = fs.createReadStream('index.html');
// Store both a compressed and an uncompressed version of the resource.
response.setHeader('Vary', 'Accept-Encoding');
let acceptEncoding = request.headers['accept-encoding'];
if (!acceptEncoding) {
acceptEncoding = '';
}
const acceptEncoding = request.headers['accept-encoding'] || '';
const onError = (err) => {
if (err) {

View File

@ -246,11 +246,11 @@ will now correctly change as the underlying `ArrayBuffer` size is changed.
```js
const ab = new ArrayBuffer(10, { maxByteLength: 20 });
const buffer = Buffer.from(ab);
console.log(buffer.byteLength); 10
console.log(buffer.byteLength); // 10
ab.resize(15);
console.log(buffer.byteLength); 15
console.log(buffer.byteLength); // 15
ab.resize(5);
console.log(buffer.byteLength); 5
console.log(buffer.byteLength); // 5
```
Contributed by James M Snell in [#55377](https://github.com/nodejs/node/pull/55377).

View File

@ -538,7 +538,7 @@ The arguments of `createBenchmark` are:
source: ['buffer', 'string'],
len: [2048],
n: [50, 2048],
}
},
}, { byGroups: true });
```

View File

@ -43,9 +43,7 @@ export default [
'**/node_modules/**',
'benchmark/fixtures/**',
'benchmark/tmp/**',
'doc/**/*.js',
'doc/changelogs/CHANGELOG_V1*.md',
'!doc/api_assets/*.js',
'!doc/changelogs/CHANGELOG_V18.md',
'lib/punycode.js',
'test/.tmp.*/**',