From 94105c092f2a6ca3e0a6ae3789f60badc9f63d31 Mon Sep 17 00:00:00 2001 From: Livia Medeiros Date: Wed, 20 Nov 2024 19:10:38 +0900 Subject: [PATCH] tools: lint js in `doc/**/*.md` PR-URL: https://github.com/nodejs/node/pull/55904 Reviewed-By: Colin Ihrig Reviewed-By: Matteo Collina Reviewed-By: Yagiz Nizipli Reviewed-By: Luigi Pinca Reviewed-By: Chemi Atlow Reviewed-By: Antoine du Hamel --- doc/api/errors.md | 2 +- doc/api/inspector.md | 2 +- doc/api/modules.md | 2 +- doc/api/perf_hooks.md | 2 +- doc/api/process.md | 6 +++--- doc/api/punycode.md | 2 +- doc/api/stream.md | 4 ++-- doc/api/test.md | 2 +- doc/api/tls.md | 8 ++++---- doc/api/tracing.md | 2 +- doc/api/util.md | 2 +- doc/api/v8.md | 2 +- doc/api/vm.md | 8 ++++---- doc/api/worker_threads.md | 4 +++- doc/api/zlib.md | 5 +---- doc/contributing/writing-and-running-benchmarks.md | 2 +- eslint.config.mjs | 2 -- 17 files changed, 27 insertions(+), 30 deletions(-) diff --git a/doc/api/errors.md b/doc/api/errors.md index 5db362cf4d86f5..eee56bf9a84933 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/inspector.md b/doc/api/inspector.md index 2d8bf185de0971..4a3e61d5be6c00 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 0f12bc66c03075..543fe02c57dd6b 100644 --- a/doc/api/modules.md +++ b/doc/api/modules.md @@ -889,7 +889,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 229b8eb13831c4..4495d23ce12a63 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 4b5953fba1d1bf..355209cd92f0f7 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -2099,10 +2099,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 fbd9d3c93cb7ab..02049a262b7282 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 }); ``` @@ -3916,7 +3916,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 d8278604305005..a3c09cac379c0b 100644 --- a/doc/api/test.md +++ b/doc/api/test.md @@ -3256,7 +3256,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 0ac0b7e740e5c7..42a664d6cbe213 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 d46092a815774d..38265c040b40b2 100644 --- a/doc/api/util.md +++ b/doc/api/util.md @@ -483,7 +483,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 e7164c43364246..ed2a030b5fd015 100644 --- a/doc/api/v8.md +++ b/doc/api/v8.md @@ -1294,7 +1294,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 f8575e3815403a..06200e475fcd2e 100644 --- a/doc/api/vm.md +++ b/doc/api/vm.md @@ -1618,12 +1618,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 @@ -1648,7 +1648,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 } ``` @@ -1677,7 +1677,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 edba8c15c409d7..36a088027edc5f 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 f82fd626ab89e1..8919ad5fd267ba 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/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.*/**',