diff --git a/doc/api/errors.md b/doc/api/errors.md index 7d076312a726d9..df087ab23bdb9b 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -61,7 +61,7 @@ Errors that occur within _Asynchronous APIs_ may be reported in multiple ways: ```js - const fs = require('fs/promises'); + const fs = require('node:fs/promises'); (async () => { let data; diff --git a/doc/api/esm.md b/doc/api/esm.md index 64d2e537ecd9d8..8a80e0b1fe7202 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -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); diff --git a/doc/api/inspector.md b/doc/api/inspector.md index 64db50b8fc1da4..2892779403d256 100644 --- a/doc/api/inspector.md +++ b/doc/api/inspector.md @@ -505,7 +505,7 @@ inspector.Network.requestWillBeSent({ request: { url: 'https://nodejs.org/en', method: 'GET', - } + }, }); ``` diff --git a/doc/api/modules.md b/doc/api/modules.md index 6d62b85bd2f12f..720a47205edb2a 100644 --- a/doc/api/modules.md +++ b/doc/api/modules.md @@ -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! - + ```js const assert = require('node:assert'); diff --git a/doc/api/perf_hooks.md b/doc/api/perf_hooks.md index 7c3144939244b6..fe345287198297 100644 --- a/doc/api/perf_hooks.md +++ b/doc/api/perf_hooks.md @@ -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'); diff --git a/doc/api/process.md b/doc/api/process.md index 1a2638b8752f75..01083c74c95089 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -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() {} } ``` diff --git a/doc/api/punycode.md b/doc/api/punycode.md index 6aa01a8348797b..f2e9bc09fbbb00 100644 --- a/doc/api/punycode.md +++ b/doc/api/punycode.md @@ -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 diff --git a/doc/api/stream.md b/doc/api/stream.md index 8dc5173500e623..f890f4fd529b01 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -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) { diff --git a/doc/api/test.md b/doc/api/test.md index d01e04dbaf6505..2ca8c0e6877124 100644 --- a/doc/api/test.md +++ b/doc/api/test.md @@ -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)], }); }); ``` diff --git a/doc/api/tls.md b/doc/api/tls.md index f19a75370b1cf5..3436ba6697950f 100644 --- a/doc/api/tls.md +++ b/doc/api/tls.md @@ -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' }); }); ``` diff --git a/doc/api/tracing.md b/doc/api/tracing.md index e1a72a708863a5..ddd1bae52a62c4 100644 --- a/doc/api/tracing.md +++ b/doc/api/tracing.md @@ -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(); diff --git a/doc/api/util.md b/doc/api/util.md index dc8e3c38ddfca6..cf193528368188 100644 --- a/doc/api/util.md +++ b/doc/api/util.md @@ -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 }); ``` diff --git a/doc/api/v8.md b/doc/api/v8.md index 4df6e98a48fe78..670283e17f5d80 100644 --- a/doc/api/v8.md +++ b/doc/api/v8.md @@ -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(() => { diff --git a/doc/api/vm.md b/doc/api/vm.md index 01317b5843ad34..a5dd038070a498 100644 --- a/doc/api/vm.md +++ b/doc/api/vm.md @@ -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 } ``` diff --git a/doc/api/worker_threads.md b/doc/api/worker_threads.md index f1b5c5b652f4f1..afecd991da9dd3 100644 --- a/doc/api/worker_threads.md +++ b/doc/api/worker_threads.md @@ -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. + + ```js const b = Symbol('b'); diff --git a/doc/api/zlib.md b/doc/api/zlib.md index 36977eae86af6f..c79c19b697e066 100644 --- a/doc/api/zlib.md +++ b/doc/api/zlib.md @@ -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) { diff --git a/doc/changelogs/CHANGELOG_V23.md b/doc/changelogs/CHANGELOG_V23.md index 47b30d19b91bae..b18ffc81ff8ea6 100644 --- a/doc/changelogs/CHANGELOG_V23.md +++ b/doc/changelogs/CHANGELOG_V23.md @@ -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). diff --git a/doc/contributing/writing-and-running-benchmarks.md b/doc/contributing/writing-and-running-benchmarks.md index 3d16c7d14fc033..63fbf75c798833 100644 --- a/doc/contributing/writing-and-running-benchmarks.md +++ b/doc/contributing/writing-and-running-benchmarks.md @@ -538,7 +538,7 @@ The arguments of `createBenchmark` are: source: ['buffer', 'string'], len: [2048], n: [50, 2048], - } + }, }, { byGroups: true }); ``` diff --git a/eslint.config.mjs b/eslint.config.mjs index f37774bace871d..8e574a312d4a3e 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -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.*/**',